1 package ru
.deadsoftware
.cavecraft
.game
;
3 import com
.badlogic
.gdx
.Gdx
;
4 import com
.badlogic
.gdx
.graphics
.GL20
;
5 import com
.badlogic
.gdx
.graphics
.OrthographicCamera
;
6 import com
.badlogic
.gdx
.graphics
.glutils
.ShapeRenderer
;
7 import com
.badlogic
.gdx
.graphics
.Color
;
8 import ru
.deadsoftware
.cavecraft
.GameScreen
;
10 public class GameRenderer
{
12 private GameProc gameProc
;
14 OrthographicCamera camera
;
15 ShapeRenderer shapeRenderer
;
17 public GameRenderer(GameProc gameProc
) {
18 Gdx
.gl
.glClearColor(0f,.8f,.8f,1f);
19 this.gameProc
= gameProc
;
20 camera
= new OrthographicCamera();
21 camera
.setToOrtho(true, GameScreen
.getWidth(), GameScreen
.getHeight());
24 shapeRenderer
= new ShapeRenderer();
25 shapeRenderer
.setProjectionMatrix(camera
.combined
);
28 public void drawWorld() {
29 shapeRenderer
.setAutoShapeType(true);
30 shapeRenderer
.begin(ShapeRenderer
.ShapeType
.Filled
);
31 for (int y
=0; y
<gameProc
.world
.getHeight(); y
++) {
32 for (int x
=0; x
<gameProc
.world
.getWidth(); x
++) {
33 if (gameProc
.world
.getBackMap(x
,y
)>0) {
34 shapeRenderer
.setColor(Color
.DARK_GRAY
);
35 shapeRenderer
.rect(x
*32-camera
.position
.x
,
36 y
*32-camera
.position
.y
,32,32);
38 if (gameProc
.world
.getForeMap(x
,y
)>0) {
39 shapeRenderer
.setColor(Color
.GRAY
);
40 shapeRenderer
.rect(x
*32-camera
.position
.x
,
41 y
*32-camera
.position
.y
,32,32);
45 shapeRenderer
.setColor(Color
.ORANGE
);
46 shapeRenderer
.set(ShapeRenderer
.ShapeType
.Line
);
47 shapeRenderer
.rect(gameProc
.cursorX
*32-camera
.position
.x
,
48 gameProc
.cursorY
*32-camera
.position
.y
,32,32);
52 public void render() {
53 Gdx
.gl
.glClear(GL20
.GL_COLOR_BUFFER_BIT
);