// Original
package test;
import controllers.EmptyController;
import controllers.KeyboardController;
import engine.Car;
import engine.Game;
// modify
package test;
import controllers.ArriveController;
import engine.Car;
import engine.Game;
나머지 import는 다 똑같은데, ArriveController를 넣어주었다.
그리고 EmptyController랑 KeyboardController는 필요 없으니까 빼주었다.
// Original
GameObject car1 = new Car("graphics/redcar.png",200,300,-Math.PI/2, new EmptyController());
// modify
GameObject car1 = new Car("graphics/redcar.png", 200, 300, -Math.PI / 2, new ArriveController(marker));
다른 부분은 크게 바꿀 필요는 없고,
맨 뒤에 컨트롤러만 새로 만든 것을 가져오도록 바꾸었다.
▶ 처음 주어진 ArriveScenario
더보기
# problem ArriveScenario
package test;
import controllers.EmptyController;
import controllers.KeyboardController;
import engine.Car;
import engine.Game;
import engine.GameObject;
import engine.GameWindow;
import engine.Marker;
import engine.Obstacle;
import java.awt.Color;
/**
*
* @author santi
*/
public class ArriveScenario {
/*
Goal of this exercise:
- Write a controller for "car1" that uses the "Arrive" steerig behavior to arrive to
a given marker.
- To make sure it works, test your controller by placing the marker in different positions
in the map.
*/
public static void main(String args[]) throws Exception {
Game game = new Game(800,600, 25);
// set up the outside walls:
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));
// set up the cars and markers:
GameObject marker = new Marker(600,300,10, Color.green);
GameObject car1 = new Car("graphics/redcar.png",200,300,-Math.PI/2, new EmptyController());
game.add(marker);
game.add(car1);
GameWindow.newWindow(game);
}
}
▶ 변형한 ArriveScenario
더보기
package test;
import controllers.ArriveController;
import engine.Car;
import engine.Game;
import engine.GameObject;
import engine.GameWindow;
import engine.Marker;
import engine.Obstacle;
import java.awt.Color;
public class ArriveScenario {
public static void main(String args[]) throws Exception {
Game game = new Game(800, 600, 25);
// Set up the outside walls
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));
// Set up the marker
GameObject marker = new Marker(600, 300, 10, Color.GREEN);
// Set up car1 with the ArriveController
GameObject car1 = new Car("graphics/redcar.png", 200, 300, -Math.PI / 2, new ArriveController(marker));
// Add objects to the game
game.add(marker);
game.add(car1);
// Show the game window
GameWindow.newWindow(game);
}
}
'Game AI & Unity > Java Steering game' 카테고리의 다른 글
[Game AI][Steering Behavior] Task_Arrive (0) | 2024.03.21 |
---|---|
[Game AI][Steering Behavior] Task_Arrive (controllers.ArriveController) (0) | 2024.03.21 |
[Game AI][Steering Behavior] Task_Arrive (Problem) (0) | 2024.03.21 |
[Game AI][Steering Behavior] 19. Task_Seek (0) | 2024.03.21 |
[Game AI][Steering Behavior] 18. Task_Seek (controllers.SeekController) (0) | 2024.03.20 |