From ea4426f0a08b906c316d901c61e5dc0e544eb98b Mon Sep 17 00:00:00 2001 From: Matt Low Date: Tue, 24 Dec 2019 22:56:31 +0400 Subject: [PATCH] Dot eater --- core/src/com/me/pacman/entity/Pacman.java | 15 +++++++++++++++ core/src/com/me/pacman/level/Level.java | 4 ++++ .../com/me/pacman/desktop/DesktopLauncher.java | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/src/com/me/pacman/entity/Pacman.java b/core/src/com/me/pacman/entity/Pacman.java index 9d0ac9b..e335134 100644 --- a/core/src/com/me/pacman/entity/Pacman.java +++ b/core/src/com/me/pacman/entity/Pacman.java @@ -1,6 +1,7 @@ package com.me.pacman.entity; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.me.pacman.level.LevelTile; import com.me.pacman.state.PlayState; public class Pacman extends MovableEntity { @@ -10,6 +11,8 @@ public class Pacman extends MovableEntity { private PlayState state; private int counter = 1; + private int freezeFrames = 0; + public Pacman(PlayState state) { super(state, 14, 7.5f, 7.5f, true, Direction.EAST, 0.3f); this.state = state; @@ -38,11 +41,23 @@ public class Pacman extends MovableEntity { @Override public void update(float dt) { + if (freezeFrames > 0) { + freezeFrames--; + return; + } + super.update(dt); if (!state.paused && canMove && age % 4 == 0) { counter += 1; } + + switch (state.level.getComponent(x, y)) { + case PELLET: + state.level.setComponent(x, y, LevelTile.EMPTY); + freezeFrames = 1; + break; + } } } diff --git a/core/src/com/me/pacman/level/Level.java b/core/src/com/me/pacman/level/Level.java index 044cad6..aaec5b8 100644 --- a/core/src/com/me/pacman/level/Level.java +++ b/core/src/com/me/pacman/level/Level.java @@ -36,6 +36,10 @@ public class Level { components[y][x] = component; } + public void setComponent(float x, float y, LevelTile component) { + setComponent((int) x, (int) y, component); + } + public void render(int offsetX, int offsetY) { for (int i = 0; i < components.length; i++) { LevelTile[] row = components[i]; diff --git a/desktop/src/com/me/pacman/desktop/DesktopLauncher.java b/desktop/src/com/me/pacman/desktop/DesktopLauncher.java index acb5da2..e724421 100644 --- a/desktop/src/com/me/pacman/desktop/DesktopLauncher.java +++ b/desktop/src/com/me/pacman/desktop/DesktopLauncher.java @@ -10,7 +10,7 @@ public class DesktopLauncher { config.title = PacDude.TITLE + " - " + PacDude.VERSION; config.width = PacDude.LEVEL_WIDTH * 2; config.height = PacDude.LEVEL_HEIGHT * 2; - config.resizable = true; + config.resizable = false; new LwjglApplication(new PacDude(), config); } }