Skip to content

Commit 06c2e17

Browse files
committed
Merge branch 'master' into engine-release
2 parents 9de9899 + 40658ca commit 06c2e17

4 files changed

Lines changed: 17 additions & 10 deletions

File tree

client/src/playback/Actions.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export default class Actions {
4646
//this.actions.splice(i, 1)
4747

4848
// Otherwise, this is faster
49-
this.actions[i] = this.actions[this.actions.length - 1]
50-
this.actions[i].finish(round)
49+
[this.actions[i], this.actions[this.actions.length-1]] = [this.actions[this.actions.length - 1], this.actions[i]]
50+
this.actions[this.actions.length-1].finish(round)
5151
this.actions.pop()
5252

5353
i--
@@ -385,10 +385,14 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
385385
[schema.Action.CatScratch]: class CatScratchAction extends Action<schema.CatScratch> {
386386
draw(match: Match, ctx: CanvasRenderingContext2D): void {
387387
// cat scratching animation
388-
389388
const body = match.currentRound.bodies.getById(this.robotId)
390389
const pos = match.map.indexToLocation(this.actionData.loc())
391390
const coords = renderUtils.getRenderCoords(pos.x, pos.y, match.map.dimension, true)
391+
392+
const dir = body.direction
393+
body.textureOverride = true
394+
body.imgPath = `robots/cat/cat_scratch_${dir}.png`
395+
392396
const reflected = body.pos.x < pos.x
393397

394398
const interpolationFactor = match.getInterpolationFactor()
@@ -407,12 +411,11 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
407411
}
408412
ctx.stroke()
409413
ctx.globalAlpha = 1
410-
body.imgPath = `robots/cat/cat_scratch_${body.direction}.png`
411414
}
412415

413416
finish(round: Round): void {
414417
const body = round.bodies.getById(this.robotId)
415-
body.imgPath = 'robots/cat/cat.png'
418+
body.textureOverride = false
416419
}
417420
},
418421
[schema.Action.CatPounce]: class CatPounceAction extends Action<schema.CatPounce> {
@@ -421,6 +424,7 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
421424
const body = round.bodies.getById(this.robotId)
422425
const startPos = round.map.indexToLocation(this.actionData.startLoc())
423426
const endPos = round.map.indexToLocation(this.actionData.endLoc())
427+
console.log('pounce from', startPos, 'to', endPos)
424428
}
425429
draw(match: Match, ctx: CanvasRenderingContext2D): void {
426430
// cat pouncing animation
@@ -431,6 +435,7 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
431435
const endCoords = renderUtils.getRenderCoords(endPos.x, endPos.y, match.map.dimension, true)
432436
const angle = Math.atan2(endPos.y - startPos.y, endPos.x - startPos.x)
433437

438+
body.textureOverride = true
434439
let texture: string
435440
if (angle >= (7 * Math.PI) / 4 || angle <= Math.PI / 4) {
436441
texture = 'robots/cat/cat_pounce_5.png'
@@ -454,7 +459,7 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
454459
}
455460
finish(round: Round): void {
456461
const body = round.bodies.getById(this.robotId)
457-
body.imgPath = 'robots/cat/cat.png'
462+
body.textureOverride = false
458463
}
459464
},
460465
[schema.Action.PlaceTrap]: class PlaceTrapAction extends Action<schema.PlaceTrap> {
@@ -508,7 +513,8 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
508513
draw(match: Match, ctx: CanvasRenderingContext2D): void {
509514
// trap triggering animation
510515
const body = match.currentRound.bodies.getById(this.robotId)
511-
const pos = match.map.indexToLocation(this.actionData.loc())
516+
// const pos = match.map.indexToLocation(this.actionData.loc())
517+
const pos = body.getInterpolatedCoords(match)
512518
const coords = renderUtils.getRenderCoords(pos.x, pos.y, match.map.dimension, true)
513519

514520
const size = body.size - 1

client/src/playback/Bodies.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ export class Body {
367367
public beingCarried: boolean = false
368368
public bytecodesUsed: number = 0
369369
public cheese: number = 0
370+
public textureOverride: boolean = false
370371

371372
constructor(
372373
private game: Game,
@@ -793,7 +794,7 @@ export const BODY_DEFINITIONS: Record<schema.RobotType, typeof Body> = {
793794

794795
public draw(match: Match, ctx: CanvasRenderingContext2D): void {
795796
const dir = this.direction
796-
this.imgPath = `robots/${this.team.colorName.toLowerCase()}/rat_${dir}_64x64.png`
797+
if (!this.textureOverride) this.imgPath = `robots/${this.team.colorName.toLowerCase()}/rat_${dir}_64x64.png`
797798
super.draw(match, ctx)
798799
}
799800
},
@@ -811,7 +812,7 @@ export const BODY_DEFINITIONS: Record<schema.RobotType, typeof Body> = {
811812

812813
public draw(match: Match, ctx: CanvasRenderingContext2D): void {
813814
const dir = this.direction
814-
this.imgPath = `robots/${this.team.colorName.toLowerCase()}/rat_king_64x64.png`
815+
if (!this.textureOverride) this.imgPath = `robots/${this.team.colorName.toLowerCase()}/rat_king_64x64.png`
815816
super.draw(match, ctx)
816817
}
817818
},
@@ -829,7 +830,7 @@ export const BODY_DEFINITIONS: Record<schema.RobotType, typeof Body> = {
829830

830831
public draw(match: Match, ctx: CanvasRenderingContext2D): void {
831832
const dir = this.direction
832-
this.imgPath = `robots/cat/cat_${dir}.png`
833+
if (!this.textureOverride) this.imgPath = `robots/cat/cat_${dir}.png`
833834
super.draw(match, ctx)
834835
}
835836
}
438 KB
Loading
436 KB
Loading

0 commit comments

Comments
 (0)