-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfish.cpp
More file actions
135 lines (89 loc) · 2.82 KB
/
Copy pathfish.cpp
File metadata and controls
135 lines (89 loc) · 2.82 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
132
133
134
135
#include "fish.h"
fish::fish(): pellets(){
byte fishType = rand() % 3;
resetFish();
}
void fish::drawFish(){
sprite.drawSelfMasked( xLoc, yLoc, lilFish, fishType+(pelDirect*3));
}
void fish::updateFish(){
xLoc += moveDirection;
if( moveDirection > 0 && xLoc >176 || moveDirection < 0 && xLoc < -50){
resetFish();
}
}
void fish::resetFish(){
fishType = rand() % 3;
pelDirect = rand() % 2;
yLoc =rand() %36 + 13;
if(pelDirect==0){
xLoc =-1;
pelDirection = right;
moveDirection = rand() %2 + 1;
}
else if(pelDirect==1){
xLoc =129;
pelDirection = left;
moveDirection = rand() %2 + -2;
}
}
bool fish::fishCollision(int plyrX, int plyrY, int spriteDimX, int spriteDimY){
Rect playerRect = {plyrX,
plyrY,
spriteDimX,
spriteDimY };
Rect fishRect = {xLoc+1, yLoc+1, 6, 6 };
if(arduboy.collide(playerRect, fishRect)){
return true;
}
return false;
}
bigFish::bigFish(){
byte fishType = rand() % 2;
resetBigFish();
}
void bigFish::drawBigFish(){
sprite.drawSelfMasked( xLoc, yLoc, bigFishArray, (fishType+(pelDirect*4)));
if(pelDirect == 0){
sprite.drawSelfMasked( xLoc-8, yLoc, bigFishArray, fishType+2+(pelDirect*4));
}else{
sprite.drawSelfMasked( xLoc+8, yLoc, bigFishArray, fishType+2+(pelDirect*4));
}
}
bool bigFish::fishBigCollision(int plyrX, int plyrY, int spriteDimX, int spriteDimY){
Rect playerRect = {plyrX,
plyrY,
spriteDimX,
spriteDimY };
Rect fishRect;
if (pelDirect == 0){
fishRect = {xLoc-8, yLoc+1, 16, 6 };
}else{
fishRect = {xLoc, yLoc+1, 16, 6 };
}
if(arduboy.collide(playerRect, fishRect)){
return true;
}
return false;
}
void bigFish::resetBigFish(){
fishType = rand() % 2;
pelDirect = rand() % 2;
yLoc =rand() %36 + 13;
if(pelDirect==0){
xLoc =-1;
pelDirection = right;
moveDirection = rand() %2 + 1;
}
else if(pelDirect==1){
xLoc =129;
pelDirection = left;
moveDirection = rand() %2 + -2;
}
}
void bigFish::updateBigFish(){
xLoc += moveDirection;
if( moveDirection > 0 && xLoc >200 || moveDirection < 0 && xLoc < -100){
resetBigFish();
}
}