-
-
Save larsbutler/3424865 to your computer and use it in GitHub Desktop.
GameKernel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import javax.swing.Timer; | |
public class GameKernel implements Runnable { | |
public static int playerX = 400; | |
public static int playerY = 300; | |
private int moveVel = 10; | |
private int direction = 1; | |
private Timer timer; | |
public static final int TIMESTEP_MS = 10; | |
public void run() { | |
final GameWindow gw = new GameWindow(); | |
ActionListener taskPerformer = new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
update(); | |
gw.render(); | |
} | |
}; | |
timer = new Timer(TIMESTEP_MS, taskPerformer); | |
timer.start(); | |
} | |
public void update() { | |
playerX += direction * moveVel; | |
if (playerX >= GameWindow.SIZE.width - 100) { | |
direction *= -1; | |
} | |
else if (playerX <= 100) { | |
direction *= -1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment