-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnemyLayer.d
executable file
·74 lines (68 loc) · 1.56 KB
/
EnemyLayer.d
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
module EnemyLayer;
private import Layer;
private import Actor;
private import Entity;
private import Vector;
private import Sofu.Sofu;
private import Scene;
private import Graphics;
private import Animation;
private import BulletLayer;
class Enemy : Entity {
this(Sofu.Map.Map data,BulletLayer layer){
_layer=layer;
_position = new Vector2d(data.list("Position"));
Vector2d size = new Vector2d(data.list("Size"));
super(new Rect(_position, _position + size));
_anim = new Animation(data.map("Animation"));
if (data.value("Type").toUTF8() == "Shooting") {
_shoot=true;
_bullet=data.map("Bullet");
_bullettime=data.value("Bullettime").toDouble();
_timeleft=_bullettime;
}
}
void draw () {
_anim.get().draw(drawPosition());
}
void advance(double frametime) {
_anim.next(frametime);
super.advance(frametime);
if (_shoot) {
_timeleft-=frametime;
if (_timeleft<0) {
_timeleft+=_bullettime;
Bullet bullet=new Bullet(_bullet,_position);
layer.addEntity(bullet);
}
}
}
private:
Vector2d _position;
bit _shoot=false;
Animation _anim;
double _timeleft;
double _bullettime;
Sofu.Map.Map _bullet;
BulletLayer _layer;
}
class EnemyLayer : Layer
{
this(Scene scene)
{
super(scene);
}
bit collide(Actor actor)
{
bit result;
foreach(Entity entity; _entities) {
if(actor.extent().overlaps(entity.extent())) {
result = true;
}
}
if(result) {
actor.hitBullet();
}
return result;
}
}