package org.cloudbus.cloudsim.codes.mygame.leiting.src;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

/**
 * ClassName Player
 * Description
 * Create by HW
 * Date 2022/4/5 15:39
 */
public class Player extends KeyAdapter {
    GameFrame gameFrame;

    public Player(GameFrame gameFrame) {
        this.gameFrame = gameFrame;
    }

    @Override
    public void keyPressed(KeyEvent e) {
        int keyCode = e.getKeyCode();
        //38上 ,40下,37左 39右
        switch (keyCode){
            case 38:
                gameFrame.plane.up=true;
                break;
            case 40:
                gameFrame.plane.down=true;
                break;
            case 37:
                gameFrame.plane.left=true;
                break;
            case 39:
                gameFrame.plane.right=true;
                break;
            case 66:
                gameFrame.bullets.add(new Bullets(gameFrame.plane.x+45,gameFrame.plane.y-10));;
                break;
            default:
                break;
        }
    }

    /**
     * 装弹
     */

    private void addBullets() {

    }

    @Override
    public void keyReleased(KeyEvent e) {
        int keyCode = e.getKeyCode();
        //38上 ,40下,37左 39右
        switch (keyCode){
            case 38:
                gameFrame.plane.up=false;
                break;
            case 40:
                gameFrame.plane.down=false;
                break;
            case 37:
                gameFrame.plane.left=false;
                break;
            case 39:
                gameFrame.plane.right=false;
                break;
            default:
                break;
        }
    }
}
