diff --git a/package-lock.json b/package-lock.json index dcc5983..92c6b0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "reapers", - "version": "1.0.0-alpha5", + "version": "1.0.0-alpha6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "reapers", - "version": "1.0.0-alpha5", + "version": "1.0.0-alpha6", "license": "Apache-2.0", "dependencies": { "kontra": "^8.0.0", diff --git a/package.json b/package.json index 4f7355e..8e1e640 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "reapers", - "version": "1.0.0-alpha5", + "version": "1.0.0-alpha6", "description": "The Reapers: Tournament of Destiny is a JS fighting game for the js13kGames 2022 competition", "keywords": [ "game", diff --git a/src/code/data/Attacks.ts b/src/code/data/Attacks.ts index 530d899..0f25126 100644 --- a/src/code/data/Attacks.ts +++ b/src/code/data/Attacks.ts @@ -2,22 +2,11 @@ import { Attack } from "../types/Attack"; export const Jab: Attack = { damage: 10, - startup: 5, - active: 4, - recovery: 4, + startup: 15, + active: 12, + recovery: 12, width: 18, height: 10, y: 10, - advantage: -1, -}; - -export const Strong: Attack = { - damage: 20, - startup: 5, - active: 8, - recovery: 8, - width: 20, - height: 20, - y: 2, - advantage: 2, + advantage: -10, }; diff --git a/src/code/functions/CheckFighterCollisions.ts b/src/code/functions/CheckFighterCollisions.ts index 1fcfdab..f41b8ef 100644 --- a/src/code/functions/CheckFighterCollisions.ts +++ b/src/code/functions/CheckFighterCollisions.ts @@ -1,43 +1,75 @@ import { collides } from "kontra"; import { canvas, player1, player2 } from "../data/Instances"; import { fighterWalkSpeed } from "../data/Constants"; -import { TrainingData } from "../modules/TrainingPanel/TrainingPanel"; import { GameConfig } from "../data/GameConfig"; export default function CheckFighterCollisions() { // Player collisions if (collides(player1.hitbox, player2.hitbox)) { - if (player1.hitbox.dx > 0 && player2.hitbox.dx === 0) { + // Player 1 is moving, player 2 is not + if (player1.hitbox.dx != 0 && player2.hitbox.dx === 0) { + // Push player 2 back if (player2.hitbox.x + player2.hitbox.width < canvas.width) { player2.hitbox.x += fighterWalkSpeed; } + + // Don't let player 1 move past player 2 in corner if (player2.hitbox.x + player2.hitbox.width === canvas.width) { - player1.hitbox.x = player1.hitbox.x - 1; + player1.hitbox.x -= fighterWalkSpeed; + } + + // Player 2 is moving, player 1 is not + } else if (player2.hitbox.dx != 0 && player1.hitbox.dx === 0) { + // Push player 1 back + if (player1.hitbox.x > 0) { + player1.hitbox.x -= fighterWalkSpeed; + } + + // Don't let player 2 move past player 1 in corner + if (player1.hitbox.x === 0) { + player2.hitbox.x += fighterWalkSpeed; + } + + // Both players are colliding, and both are moving or aren't moving at all + } else { + // If both players are pushing each other, don't move them + if (player1.hitbox.dx > 0 && player2.hitbox.dx < 0) { + player1.hitbox.x += -fighterWalkSpeed; + player2.hitbox.x += fighterWalkSpeed; } } } - // Player 1 hits player 2 - if (collides(player1.hurtbox, player2.hitbox)) { - player2.hitboxColor = "red"; - if (player1.doingAttack) { - if (!player1.attackAlreadyHit) { - if (player1.doingAttack.damage >= player2.health) { - player2.sprite.playAnimation("ko"); - player1.attackAlreadyHit = true; + // Player hits + if ( + collides(player1.hurtbox, player2.hitbox) || + collides(player2.hurtbox, player1.hitbox) + ) { + const whoIsHurt = collides(player1.hurtbox, player2.hitbox) + ? player2 + : player1; + const whoIsAttacking = collides(player1.hurtbox, player2.hitbox) + ? player1 + : player2; + + whoIsHurt.hitboxColor = "red"; + if (whoIsAttacking.doingAttack) { + if (!whoIsAttacking.attackAlreadyHit) { + if (whoIsAttacking.doingAttack.damage >= whoIsHurt.health) { + whoIsHurt.sprite.playAnimation("ko"); + whoIsAttacking.attackAlreadyHit = true; GameConfig.fightersCanAct = false; - player2.health = 0; - player1.roundsWon += 1; + whoIsHurt.health = 0; + whoIsAttacking.roundsWon += 1; } else { - player2.sprite.playAnimation("hit"); - player2.recoil = 10; - player2.health -= player1.doingAttack.damage; - player2.canMove = false; - player2.stun = - player1.attackingFrames + player1.doingAttack.advantage; - TrainingData.frameAdvantage = player1.doingAttack.advantage; - TrainingData.damage = player1.doingAttack.damage; - player1.attackAlreadyHit = true; + whoIsHurt.sprite.playAnimation("hit"); + whoIsHurt.recoil = 10; + whoIsHurt.health -= whoIsAttacking.doingAttack.damage; + whoIsHurt.canMove = false; + whoIsHurt.stun = + whoIsAttacking.attackingFrames + + whoIsAttacking.doingAttack.advantage; + whoIsAttacking.attackAlreadyHit = true; } } } diff --git a/src/code/functions/PrepareFightScene.ts b/src/code/functions/PrepareFightScene.ts index 4b3ccb5..00fe948 100644 --- a/src/code/functions/PrepareFightScene.ts +++ b/src/code/functions/PrepareFightScene.ts @@ -11,6 +11,7 @@ import { WinScreen } from "../modules/WinScreen/WinScreen"; import { GameConfig } from "../data/GameConfig"; import CheckGameState from "./CheckGameState"; import CheckFighterCollisions from "./CheckFighterCollisions"; +import { toggleTrainingPanel } from "../modules/TrainingPanel/TrainingPanel"; export default function PrepareFightScene() { fightScene.add([ @@ -24,6 +25,7 @@ export default function PrepareFightScene() { ]); fightScene.update = function (dt) { + toggleTrainingPanel(); CheckFighterCollisions(); if (GameConfig.fightersCanAct === false) { CheckGameState(dt); diff --git a/src/code/modules/TrainingPanel/TrainingPanel.ts b/src/code/modules/TrainingPanel/TrainingPanel.ts index 622e146..1d74448 100644 --- a/src/code/modules/TrainingPanel/TrainingPanel.ts +++ b/src/code/modules/TrainingPanel/TrainingPanel.ts @@ -1,23 +1,5 @@ import { GameConfig } from "../../data/GameConfig"; -import { renderText } from "../../data/Instances"; -import { onKey, GameObject } from "kontra"; - -let lastMove = ""; -let lastWrite = 0; - -interface TrainingData { - attackFrames: number; - frameAdvantage: number; - damage: number; -} - -export const TrainingData: TrainingData = { - attackFrames: 0, - frameAdvantage: 0, - damage: 0, -}; - -const moveList: string[] = []; +import { onKey } from "kontra"; export const toggleTrainingPanel = () => { onKey("t", () => { @@ -28,70 +10,3 @@ export const toggleTrainingPanel = () => { export const isTrainingPanelEnabled = () => { return GameConfig.showTrainingData ? true : false; }; - -const TrainingPanelText = GameObject({ - x: 2, - y: 2, - render: function () { - renderText(`ATTACK FRAMES: ${TrainingData.attackFrames}`, 0, 0, 5, "white"); - renderText( - `FRAME ADVANTAGE: ${TrainingData.frameAdvantage}`, - 0, - 6, - 5, - "white" - ); - renderText(`DAMAGE: ${TrainingData.damage}`, 0, 12, 5, "white"); - }, -}); - -/* -const TrainingPanelMoveList = Text({ - text: `${moveList.join("\n")}`, - x: -68, - y: 36, - font: "8px monospace", -}); -*/ - -export const TrainingPanelMoveList = GameObject({}); - -export const addMoveToTrainingPanel = (moves: string[]) => { - function updateMoves(moves: string) { - moveList.unshift(moves); - TrainingPanelMoveList.text = `${moveList.join("\n")}`; - lastWrite = 8; - } - - const currentMove: string = moves.join(" "); - if (lastWrite > 0) { - lastWrite--; - } - - if (moves.length > 0) { - if (currentMove !== lastMove) { - updateMoves(currentMove); - } else { - if (lastWrite === 0) { - updateMoves(currentMove); - } - } - } - - lastMove = currentMove; - movesToAddToTraining = []; - - if (moveList.length > 10) { - moveList.pop(); - } -}; - -export let movesToAddToTraining: string[] = []; - -export const TrainingPanel = GameObject({ - x: 70, - y: 2, - width: 88, - height: 26, - children: [TrainingPanelText, TrainingPanelMoveList], -}); diff --git a/src/code/objects/Fighter.ts b/src/code/objects/Fighter.ts index 04dd3f2..64dbfe9 100644 --- a/src/code/objects/Fighter.ts +++ b/src/code/objects/Fighter.ts @@ -18,12 +18,7 @@ import { } from "../data/Constants"; import { Attack } from "../types/Attack"; import { Jab } from "../data/Attacks"; -import { - movesToAddToTraining, - isTrainingPanelEnabled, - addMoveToTrainingPanel, - TrainingData, -} from "../modules/TrainingPanel/TrainingPanel"; +import { isTrainingPanelEnabled } from "../modules/TrainingPanel/TrainingPanel"; import { GameConfig } from "../data/GameConfig"; import PlaySfx from "../../sounds/PlaySfx"; import { attackSfx } from "../../sounds/Sfx"; @@ -63,7 +58,7 @@ export default class Fighter { this.position = position; this.sprite = Sprite({ - x: this.position === Position.Left ? -18 : -24, + x: this.position === Position.Left ? -12 : -24, }); this.hurtbox = GameObject({}); @@ -141,14 +136,6 @@ export default class Fighter { if (this.canMove === false) { this.stop(); } - - if (this.movingLeft) { - movesToAddToTraining.unshift("⬅️"); - } - - if (this.movingRight) { - movesToAddToTraining.unshift("➡️"); - } } if (this.position === Position.Right) { @@ -169,8 +156,6 @@ export default class Fighter { if (this.position === Position.Left) { onKey("k", () => { if (GameConfig.fightersCanAct) { - movesToAddToTraining.push("🗡"); - TrainingData.attackFrames = Jab.startup + Jab.active + Jab.recovery; this.attack(Jab); } }); @@ -179,7 +164,6 @@ export default class Fighter { if (this.position === Position.Right) { onKey("y", () => { if (GameConfig.fightersCanAct) { - TrainingData.attackFrames = Jab.startup + Jab.active + Jab.recovery; this.attack(Jab); } }); @@ -187,9 +171,6 @@ export default class Fighter { if (this.attackingFrames > 0) { this.attackingFrames--; - if (this.position === Position.Left) { - TrainingData.attackFrames = this.attackingFrames; - } if (this.startupFrames > 0) { this.startupFrames--; @@ -206,7 +187,10 @@ export default class Fighter { height: this.doingAttack.height, y: this.doingAttack.y, ttl: this.doingAttack.active, - x: this.hitbox.width, + x: + this.position === Position.Left + ? this.hitbox.width + : -this.doingAttack.width, render: function (this: GameObject) { if (isTrainingPanelEnabled()) { const context = getContext(); @@ -324,10 +308,6 @@ export default class Fighter { } update() { - if (this.position === Position.Left) { - addMoveToTrainingPanel(movesToAddToTraining); - } - this.handleMovement(); this.handleAttack(); this.handleStun(); diff --git a/src/main.ts b/src/main.ts index da10983..c10f6d4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,6 +11,7 @@ import { } from "./code/data/Instances"; import { LoadAssets } from "./code/functions/LoadAssets"; import { Scene } from "./code/types/Scene"; + import PlayMusic from "./sounds/PlayMusic"; import { song } from "./sounds/Music";