-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObstacles.java
More file actions
72 lines (59 loc) · 1.92 KB
/
Obstacles.java
File metadata and controls
72 lines (59 loc) · 1.92 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
package com.mygdx.game;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import java.util.Random;
public class Obstacles {
class WallPair {
Vector2 position;
float speed;
int offset;
Rectangle emptySpace;
public WallPair(Vector2 pos) {
position = pos;
speed = 2.5f;
offset = new Random().nextInt(250);
emptySpace = new Rectangle(position.x, position.y - offset + 300, 50, betweenDistance);
}
public void update() {
position.x -= speed;
if(position.x < -50) {
position.x = 800;
offset = new Random().nextInt(250);
}
emptySpace.x = position.x;
}
}
static WallPair[] obs;
Texture tx;
int betweenDistance;
public Obstacles() {
tx = new Texture("wall.png");
obs = new WallPair[4];
betweenDistance = 235;
int StartPosX = 400;
for(int i = 0; i < obs.length; i++) {
obs[i] = new WallPair(new Vector2(StartPosX, 0));
StartPosX += 220;
}
}
public void render(SpriteBatch batch) {
for(int i = 0; i < obs.length; i++) {
batch.draw(tx, obs[i].position.x, obs[i].position.y - obs[i].offset);
batch.draw(tx, obs[i].position.x, obs[i].position.y + betweenDistance + tx.getHeight() - obs[i].offset);
}
}
public void update() {
for(int i = 0; i < obs.length; i++) {
obs[i].update();
}
}
public void recreate() {
int StartPosX = 400;
for(int i = 0; i < obs.length; i++) {
obs[i] = new WallPair(new Vector2(StartPosX, 0));
StartPosX += 220;
}
}
}