forked from lanmonster/frogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Frog.cpp
100 lines (84 loc) · 1.64 KB
/
Frog.cpp
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
/*
$file: Frogger Remake ( For the console)
$purpose: Frog Class
$author: Kyle Lanmon / Michael Boyle (Softrix)
*/
#include "Frog.h"
Frog::Frog()
{
resetPosition();
}
// move frog
void Frog::plrMoveFrog(char key)
{
clearFrog();
switch (key)
{
case vk_left:
if (xPos > MIN_COL)
xPos -= 5;
break;
case vk_right:
if (xPos < MAX_COL)
xPos += 5;
break;
case vk_up:
if (yPos > MIN_ROW)
if (yPos == 52 || yPos == 29 || yPos == 26 || yPos == 3)
yPos -= 3;
else
yPos -= 5;
break;
case vk_down:
if (yPos < MAX_ROW && yPos > 2)
if (yPos == 49 || yPos == 26 || yPos == 23)
yPos += 3;
else
yPos += 5;
break;
}
}
// update frogs xpos
void Frog::logMoveFrog(char dir)
{
switch (dir) {
case 'L':
xPos--;
break;
case 'R':
xPos++;
break;
}
}
// draw frog
void Frog::drawFrog()
{
for (int i = xPos; i < xPos + 3; i++)
{
console.draw(i, yPos, green, SQUARE);
console.draw(i, yPos + 1, green, SQUARE);
}
}
// clear at old position of frog
void Frog::clearFrog()
{
colour blankColour = black; // default
if (yPos == 52 || yPos == 26) // pathway
blankColour = magenta;
else if (yPos >= 29 && yPos <= 49) // road
blankColour = black;
else if (yPos >= 0 && yPos <= 23) // water
blankColour = darkblue;
// redraw frog at selected colour
for (int i = xPos; i < xPos + 3; i++) {
console.draw(i, yPos, blankColour, SQUARE);
console.draw(i, yPos + 1, blankColour, SQUARE);
}
}
// reset position of frog
void Frog::resetPosition()
{
xPos = 41;
yPos = 52;
ink = green;
}