-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemy.cs
82 lines (76 loc) · 2.5 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
namespace ActionGame
{
class enemy:GraphicalGameObject
{
//testc
World world;
progressBar bar;
public bool isExplosion = false;
public int HP=1;
public enemy(Game1 game, World world, Point point,int HP) : base(game, game.assets.enemy)
{
this.world = world;
this.HP = HP;
setLocation(point.X, point.Y);
setSize(100,100);
velocityY = 0.3f;
addAnimator(2);
bar = new progressBar(game, new Rectangle((int)X, (int)Y, 100, 20), game.assets.black, game.assets.barBack, game.assets.bar);
bar.MaxValue = HP;
bar.Value = HP;
bar.animationSpeed = 2f;
bar.addAnimator(1);
bar.showSplit = true;
}
public override void update(float delta)
{
X += velocityX * delta;
Y += velocityY * delta;
if (Y > 800) world.Renemys.Add(this);
bar.X = X;
bar.Y = Y-50;
bar.update(delta);
base.update(delta);
}
public override void Draw(SpriteBatch batch, float screenAlpha)
{
bar.Draw(batch, 1);
base.Draw(batch, screenAlpha);
}
public void hit()
{
if (HP != 1) {
HP--;
bar.setValue(HP);
animator[0].setLimit(1f);
animator[0].start(GameObjectAnimator.FLASH, new float[] { 0.05f, 0.05f, 0.05f, 0.05f, -1 });
}
else
{
world.screen.score += 10;
HP = 0;
bar.setValue(HP);
bar.animator[0].start(GameObjectAnimator.fadeInOut, new float[] { 1, 1 });
game.assets.bombSound.Play();
velocityY = 0.1f;
isExplosion = true;
animator[1].FinishAnimation += new EventHandler(this.die);
animator[1].start(GameObjectAnimator.EXPLOSION, new float[] { });
}
}
public void die(Object sender, EventArgs e)
{
//System.Windows.Forms.MessageBox.Show("die");
world.Renemys.Add(this);
}
}
}