Refactor
This commit is contained in:
parent
13d1948d48
commit
02a4c7d5ed
@ -1,6 +1,5 @@
|
|||||||
package com.me.pacman.entity;
|
package com.me.pacman.entity;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.me.pacman.PacDude;
|
import com.me.pacman.PacDude;
|
||||||
@ -26,7 +25,7 @@ public abstract class Entity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.renderSprite(texture, pos.x, pos.y);
|
state.drawSprite(texture, pos.x, pos.y);
|
||||||
|
|
||||||
if (PacDude.DEBUG) {
|
if (PacDude.DEBUG) {
|
||||||
state.level.renderTile(LevelTile.DEBUG, (int) pos.x, (int) pos.y, LevelState.LEVEL_OFFSET_X, LevelState.LEVEL_OFFSET_Y);
|
state.level.renderTile(LevelTile.DEBUG, (int) pos.x, (int) pos.y, LevelState.LEVEL_OFFSET_X, LevelState.LEVEL_OFFSET_Y);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.me.pacman.entity;
|
package com.me.pacman.entity;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.me.pacman.entity.ai.Behaviour;
|
import com.me.pacman.entity.ai.Behaviour;
|
||||||
@ -79,7 +78,7 @@ public class Ghost extends MovableEntity {
|
|||||||
|
|
||||||
// draw eyes so the ghost can see
|
// draw eyes so the ghost can see
|
||||||
if (state.frightTimer <= 0 || caught) {
|
if (state.frightTimer <= 0 || caught) {
|
||||||
state.renderSprite(sprite[1][currDirection.ordinal()], pos.x, pos.y);
|
state.drawSprite(sprite[1][currDirection.ordinal()], pos.x, pos.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ public abstract class LevelState extends State {
|
|||||||
super(game);
|
super(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderSprite(TextureRegion sprite, float x, float y) {
|
public void drawSprite(TextureRegion sprite, float x, float y) {
|
||||||
game.batch.draw(sprite, (int) (x * 8) + (LEVEL_OFFSET_X - 8), (int) (y * 8) + (LEVEL_OFFSET_Y - 8));
|
game.batch.draw(sprite, (int) (x * 8) + (LEVEL_OFFSET_X - 8), (int) (y * 8) + (LEVEL_OFFSET_Y - 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,6 +235,63 @@ public class PlayState extends LevelState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render() {
|
||||||
|
game.assets.getFont().setColor(Color.WHITE);
|
||||||
|
game.assets.getFont().draw(game.batch, "" + score, 40, 279);
|
||||||
|
for (int i = 0; i < lives; i++) {
|
||||||
|
game.batch.draw(lifeSprite, i * 16, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
level.render(LEVEL_OFFSET_X, LEVEL_OFFSET_Y);
|
||||||
|
|
||||||
|
if (state == GameState.ROUND_WON) {
|
||||||
|
// draw flashing level background
|
||||||
|
game.batch.draw((int) (stateTimer * 4) % 2 == 0? levelBackground : winBackground, LEVEL_OFFSET_X, LEVEL_OFFSET_Y);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
game.batch.draw(levelBackground, LEVEL_OFFSET_X, LEVEL_OFFSET_Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state != GameState.GHOST_CAUGHT_POINTS_WAIT) {
|
||||||
|
pacman.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
case PRE_NEW_GAME:
|
||||||
|
case PACMAN_CAUGHT:
|
||||||
|
case GAME_OVER:
|
||||||
|
break;
|
||||||
|
case GHOST_CAUGHT_POINTS_WAIT:
|
||||||
|
drawSprite(game.assets.points[0][ghostsCaught-1], lastGhostCaptured.pos.x, lastGhostCaptured.pos.y);
|
||||||
|
default:
|
||||||
|
for (Ghost ghost : ghosts) {
|
||||||
|
if (state == GameState.GHOST_CAUGHT_POINTS_WAIT && ghost == lastGhostCaptured) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ghost.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (paused) {
|
||||||
|
game.assets.getFont().setColor(Color.YELLOW);
|
||||||
|
game.assets.getFont().draw(game.batch, "paused", 90, 151);
|
||||||
|
} else {
|
||||||
|
switch (state) {
|
||||||
|
case PRE_NEW_GAME:
|
||||||
|
case NEW_ROUND_WAIT:
|
||||||
|
case START_ROUND_WAIT:
|
||||||
|
game.assets.getFont().setColor(Color.YELLOW);
|
||||||
|
game.assets.getFont().draw(game.batch, "ready!", 92, 127);
|
||||||
|
break;
|
||||||
|
case GAME_OVER:
|
||||||
|
game.assets.getFont().setColor(Color.RED);
|
||||||
|
game.assets.getFont().draw(game.batch, "game over", 78, 127);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void pelletEaten(float x, float y) {
|
private void pelletEaten(float x, float y) {
|
||||||
level.setTile(x, y, LevelTile.EMPTY);
|
level.setTile(x, y, LevelTile.EMPTY);
|
||||||
|
|
||||||
@ -305,63 +362,6 @@ public class PlayState extends LevelState {
|
|||||||
setGameState(GameState.GHOST_CAUGHT_POINTS_WAIT);
|
setGameState(GameState.GHOST_CAUGHT_POINTS_WAIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render() {
|
|
||||||
game.assets.getFont().setColor(Color.WHITE);
|
|
||||||
game.assets.getFont().draw(game.batch, "" + score, 40, 279);
|
|
||||||
for (int i = 0; i < lives; i++) {
|
|
||||||
game.batch.draw(lifeSprite, i * 16, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
level.render(LEVEL_OFFSET_X, LEVEL_OFFSET_Y);
|
|
||||||
|
|
||||||
if (state == GameState.ROUND_WON) {
|
|
||||||
// draw flashing level background
|
|
||||||
game.batch.draw((int) (stateTimer * 4) % 2 == 0? levelBackground : winBackground, LEVEL_OFFSET_X, LEVEL_OFFSET_Y);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
game.batch.draw(levelBackground, LEVEL_OFFSET_X, LEVEL_OFFSET_Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state != GameState.GHOST_CAUGHT_POINTS_WAIT) {
|
|
||||||
pacman.render();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (state) {
|
|
||||||
case PRE_NEW_GAME:
|
|
||||||
case PACMAN_CAUGHT:
|
|
||||||
case GAME_OVER:
|
|
||||||
break;
|
|
||||||
case GHOST_CAUGHT_POINTS_WAIT:
|
|
||||||
renderSprite(game.assets.points[0][ghostsCaught-1], lastGhostCaptured.pos.x, lastGhostCaptured.pos.y);
|
|
||||||
default:
|
|
||||||
for (Ghost ghost : ghosts) {
|
|
||||||
if (state == GameState.GHOST_CAUGHT_POINTS_WAIT && ghost == lastGhostCaptured) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ghost.render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (paused) {
|
|
||||||
game.assets.getFont().setColor(Color.YELLOW);
|
|
||||||
game.assets.getFont().draw(game.batch, "paused", 90, 151);
|
|
||||||
} else {
|
|
||||||
switch (state) {
|
|
||||||
case PRE_NEW_GAME:
|
|
||||||
case NEW_ROUND_WAIT:
|
|
||||||
case START_ROUND_WAIT:
|
|
||||||
game.assets.getFont().setColor(Color.YELLOW);
|
|
||||||
game.assets.getFont().draw(game.batch, "ready!", 92, 127);
|
|
||||||
break;
|
|
||||||
case GAME_OVER:
|
|
||||||
game.assets.getFont().setColor(Color.RED);
|
|
||||||
game.assets.getFont().draw(game.batch, "game over", 78, 127);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateScatterTimer(float dt) {
|
private void updateScatterTimer(float dt) {
|
||||||
if (scatterChaseTransition < 6) {
|
if (scatterChaseTransition < 6) {
|
||||||
scatterChaseTimer -= dt;
|
scatterChaseTimer -= dt;
|
||||||
|
Loading…
Reference in New Issue
Block a user