Skip to content

Commit

Permalink
Merge pull request #7 from mattjennings/dev
Browse files Browse the repository at this point in the history
d
  • Loading branch information
mattjennings authored Jul 9, 2023
2 parents d671b1f + eeb7fc7 commit 5866ac6
Show file tree
Hide file tree
Showing 29 changed files with 54 additions and 21 deletions.
Binary file added public/sfx/Bell1.mp3
Binary file not shown.
Binary file added public/sfx/BiggerKick.mp3
Binary file not shown.
Binary file added public/sfx/ChimeyCrunchConfirm.mp3
Binary file not shown.
Binary file added public/sfx/Clack.mp3
Binary file not shown.
Binary file added public/sfx/CleanImpact.mp3
Binary file not shown.
Binary file added public/sfx/CollapseFallDirt.mp3
Binary file not shown.
Binary file added public/sfx/CombatBlockA.mp3
Binary file not shown.
Binary file added public/sfx/CrowdA.mp3
Binary file not shown.
Binary file added public/sfx/CrowdBHigh.mp3
Binary file not shown.
Binary file added public/sfx/CrowdBLow.mp3
Binary file not shown.
Binary file added public/sfx/DashA.mp3
Binary file not shown.
Binary file added public/sfx/DashB.mp3
Binary file not shown.
Binary file added public/sfx/Foosh.mp3
Binary file not shown.
Binary file added public/sfx/GrassFootstep.mp3
Binary file not shown.
Binary file added public/sfx/ImpactThudGore.mp3
Binary file not shown.
Binary file added public/sfx/MenuClick.mp3
Binary file not shown.
Binary file added public/sfx/MiniCarryKick.mp3
Binary file not shown.
Binary file added public/sfx/NinjaStar.mp3
Binary file not shown.
Binary file added public/sfx/PunchRobot.mp3
Binary file not shown.
Binary file added public/sfx/Stung.mp3
Binary file not shown.
Binary file added public/sfx/TackleA.mp3
Binary file not shown.
Binary file added public/sfx/ThrowPass.mp3
Binary file not shown.
Binary file added public/sfx/WatchOut.mp3
Binary file not shown.
Binary file added public/sfx/Whistle.mp3
Binary file not shown.
Binary file added public/sfx/WooshClack.mp3
Binary file not shown.
Binary file added public/sfx/WooshImpact.mp3
Binary file not shown.
Binary file added public/sfx/WooshImpactClean.mp3
Binary file not shown.
34 changes: 20 additions & 14 deletions src/actors/team-goalie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class TeamGoalie extends BasePlayer {
team: Team
net: Net

power = 200
power = 300
friction = 0.1
slideDuration = 400
slideSpeed = 300
Expand Down Expand Up @@ -73,22 +73,26 @@ export class TeamGoalie extends BasePlayer {
}

update(engine: Engine, delta: number): void {
const netTop = this.net.pos.y - this.net.height / 2
const netBottom = this.net.pos.y
const { top: netTop, bottom: netBottom } = this.getGoalBounds()

const goalieTop = this.pos.y
const goalieBottom = this.pos.y + this.height
const ball = this.scene.ball
const distanceToBall = ball.pos.distance(this.pos)

const target = ex.vec(
this.getLineX(),
ex.clamp(ball.pos.y, netTop, netBottom)
ex.clamp(ball.pos.y, netTop + 16, netBottom - 8)
)

const shouldMoveUp = ball.pos.y < goalieTop && goalieTop > netTop
const shouldMoveDown = ball.pos.y > goalieBottom && goalieBottom < netBottom
const shouldMoveUp =
ball.pos.y < goalieTop && Math.abs(goalieTop - target.y) > 5
const shouldMoveDown =
ball.pos.y > goalieBottom && Math.abs(target.y - goalieBottom) > 5

if (!this.isSliding()) {
if (this.shouldSlide()) {
this.slide(this.pos.y < ball.pos.y ? 'down' : 'up')
} else if (!this.isSliding()) {
if (!this.isLinedUpWithBall() && (shouldMoveUp || shouldMoveDown)) {
this.moveTo(target, 50)
} else {
Expand All @@ -103,17 +107,13 @@ export class TeamGoalie extends BasePlayer {
}

if (
distanceToBall < 20 &&
distanceToBall < 30 &&
Math.abs(ball.vel.x) < 100 &&
Math.abs(ball.vel.y) < 100
) {
this.kickBall()
}

if (this.shouldSlide()) {
this.slide(this.pos.y < ball.pos.y ? 'down' : 'up')
}

this.currentGraphic().flipHorizontal = this.team === 'away'

if (this._slideTime > 0) {
Expand All @@ -132,12 +132,17 @@ export class TeamGoalie extends BasePlayer {
}

isInNet() {
const top = this.net.pos.y - this.net.height / 2
const bottom = this.net.pos.y
const { top, bottom } = this.getGoalBounds()

return this.pos.y > top && this.pos.y < bottom
}

getGoalBounds() {
return {
top: this.net.pos.y - this.net.height / 2,
bottom: this.net.pos.y,
}
}
kickBall() {
this.scene.ball.kick(
ex.vec(
Expand All @@ -157,6 +162,7 @@ export class TeamGoalie extends BasePlayer {
const ballIsMoving = Math.abs(ball.vel.x) > 100
const isMovingTowardsGoal =
this.team === 'home' ? ball.vel.x < 0 : ball.vel.x > 0
// const ballIsGoingIntoNet =

return (
this.isInNet() &&
Expand Down
41 changes: 34 additions & 7 deletions src/actors/team-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,22 @@ export class TeamPlayer extends BasePlayer {
if (this.teamPosition === 'defender') {
this.clearBall()
} else {
this.kickBall(
this.getGoalPosition(),
this.isSprinting ? this.power * 1.5 : this.power
)
// kick back out infront of net
if (this.isBehindOpposingNet()) {
const center = this.team === 'home' ? -150 : 150

this.kickBall(
ex.vec(this.getShotPosition().x + center, this.getShotPosition().y),
this.power * 0.5
)
}
// kick ball towards net
else {
this.kickBall(
this.getShotPosition(),
this.isSprinting ? this.power * 1.5 : this.power
)
}
}
}

Expand All @@ -238,6 +250,16 @@ export class TeamPlayer extends BasePlayer {
}
}

isBehindOpposingNet() {
if (this.team === 'home') {
const net = this.scene.away.net
return this.pos.x + this.width > net.pos.x - net.width
} else {
const net = this.scene.home.net
return this.pos.x - this.width < net.pos.x + net.width
}
}

kickBall(direction: ex.Vector, power = this.power) {
// kickBall() gets called every frame, so setting a 10% chance of kicking
// actually leads to some decent results
Expand Down Expand Up @@ -271,7 +293,7 @@ export class TeamPlayer extends BasePlayer {
clearBall() {
this.kickBall(
ex.vec(
this.getGoalPosition().x,
this.getShotPosition().x,
random.pickOne([0, this.scene.field.height])
)
)
Expand All @@ -283,14 +305,19 @@ export class TeamPlayer extends BasePlayer {
}
}

getGoalPosition() {
getShotPosition() {
const net = this.team === 'home' ? this.scene.away.net : this.scene.home.net

const netCenter = net.pos.y - net.height / 4
const goalie =
this.team === 'home' ? this.scene.away.goalie : this.scene.home.goalie

// const freeYSpace = this.console.log(freeYSpace)
return ex.vec(
net.team === 'home'
? net.pos.x - net.width / 4
: net.pos.x + net.width / 4,
net.pos.y - net.height / 4
netCenter
)
}

Expand Down

0 comments on commit 5866ac6

Please sign in to comment.