I am not very good with GridWorld, but for my final project, we were asked to use gridworld in order to create a game. I want to make an subclass of Bug that when you press 'W' for example, it moves up on the grid, when you press 'S' moves down, press 'A' moves left, 'D' moves right. This is the only problem I have with my game. Could someone please help me on how I can go about this.
1 Replies - 4732 Views - Last Post: 25 May 2012 - 03:09 PM
#1
How to make an actor that moves when keys are pressed?
Posted 22 May 2012 - 07:15 AM
Replies To: How to make an actor that moves when keys are pressed?
#2
Re: How to make an actor that moves when keys are pressed?
Posted 25 May 2012 - 03:09 PM
java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addKeyEventDispatcher(new java.awt.KeyEventDispatcher() {
public boolean dispatchKeyEvent(java.awt.event.KeyEvent event) {
String key = javax.swing.KeyStroke.getKeyStrokeForEvent(event).toString();
if (key.equals("pressed UP"))
world.getPlayer().setPacDir(0);
if (key.equals("pressed RIGHT"))
world.getPlayer().setPacDir(90);
if (key.equals("pressed DOWN"))
world.getPlayer().setPacDir(180);
if (key.equals("pressed LEFT"))
world.getPlayer().setPacDir(270);
return true;
}
});
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote



|