5
5
import com .badlogic .gdx .Input ;
6
6
import com .badlogic .gdx .InputProcessor ;
7
7
import com .badlogic .gdx .graphics .Color ;
8
+ import com .badlogic .gdx .graphics .OrthographicCamera ;
8
9
import com .badlogic .gdx .graphics .Texture ;
9
10
import com .badlogic .gdx .graphics .g2d .BitmapFont ;
10
11
import com .badlogic .gdx .graphics .g2d .Sprite ;
11
12
import com .badlogic .gdx .graphics .g2d .SpriteBatch ;
12
13
import com .badlogic .gdx .graphics .glutils .ShapeRenderer ;
13
14
import com .badlogic .gdx .math .Rectangle ;
14
15
import com .badlogic .gdx .utils .ScreenUtils ;
16
+ import com .badlogic .gdx .utils .viewport .FitViewport ;
17
+ import com .badlogic .gdx .utils .viewport .Viewport ;
15
18
16
19
import java .util .*;
17
20
34
37
*/
35
38
36
39
37
- public class MyGdxGame extends ApplicationAdapter implements InputProcessor {
40
+ public class FlappyBirdCloneGame extends ApplicationAdapter implements InputProcessor {
38
41
enum Difficulty {
39
42
EASY , MEDIUM , HARD
40
43
};
@@ -54,6 +57,8 @@ Difficulty.HARD, new Settings("Hard",65f, 1.5f, 240f, 120f, 80f)
54
57
55
58
Difficulty difficulty = Difficulty .EASY ;
56
59
60
+ OrthographicCamera camera ;
61
+ Viewport viewport ;
57
62
SpriteBatch batch ;
58
63
59
64
Sprite backgroundSprite ;
@@ -105,6 +110,8 @@ public void create () {
105
110
Gdx .input .setInputProcessor (this );
106
111
batch = new SpriteBatch ();
107
112
font = new BitmapFont ();
113
+ camera = new OrthographicCamera ();
114
+ viewport = new FitViewport (400 , 450 , camera );
108
115
109
116
backgroundSprite = new Sprite (new Texture ("sprites/background-day.png" ));
110
117
floorSprite = new Sprite (new Texture ("sprites/base.png" ));
@@ -144,6 +151,8 @@ private void respawn() {
144
151
145
152
@ Override
146
153
public void render () {
154
+ // camera.update();
155
+ // batch.setProjectionMatrix(camera.combined);
147
156
this .update (Gdx .graphics .getDeltaTime ());
148
157
149
158
ScreenUtils .clear (0 , 0 , 0.75f , 1 );
@@ -380,25 +389,25 @@ public boolean keyDown(int keycode) {
380
389
@ Override
381
390
public boolean keyUp (int keycode ) {
382
391
switch (keycode ) {
383
- case com . badlogic . gdx . Input .Keys .W :
392
+ case Input .Keys .W :
384
393
iUp = false ;
385
394
break ;
386
- case com . badlogic . gdx . Input .Keys .S :
395
+ case Input .Keys .S :
387
396
iDown = false ;
388
397
break ;
389
- case com . badlogic . gdx . Input .Keys .A :
398
+ case Input .Keys .A :
390
399
iLeft = false ;
391
400
break ;
392
- case com . badlogic . gdx . Input .Keys .D :
401
+ case Input .Keys .D :
393
402
iRight = false ;
394
403
break ;
395
- case com . badlogic . gdx . Input .Keys .J :
404
+ case Input .Keys .J :
396
405
cheat_freemove = !cheat_freemove ;
397
406
break ;
398
- case com . badlogic . gdx . Input .Keys .K :
407
+ case Input .Keys .K :
399
408
cheat_noclip = !cheat_noclip ;
400
409
break ;
401
- case com . badlogic . gdx . Input .Keys .L :
410
+ case Input .Keys .L :
402
411
cheat_drawboxes = !cheat_drawboxes ;
403
412
break ;
404
413
case Input .Keys .UP :
@@ -421,7 +430,11 @@ public boolean keyUp(int keycode) {
421
430
}
422
431
423
432
424
-
433
+ @ Override
434
+ public void resize (int width , int height ) {
435
+ // viewport.update(width, height, true);
436
+ super .resize (width , height );
437
+ }
425
438
426
439
@ Override
427
440
public boolean keyTyped (char character ) {
0 commit comments