Skip to content

Commit

Permalink
Just a few more fixes
Browse files Browse the repository at this point in the history
- Fix FollowPath crash when path has null points
- Player does not update in transition phase
- Walk sfx matches with animation
- Fix hitbox sprite drawing in old position for one frame
  • Loading branch information
nrebei2 committed May 22, 2023
1 parent 3714046 commit 9d519f1
Show file tree
Hide file tree
Showing 14 changed files with 345 additions and 239 deletions.
Binary file removed assets/dash.wav
Binary file not shown.
4 changes: 2 additions & 2 deletions assets/jsons/enemies.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"damage": 1,
"cooldown": 2,
"length": 0.3,
"immunity": 0.2,
"immunity": 0.1,
"lockout": 0.3,
"hitbox": {
"range": 0.75,
Expand Down Expand Up @@ -251,7 +251,7 @@
"range": 4,
"cooldown": 3,
"length": 0.3,
"immunity": 0.3,
"immunity": 0.1,
"lockout": 0.3
},
"arrow": {
Expand Down
4 changes: 2 additions & 2 deletions assets/jsons/player.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@
},
"health": 5,
"attack": {
"knockback": 0.8,
"knockback": 0.55,
"damage": 1.0,
"cooldown": 0.08,
"length": 0.7,
"immunity": 0.35,
"immunity": 0.175,
"lockout": 0.5,
"hitbox": {
"range": 1,
Expand Down
1 change: 1 addition & 0 deletions core/src/infinityx/lunarhaze/ai/FollowPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public FollowPath(Steerable<Vector2> owner, Path<Vector2, P> path, float pathOff

@Override
protected SteeringAcceleration<Vector2> calculateRealSteering(SteeringAcceleration<Vector2> steering) {
if (path == null) return steering.setZero();

// Predictive or non-predictive behavior?
Vector2 location = (predictionTime == 0) ?
Expand Down
2 changes: 2 additions & 0 deletions core/src/infinityx/lunarhaze/combat/MeleeHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package infinityx.lunarhaze.combat;

import com.badlogic.gdx.Gdx;
import infinityx.lunarhaze.models.AttackingGameObject;

/**
Expand All @@ -25,6 +26,7 @@ public void initiateAttack() {
super.initiateAttack();
hitbox.animation.reset();
hitbox.setActive(true);
hitbox.updateHitboxPosition();
}

@Override
Expand Down
10 changes: 4 additions & 6 deletions core/src/infinityx/lunarhaze/controllers/GameplayController.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ public void resolveActions(float delta) {

// FSM for state and phase
if (gameState == GameState.PLAY) {
// Process the player only when the game is in play
playerController.update(delta, phase, lightingController);
switch (phase) {
case STEALTH:
lightingController.update(delta);
Expand Down Expand Up @@ -253,10 +251,10 @@ public void resolveActions(float delta) {
fail_sound.play(volume);
}
}
}
// Enemies should still update even when game is outside play
if (!(phase == Phase.TRANSITION || phase == Phase.ALLOCATE)) {
resolveEnemies(delta);
if (!(phase == Phase.TRANSITION || phase == Phase.ALLOCATE)) {
playerController.update(delta, phase, lightingController);
resolveEnemies(delta);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions core/src/infinityx/lunarhaze/controllers/LevelParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ private Board parseBoard(AssetDirectory directory, JsonValue boardFormat, RayHan
point.setColor(color[0], color[1], color[2], color[3]);
point.setSoft(light.getBoolean("soft"));
point.setStaticLight(true);
point.setXray(true);
board.setSpotlight(x, y, point);
board.setLit(x, y, false);
}
Expand Down
23 changes: 1 addition & 22 deletions core/src/infinityx/lunarhaze/controllers/PlayerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class PlayerController {
/**
* Sound for player walking on grass
*/
private Sound walk_sound;
public Sound walk_sound;

/**
* Handles attacking logic
Expand All @@ -116,16 +116,6 @@ public class PlayerController {
*/
private Boolean allocateReady;

/**
* Whether the walk_grass sound is playing
*/
private boolean isWalkGrassPlaying;

/**
* Whether the dash_sound sound is playing
*/
private boolean isDashPlaying;

private GameSetting setting;

/**
Expand Down Expand Up @@ -212,8 +202,6 @@ public PlayerController(LevelContainer levelContainer, GameSetting setting) {
stateMachine = new DefaultStateMachine<>(this, PlayerState.IDLE);
attackHandler = new PlayerAttackHandler(player, player.getAttackHitbox(), dash_sound);
allocateReady = false;
isWalkGrassPlaying = false;
isDashPlaying = false;
this.setting = setting;
}

Expand All @@ -230,15 +218,6 @@ public void resolvePlayer(float delta) {
if (setting.isSoundEnabled()) {
if (!player.isAttacked() && inputController.justDash() && attackHandler.isDashing) {
dash_sound.play(setting.getSoundVolume());
} else if (getStateMachine().isInState(PlayerState.WALK) && !isWalkGrassPlaying) {
long soundId = walk_sound.loop();
walk_sound.setLooping(soundId, true);
walk_sound.play(setting.getSoundVolume());
isWalkGrassPlaying = true;
}
if (!getStateMachine().isInState(PlayerState.WALK)) {
walk_sound.stop();
isWalkGrassPlaying = false;
}
}
}
Expand Down
32 changes: 29 additions & 3 deletions core/src/infinityx/lunarhaze/controllers/PlayerState.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ public void update(PlayerController entity) {
*/
Direction direction;

/** Cache of previous frame, used to match step with animation */
int frame;

@Override
public void enter(PlayerController entity) {
direction = entity.player.direction;
setTexture(entity, "walk");
entity.player.setTargetStealth(entity.player.getTargetStealth() + PlayerController.WALK_STEALTH);
frame = -1;
}

@Override
Expand All @@ -84,9 +88,31 @@ public void update(PlayerController entity) {


// Animations
if (entity.player.direction == direction) return;
setTexture(entity, "walk");
direction = entity.player.direction;
if (entity.player.direction != direction) {
setTexture(entity, "walk");
direction = entity.player.direction;
}

// Walk sound
if (!entity.getSetting().isSoundEnabled() || frame == entity.player.animation.getCurFrame()) return;
frame = entity.player.animation.getCurFrame();
// match sound with frames
if (entity.player.isWerewolf()) {
if (frame == 2 || frame == 5) {
entity.walk_sound.play();
}
} else {
if (direction == Direction.DOWN) {
// special case
if (frame == 0 || frame == 4) {
entity.walk_sound.play();
}
} else {
if (frame == 0 || frame == 2) {
entity.walk_sound.play();
}
}
}
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions core/src/infinityx/lunarhaze/graphics/Animation.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ public float[] getFrameDurations(String name) {
return animationData.frameDurations;
}

/**
* @return Current active frame for the current animation
*/
public int getCurFrame() {
return currentAnimation.filmStrip.getFrame();
}

/**
* Sets the frame durations array for the specified Animation.
*
Expand Down
5 changes: 5 additions & 0 deletions core/src/infinityx/lunarhaze/models/entity/Enemy.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ public Enemy() {
@Override
public void reset() {
hp = maxHp;
isAttacking = isAttacked = false;
canMove = true;
isImmune = false;
lockedOut = false;

detection = Detection.NONE;
tint.set(Color.WHITE);
setScale(1);
Expand Down
9 changes: 9 additions & 0 deletions core/src/infinityx/lunarhaze/models/entity/Werewolf.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public class Werewolf extends AttackingGameObject implements Location<Vector2> {

private ParticleEffect dashParticle;

/** Whether lycan has transitioned into a werewolf */
private boolean isWerewolf;

/**
* Required information to switch to werewolf
*/
Expand Down Expand Up @@ -187,6 +190,11 @@ public Werewolf() {
isHeavyAttacking = false;
isDashing = false;
inTallGrass = new Array<>();
isWerewolf = false;
}

public boolean isWerewolf() {
return isWerewolf;
}

/**
Expand All @@ -198,6 +206,7 @@ public void switchToWolf() {
setTexture("idle-r");
textureScale = werewolfInfo.textureScale;
walkSpeed = 2.2f;
isWerewolf = true;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions core/src/infinityx/util/astar/AStarPathFinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public Path findPath(Vector2 source, Vector2 target) {
}
}

if (sourceNode == null || targetNode == null) {
return null;
}

connectionPath.clear();
pathfinder.searchNodePath(sourceNode, targetNode, heuristic, connectionPath);

Expand Down
Loading

0 comments on commit 9d519f1

Please sign in to comment.