Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.Joey402;
- import java.awt.event.KeyEvent;
- import java.awt.event.KeyListener;
- public class gameLoop extends StickFrame implements KeyListener{
- private static final long serialVersionUID = 1L;
- public static void main(String[] args){
- while(true){
- if(left1 == true){
- stickx1--;
- }
- if(left2 == true){
- stickx2--;
- }
- if(right1 == true){
- stickx1++;
- }
- if(right2 == true){
- stickx2++;
- }
- try {
- Thread.sleep(20);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- public void keyPressed(KeyEvent e){
- if(e.getKeyCode() == 65){
- left1 = true;
- }
- if(e.getKeyCode() == 37){
- left2 = true;
- }
- if(e.getKeyCode() == 68){
- right1 = true;
- }
- if(e.getKeyCode() == 39){
- right2 = true;
- }
- }
- public void keyReleased(KeyEvent e){
- if(e.getKeyCode() == 65){
- left1 = false;
- }
- if(e.getKeyCode() == 37){
- left2 = false;
- }
- if(e.getKeyCode() == 68){
- right1 = false;
- }
- if(e.getKeyCode() == 39){
- right2 = false;
- }
- }
- public void keyTyped(KeyEvent e){
- }
- }
Add Comment
Please, Sign In to add comment