Skip to content

Commit 189d556

Browse files
Time alteration groundwork
1 parent 5116de6 commit 189d556

File tree

6 files changed

+71
-24
lines changed

6 files changed

+71
-24
lines changed

core/src/com/mygdx/game/battlewindow/ContinuousGameFrame.java

+27-4
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ public class ContinuousGameFrame extends ApplicationAdapter implements InputProc
4747
private float scaledX;
4848
private float scaledY;
4949
private float delta;
50+
private float shiftedDelta;
51+
private static float temporalModifier = 1f;
5052

5153
public Bridge bridge;
5254

55+
private final Array<Timer> timers = new Array<Timer>();
56+
5357
public ContinuousGameFrame(Bridge bridge) {
5458
instance = this;
5559
this.bridge = bridge;
@@ -111,9 +115,10 @@ protected void call() {
111115
@Override
112116
public void render() {
113117
delta = Gdx.graphics.getDeltaTime();
118+
shiftedDelta = delta * temporalModifier;
114119
elapsedTime += delta;
115120

116-
//beginTime = System.currentTimeMillis();
121+
updateTimers();
117122

118123
switch (STATUS_CURRENT) {
119124
case STATUS_INIT: {
@@ -221,8 +226,8 @@ private void draw() {
221226
}
222227

223228
private void act() {
224-
HUDs[me].act(delta);
225-
HUDs[opp].act(delta);
229+
HUDs[me].act(shiftedDelta);
230+
HUDs[opp].act(shiftedDelta);
226231

227232
if (drawMe) actPokemon(me);
228233
if (drawOpp) actPokemon(opp);
@@ -312,7 +317,7 @@ private void drawPokemon(byte player) {
312317

313318
private void actPokemon(byte player) {
314319
if (sprites[player] != null) {
315-
sprites[player].act(delta);
320+
sprites[player].act(shiftedDelta);
316321
}
317322
}
318323

@@ -387,6 +392,24 @@ private String StringFormat(Integer i) {
387392
return string;
388393
}
389394

395+
public void addTimer(Timer timer) {
396+
synchronized(timers) {
397+
timers.add(timer);
398+
}
399+
}
400+
401+
public void removeTimer(Timer timer) {
402+
synchronized (timers) {
403+
timers.removeValue(timer, true);
404+
}
405+
}
406+
407+
private void updateTimers() {
408+
for (Timer timer : timers) {
409+
timer.act(shiftedDelta);
410+
}
411+
}
412+
390413
public void drawRect(Rectangle rect) {
391414
objectDebugger.rect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
392415
}

core/src/com/mygdx/game/battlewindow/Event.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
package com.mygdx.game.battlewindow;
22

3-
import com.badlogic.gdx.utils.Timer;
4-
53
public abstract class Event {
64
public EventListener listener;
75

8-
public void run(ContinuousGameFrame frame) {
6+
public void run(final ContinuousGameFrame frame) {
97
launch(frame);
108

119
if (duration() == 0) {
1210
finish();
1311
} else if (duration() > 0) {
14-
Timer.instance().scheduleTask(new Timer.Task() {
12+
Timer timer = new Timer(duration() / 1000f) {
1513
@Override
1614
public void run() {
15+
frame.removeTimer(this);
1716
finish();
1817
}
19-
}, duration()/1000f);
18+
};
19+
frame.addTimer(timer);
2020
} else {
2121
//Duration of -1, undetermined duration, subclass needs to call finish()
2222
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.mygdx.game.battlewindow;
2+
3+
public abstract class Timer {
4+
float remaining;
5+
6+
public Timer(float duration) {
7+
this.remaining = duration;
8+
}
9+
10+
public void act(float delta) {
11+
remaining = remaining - delta;
12+
if (isCompleted()) {
13+
run();
14+
}
15+
}
16+
17+
public boolean isCompleted() {
18+
return remaining <= 0;
19+
}
20+
21+
public abstract void run();
22+
}

desktop/src/com/mygdx/game/desktop/DesktopLauncher.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,29 @@ public void unpause() {
5858

5959
@Override
6060
public void finished() {
61-
61+
int randomNum = random.nextInt(37);
62+
addEvent(new Events.BackgroundChange(randomNum));
63+
Poke me = new Poke((byte) (random.nextInt(95) + 5), "Test", (short) random.nextInt(600), (byte) random.nextInt(3), (byte) (random.nextInt(80) + 20), random.nextInt(7));
64+
//mebattle = new Poke((byte) 100, "test", (short) 4, (byte)1,(byte) 100,(short) 0,(short) 100,(short) 100);
65+
Poke opp = new Poke((byte) (random.nextInt(100) + 5), "Test", (short) 49, (byte) random.nextInt(3), (byte) (random.nextInt(80) + 20), random.nextInt(7));
66+
addEvent(new Events.SpriteChange(me, this.me, true));
67+
addEvent(new Events.SpriteChange(opp, this.opp, false));
68+
//service.offer(new Events.HUDChangeBattling(mebattle));
69+
addEvent(new Events.HUDChange(me, this.me));
70+
addEvent(new Events.HUDChange(opp, this.opp));
71+
// addEvent(new Events.SendOut(this.opp, me));
72+
// addEvent(new Events.SendOut(this.me, opp));
73+
// addEvent(new Events.SendOut(this.opp, opp));
74+
// addEvent(new Events.SendOut(this.me, me));
6275
}
6376

6477
Random random = new Random();
6578
@Override
6679
public TaskService setGame(ContinuousGameFrame game) {
6780
this.game = game;
6881
TaskService service = new DesktopService();
69-
int randomNum = random.nextInt(37);
70-
service.offer(new Events.BackgroundChange(randomNum));
71-
Poke me = new Poke((byte) (random.nextInt(95) + 5), "Test", (short) random.nextInt(600), (byte) random.nextInt(3), (byte) (random.nextInt(80) + 20), random.nextInt(7));
72-
//mebattle = new Poke((byte) 100, "test", (short) 4, (byte)1,(byte) 100,(short) 0,(short) 100,(short) 100);
73-
Poke opp = new Poke((byte) (random.nextInt(100) + 5), "Test", (short) 49, (byte) random.nextInt(3), (byte) (random.nextInt(80) + 20), random.nextInt(7));
74-
service.offer(new Events.SpriteChange(me, this.me, true));
75-
service.offer(new Events.SpriteChange(opp, this.opp, false));
76-
//service.offer(new Events.HUDChangeBattling(mebattle));
77-
service.offer(new Events.HUDChange(me, this.me));
78-
service.offer(new Events.HUDChange(opp, this.opp));
7982
return service;
8083
}
81-
Poke mebattle;
8284

8385
@Override
8486
public void alert(String message) {

html/src/com/mygdx/game/client/HtmlLauncher.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public TaskService setGame(ContinuousGameFrame game) {
6363
} catch (Exception e) {
6464
Window.alert("can't find battle");
6565
}
66-
return new TaskService2();
66+
return new HtmlService();
6767
}
6868

6969
@Override

html/src/com/mygdx/game/client/TaskService2.java html/src/com/mygdx/game/client/HtmlService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
import java.util.LinkedList;
77

8-
public class TaskService2 implements TaskService {
8+
public class HtmlService implements TaskService {
99
private LinkedList<Event> tasks;
1010
private boolean busy;
1111

12-
public TaskService2() {
12+
public HtmlService() {
1313
this.tasks = new LinkedList<Event>();
1414
}
1515

0 commit comments

Comments
 (0)