Greggy
2013-02-08 16:26:03 UTC
http://gyazo.com/f2f7ba99a808b8b4810f8b20e89f38c1
http://gyazo.com/be79cbf8ee3ed587fbd4d8f95e029fa8
http://gyazo.com/5f1081df52d3036949b356040f8895c9
Text:
package game;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.KeyEvent;
import java.util.BitSet;
/**
*
* @author Austin
*/
public class Ausc extends Game {
int characterSize = 20;
int x, y;
BitSet keyBits = new BitSet (256);
boolean A = false;
boolean D = false;
boolean W = false;
boolean S = false;
Ausc() {
title = "Ausc";
width = 400;
height = 400;
x = (width / 2) - (characterSize / 2);
y = (height / 2) - (characterSize / 2);
}
@Override
public vid update() {
if (A && S) {
moveLD();
} else if (A && W) {
moveLU();
} else if (A) {
moveL();
} else if (D && S) {
moveRD();
} else if (D) {
moveR();
} else if (S) {
moveD();
} else if (W) {
moveU();
}
}
@Override
public void draw(Graphics2d g) {
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderHints.VALUE_ANTIALIS_ON);
rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHints(rb);
g.setColor(Color.WHITE);
g.fillRecr(0, 0, width, height);
g.setColor(Color.BLACK);
g.fillOval(x, y, characterSize, characterSize);
}
@Override
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_A:
A = true;
break;
case KeyEvent.VK_D:
D = true;
break;
case KeyEvent.VK_W:
W = true;
break;
case KeyEvent.VK_S:
S = true;
break;
}
}
@Override
public void keyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_A:
A = false;
break;
case KeyEvent.VK_D:
D = false;
break;
case KeyEvent.VK_W:
W = false;
break;
case KeyEvent.VK_S:
S = false;
break;
}
}
public static void main(String[] args) {
FrameApplication.start(new Ausc());
}
private void moveLD() {
x -= step;
y += step;
}
private void moveLU() {
x -= step;
y -= step;
}
private void moveL() {
x -= step;
}
private void moveRD() {
x += step;
y += step;
}
private void moveRU() {
x += step;
y -= step;
}
private void moveR() {
x += step;
}
private void moveD() {
y += step;
}
private void moveU() {
y -= step;
}
}