-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy.cs
100 lines (89 loc) · 2.29 KB
/
Enemy.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
namespace Slip
{
public abstract class Enemy
{
public Vector2 position;
public Vector2? defaultPosition = null;
public float size;
public bool boss;
public int life = 1;
public bool invincible = false;
public int hurtCool = 0;
public bool temporary = false;
public delegate void DeathAction(Enemy enemy, Room room, Player player);
public event DeathAction OnDeath;
public float radius
{
get
{
return size / 2f;
}
}
public bool IsHurt
{
get
{
return hurtCool > 0;
}
}
public bool CanBeHit
{
get
{
return !invincible && !IsHurt;
}
}
public Enemy(Vector2 pos, float size)
{
this.position = pos;
this.size = size;
}
public void UpdateEnemy(Room room, Player player)
{
if (hurtCool > 0)
{
hurtCool--;
}
Update(room, player);
}
public abstract void Update(Room room, Player player);
public abstract void Draw(GameScreen screen, Main main);
public bool Collides(Player player)
{
return Vector2.Distance(position, player.position) < radius + player.radius;
}
public bool TakeDamage(int damage, Room room, Player player)
{
if (CanBeHit)
{
life -= damage;
if (life <= 0)
{
Kill(room, player);
return true;
}
if (boss)
{
hurtCool = 180;
room.bullets.Clear();
}
else
{
hurtCool = 60;
}
}
return false;
}
public void Kill(Room room, Player player)
{
if (OnDeath != null)
{
OnDeath(this, room, player);
}
room.enemies.Remove(this);
}
}
}