Skip to content

Commit

Permalink
Merge pull request #15 from mattjennings/dev
Browse files Browse the repository at this point in the history
a
  • Loading branch information
mattjennings authored Jul 9, 2023
2 parents 8dd6d48 + 4b768b2 commit 0b47bb1
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 9 deletions.
Binary file added public/music/Overtime1.mp3
Binary file not shown.
Binary file added public/music/Overtime2.mp3
Binary file not shown.
Binary file added public/sfx/Taunt.mp3
Binary file not shown.
1 change: 0 additions & 1 deletion src/actors/base-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export class BasePlayer extends ex.Actor {
this.isPain = true
this.isSprinting = false
this.setAnimation('Pain')
assets.snd_dashB.play()

this.vel = direction.scale(500)
}
Expand Down
5 changes: 2 additions & 3 deletions src/actors/referee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,12 @@ export class Referee extends BasePlayer {
entity.pos.distance(this.pos) < 30
) as BasePlayer[]

assets.snd_taunt.play(0.9)
if (nearbyPlayers.length) {
this.suspicion += nearbyPlayers.length * 0.5
nearbyPlayers.forEach((player) => {
player.scare(player.pos.sub(this.pos).normalize())
})
} else {
assets.snd_dashB.play()
}
}
}
Expand All @@ -177,7 +176,7 @@ export class Referee extends BasePlayer {
if (this.scene.gameHasStarted === true) {
this.suspicion += 1
}
assets.snd_crowdBLow.play()
assets.snd_crowdBLow.play(0.75)
this.scene.reset()
this.scene.gameHasStarted = true
}
Expand Down
4 changes: 4 additions & 0 deletions src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export const assets = {
snd_crowdBLow: new ex.Sound('sfx/CrowdBLow.mp3'),
snd_bell: new ex.Sound('sfx/Bell1.mp3'),
snd_watchOut: new ex.Sound('sfx/WatchOut.mp3'),
snd_taunt: new ex.Sound('sfx/Taunt.mp3'),

sng_overtime1: new ex.Sound('music/Overtime1.mp3'),
sng_overtime2: new ex.Sound('music/Overtime2.mp3'),
}

class DevLoader extends ex.Loader {
Expand Down
32 changes: 28 additions & 4 deletions src/classes/MatchScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ export default class MatchScene extends ex.Scene {
lastPosession?: Team
referee: Referee

song: ex.Sound

gameHasStarted = false
gameOver = false

field: ex.BoundingBox
zones: Record<'left' | 'mid' | 'right', ex.BoundingBox>

onInitialize(engine: ex.Engine): void {
this.playSong('intro')
// add field
const fieldSprite = assets.img_field.toSprite()

Expand Down Expand Up @@ -206,17 +209,32 @@ export default class MatchScene extends ex.Scene {

this.add(new IcecreamTruck())
this.on('goal', this.onGoal.bind(this))
assets.snd_crowdA.play()
assets.snd_crowdA.play(0.75)
}

playSong(song: 'intro' | 'game') {
const intro = assets.sng_overtime2
const game = assets.sng_overtime1

if (song === 'intro' && !intro.isPlaying()) {
this.song?.stop()
this.song = intro
intro.play()
} else if (song === 'game' && !game.isPlaying()) {
this.song?.stop()
this.song = game
game.play()
}
}
onGoal({ team }: { team: Team }) {
this[team].score++

assets.snd_crowdA.play()
assets.snd_crowdBHigh.play()
assets.snd_crowdBLow.play()
assets.snd_crowdA.play(0.75)
assets.snd_crowdBHigh.play(0.75)
assets.snd_crowdBLow.play(0.75)

if (this.home.score >= SCORE_TO_WIN) {
this.playSong('intro')
let suspicionMessage = `Team Red didn't suspect a thing.`

if (this.referee.suspicion > 30) {
Expand All @@ -233,6 +251,7 @@ export default class MatchScene extends ex.Scene {
)
)
} else if (this.away.score >= SCORE_TO_WIN) {
this.playSong('intro')
this.gameHasStarted = false
this.gameOver = true
this.engine.add(
Expand All @@ -252,6 +271,7 @@ export default class MatchScene extends ex.Scene {
this.home.score = 0
this.away.score = 0
}
this.playSong('game')
this.emit('start', {})
}

Expand Down Expand Up @@ -281,6 +301,10 @@ export default class MatchScene extends ex.Scene {
}

onPreUpdate(_engine: Engine, _delta: number): void {
if (this.song && !this.song.isPlaying()) {
this.song.play()
}

// ysort all actors
const sorted = [...this.entities].sort((a, b) => {
if (a instanceof Actor && b instanceof Actor) {
Expand Down
2 changes: 1 addition & 1 deletion src/hud/message-box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class MessageBox extends ScreenElement {

const bg = new ex.Rectangle({
width: this.scene.camera.viewport.width,
height: this.scene.camera.viewport.height - this.pos.y,
height: this.scene.camera.viewport.height,
color: ex.Color.Black,
})

Expand Down

0 comments on commit 0b47bb1

Please sign in to comment.