Render LevelComponents with sprites instead of shapes
This commit is contained in:
parent
8d6a9b7f97
commit
8336838fc4
@ -44,7 +44,9 @@ public class PacDude extends Game {
|
||||
Gdx.gl.glClearColor(0, 0, 0, 1);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
batch.begin();
|
||||
super.render();
|
||||
batch.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.me.pacman.level;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.me.pacman.PacDude;
|
||||
|
||||
public class Level {
|
||||
|
||||
@ -14,23 +14,29 @@ public class Level {
|
||||
components = loader.loadLevel();
|
||||
}
|
||||
|
||||
public void render(SpriteBatch batch, ShapeRenderer sr, int offsetX, int offsetY) {
|
||||
sr.begin(ShapeRenderer.ShapeType.Filled);
|
||||
sr.setColor(Color.valueOf("#f8b090"));
|
||||
public void render(PacDude game, int offsetX, int offsetY) {
|
||||
Texture sprites = game.assets.get("sprites/sprites_1.png");
|
||||
TextureRegion powerPellet = new TextureRegion(sprites, 16, 16, 8, 8);
|
||||
TextureRegion pellet = new TextureRegion(sprites, 24, 16, 8, 8);
|
||||
|
||||
for (int i = 0; i < components.length; i++) {
|
||||
LevelComponent[] row = components[i];
|
||||
for (int j = 0; j < row.length; j++) {
|
||||
LevelComponent component = row[j];
|
||||
TextureRegion sprite;
|
||||
switch (component) {
|
||||
case PELLET:
|
||||
sr.rect((j * 8) + (offsetX-1), (i * 8) + (offsetY-1), 2, 2);
|
||||
sprite = pellet;
|
||||
break;
|
||||
case POWER_PELLET:
|
||||
sprite = powerPellet;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
game.batch.draw(sprite, (j * 8) + offsetX + 8, (i * 8) + offsetY + 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sr.end();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ public class MenuState extends State {
|
||||
public void setup() {
|
||||
game.assets.load("level.png", Texture.class);
|
||||
game.assets.load("logo.png", Texture.class);
|
||||
game.assets.load("sprites/sprites_1.png", Texture.class);
|
||||
game.assets.finishLoading();
|
||||
|
||||
levelBackground = game.assets.get("level.png", Texture.class);
|
||||
@ -30,12 +31,9 @@ public class MenuState extends State {
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
level.render(game.batch, game.sr, 12, 28);
|
||||
|
||||
game.batch.begin();
|
||||
game.batch.draw(levelBackground, 0, 16);
|
||||
level.render(game, 0, 16);
|
||||
game.batch.draw(logo, 0, 124, 224, 120);
|
||||
game.batch.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user