Skip to content
Browse files

Should catch me up...

Twas having issues setting up eclipse, I'm hoping I got everything
settled now.
  • Loading branch information...
1 parent bd871a5 commit 5dd1c837e11a2904b94168debfe53cff8daad491 @SubSage committed Mar 5, 2013
Showing with 96 additions and 15 deletions.
  1. +17 −0 .project
  2. +1 −1 GDCalaga/Enemy.java
  3. +64 −0 GDCalaga/InputHandler.java
  4. +4 −4 GDCalaga/PlayState.java
  5. +10 −10 GDCalaga/Player.java
View
17 .project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>GDCalaga</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
2 GDCalaga/Enemy.java
@@ -55,7 +55,7 @@ public void update(float delta)
yVel*=-1;
}
- if(Math.random()*100*delta < 100){
+ if(Math.random()*1000*delta < 100){
fire();
}
View
64 GDCalaga/InputHandler.java
@@ -0,0 +1,64 @@
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+public class InputHandler implements KeyListener {
+
+ private int maxKeys = 116;
+
+ private boolean[] bufferKeyState = new boolean[maxKeys];
+ private boolean[] currentKeyState = new boolean[maxKeys];
+ private boolean[] lastKeyState = currentKeyState.clone();
+
+ //TODO: Add states for mouse position and mouse buttons
+
+ public void keyPressed(KeyEvent e)
+ {
+ bufferKeyState[e.getKeyCode()] = true;
+ }
+
+ public void keyReleased(KeyEvent e)
+ {
+ bufferKeyState[e.getKeyCode()] = false;
+ }
+
+ public void keyTyped(KeyEvent e)
+ {
+ //Not sure what this method is supposed to do
+ }
+
+ public boolean IsKeyDown(int key)
+ {
+ if(key >= maxKeys){
+ return false;
+ } else {
+ return currentKeyState[key];
+ }
+ }
+
+ public boolean WasKeyPressed(int key)
+ {
+ if(key >= maxKeys){
+ return false;
+ } else {
+ return currentKeyState[key] && !lastKeyState[key];
+ }
+ }
+
+ public boolean WasKeyReleased(int key)
+ {
+ if(key >= maxKeys){
+ return false;
+ } else {
+ return !currentKeyState[key] && lastKeyState[key];
+ }
+ }
+
+ public void update()
+ {
+ for(int i = 0; i < maxKeys; i++){
+ lastKeyState[i] = currentKeyState[i];
+ currentKeyState[i] = bufferKeyState[i];
+ }
+ }
+
+}
View
8 GDCalaga/PlayState.java
@@ -32,16 +32,16 @@ public void update(GameContainer container, StateBasedGame game, int delta)
Entities.update(delta);
if(input.isKeyDown(Input.KEY_W)){
- player.moveUp();
+ player.moveUp(delta);
}
if(input.isKeyDown(Input.KEY_S)){
- player.moveDown();
+ player.moveDown(delta);
}
if(input.isKeyDown(Input.KEY_A)){
- player.moveLeft();
+ player.moveLeft(delta);
}
if(input.isKeyDown(Input.KEY_D)){
- player.moveRight();
+ player.moveRight(delta);
}
View
20 GDCalaga/Player.java
@@ -15,8 +15,8 @@ public Player(EntityManager manager, int xpos, int ypos)
y=ypos;
width=25;
height=25;
- xVel=20;
- yVel=20;
+ xVel=220;
+ yVel=220;
health=10;
alliance=1;
@@ -47,24 +47,24 @@ public void draw(Graphics g)
}
- public void moveUp()
+ public void moveUp(float delta)
{
- y-=yVel;
+ y-=yVel*delta/1000;
}
- public void moveDown()
+ public void moveDown(float delta)
{
- y+=yVel;
+ y+=yVel*delta/1000;
}
- public void moveLeft()
+ public void moveLeft(float delta)
{
- x-=xVel;
+ x-=xVel*delta/1000;
}
- public void moveRight()
+ public void moveRight(float delta)
{
- x+=xVel;
+ x+=xVel*delta/1000;
}
public void fire()

0 comments on commit 5dd1c83

Please sign in to comment.
Something went wrong with that request. Please try again.