Skip to content

Instantly share code, notes, and snippets.

@pmudry
Created January 10, 2020 07:24
Show Gist options
  • Save pmudry/fa7ad6abf8469ca81ffe9cdaca94b2d0 to your computer and use it in GitHub Desktop.
Save pmudry/fa7ad6abf8469ca81ffe9cdaca94b2d0 to your computer and use it in GitHub Desktop.
import hevs.graphics.FunGraphics;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
/**
* This class demonstrate how to implement keyboard events
* using the FunGraphics library.
*/
public class Demo {
int offset = 0;
FunGraphics funGraphics;
public Demo() {
// Inits the graphic window
funGraphics = new FunGraphics(640, 480);
// Do something when a key has been pressed
funGraphics.setKeyManager(new KeyAdapter() {
// Will be called when a key has been pressed
public void keyPressed(KeyEvent e) {
if(e.getKeyChar() == 'a'){
System.out.println("a pressed");
}
if(e.getKeyCode() == KeyEvent.VK_RIGHT){
offset++;
}
}
});
while(true)
{
funGraphics.clear();
//draw our object
funGraphics.drawRect(50+offset*2, 50+offset*2, 75, 75);
//refresh the screen at 60 FPS
funGraphics.syncGameLogic(60);
}
}
public static void main(String[] args) {
Demo d = new Demo();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment