Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ublic class Control extends KeyAdapter {
- Background bg = new Background();
- Player p = new Player();
- private final int mUpKey = 38;
- private final int mDownKey = 40;
- private final int mLeftKey = 37;
- private final int mRightKey = 39;
- public void keyPressed(KeyEvent e) {
- int keyCode = e.getKeyCode();
- if(keyCode == mUpKey) {
- if(!(bg.getMap(p.getTileX(),p.getTileY()-1).equals("1"))) {
- p.move(0,-1);
- }
- }
- if(keyCode == mDownKey) {
- if(!(bg.getMap(p.getTileX(),p.getTileY()+1).equals("1"))) {
- p.move(0,1);
- }
- }
- if(keyCode == mLeftKey) {
- if(!(bg.getMap(p.getTileX(),p.getTileY()-1).equals("1"))) {
- p.move(-1,0);
- }
- }
- if(keyCode == mRightKey) {
- if(!(bg.getMap(p.getTileX(),p.getTileY()-1).equals("1"))) {
- p.move(1,0);
- }
- }
- }
- }
- public void actionPerformed(ActionEvent e) {
- if(isFirst){
- g=getGraphics();
- }
- repaint();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement