1010import uk .org .ulcompsoc .tesseract .components .Position ;
1111import uk .org .ulcompsoc .tesseract .components .RelativePosition ;
1212import uk .org .ulcompsoc .tesseract .components .Renderable ;
13+ import uk .org .ulcompsoc .tesseract .components .Renderable .Facing ;
1314import uk .org .ulcompsoc .tesseract .components .Stats ;
1415import uk .org .ulcompsoc .tesseract .components .Text ;
16+ import uk .org .ulcompsoc .tesseract .components .WorldPlayerInputListener ;
1517import uk .org .ulcompsoc .tesseract .systems .BattleAttackSystem ;
1618import uk .org .ulcompsoc .tesseract .systems .BattleDialogRenderSystem ;
1719import uk .org .ulcompsoc .tesseract .systems .BattleInputSystem ;
1820import uk .org .ulcompsoc .tesseract .systems .BattleMessageSystem ;
1921import uk .org .ulcompsoc .tesseract .systems .FocusTakingSystem ;
22+ import uk .org .ulcompsoc .tesseract .systems .MovementSystem ;
2023import uk .org .ulcompsoc .tesseract .systems .RenderSystem ;
2124import uk .org .ulcompsoc .tesseract .systems .TextRenderSystem ;
25+ import uk .org .ulcompsoc .tesseract .systems .WorldPlayerInputSystem ;
2226import uk .org .ulcompsoc .tesseract .tiled .TesseractMap ;
2327
2428import com .badlogic .ashley .core .Engine ;
2529import com .badlogic .ashley .core .Entity ;
2630import com .badlogic .gdx .Application ;
2731import com .badlogic .gdx .ApplicationAdapter ;
2832import com .badlogic .gdx .Gdx ;
33+ import com .badlogic .gdx .Input .Keys ;
2934import com .badlogic .gdx .graphics .Camera ;
3035import com .badlogic .gdx .graphics .Color ;
3136import com .badlogic .gdx .graphics .GL20 ;
4045import com .badlogic .gdx .math .Rectangle ;
4146
4247public class TesseractMain extends ApplicationAdapter {
48+ public static final String PLAYER_NAME = "Valiant Hero™" ;
49+
4350 private SpriteBatch batch = null ;
4451 private Camera camera = null ;
4552
@@ -68,8 +75,10 @@ public class TesseractMain extends ApplicationAdapter {
6875 private Entity rageText = null ;
6976
7077 public static final String [] mapNames = { "world1/world1.tmx" };
71- private TesseractMap [] maps = null ;
72- public static TesseractMap currentMap = null ;
78+ public static final Color [] mapColors = { new Color (80.0f / 255.0f , 172.0f / 255.0f , 61.0f / 255.0f ,
79+ 1.0f ) };
80+ private static TesseractMap [] maps = null ;
81+ public static int currentMapIndex = 0 ;
7382
7483 @ SuppressWarnings ("unused" )
7584 private GameState gameState = null ;
@@ -95,27 +104,11 @@ public void create() {
95104
96105 batch = new SpriteBatch ();
97106 camera = new OrthographicCamera (Gdx .graphics .getWidth (), Gdx .graphics .getHeight ());
98- ((OrthographicCamera ) camera ).setToOrtho (false , Gdx .graphics .getWidth () / 2 , Gdx .graphics .getHeight () / 2 );
99107
100- // if (Gdx.app.getType() == ApplicationType.WebGL) {
101108 font = new BitmapFont (Gdx .files .internal ("fonts/robotobm16.fnt" ), Gdx .files .internal ("fonts/robotobm16.png" ),
102109 false );
103110 bigFont = new BitmapFont (Gdx .files .internal ("fonts/robotobm24.fnt" ),
104111 Gdx .files .internal ("fonts/robotobm24.png" ), false );
105- // } else {
106- // com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator
107- // fontGenerator = new
108- // com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator(
109- // Gdx.files.internal("fonts/RobotoRegular.ttf"));
110- // com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter
111- // parameter = new
112- // com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter();
113- // parameter.size = 16;
114- // font = fontGenerator.generateFont(parameter);
115- // parameter.size = 24;
116- // bigFont = fontGenerator.generateFont(parameter);
117- // fontGenerator.dispose();
118- // }
119112
120113 playerTexture = new Texture (Gdx .files .internal ("player/basicPlayer.png" ));
121114 playerRegions = TextureRegion .split (playerTexture , WorldConstants .TILE_WIDTH , WorldConstants .TILE_HEIGHT )[0 ];
@@ -133,19 +126,40 @@ public void create() {
133126 initBattleEngine (battleEngine );
134127 initWorldEngine (worldEngine );
135128
136- currentEngine = worldEngine ;
129+ changeToWorld () ;
137130 }
138131
139132 @ Override
140133 public void render () {
141134 float deltaTime = Gdx .graphics .getDeltaTime ();
142135
143- Gdx .gl .glClearColor (0.0f , 0.8f , 0.0f , 0.0f );
136+ Gdx .gl .glClearColor (mapColors [currentMapIndex ].r , mapColors [currentMapIndex ].g , mapColors [currentMapIndex ].b ,
137+ mapColors [currentMapIndex ].a );
144138 Gdx .gl .glClear (GL20 .GL_COLOR_BUFFER_BIT );
145139
140+ if (Gdx .input .isKeyJustPressed (Keys .F10 )) {
141+ if (currentEngine .equals (battleEngine )) {
142+ changeToWorld ();
143+ } else {
144+ changeToBattle ();
145+ }
146+ }
146147 currentEngine .update (deltaTime );
147148 }
148149
150+ public void changeToBattle () {
151+ this .currentEngine = battleEngine ;
152+
153+ ((OrthographicCamera ) camera ).setToOrtho (false , Gdx .graphics .getWidth (), Gdx .graphics .getHeight ());
154+ camera .update ();
155+ }
156+
157+ public void changeToWorld () {
158+ this .currentEngine = worldEngine ;
159+ ((OrthographicCamera ) camera ).setToOrtho (false , Gdx .graphics .getWidth () / 2 , Gdx .graphics .getHeight () / 2 );
160+ camera .update ();
161+ }
162+
149163 public void initWorldEngine (Engine engine ) {
150164 maps = new TesseractMap [mapNames .length ];
151165 TmxMapLoader mapLoader = new TmxMapLoader ();
@@ -163,39 +177,44 @@ public void initWorldEngine(Engine engine) {
163177 engine .addEntity (maps [i ].zLayerEntity );
164178 }
165179
166- currentMap = maps [ 0 ] ;
180+ currentMapIndex = 0 ;
167181
168182 worldPlayerEntity = new Entity ();
169- worldPlayerEntity .add (new Renderable (playerRegions [1 ], playerRegions [0 ], playerRegions [3 ], playerRegions [ 2 ])
170- .setPrioritity (50 ));
171- worldPlayerEntity .add (currentMap .findPlayerPosition ());
183+ worldPlayerEntity .add (new Renderable (Facing . DOWN , playerRegions [1 ], playerRegions [0 ], playerRegions [3 ],
184+ playerRegions [ 2 ]) .setPrioritity (50 ));
185+ worldPlayerEntity .add (getCurrentMap () .findPlayerPosition ());
172186 worldPlayerEntity .add (new FocusTaker (camera ));
187+ worldPlayerEntity .add (new Player (PLAYER_NAME ));
188+ worldPlayerEntity .add (new WorldPlayerInputListener ());
173189
174190 engine .addEntity (worldPlayerEntity );
175191
192+ engine .addSystem (new WorldPlayerInputSystem (50 ));
193+ engine .addSystem (new MovementSystem (getCurrentMap (), 75 ));
194+ engine .addSystem (new FocusTakingSystem (100 ));
176195 engine .addSystem (new RenderSystem (batch , camera , 1000 ));
177- engine .addSystem (new FocusTakingSystem (10 ));
178196 }
179197
180198 public void initBattleEngine (Engine engine ) {
181- final int yTile = 12 ;
199+ final float yTile = 12 * WorldConstants . TILE_HEIGHT ;
182200
183201 battlePlayerEntity = new Entity ();
184202
185- battlePlayerEntity .add (new Position (17 , yTile ));
186- battlePlayerEntity .add (new Renderable (playerRegions [1 ], playerRegions [0 ], playerRegions [3 ], playerRegions [ 2 ])
187- .setPrioritity (50 ));
203+ battlePlayerEntity .add (new Position (17 * WorldConstants . TILE_WIDTH , yTile ));
204+ battlePlayerEntity .add (new Renderable (Facing . DOWN , playerRegions [1 ], playerRegions [0 ], playerRegions [3 ],
205+ playerRegions [ 2 ]) .setPrioritity (50 ));
188206 battlePlayerEntity .add (new Stats (100 , 25 , 4 ));
189207
190- Player playerComp = new Player ();
208+ Player playerComp = new Player (PLAYER_NAME );
191209 battlePlayerEntity .add (playerComp );
192210 battlePlayerEntity .add (new Named (playerComp .name ));
193211
194212 TextureRegion slimeRegion = TextureRegion .split (slimeTexture , WorldConstants .TILE_WIDTH ,
195213 WorldConstants .TILE_HEIGHT )[0 ][0 ];
196214
197215 slimeEntity = new Entity ();
198- slimeEntity .add (new Position (3 , yTile )).add (new Renderable (slimeRegion ).setPrioritity (50 ));
216+ slimeEntity .add (new Position (3 * WorldConstants .TILE_WIDTH , yTile )).add (
217+ new Renderable (slimeRegion ).setPrioritity (50 ));
199218 slimeEntity .add (new Stats (50 , 2 , 2 ));
200219
201220 Enemy slime1 = new Enemy ("Green Ooze" );
@@ -271,6 +290,10 @@ public void initBattleEngine(Engine engine) {
271290 engine .addSystem (new TextRenderSystem (batch , font , 3000 ));
272291 }
273292
293+ public static TesseractMap getCurrentMap () {
294+ return maps [currentMapIndex ];
295+ }
296+
274297 @ Override
275298 public void dispose () {
276299 super .dispose ();
0 commit comments