-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBird.java
40 lines (34 loc) · 1.03 KB
/
Bird.java
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
package com.mygdx.game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
public class Bird {
Texture img;
Vector2 position;
float vy; // скорость птички
float gravity; // гравитационная постоянная
public Bird() {
img = new Texture("bird1.png");
position = new Vector2(100,300);
vy = 0;
gravity = -0.6f;
}
public void render(SpriteBatch batch) {
batch.draw(img, position.x, position.y);
}
public void update() {
// отслеживание нажатия пробела
if (Gdx.input.isKeyPressed(Input.Keys.SPACE)) {
vy = 9;
}
vy += gravity;
position.y += vy;
}
// пересоздание при рестарте
public void recreate() {
position = new Vector2(100,300);
vy = 0;
}
}