Skip to content

Commit

Permalink
Boss fights, progress, more reasonable damage, bosses disappear
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtCoDFish committed Aug 25, 2014
1 parent 6ec1b9d commit dc8f557
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 37 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ Your cube planet has several different worlds to visit to beat bosses, become mo

Find out now!

Latest playable version at http://www.ulcompsoc.org.uk/ld30/ - *DOES NOT WORK FOR v0.3, USE JAR FROM RELEASES PAGE*
~~Latest playable version at http://www.ulcompsoc.org.uk/ld30/ - *DOES NOT WORK FOR v0.3, USE JAR FROM RELEASES PAGE*~~
Sorry, HTML version not supported for Ludum Dare release.

### Code Roadmap
1. ~~Basic Battle System~~
2. ~~Map Rendering, World Interactions and Random Battles~~
3. World Changes
4. Better Battle System - AI, Spells etc
4. ~~Better Battle System - AI, Spells etc~~
5. Cube
6. Inventory/Items/Weapons

Expand Down
93 changes: 80 additions & 13 deletions core/src/uk/org/ulcompsoc/tesseract/TesseractMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import uk.org.ulcompsoc.tesseract.animations.SlimeFrameResolver;
import uk.org.ulcompsoc.tesseract.battle.BattlePerformers;
import uk.org.ulcompsoc.tesseract.components.BattleDialog;
import uk.org.ulcompsoc.tesseract.components.Boss;
import uk.org.ulcompsoc.tesseract.components.Combatant;
import uk.org.ulcompsoc.tesseract.components.Enemy;
import uk.org.ulcompsoc.tesseract.components.FocusTaker;
Expand Down Expand Up @@ -54,6 +55,8 @@
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.math.GridPoint2;
Expand All @@ -74,6 +77,8 @@ public class TesseractMain extends ApplicationAdapter {

private ShaderProgram vortexProgram = null;

private FreeTypeFontGenerator fontGenerator = null;

private BitmapFont font10 = null;
private BitmapFont font12 = null;
private BitmapFont font16 = null;
Expand All @@ -90,6 +95,7 @@ public class TesseractMain extends ApplicationAdapter {
BattleVictoryListener battleVictoryListener = null;

private static boolean battleChangeFlag = false;
private static boolean bossIncomingFlag = false;
private static boolean worldChangeFlag = false;
private static boolean diffWorldFlag = false;
private float transitionTime = -1.0f;
Expand All @@ -105,6 +111,9 @@ public class TesseractMain extends ApplicationAdapter {

private Texture[] bossTextures = null;
private Animation[] bossAnims = null;
private Stats[] bossStats = { new Stats(250, 15, 10, 3),
new Stats(500, 15, 10, 5), new Stats(500, 40, 10, 5), new Stats(500, 40, 10, 5), new Stats(500, 40, 10, 5),
new Stats(500, 40, 10, 5) };

private DialogueFinishListener healNPCListener = null;
private DialogueFinishListener bossBattleListener = null;
Expand Down Expand Up @@ -174,14 +183,32 @@ public void create() {

loadShader();

font10 = new BitmapFont(Gdx.files.internal("fonts/robotobm10.fnt"), Gdx.files.internal("fonts/robotobm10.png"),
false);
font12 = new BitmapFont(Gdx.files.internal("fonts/robotobm12.fnt"), Gdx.files.internal("fonts/robotobm12.png"),
false);
font16 = new BitmapFont(Gdx.files.internal("fonts/robotobm16.fnt"), Gdx.files.internal("fonts/robotobm16.png"),
false);
font24 = new BitmapFont(Gdx.files.internal("fonts/robotobm24.fnt"), Gdx.files.internal("fonts/robotobm24.png"),
false);
fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/RobotoRegular.ttf"));
FreeTypeFontParameter para = new FreeTypeFontParameter();

para.size = 10;
font10 = fontGenerator.generateFont(para);
// font10 = new BitmapFont(Gdx.files.internal("fonts/robotobm10.fnt"),
// Gdx.files.internal("fonts/robotobm10.png"),
// false);

para.size = 12;
font12 = fontGenerator.generateFont(para);
// font12 = new BitmapFont(Gdx.files.internal("fonts/robotobm12.fnt"),
// Gdx.files.internal("fonts/robotobm12.png"),
// false);

para.size = 16;
font16 = fontGenerator.generateFont(para);
// font16 = new BitmapFont(Gdx.files.internal("fonts/robotobm16.fnt"),
// Gdx.files.internal("fonts/robotobm16.png"),
// false);

para.size = 24;
font24 = fontGenerator.generateFont(para);
// font24 = new BitmapFont(Gdx.files.internal("fonts/robotobm24.fnt"),
// Gdx.files.internal("fonts/robotobm24.png"),
// false);

playerTexture = new Texture(Gdx.files.internal("player/basicPlayer.png"));
playerRegions = TextureRegion.split(playerTexture, WorldConstants.TILE_WIDTH, WorldConstants.TILE_HEIGHT)[0];
Expand Down Expand Up @@ -246,39 +273,49 @@ public void render() {
} else if (battleChangeFlag) {
battleChangeFlag = false;
vortexOff();
changeToBattle();
changeToBattle(bossIncomingFlag);
}
}
}

currentEngine.update(deltaTime);
}

public void flagBattleChange() {
public void flagBattleChange(boolean boss) {
battleChangeFlag = true;
bossIncomingFlag = boss;
transitionTime = BATTLE_START_TRANSITION_TIME;
vortexOn();
}

public void flagWorldChange(boolean boss) {
worldChangeFlag = true;
diffWorldFlag = false;

if (boss) {
getCurrentMap().setBossBeaten();
}

transitionTime = BATTLE_END_TRANSITION_TIME;
}

public static boolean isTransitioning() {
return battleChangeFlag || worldChangeFlag;
}

public void changeToBattle() {
public void changeToBattle(boolean boss) {
Gdx.app.debug("BATTLE_CHANGE", "Changing to battle view.");

this.currentEngine = battleEngine;

((OrthographicCamera) camera).setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.update();

addSlimes(battleEngine, random.nextInt(3) + 1);
if (boss) {
addBoss(battleEngine);
} else {
addSlimes(battleEngine, random.nextInt(3) + 1);
}
battleEngine.getSystem(BattleMessageSystem.class).clearAllMessages();
}

Expand All @@ -291,6 +328,10 @@ public void changeToWorld(boolean diffWorld) {

this.currentEngine = worldEngines[currentMapIndex];

if (getCurrentMap().bossBeaten) {
currentEngine.removeEntity(getCurrentMap().bossEntity);
}

if (diffWorld) {
worldPlayerEntity.add(getCurrentMap().findPlayerPosition());
currentEngine.addEntity(worldPlayerEntity);
Expand Down Expand Up @@ -442,6 +483,27 @@ public void initBattleEngine(Engine engine) {
engine.addSystem(new TextRenderSystem(batch, font16, 3000));
}

private void addBoss(Engine engine) {
TesseractMap map = getCurrentMap();

if (map.bossBeaten) {
Gdx.app.debug("ADD_BOSS", "Trying to fight a boss for the second time.");
}

Entity boss = new Entity();
final float yMiddle = 12 * WorldConstants.TILE_HEIGHT;
boss.add(new Position(3 * WorldConstants.TILE_WIDTH, yMiddle));
boss.add(new Renderable(bossAnims[currentMapIndex]).setAnimationResolver(new PingPongFrameResolver(0.1f)));
boss.add(bossStats[currentMapIndex]);
boss.add(new Boss());
boss.add(new Combatant());
Enemy enemy = ComponentMapper.getFor(Enemy.class).get(map.bossEntity);
boss.add(enemy);
boss.add(new Named(enemy.speciesName));

engine.addEntity(boss);
}

private void addSlimes(Engine engine, int count) {
if (count < 1 || count > 3) {
throw new GdxRuntimeException("Only between 1-3 slimes supported.");
Expand Down Expand Up @@ -554,6 +616,7 @@ public void loadBossFiles() {

public void startBossBattle() {
Gdx.app.debug("BOSS_BATTLE", "Let's get ready to rumble.");
flagBattleChange(true);
}

public void healToFull() {
Expand All @@ -565,6 +628,10 @@ public void healToFull() {
public void dispose() {
super.dispose();

if (fontGenerator != null) {
fontGenerator.dispose();
}

for (TesseractMap map : maps) {
if (map != null) {
map.dispose();
Expand Down Expand Up @@ -675,7 +742,7 @@ public void receive(Signal<Entity> signal, Entity object) {

if (rand <= prob) {
monsterTilesVisited = 0;
flagBattleChange();
flagBattleChange(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package uk.org.ulcompsoc.tesseract.animations;

import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Animation.PlayMode;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

/**
* @author Ashley Davis (SgtCoDFish)
*/
public class PingPongFrameResolver extends AnimationFrameResolver {
boolean first = true;

public PingPongFrameResolver() {
this(0.0f);
Expand All @@ -19,4 +24,14 @@ public float resolveTime(float deltaTime) {
return animTime;
}

@Override
public TextureRegion resolveFrame(Animation anim, float deltaTime) {
if (first) {
anim.setPlayMode(PlayMode.LOOP_PINGPONG);
first = false;
}

return super.resolveFrame(anim, deltaTime);
}

}
4 changes: 1 addition & 3 deletions core/src/uk/org/ulcompsoc/tesseract/battle/BattleAttack.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package uk.org.ulcompsoc.tesseract.battle;

import java.util.Random;

import uk.org.ulcompsoc.tesseract.components.Stats;

import com.badlogic.ashley.core.Entity;
Expand All @@ -22,7 +20,7 @@ public BattleAttack(Entity attacker, Entity target, AttackType attackType) {

public static int resolveDamage(Stats attacker, Stats defender) {
double atk = attacker.getAttack() - defender.getDefence();
atk = atk + atk * (new Random().nextInt(11) - 5) * 0.1;
// atk = atk + atk * (new Random().nextInt(11) - 5) * 0.1;

return Math.max((int) Math.floor(atk), 1);
}
Expand Down
12 changes: 9 additions & 3 deletions core/src/uk/org/ulcompsoc/tesseract/battle/BattlePerformers.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import uk.org.ulcompsoc.tesseract.MouseClickPerformer;
import uk.org.ulcompsoc.tesseract.TesseractMain;
import uk.org.ulcompsoc.tesseract.TesseractStrings;
import uk.org.ulcompsoc.tesseract.WorldConstants;
import uk.org.ulcompsoc.tesseract.components.Combatant;
import uk.org.ulcompsoc.tesseract.components.Enemy;
import uk.org.ulcompsoc.tesseract.components.MouseClickListener;
import uk.org.ulcompsoc.tesseract.components.Position;
import uk.org.ulcompsoc.tesseract.components.Renderable;
import uk.org.ulcompsoc.tesseract.components.TargetMarker;
import uk.org.ulcompsoc.tesseract.systems.BattleAttackSystem;
import uk.org.ulcompsoc.tesseract.systems.BattleMessageSystem;
Expand Down Expand Up @@ -40,9 +41,12 @@ public void perform(Entity invoker, Engine engine) {
Entity e = enemies.get(i);
Vector2 pos = posMapper.get(e).position;

final Renderable r = ComponentMapper.getFor(Renderable.class).get(e);
final float imgW = r.width;
final float imgH = r.height;

e.add(new TargetMarker());
e.add(new MouseClickListener(new Rectangle(pos.x, pos.y, WorldConstants.TILE_WIDTH,
WorldConstants.TILE_HEIGHT), enemyTargetPerformer));
e.add(new MouseClickListener(new Rectangle(pos.x, pos.y, imgW, imgH), enemyTargetPerformer));
}
}
}
Expand All @@ -53,6 +57,7 @@ public static class DefendPerformer implements MouseClickPerformer {
public void perform(Entity invoker, Engine engine) {
// Gdx.app.debug("PERFORM_JUMP", "Performing defend.");
battleMessageSystem.addMessage(TesseractStrings.getDefendMessage());
ComponentMapper.getFor(Combatant.class).get(TesseractMain.battlePlayerEntity).addBuff(new DefenceBuff());
}
}

Expand All @@ -61,6 +66,7 @@ public static class QuaffPerformer implements MouseClickPerformer {
public void perform(Entity invoker, Engine engine) {
// Gdx.app.debug("PERFORM_QUAFF", "Performing a quaff.");
battleMessageSystem.addMessage(TesseractStrings.getQuaffMessage());
ComponentMapper.getFor(Combatant.class).get(TesseractMain.battlePlayerEntity).addBuff(new HealBuff(5));
}
}

Expand Down
6 changes: 5 additions & 1 deletion core/src/uk/org/ulcompsoc/tesseract/battle/DefenceBuff.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public class DefenceBuff implements BuffPerformer {
private Stats stats = null;
private int buffAmt = 0;

public DefenceBuff() {
this(5.0f);
}

public DefenceBuff(float duration) {
this.duration = duration;
}
Expand All @@ -26,7 +30,7 @@ public void doBuff(Entity target) {
this.target = target;
stats = statsMapper.get(target);

buffAmt = stats.getLevel();
buffAmt = stats.getDefence();

stats.fortitude += buffAmt;

Expand Down
6 changes: 5 additions & 1 deletion core/src/uk/org/ulcompsoc/tesseract/battle/HealBuff.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class HealBuff implements BuffPerformer {

private int healPerTick = 0;

public HealBuff(int ticks) {
this(5.0f, ticks);
}

public HealBuff(float duration, int ticks) {
this.duration = duration;
this.ticks = ticks;
Expand All @@ -34,7 +38,7 @@ public void doBuff(Entity target) {
this.target = target;
this.stats = statsMapper.get(target);

this.healPerTick = (int) Math.floor(stats.maxHP * 0.1f);
this.healPerTick = (int) Math.floor(stats.maxHP * 0.05f);
this.timeElapsed = 0.0f;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ public class Combatant extends Component {
public boolean hasHealAnimation = false;
public boolean hasThinkingAnimation = false;

public List<BuffPerformer> buffs = new ArrayList<BuffPerformer>();
public List<BuffPerformer> addedBuffs = new ArrayList<BuffPerformer>();
public List<BuffPerformer> updatingBuffs = new ArrayList<BuffPerformer>();

// changed in buffsystem
public float thinkingTime = -1.0f;

public void addBuff(BuffPerformer buff) {
addedBuffs.add(buff);
}

public boolean canAct() {
return thinkingTime < -0.5f;
}
Expand Down
Loading

0 comments on commit dc8f557

Please sign in to comment.