-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyGdxGame.java
More file actions
69 lines (61 loc) · 1.51 KB
/
MyGdxGame.java
File metadata and controls
69 lines (61 loc) · 1.51 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
package com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.ScreenUtils;
public class MyGdxGame extends ApplicationAdapter {
SpriteBatch batch;
//Texture img;
Background bg;
Bird bird;
Obstacles obstacles;
boolean gameOver;
Texture restart;
@Override
public void create () {
batch = new SpriteBatch();
bg = new Background();
bird = new Bird();
obstacles = new Obstacles();
gameOver = false;
restart = new Texture("RestartBtn.png");
}
@Override
public void render () {
update();
ScreenUtils.clear(1, 1, 1, 0.5f);
batch.begin();
bg.render(batch);
obstacles.render(batch);
if(!gameOver) bird.render(batch);
else batch.draw(restart,200, 200);
batch.end();
}
public void update() {
bg.update();
bird.update();
obstacles.update();
for(int i = 0; i < Obstacles.obs.length; i++) {
if(bird.position.x >= Obstacles.obs[i].position.x && bird.position.x <= Obstacles.obs[i].position.x + 50) {
if(!Obstacles.obs[i].emptySpace.contains(bird.position)) {
gameOver = true;
}
}
}
if(bird.position.y < 0 || bird.position.y > 600) {
gameOver = true;
}
if(Gdx.input.isKeyPressed(Input.Keys.SPACE) && gameOver) {
bird.recreate();
obstacles.recreate();
gameOver = false;
}
}
@Override
public void dispose () {
batch.dispose();
}
}