test.SeekScenario
- 수정해야할 부분
GameObject car2 = new Car("graphics/bluecar.png",600,300,-Math.PI/2, new EmptyController());
GameObject car2 = new Car("graphics/bluecar.png", 600, 300, -Math.PI / 2, new SeekController(car1));
위에 있는 코드를 아래처럼 바꾸면 된다.
EmptyController() 대신 우리가 만든 SeekController(car1)을 추가해주는 것이다.
여기서 car1은 car2가 추적해야되는 대상을 나타낸다.
SeekController는 이 정보를 사용해서 car2가 car1을 추적하도록 만들 수 있다.
(해당 자동차를 추적하고, 그 자동차를 향해 움직이도록 하는 것)
더보기
▷ SeekScenario 원래 코드
package test;
import controllers.EmptyController;
import controllers.KeyboardController;
import engine.Car;
import engine.Game;
import engine.GameObject;
import engine.GameWindow;
import engine.Obstacle;
import java.awt.Color;
/**
*
* @author santi
*/
public class SeekScenario {
/*
Goal of this exercise:
- Write a controller for "car2" that uses the "Seek" steerig behavior to always run
after car1 (that is controlled using the arrow keys).
*/
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 car1 = new Car("graphics/redcar.png",200,300,-Math.PI/2, new KeyboardController());
GameObject car2 = new Car("graphics/bluecar.png",600,300,-Math.PI/2, new EmptyController());
game.add(car1);
game.add(car2);
GameWindow.newWindow(game);
}
}
더보기
▷ SeekScenario 수정된 코드
package test;
import controllers.EmptyController;
import controllers.KeyboardController;
import controllers.SeekController;
import engine.Car;
import engine.Game;
import engine.GameObject;
import engine.GameWindow;
import engine.Obstacle;
import java.awt.Color;
/**
*
* @author santi
*/
public class SeekScenario {
/*
Goal of this exercise:
- Write a controller for "car2" that uses the "Seek" steerig behavior to always run
after car1 (that is controlled using the arrow keys).
*/
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 car1 = new Car("graphics/redcar.png", 200, 300, -Math.PI / 2, new KeyboardController());
GameObject car2 = new Car("graphics/bluecar.png", 600, 300, -Math.PI / 2, new SeekController(car1));
game.add(car1);
game.add(car2);
GameWindow.newWindow(game);
}
}
'Game AI & Unity > Java Steering game' 카테고리의 다른 글
[Game AI][Steering Behavior] 19. Task_Seek (0) | 2024.03.21 |
---|---|
[Game AI][Steering Behavior] 18. Task_Seek (controllers.SeekController) (0) | 2024.03.20 |
[Game AI][Steering Behavior] 16. Task _Seek (Problem) (0) | 2024.03.20 |
[Game AI][Steering Behavior] 15 KeyboardExample.java (0) | 2024.03.20 |
[Game AI][Steering Behavior] 14 engine.RotatedRectangle (0) | 2024.03.20 |