66import uk .org .ulcompsoc .tesseract .animations .SlimeFrameResolver ;
77import uk .org .ulcompsoc .tesseract .battle .BattlePerformers ;
88import uk .org .ulcompsoc .tesseract .components .BattleDialog ;
9+ import uk .org .ulcompsoc .tesseract .components .Boss ;
910import uk .org .ulcompsoc .tesseract .components .Combatant ;
1011import uk .org .ulcompsoc .tesseract .components .Enemy ;
1112import uk .org .ulcompsoc .tesseract .components .FocusTaker ;
5455import com .badlogic .gdx .graphics .g2d .BitmapFont ;
5556import com .badlogic .gdx .graphics .g2d .SpriteBatch ;
5657import com .badlogic .gdx .graphics .g2d .TextureRegion ;
58+ import com .badlogic .gdx .graphics .g2d .freetype .FreeTypeFontGenerator ;
59+ import com .badlogic .gdx .graphics .g2d .freetype .FreeTypeFontGenerator .FreeTypeFontParameter ;
5760import com .badlogic .gdx .graphics .glutils .ShaderProgram ;
5861import com .badlogic .gdx .maps .tiled .TmxMapLoader ;
5962import com .badlogic .gdx .math .GridPoint2 ;
@@ -74,6 +77,8 @@ public class TesseractMain extends ApplicationAdapter {
7477
7578 private ShaderProgram vortexProgram = null ;
7679
80+ private FreeTypeFontGenerator fontGenerator = null ;
81+
7782 private BitmapFont font10 = null ;
7883 private BitmapFont font12 = null ;
7984 private BitmapFont font16 = null ;
@@ -90,6 +95,7 @@ public class TesseractMain extends ApplicationAdapter {
9095 BattleVictoryListener battleVictoryListener = null ;
9196
9297 private static boolean battleChangeFlag = false ;
98+ private static boolean bossIncomingFlag = false ;
9399 private static boolean worldChangeFlag = false ;
94100 private static boolean diffWorldFlag = false ;
95101 private float transitionTime = -1.0f ;
@@ -105,6 +111,9 @@ public class TesseractMain extends ApplicationAdapter {
105111
106112 private Texture [] bossTextures = null ;
107113 private Animation [] bossAnims = null ;
114+ private Stats [] bossStats = { new Stats (250 , 15 , 10 , 3 ),
115+ new Stats (500 , 15 , 10 , 5 ), new Stats (500 , 40 , 10 , 5 ), new Stats (500 , 40 , 10 , 5 ), new Stats (500 , 40 , 10 , 5 ),
116+ new Stats (500 , 40 , 10 , 5 ) };
108117
109118 private DialogueFinishListener healNPCListener = null ;
110119 private DialogueFinishListener bossBattleListener = null ;
@@ -174,14 +183,32 @@ public void create() {
174183
175184 loadShader ();
176185
177- font10 = new BitmapFont (Gdx .files .internal ("fonts/robotobm10.fnt" ), Gdx .files .internal ("fonts/robotobm10.png" ),
178- false );
179- font12 = new BitmapFont (Gdx .files .internal ("fonts/robotobm12.fnt" ), Gdx .files .internal ("fonts/robotobm12.png" ),
180- false );
181- font16 = new BitmapFont (Gdx .files .internal ("fonts/robotobm16.fnt" ), Gdx .files .internal ("fonts/robotobm16.png" ),
182- false );
183- font24 = new BitmapFont (Gdx .files .internal ("fonts/robotobm24.fnt" ), Gdx .files .internal ("fonts/robotobm24.png" ),
184- false );
186+ fontGenerator = new FreeTypeFontGenerator (Gdx .files .internal ("fonts/RobotoRegular.ttf" ));
187+ FreeTypeFontParameter para = new FreeTypeFontParameter ();
188+
189+ para .size = 10 ;
190+ font10 = fontGenerator .generateFont (para );
191+ // font10 = new BitmapFont(Gdx.files.internal("fonts/robotobm10.fnt"),
192+ // Gdx.files.internal("fonts/robotobm10.png"),
193+ // false);
194+
195+ para .size = 12 ;
196+ font12 = fontGenerator .generateFont (para );
197+ // font12 = new BitmapFont(Gdx.files.internal("fonts/robotobm12.fnt"),
198+ // Gdx.files.internal("fonts/robotobm12.png"),
199+ // false);
200+
201+ para .size = 16 ;
202+ font16 = fontGenerator .generateFont (para );
203+ // font16 = new BitmapFont(Gdx.files.internal("fonts/robotobm16.fnt"),
204+ // Gdx.files.internal("fonts/robotobm16.png"),
205+ // false);
206+
207+ para .size = 24 ;
208+ font24 = fontGenerator .generateFont (para );
209+ // font24 = new BitmapFont(Gdx.files.internal("fonts/robotobm24.fnt"),
210+ // Gdx.files.internal("fonts/robotobm24.png"),
211+ // false);
185212
186213 playerTexture = new Texture (Gdx .files .internal ("player/basicPlayer.png" ));
187214 playerRegions = TextureRegion .split (playerTexture , WorldConstants .TILE_WIDTH , WorldConstants .TILE_HEIGHT )[0 ];
@@ -246,39 +273,49 @@ public void render() {
246273 } else if (battleChangeFlag ) {
247274 battleChangeFlag = false ;
248275 vortexOff ();
249- changeToBattle ();
276+ changeToBattle (bossIncomingFlag );
250277 }
251278 }
252279 }
253280
254281 currentEngine .update (deltaTime );
255282 }
256283
257- public void flagBattleChange () {
284+ public void flagBattleChange (boolean boss ) {
258285 battleChangeFlag = true ;
286+ bossIncomingFlag = boss ;
259287 transitionTime = BATTLE_START_TRANSITION_TIME ;
260288 vortexOn ();
261289 }
262290
263291 public void flagWorldChange (boolean boss ) {
264292 worldChangeFlag = true ;
265293 diffWorldFlag = false ;
294+
295+ if (boss ) {
296+ getCurrentMap ().setBossBeaten ();
297+ }
298+
266299 transitionTime = BATTLE_END_TRANSITION_TIME ;
267300 }
268301
269302 public static boolean isTransitioning () {
270303 return battleChangeFlag || worldChangeFlag ;
271304 }
272305
273- public void changeToBattle () {
306+ public void changeToBattle (boolean boss ) {
274307 Gdx .app .debug ("BATTLE_CHANGE" , "Changing to battle view." );
275308
276309 this .currentEngine = battleEngine ;
277310
278311 ((OrthographicCamera ) camera ).setToOrtho (false , Gdx .graphics .getWidth (), Gdx .graphics .getHeight ());
279312 camera .update ();
280313
281- addSlimes (battleEngine , random .nextInt (3 ) + 1 );
314+ if (boss ) {
315+ addBoss (battleEngine );
316+ } else {
317+ addSlimes (battleEngine , random .nextInt (3 ) + 1 );
318+ }
282319 battleEngine .getSystem (BattleMessageSystem .class ).clearAllMessages ();
283320 }
284321
@@ -291,6 +328,10 @@ public void changeToWorld(boolean diffWorld) {
291328
292329 this .currentEngine = worldEngines [currentMapIndex ];
293330
331+ if (getCurrentMap ().bossBeaten ) {
332+ currentEngine .removeEntity (getCurrentMap ().bossEntity );
333+ }
334+
294335 if (diffWorld ) {
295336 worldPlayerEntity .add (getCurrentMap ().findPlayerPosition ());
296337 currentEngine .addEntity (worldPlayerEntity );
@@ -442,6 +483,27 @@ public void initBattleEngine(Engine engine) {
442483 engine .addSystem (new TextRenderSystem (batch , font16 , 3000 ));
443484 }
444485
486+ private void addBoss (Engine engine ) {
487+ TesseractMap map = getCurrentMap ();
488+
489+ if (map .bossBeaten ) {
490+ Gdx .app .debug ("ADD_BOSS" , "Trying to fight a boss for the second time." );
491+ }
492+
493+ Entity boss = new Entity ();
494+ final float yMiddle = 12 * WorldConstants .TILE_HEIGHT ;
495+ boss .add (new Position (3 * WorldConstants .TILE_WIDTH , yMiddle ));
496+ boss .add (new Renderable (bossAnims [currentMapIndex ]).setAnimationResolver (new PingPongFrameResolver (0.1f )));
497+ boss .add (bossStats [currentMapIndex ]);
498+ boss .add (new Boss ());
499+ boss .add (new Combatant ());
500+ Enemy enemy = ComponentMapper .getFor (Enemy .class ).get (map .bossEntity );
501+ boss .add (enemy );
502+ boss .add (new Named (enemy .speciesName ));
503+
504+ engine .addEntity (boss );
505+ }
506+
445507 private void addSlimes (Engine engine , int count ) {
446508 if (count < 1 || count > 3 ) {
447509 throw new GdxRuntimeException ("Only between 1-3 slimes supported." );
@@ -554,6 +616,7 @@ public void loadBossFiles() {
554616
555617 public void startBossBattle () {
556618 Gdx .app .debug ("BOSS_BATTLE" , "Let's get ready to rumble." );
619+ flagBattleChange (true );
557620 }
558621
559622 public void healToFull () {
@@ -565,6 +628,10 @@ public void healToFull() {
565628 public void dispose () {
566629 super .dispose ();
567630
631+ if (fontGenerator != null ) {
632+ fontGenerator .dispose ();
633+ }
634+
568635 for (TesseractMap map : maps ) {
569636 if (map != null ) {
570637 map .dispose ();
@@ -675,7 +742,7 @@ public void receive(Signal<Entity> signal, Entity object) {
675742
676743 if (rand <= prob ) {
677744 monsterTilesVisited = 0 ;
678- flagBattleChange ();
745+ flagBattleChange (false );
679746 }
680747 }
681748 }
0 commit comments