From 0bd4d7f04257f6c7ba8881c159bbcf446b8e2961 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Thu, 26 Dec 2019 16:26:37 +0400 Subject: [PATCH] Implement BinkyScatterBehaviour --- .../entity/ai/BlinkyScatterBehaviour.java | 18 ++++++++++++++++++ core/src/com/me/pacman/state/PlayState.java | 14 ++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 core/src/com/me/pacman/entity/ai/BlinkyScatterBehaviour.java diff --git a/core/src/com/me/pacman/entity/ai/BlinkyScatterBehaviour.java b/core/src/com/me/pacman/entity/ai/BlinkyScatterBehaviour.java new file mode 100644 index 0000000..c6705dd --- /dev/null +++ b/core/src/com/me/pacman/entity/ai/BlinkyScatterBehaviour.java @@ -0,0 +1,18 @@ +package com.me.pacman.entity.ai; + +import com.me.pacman.PacDude; +import com.me.pacman.state.PlayState; + +public class BlinkyScatterBehaviour extends Behaviour { + + private static final Target target = new Target((PacDude.LEVEL_WIDTH / 8) - 2, PacDude.LEVEL_HEIGHT / 8); + + public BlinkyScatterBehaviour(PlayState state) { + super(state); + } + + @Override + public Target getTarget() { + return target; + } +} diff --git a/core/src/com/me/pacman/state/PlayState.java b/core/src/com/me/pacman/state/PlayState.java index 978e418..3f77564 100644 --- a/core/src/com/me/pacman/state/PlayState.java +++ b/core/src/com/me/pacman/state/PlayState.java @@ -12,6 +12,7 @@ import com.me.pacman.entity.Direction; import com.me.pacman.entity.Ghost; import com.me.pacman.entity.Pacman; import com.me.pacman.entity.ai.BlinkyChaseBehaviour; +import com.me.pacman.entity.ai.BlinkyScatterBehaviour; import com.me.pacman.level.Level; import com.me.pacman.level.LevelTile; @@ -189,8 +190,9 @@ public class PlayState extends LevelState { level = new Level(game,"level"); pacman = new Pacman(this, false); - ghosts[0] = new Ghost(this, 14, 19.5f, Direction.LEFT, 0, new BlinkyChaseBehaviour(this), null); - ghosts[0].currentBehaviour = ghosts[0].chaseBehaviour; + if (newGameTimer <= 0) { + placeGhosts(); + } game.assets.siren.stop(sirenId); @@ -213,8 +215,12 @@ public class PlayState extends LevelState { random = new Random(897198256012865L); pacman = new Pacman(this, false); - ghosts[0] = new Ghost(this, 14, 19.5f, Direction.LEFT, 0, new BlinkyChaseBehaviour(this), null); - ghosts[0].currentBehaviour = ghosts[0].chaseBehaviour; + placeGhosts(); + } + + public void placeGhosts() { + ghosts[0] = new Ghost(this, 14, 19.5f, Direction.LEFT, 0, new BlinkyChaseBehaviour(this), new BlinkyScatterBehaviour(this)); + ghosts[0].currentBehaviour = ghosts[0].scatterBehaviour; } public void startGame() {