-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpellets.cpp
More file actions
131 lines (90 loc) · 2.79 KB
/
Copy pathpellets.cpp
File metadata and controls
131 lines (90 loc) · 2.79 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "pellets.h"
pellets::pellets(){
pelDirect = rand() %2;
if(pelDirect==0){
xLoc =-1;
pelDirection = right;
moveDirection = rand() %2 +1;
}
else if(pelDirect==1){
xLoc =128;
pelDirection = left;
moveDirection = rand() %2 -2;
}
yLoc;
}
void pellets::updatePellet(){
xLoc += moveDirection;
if( moveDirection > 0 && xLoc >130 || moveDirection < 0 && xLoc < -2){
resetPellet();
}
}
void pellets::resetPellet(){
pelDirect = rand() % 2;
yLoc =rand() %40 + 17;
if(pelDirect==0){
xLoc =-1;
pelDirection = right;
moveDirection = rand() %2 + 1;
}
else if(pelDirect==1){
xLoc =129;
pelDirection = left;
moveDirection = rand() %2 + -2;
}
}
void pellets::drawPellet(){
arduboy.drawPixel( xLoc, yLoc, WHITE);
}
bool pellets::pelletCollision(int plyrX, int plyrY, int spriteDim, int collisionCase){
Rect playerRect = {2,2,2,2};
if((playerDirection == up || playerDirection == down) && collisionCase == 0){
playerRect = { plyrX,
plyrY +2,
spriteDim,
spriteDim-4 };
}
else if((playerDirection == left || playerDirection == right) && collisionCase == 0){
playerRect = { plyrX+2,
plyrY,
spriteDim - 4,
spriteDim };
}
else{
playerRect = { plyrX,
plyrY,
spriteDim,
spriteDim };
}
Rect pelletRect = {xLoc, yLoc, 1, 1 };
if(collisionCase == 0){ // same
if(arduboy.collide(playerRect, pelletRect) && pelDirection == playerDirection ) {
return true;
}
}
else if(collisionCase == 1){ //aything but the same
if(arduboy.collide(playerRect, pelletRect) && pelDirection != playerDirection ) {
return true;
}
}else if(collisionCase == 2){ //aything but the same
if(arduboy.collide(playerRect, pelletRect)) {
return true;
}
}
return false;
}
void spawnPellets(pellets pelletArray[]){
for(int counter = 0; counter < 10; counter++){
// pelletArray[counter].spawnPellet();
}
}
void updatePellets(pellets pelletArray[]){
for(int counter = 0; counter < 10; counter++){
pelletArray[counter].updatePellet();
}
}
void drawPellets(pellets pelletArray[]){
for(int counter = 0; counter < 10; counter++){
pelletArray[counter].drawPellet();
}
}