Skip to content

Commit f8ed296

Browse files
committed
Adds game loop. Now the basic gameplay is almost ready
1 parent a22d88f commit f8ed296

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

Diff for: core/src/com/sdsmdg/kd/gameplay/objects/Magnus.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
import com.sdsmdg.kd.gameplay.controllers.MagnusController;
88
import com.sdsmdg.kd.gameplay.utilities.Geometry;
99
import com.sdsmdg.kd.helpers.InputHandler;
10+
import com.sdsmdg.kd.screens.GameScreen;
1011

1112
public class Magnus {
1213
/** CLASS MEMBERS *******************************************************/
1314
public Vector2 magnusPosition;
1415
MagnusController magnusController;
1516
public double magnusVelocity;
1617
public int magnusRadius;
18+
public int magnusSleepTime;
1719
float screenWidth;
1820
float screenHeight;
1921
private RandomXS128 random;
2022
private Vector2 mVelocityComponent;
21-
private boolean temp;
23+
public static boolean temp;
2224
/**--------------------------------------------------------------------**/
2325

2426
/** CONSTRUCTOR *********************************************************/
@@ -28,6 +30,7 @@ public Magnus() {
2830
this.random = new RandomXS128();
2931
this.magnusController = new MagnusController(this);
3032
this.temp = false;
33+
this.magnusSleepTime = random.nextInt(15) + 15;
3134
int gameWidth = 136;
3235
int gameHeight = (int)((screenHeight/screenWidth) * gameWidth);
3336

@@ -52,23 +55,28 @@ public void prepareForSleepAndAttack(){
5255
if (magnusPosition.x > screenWidth) {
5356
magnusPosition.x = screenWidth;
5457
mVelocityComponent.set(0,0);
58+
GameScreen.isTouched = false;
5559
}
56-
else if (magnusPosition.x < 0) {
60+
if (magnusPosition.x < 0) {
5761
magnusPosition.x = 0;
5862
mVelocityComponent.set(0,0);
63+
GameScreen.isTouched = false;
5964
}
60-
else if (magnusPosition.y > screenHeight) {
65+
if (magnusPosition.y > screenHeight) {
6166
magnusPosition.y = screenHeight;
6267
mVelocityComponent.set(0,0);
68+
GameScreen.isTouched = false;
6369
}
64-
else if (magnusPosition.y < 0) {
70+
if (magnusPosition.y < 0) {
6571
magnusPosition.y = 0;
6672
mVelocityComponent.set(0,0);
73+
GameScreen.isTouched = false;
6774
}
6875

6976
magnusController.destinationPoint = new Vector2(InputHandler.touch.x,InputHandler.touch.y);
7077
magnusController.initialPoint = magnusPosition;
7178
magnusVelocity = random.nextInt(15) + 15 + (int)(magnusController.score / 1000);
79+
magnusSleepTime = random.nextInt(15) + 15;
7280
}
7381
}
7482

Diff for: core/src/com/sdsmdg/kd/gameworld/GameWorld.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ public GameWorld() {
2121
/** UPDATE METHOD *******************************************************/
2222
public void update(float delta) {
2323
if (GameScreen.isTouched){
24-
magnusController.MagnusControl();
24+
if (magnus.magnusSleepTime>0) {
25+
magnus.magnusSleepTime--;
26+
Magnus.temp = false;
27+
}
28+
else {
29+
magnus.magnusSleepTime=0;
30+
magnusController.MagnusControl();
31+
}
2532
}
2633
Gdx.app.log("GameWorld", "update");
2734
}

0 commit comments

Comments
 (0)