a4a6c94f698892faf86e7fd98cd3f30a27e7a088
1 package ru
.deadsoftware
.cavecraft
.game
;
3 import com
.badlogic
.gdx
.Gdx
;
4 import com
.badlogic
.gdx
.Input
;
5 import com
.badlogic
.gdx
.utils
.Array
;
6 import com
.badlogic
.gdx
.utils
.TimeUtils
;
7 import ru
.deadsoftware
.cavecraft
.*;
8 import ru
.deadsoftware
.cavecraft
.game
.mobs
.Mob
;
9 import ru
.deadsoftware
.cavecraft
.game
.mobs
.Pig
;
10 import ru
.deadsoftware
.cavecraft
.game
.objects
.Player
;
12 public class GameProc
{
14 public static double RUN_TIME
= 0;
18 public Array
<Mob
> mobs
;
20 public GameWorld world
;
21 public GameRenderer renderer
;
22 public GamePhysics physics
;
24 public int cursorX
, cursorY
;
28 public boolean isTouchDown
, isKeyDown
;
29 public int touchDownX
, touchDownY
, keyDownCode
;
30 public int touchDownButton
;
31 public long touchDownTime
;
34 world
= new GameWorld();
35 if (WorldSaver
.exists()) {
38 world
.generate(1024, 256);
41 renderer
= new GameRenderer(this,320,
42 320*((float)GameScreen
.getHeight()/GameScreen
.getWidth()));
44 renderer
= new GameRenderer(this,480,
45 480*((float)GameScreen
.getHeight()/GameScreen
.getWidth()));
47 physics
= new GamePhysics(this);
48 player
= new Player(world
.getSpawnPoint(0));
49 mobs
= new Array
<Mob
>();
50 for (int i
=0; i
<world
.getWidth(); i
+=64) {
51 mobs
.add(new Pig(i
*16, (int)world
.getSpawnPoint(i
).y
, world
));
53 if (!CaveGame
.TOUCH
) ctrlMode
= 1;
56 public void resetRenderer() {
58 renderer
= new GameRenderer(this,320,
59 320*((float)GameScreen
.getHeight()/GameScreen
.getWidth()));
61 renderer
= new GameRenderer(this,480,
62 480*((float)GameScreen
.getHeight()/GameScreen
.getWidth()));
66 private boolean isAutoselectable(int x
, int y
) {
67 return (world
.getForeMap(x
,y
)>0 &&
68 Items
.BLOCKS
.getValueAt(world
.getForeMap(x
,y
)).collision
);
71 private void moveCursor() {
72 if (ctrlMode
== 0 && CaveGame
.TOUCH
) {
73 cursorX
= (int) (player
.position
.x
+ player
.texWidth
/ 2) / 16;
74 if (player
.dir
== 0) cursorX
--;
76 cursorY
= (int) (player
.position
.y
+ player
.texWidth
) / 16;
77 if (!isAutoselectable(cursorX
, cursorY
)) {
80 if (!isAutoselectable(cursorX
, cursorY
)) {
83 if (!isAutoselectable(cursorX
, cursorY
)) {
84 if (player
.dir
== 0) cursorX
++;
87 } else if (!CaveGame
.TOUCH
){
88 cursorX
= (int)(Gdx
.input
.getX()*
89 (renderer
.camera
.viewportWidth
/GameScreen
.getWidth())+renderer
.camera
.position
.x
)/16;
90 cursorY
= (int)(Gdx
.input
.getY()*
91 (renderer
.camera
.viewportHeight
/GameScreen
.getHeight())+renderer
.camera
.position
.y
)/16;
92 if ((Gdx
.input
.getX()*
93 (renderer
.camera
.viewportWidth
/GameScreen
.getWidth())+renderer
.camera
.position
.x
)<0)
98 private void checkCursorBounds() {
99 if (cursorY
< 0) cursorY
= 0;
100 if (cursorY
>= world
.getHeight()) cursorY
= world
.getHeight()-1;
102 if (cursorX
*16+8<player
.position
.x
+player
.texWidth
/2)
104 if (cursorX
*16+8>player
.position
.x
+player
.texWidth
/2)
109 public void update(float delta
) {
112 physics
.update(delta
);
116 if (isTouchDown
&& TimeUtils
.timeSinceMillis(touchDownTime
) > 500) {
117 if (touchDownButton
== Input
.Buttons
.RIGHT
) {
118 world
.placeToBackground(cursorX
, cursorY
,
119 player
.inventory
[invSlot
]);
120 } else if (touchDownButton
==Input
.Buttons
.LEFT
&&
121 touchDownY
< Assets
.invBar
.getRegionHeight() &&
122 touchDownX
>renderer
.camera
.viewportWidth
/2-Assets
.invBar
.getRegionWidth()/2 &&
123 touchDownX
<renderer
.camera
.viewportWidth
/2+Assets
.invBar
.getRegionWidth()/2) {
124 CaveGame
.STATE
= GameState
.GAME_CREATIVE_INV
;