Game AI & Unity/Java Steering game

[Game AI][Steering Behavior] 15 KeyboardExample.java

bay07 2024. 3. 20. 14:48

1. 전체적인 코드 보기 

package test;

import controllers.KeyboardController;
import engine.Car;
import engine.Game;
import engine.GameWindow;
import engine.Obstacle;
import java.awt.Color;

/**
 *
 * @author santi
 */
public class KeyboardExample {
    public static void main(String args[]) throws Exception {
        Game game = new Game(800,600, 25);
        game.add(new Car("graphics/redcar.png",400,300,0, new KeyboardController()));
        game.add(new Obstacle(0,0,800,25,Color.GRAY));
        game.add(new Obstacle(0,575,800,25,Color.GRAY));
        game.add(new Obstacle(0,0,25,600,Color.GRAY));
        game.add(new Obstacle(775,0,25,600,Color.GRAY));
        GameWindow.newWindow(game);
    }
}

 

2. KeyboardExample.java

키보드를 사용해서 빨간색 자동차를 움직인다

자동차가 회색 장애물에 부딪히면 멈추도록 구현 

3. 각각의 요소 설명

Game game = new Game(800,600, 25); 800 x 600의 크기의 새로운 게임 생성
초당 25프레임으로 실행됨
game.add(new Car("graphics/redcar.png",400,300,0, new KeyboardController())); 빨간색 자동차 추가
초기 위치 (400,300)
초기 각도 0
KeyboardController()에 의해 제어됨
game.add(new Obstacle(0,0,800,25,Color.GRAY)); 회색 장애물 추가 (위쪽 가장자리)
game.add(new Obstacle(0,575,800,25,Color.GRAY)); 회색 장애물 추가 (아래쪽 가장자리)
game.add(new Obstacle(0,0,25,600,Color.GRAY)); 회색 장애물 추가 (왼쪽 가장자리)
game.add(new Obstacle(775,0,25,600,Color.GRAY)); 회색 장애물 추가 (오른쪽 가장자리)
GameWindow.newWindow(game); 새로운 창 생성
게임 실행