forked from DanielleMorganLapis/Harambe-s-Revenge
/
Keeper.h
118 lines (107 loc) · 3.34 KB
/
Keeper.h
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef KEEPER_H
#define KEEPER_H
#include "Bullet.h"
#define KEEPERSPEEDMAX ((30<<SUBPIXELBITS)/FPS)
#define KEEPERDIRECTIONCHANGEFRAMEMIN FPS/4
#define KEEPERDIRECTIONCHANGEFRAMEMAX FPS/2
#define BULLETFRAMEMIN FPS*3
#define BULLETFRAMEMAX FPS*7
class Keeper : public Entity
{
public:
Keeper(int16_t tX, int16_t tY,Bullet *tMahBullet):
Entity(tX,tY),
mahBullet(tMahBullet),
framecount(0),
bulletframecount((rand() % (BULLETFRAMEMAX-BULLETFRAMEMIN))+BULLETFRAMEMIN)
{
}
virtual ~Keeper()
{
}
virtual EntityIdentification ImA()
{
return ID_Keeper;
}
virtual uint8_t *GetSprite()
{
return dir ? &keeperRight[2] : &keeper[2];
}
virtual uint8_t GetWidth()
{
return keeper[0];
}
virtual uint8_t GetHeight()
{
return keeper[1];
}
virtual void Input(Arduboy2 &arduboy,ArduboyTones &sound,uint16_t tNumEntity, Entity **tEntities)
{
if (framecount) framecount--;
if (bulletframecount) bulletframecount--;
switch(rand() % 6)
{
case 0://Move random
if (!framecount)
{
unsigned int direct=rand() % 9;
Point tDirection;
memcpy_P(&tDirection, &directions[direct], sizeof(Point));
velocity.x=tDirection.x*KEEPERSPEEDMAX;
velocity.y=tDirection.y*KEEPERSPEEDMAX;
framecount=rand() % KEEPERDIRECTIONCHANGEFRAMEMAX;
if (framecount<KEEPERDIRECTIONCHANGEFRAMEMIN) framecount=KEEPERDIRECTIONCHANGEFRAMEMIN;
}
break;
case 1://Move toward
if (!framecount)
{
if (tNumEntity && tEntities[0])
{
int16_t x=tEntities[0]->pos.x-pos.x,
y=tEntities[0]->pos.y-pos.y;
if (abs(x)<(1<<SUBPIXELBITS)) velocity.x=0;
else if (x>0) velocity.x=KEEPERSPEEDMAX;
else velocity.x=KEEPERSPEEDMAX*-1;
if (abs(y)<(1<<SUBPIXELBITS)) velocity.y=0;
else if (y>0) velocity.y=KEEPERSPEEDMAX;
else velocity.y=KEEPERSPEEDMAX*-1;
}
framecount=rand() % KEEPERDIRECTIONCHANGEFRAMEMAX;
if (framecount<KEEPERDIRECTIONCHANGEFRAMEMIN) framecount=KEEPERDIRECTIONCHANGEFRAMEMIN;
}
break;
case 2://Shoot
if (!bulletframecount)
{
if (tNumEntity && tEntities[0] && mahBullet && mahBullet->range<=0)
{
int16_t x=tEntities[0]->pos.x-pos.x,
y=tEntities[0]->pos.y-pos.y;
memset(&velocity,0,sizeof(velocity));
mahBullet->pos.x=pos.x;
mahBullet->pos.y=pos.y;
if (abs(x)<(tEntities[0]->GetWidth()<<SUBPIXELBITS)) mahBullet->velocity.x=0;
else if (x>0) mahBullet->velocity.x=BULLETTSPEED;
else mahBullet->velocity.x=BULLETTSPEED*-1;
if (abs(y)<(tEntities[0]->GetHeight()<<SUBPIXELBITS)) mahBullet->velocity.y=0;
else if (y>0) mahBullet->velocity.y=BULLETTSPEED;
else mahBullet->velocity.y=BULLETTSPEED*-1;
if (mahBullet->velocity.x || mahBullet->velocity.y)
{
sound.tones(bulletFire);
mahBullet->range=BULLETTRANGE;
bulletframecount=rand() % BULLETFRAMEMAX;
if (bulletframecount<BULLETFRAMEMIN) bulletframecount=BULLETFRAMEMIN;
}
}
}
break;
default:
break;
}
}
Bullet *mahBullet;
uint16_t framecount,bulletframecount;
};
#endif //KEEPER_H