<commit_before>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Monster {
    public abstract class AbstractEnemy : MonoBehaviour {

        protected int health;

        protected float movementSpeed;

        protected int damageAmount;

        protected int dammageOnCollision;

        protected SpriteRenderer spriteRenderer;

        public Sprite[] facingSprites;

        public int direction;

        public float movementTimer;


        public float movementTimerLeft;

        // Use this for initialization
        virtual protected void Start () {
            this.spriteRenderer = GetComponent<SpriteRenderer>();
            this.health = 1;
            this.movementSpeed = 1f;
            this.damageAmount = 1;
            this.movementTimerLeft = 0;
            this.movementTimer = 1.5f;
            this.direction = Random.Range(0, 3);
            this.dammageOnCollision = 1;
        }
        
        // Update is called once per frame
        virtual protected void Update () {
            
            this.movementTimerLeft -= Time.deltaTime;
            if (movementTimerLeft <= 0) {
                this.direction = Random.Range(0, 3);
                this.movementTimerLeft = this.movementTimer;

                // Use facing sprite for simple enemies
                // (Used to learn Sprite system without animation)
                if (this.facingSprites.Length > 0 && this.facingSprites.Length == 4) {
                    this.spriteRenderer.sprite = this.facingSprites[this.direction];
                }
            }
            
            this.handleMovement();
        }

        protected void handleMovement()
        {
            if (this.direction == (int)Enums.Direction.North) {
                transform.Translate(0, this.movementSpeed * Time.deltaTime, 0);
            } else if (this.direction == (int)Enums.Direction.South) {
                transform.Translate(0, -this.movementSpeed * Time.deltaTime, 0);
            } else if (this.direction == (int)Enums.Direction.West) {
                transform.Translate(-this.movementSpeed * Time.deltaTime, 0, 0);
            } else if (this.direction == (int)Enums.Direction.East) {
                transform.Translate(this.movementSpeed * Time.deltaTime, 0, 0);
            }
        }

        /// <summary>
        /// Sent when another object enters a trigger collider attached to this
        /// object (2D physics only).
        /// </summary>
        /// <param name="other">The other Collider2D involved in this collision.</param>
        void OnTriggerEnter2D(Collider2D other)
        {
            if (other.gameObject.tag == "sword") {

                Weapon weapon = other.gameObject.GetComponent<Weapon>();
                
                this.health -= weapon.getDamage();

                if (this.health <= 0) {
                    this.deathAnimation();
                    Destroy(gameObject);
                }

                GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerAttack>().releaseAllAction();
                weapon.destroyWeapon();
            }
        }

        abstract public void deathAnimation();
    }
}<commit_msg>Decrease player life when having collision with enemy<commit_after>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Monster {
    public abstract class AbstractEnemy : MonoBehaviour {

        protected int health;

        protected float movementSpeed;

        protected int damageAmount;

        protected int dammageOnCollision;

        protected SpriteRenderer spriteRenderer;

        public Sprite[] facingSprites;

        public int direction;

        public float movementTimer;


        public float movementTimerLeft;

        // Use this for initialization
        virtual protected void Start () {
            this.spriteRenderer = GetComponent<SpriteRenderer>();
            this.health = 1;
            this.movementSpeed = 1f;
            this.damageAmount = 1;
            this.movementTimerLeft = 0;
            this.movementTimer = 1.5f;
            this.direction = Random.Range(0, 3);
            this.dammageOnCollision = 1;
        }
        
        // Update is called once per frame
        virtual protected void Update () {
            
            this.movementTimerLeft -= Time.deltaTime;
            if (movementTimerLeft <= 0) {
                this.direction = Random.Range(0, 3);
                this.movementTimerLeft = this.movementTimer;

                // Use facing sprite for simple enemies
                // (Used to learn Sprite system without animation)
                if (this.facingSprites.Length > 0 && this.facingSprites.Length == 4) {
                    this.spriteRenderer.sprite = this.facingSprites[this.direction];
                }
            }
            
            this.handleMovement();
        }

        protected void handleMovement()
        {
            if (this.direction == (int)Enums.Direction.North) {
                transform.Translate(0, this.movementSpeed * Time.deltaTime, 0);
            } else if (this.direction == (int)Enums.Direction.South) {
                transform.Translate(0, -this.movementSpeed * Time.deltaTime, 0);
            } else if (this.direction == (int)Enums.Direction.West) {
                transform.Translate(-this.movementSpeed * Time.deltaTime, 0, 0);
            } else if (this.direction == (int)Enums.Direction.East) {
                transform.Translate(this.movementSpeed * Time.deltaTime, 0, 0);
            }
        }

        /// <summary>
        /// Sent when another object enters a trigger collider attached to this
        /// object (2D physics only).
        /// </summary>
        /// <param name="other">The other Collider2D involved in this collision.</param>
        void OnTriggerEnter2D(Collider2D other)
        {
            if (other.gameObject.tag == "sword") {

                Weapon weapon = other.gameObject.GetComponent<Weapon>();
                
                this.health -= weapon.getDamage();

                if (this.health <= 0) {
                    this.deathAnimation();
                    Destroy(gameObject);
                }

                GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerAttack>().releaseAllAction();
                weapon.destroyWeapon();
            }
        }

        /// <summary>
        /// Sent when an incoming collider makes contact with this object's
        /// collider (2D physics only).
        /// </summary>
        /// <param name="other">The Collision2D data associated with this collision.</param>
        void OnCollisionEnter2D(Collision2D other)
        {
            switch(other.gameObject.tag) {
                case "Player":
                    this.handlePlayerCollision(other.gameObject.GetComponent<Player>());
                break;
            }
        }

        void OnCollisionStay2D(Collision2D other)
        {
            switch(other.gameObject.tag) {
                case "Player":
                    this.handlePlayerCollision(other.gameObject.GetComponent<Player>());
                break;
            }
        }

        private void handlePlayerCollision(Player player) 
        {
            player.decreaseLife(this.damageAmount);
        }

        abstract public void deathAnimation();
    }
}
{'fraction_non_alphanumeric': 0.09485204702067289, 'fraction_numerical': 0.008107012565869477, 'mean_word_length': 1.6867513611615246, 'pattern_counts': {'":': 2, '<': 27, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4318028', 'n_tokens_mistral': 1958, 'n_tokens_neox': 1804, 'n_words': 426}