-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.pde
More file actions
161 lines (142 loc) · 3.69 KB
/
Game.pde
File metadata and controls
161 lines (142 loc) · 3.69 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
int pixelsize = 4;
int gridsize = pixelsize * 7 + 5;
Player player;
ArrayList Goblins = new ArrayList();
ArrayList fireballs = new ArrayList();
int direction = 1;
int speed = 2;
boolean wall = false;
int score = 0;
PFont f;
PImage field, wizard, goblin, fireball;
int stage = 0;
void setup() {
//loads all the images for the game
field = loadImage("field.png");
field.resize(800,550);
wizard = loadImage("wizard.png");
wizard.resize(40,40);
goblin = loadImage("goblin.png");
goblin.resize(50,50);
fireball = loadImage("fireball.png");
fireball.resize(25,25);
noStroke();
size(800, 550);
player = new Player();
createEnemies();
f = createFont("Arial", 36, true);
}
//Draws the stages
void draw(){
if(stage == 0)
loadingScreen();
if(stage == 1)
game();
if(stage == 2)
lose();
if(stage == 3)
win();
}
void game() {
background(field);
drawScore();
// creates player model
player.display();
//creates fireballs
for (int i = 0; i < fireballs.size(); i++) {
Fireball fireball = (Fireball) fireballs.get(i);
fireball.display();
}
//Makes sure the Goblins are staying within the screen
for (int i = 0; i < Goblins.size(); i++) {
Goblins goblins = (Goblins) Goblins.get(i);
if (goblins.outside() == true) {
speed += 1;
direction *= (-1);
wall = true;
break;
}
}
//Keeps track of the goblin army and if they are alive
for (int i = 0; i < Goblins.size(); i++) {
Goblins goblins = (Goblins) Goblins.get(i);
if (!goblins.alive()) {
Goblins.remove(i);
}
if(Goblins.size() == 0){
stage = 3;
}
else {
goblins.display();
}
}
//Checks for the lose condition
for (int i = 0; i < Goblins.size(); i++) {
Goblins goblins = (Goblins) Goblins.get(i);
if (goblins.reachCastle() > 500) {
stage = 2;
}
}
wall = false;
}
void drawScore() {
textFont(f);
text("Score: " + String.valueOf(score), 300, 50);
}
//creates the enemies that will spawn
void createEnemies() {
for (int i = 0; i < width/gridsize/2; i++) {
for (int j = 0; j <= 5; j++) {
Goblins.add(new Goblins(i*gridsize, j*gridsize + 70));
}
}
}
//Loading Screen
void loadingScreen(){
background(0);
stroke(0,255,0);
noFill();
textSize(36);
text("Welcome to Wizard Defense!", 170, 100);
textSize(12);
text("Left Arrow Key = Move Left", 60, 300);
text("Right Arrow Key = Move Right", 60, 320);
text("Spacebar = Fire Fireball", 60, 340);
textSize(36);
text("Click on the Screen to Start!", 170, 500);
}
//Lose Screen
void lose(){
background(0);
stroke(0,255,0);
noFill();
textSize(36);
text("You lose! Your final score was: " + String.valueOf(score), 170, 100);
textSize(12);
text("Left Arrow Key = Move Left", 60, 300);
text("Right Arrow Key = Move Right", 60, 320);
text("Spacebar = Fire Fireball", 60, 340);
textSize(36);
text("Please Close the Game to Restart", 170, 500);
}
void win(){
background(0,255,0);
stroke(0,255,0);
noFill();
textSize(36);
text("You Win! Your final score was: " + String.valueOf(score), 170, 100);
textSize(12);
text("Left Arrow Key = Move Left", 60, 300);
text("Right Arrow Key = Move Right", 60, 320);
text("Spacebar = Fire Fireball", 60, 340);
textSize(36);
text("Please Close the Game to Restart", 170, 500);
}
void mousePressed(){
if(stage == 0){
stage = 1;
}
else if(stage == 2){
stage = 1;
}
}