diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
index b8b53249be9296363957889c991ae7bf377f5a80..e64ed135335265ce1d48948e10af7c1c0e7cac11 100644 (file)
package ru.deadsoftware.cavecraft.game;
import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2;
-import ru.deadsoftware.cavecraft.Assets;
-import ru.deadsoftware.cavecraft.CaveGame;
-import ru.deadsoftware.cavecraft.Items;
-import ru.deadsoftware.cavecraft.GameScreen;
+import ru.deadsoftware.cavecraft.*;
import ru.deadsoftware.cavecraft.game.mobs.Mob;
import ru.deadsoftware.cavecraft.game.objects.Player;
-public class GameRenderer {
+public class GameRenderer extends Renderer{
private GameProc gameProc;
- public OrthographicCamera camera, fontCam;
- ShapeRenderer shapeRenderer;
- SpriteBatch spriteBatch, fontBatch;
+ public OrthographicCamera fontCam;
+ SpriteBatch fontBatch;
public GameRenderer(GameProc gameProc) {
Gdx.gl.glClearColor(0f,.6f,.6f,1f);
Assets.minecraftFont.draw(fontBatch, str, x, y);
}
- private void drawWorld() {
- int minX = (int) (camera.position.x/16);
- int minY = (int) (camera.position.y/16);
+ private void drawWorldBackground() {
+ int minX = (int) (camera.position.x/16)-1;
+ int minY = (int) (camera.position.y/16)-1;
int maxX = (int) ((camera.position.x+camera.viewportWidth)/16)+1;
int maxY = (int) ((camera.position.y+camera.viewportHeight)/16)+1;
- if (minX<0) minX=0;
if (minY<0) minY=0;
- if (maxX>gameProc.world.getWidth()) maxX = gameProc.world.getWidth();
if (maxY>gameProc.world.getHeight()) maxY = gameProc.world.getHeight();
for (int y=minY; y<maxY; y++) {
for (int x=minX; x<maxX; x++) {
- if (gameProc.world.getForeMap(x,y)>0){/* &&
- !Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).foreground) {
- spriteBatch.draw(
- Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture(),
- x * 16 - camera.position.x,y * 16 - camera.position.y);*/
+ if (gameProc.world.getForeMap(x,y)>0){
} else if (gameProc.world.getBackMap(x,y)>0) {
spriteBatch.draw(
Items.BLOCKS.getValueAt(gameProc.world.getBackMap(x,y)).getTexture(),
}
private void drawWorldForeground(){
- int minX = (int) (camera.position.x/16);
- int minY = (int) (camera.position.y/16);
+ int minX = (int) (camera.position.x/16)-1;
+ int minY = (int) (camera.position.y/16)-1;
int maxX = (int) ((camera.position.x+camera.viewportWidth)/16)+1;
int maxY = (int) ((camera.position.y+camera.viewportHeight)/16)+1;
- if (minX<0) minX=0;
if (minY<0) minY=0;
- if (maxX>gameProc.world.getWidth()) maxX = gameProc.world.getWidth();
if (maxY>gameProc.world.getHeight()) maxY = gameProc.world.getHeight();
for (int y=minY; y<maxY; y++) {
for (int x=minX; x<maxX; x++) {
- if (gameProc.world.getForeMap(x,y)>0) { /*&&
- Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).foreground) {*/
+ if (gameProc.world.getForeMap(x,y)>0) {
spriteBatch.draw(
Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture(),
x * 16 - camera.position.x,y * 16 - camera.position.y);
}
private void drawMob(Mob mob) {
+ mob.draw(spriteBatch,
+ mob.position.x-camera.position.x-gameProc.world.getWidth()*16, mob.position.y-camera.position.y);
mob.draw(spriteBatch,
mob.position.x-camera.position.x, mob.position.y-camera.position.y);
+ mob.draw(spriteBatch,
+ mob.position.x-camera.position.x+gameProc.world.getWidth()*16, mob.position.y-camera.position.y);
}
private void drawPlayer(Player pl) {
}
private void drawGamePlay() {
- drawWorld();
+ drawWorldBackground();
Mob.animateMobs();
for (Mob mob : gameProc.mobs) drawMob(mob);
drawPlayer(gameProc.player);
drawGUI();
}
+ @Override
public void render() {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);