-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlatformerMap.java
More file actions
230 lines (201 loc) · 6.41 KB
/
PlatformerMap.java
File metadata and controls
230 lines (201 loc) · 6.41 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
public class PlatformerMap extends GameMap {
Image background, platform;
Dimension a = Toolkit.getDefaultToolkit().getScreenSize();
int mapX = a.width;
int mapY = a.height;
Doge doge;
GameObject platform1, platform2, platform3, platform4, platform5, platform6, platform7;
Portal portal;
Enemy pepe;
boolean jump;
int jumpCounter;
int shootCounter, pepeCounter;
int turnCounter;
public PlatformerMap() {
doge = (new Doge(mapX/200,0, mapX/36, 3, 0, 0));
platform1 = new Platform(0, mapY/2, mapX/2, mapY/2);
platform2 = new Platform(mapX/8, mapY/2, mapX/2, mapY/2);
platform3 = new Platform(mapX/4, mapY/2, mapX/2, mapY/2);
platform4 = new Platform((int)(mapX/2.5), (int)(mapY/1.4), mapX/2, mapY/2);
platform5 = new Platform((int)(mapX/2), (int)(mapY/2.5), mapX/2, mapY/2);
platform6 = new Platform((int)(mapX/1.6), (int)(mapY/2.5), mapX/2, mapY/2);
platform7 = new MiniPlatform((int)(mapX/1.2), (int)(mapY/1.5), mapX/8, mapY/2);
portal = new Portal((int)(mapX/1.1), (int)(mapY/1.5), mapX/6, mapY/3);
pepe = new Enemy(mapY/100, Math.PI, mapX/10, 500 ,(int)(mapX/1.8d), (int)(mapY/4.55));
addGameObject(platform1);
addGameObject(platform2);
addGameObject(platform3);
addGameObject(platform4);
addGameObject(platform5);
addGameObject(platform6);
addGameObject(platform7);
addGameObject(portal);
addGameObject(pepe);
addGameObject(doge);
//159,293
}
public void tick(){
super.tick();
if (jump && jumpCounter < 10){
doge.setY(doge.getY()-(mapY/35));
jumpCounter++;
}
else if (!intersect()){
doge.setY(doge.getY()+(mapY/35));
}
if (!enemyIntersect()){
pepe.setY(pepe.getY()+(mapY/35));
}
doge.setBoundingRect(doge.getX(), doge.getY(), mapX/18, mapX/12);
pepe.setBoundingRect(pepe.getX(), pepe.getY(), mapX/10, mapX/10);
if (intersect()){
jump = false;
//JOptionPane.showMessageDialog(null, "intersection");
}
shootCounter++;
//System.out.println("doge" + doge.getBoundingRect());
//System.out.println("platform" + platform1.getBoundingRect());
if(doge.getBoundingRect().intersects(portal.getBoundingRect()))
changeStage();
if (pepeCounter % 10 ==0){
addGameObject(pepe.shoot());
}
pepeCounter++;
if (turnCounter % 20 ==0){
pepe.turn();
}
turnCounter++;
}
public void changeStage(){
platform1.setX(0);
platform1.setY((int)(0.2*mapY));
platform2.setX(mapX/8);
platform2.setY((int)(Math.random()*mapY));
platform3.setX((int)(mapX/3.5));
platform3.setY((int)(Math.random()*mapY));
platform4.setX(mapX/2);
platform4.setY((int)(Math.random()*mapY));
platform5.setX((int)(mapX/1.6));
platform5.setY((int)(Math.random()*mapY));
platform6.setX((int)(mapX/1.2));
platform6.setY((int)(Math.random()*mapY));
platform7.setX((int)(mapX/1.1));
platform7.setY((int)(Math.random()*mapY));
// platform1.setBoundingRect(this.getX(), this.getY(), mapX/4, mapY/16);
// platform2.setBoundingRect(this.getX(), this.getY(), mapX/4, mapY/16);
// platform3.setBoundingRect(this.getX(), this.getY(), mapX/4, mapY/16);
// this.setBoundingRect(this.getX(), this.getY(), mapX/4, mapY/16);
// this.setBoundingRect(this.getX(), this.getY(), mapX/4, mapY/16);
// this.setBoundingRect(this.getX(), this.getY(), mapX/4, mapY/16);
// this.setBoundingRect(this.getX(), this.getY(), mapX/4, mapY/16);
for (int i=0; i<movers.size(); i++){
if (movers.get(i) instanceof Enemy){
movers.remove(i);
}
}
pepe = new Enemy(mapY/100, Math.PI, mapX/10, 500 ,(int)(mapX/1.8d), (int)(mapY/4.55));
addGameObject(pepe);
doge.setX(0);
doge.setY(0);
}
public boolean intersect(){
for (int i=0; i<movers.size(); i++){
if (movers.get(i) instanceof Platform || movers.get(i) instanceof MiniPlatform){
if (doge.getBoundingRect().intersects(movers.get(i).getBoundingRect())){
return true;
}
}
}
return false;
}
@Override
public void openBackgroundImage() {
// TODO Auto-generated method stub
try {
URL url = getClass().getResource("images/background.jpg");
background = ImageIO.read(url);
} catch (Exception e) {
System.out.println("problem opening the background");
e.printStackTrace();
}
try {
URL url = getClass().getResource("images/platform.png");
platform = ImageIO.read(url);
} catch (Exception e) {
System.out.println("problem opening the background");
e.printStackTrace();
}
}
public boolean enemyIntersect(){
for (int i=0; i<movers.size(); i++){
if (movers.get(i) instanceof Platform || movers.get(i) instanceof MiniPlatform){
if (pepe.getBoundingRect().intersects(movers.get(i).getBoundingRect())){
return true;
}
}
}
return false;
}
public void draw(Graphics g){
for (int i=0; i<movers.size(); i++){
//System.out.println(movers.get(i));
movers.get(i).draw(g);
}
g.drawImage(background, 0,0, mapX, mapY, null);
//g.drawImage(platform, 0 , (int)(0.82*mapY), mapX/2, mapY/8, null);
//g.drawImage(platform, mapX/2 , (int)(0.82*mapY), mapX/2, mapY/8, null);
g.setColor(Color.YELLOW);
//g.drawLine(0, (int)(0.82*mapY), mapX, (int)(0.82*mapY));
//---------------------
g.setFont(new Font("Comic Sans MS", Font.PLAIN, 300));
g.setColor(Color.YELLOW);
g.drawString("Wow", mapX/8, (int)(mapY * 0.75));
//---------------------
super.draw(g);
}
public void shoot(){
if(shootCounter >5){
addGameObject(doge.shoot());
shootCounter = 0;
}
}
public void stopDoge(){
doge.setSpeed(0);
}
public void moveDown(){
//t.setY((int)(t.getY()-10));
// if (!intersect()){
// doge.setDirection((Math.PI/2));
// doge.setSpeed(mapY/160);
// }
}
public void moveUp(){
//t.setY((int)(doge.getY()+10));
if (intersect()){
jump = true;
jumpCounter = 0;
}
}
public void moveRight(){
//doge.setX((int)(doge.getX()+10));
doge.setDirection(0);
if(intersect())
doge.setSpeed(doge.getSpeed()+5);
}
public void moveLeft(){
//doge.setX((int)(doge.getX()-10));
doge.setDirection(Math.PI);
if(intersect())
doge.setSpeed(doge.getSpeed()+5);
}
}