Skip to content

Instantly share code, notes, and snippets.

@NickCarneiro
Created March 7, 2012 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickCarneiro/1996766 to your computer and use it in GitHub Desktop.
Save NickCarneiro/1996766 to your computer and use it in GitHub Desktop.
Clide's running game
package game;
import java.util.ArrayList;
public class RunningGame extends Minigame {
private int correct = 2;
private IconEntity arrow_left;
private IconEntity arrow_right;
private int selected = 0;
private int leftcount = 0;
private int rightcount = 0;
private long left_time = 0;
private long right_time = 0;
private long start_time = 0;
private boolean game_started = false;
public RunningGame(ArrayList<Entity> entities, ArrayList<Entity> removeList, Engine engine) {
super(entities, removeList, engine);
}
public void setup(){
System.out.println("Setting up RunningGame");
Entity frame = new FrameEntity(engine,"sprites/background_coffee.jpg", 0, 0);
entities.add(frame);
game_started = false;
}
public void logic(){
if(game_started == false){
if(engine.leftPressed == true){
System.out.println("Starting RunningGame!");
game_started = true;
start_time = System.currentTimeMillis();
}
} else {
//we're running
if(engine.leftPressed){
leftcount++;
arrow_left = new IconEntity(engine,"sprites/left_arrow_small.png", 450, 700);
entities.add(arrow_left);
engine.leftPressed = false;
left_time = System.currentTimeMillis();
}
if(engine.rightPressed){
rightcount++;
arrow_right = new IconEntity(engine,"sprites/right_arrow_small.png", 550, 700);
entities.add(arrow_right);
engine.rightPressed = false;
right_time = System.currentTimeMillis();
}
long left_delta = System.currentTimeMillis() - left_time;
if(left_delta > 150){
removeList.add(arrow_left);
}
long right_delta = System.currentTimeMillis() - right_time;
if(right_delta > 150){
removeList.add(arrow_right);
}
//check if we're done
long delta = System.currentTimeMillis() - start_time;
if(delta > 5000){
complete = true;
if(leftcount + rightcount > 10){
//you win
result = true;
} else {
//you lose
result = false;
}
System.out.println(leftcount + " " + rightcount + " ");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment