Skip to content

Commit 00107fc

Browse files
committed
Merge branch 'master' into client-release
2 parents f1853e9 + 1073393 commit 00107fc

5 files changed

Lines changed: 38 additions & 23 deletions

File tree

client/src/components/game/game-renderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ const ZoomableGameRenderer: React.FC<{
193193
// Adjust hovered tile if hovering over a body
194194
const hoveredBody = hoveredTile ? round?.bodies.getBodyAtLocation(hoveredTile.x, hoveredTile.y) : undefined
195195

196-
if (hoveredBody && hoveredTile){
196+
if (hoveredBody && hoveredBody.pos && hoveredTile){
197197
hoveredTile = hoveredBody.pos
198198
if (hoveredBody.robotType == schema.RobotType.RAT_KING){
199199
hoveredTile = vectorAdd(hoveredTile, {x: -1, y: -1} )

client/src/components/sidebar/map-editor/MapGenerator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ function verifyMap(map: CurrentMap, bodies: Bodies): string {
149149
// Check distance from cat to other cats and cheese mines
150150
let body_type = undefined
151151
switch (body.robotType) {
152-
case RobotType.CAT:
152+
case schema.RobotType.CAT:
153153
body_type = 'Cat'
154154
break
155-
case RobotType.RAT:
155+
case schema.RobotType.RAT:
156156
body_type = 'Rat'
157157
break
158-
case RobotType.RAT_KING:
158+
case schema.RobotType.RAT_KING:
159159
body_type = 'Rat King'
160160
break
161161
default:

client/src/components/sidebar/map-editor/map-editor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,10 @@ export const MapEditorPage: React.FC<Props> = (props) => {
188188

189189
useEffect(() => {
190190
if (canvasMouseDown && hoveredTile) applyBrush(hoveredTile)
191-
if (canvasMouseDown && hoveredTile) {
191+
// added defensive checks just in case stuff is null for some reason
192+
if (canvasMouseDown && hoveredTile && typeof hoveredTile.x === 'number' && typeof hoveredTile.y === 'number') {
192193
// override the GameRenderer's canvas click
194+
if (!canvasMouseDown || !hoveredTile) return;
193195
const newSelectedBody = GameRunner.match?.currentRound.bodies.getBodyAtLocation(
194196
hoveredTile.x,
195197
hoveredTile.y

client/src/playback/Actions.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
104104
// chomping animation
105105
const src = match.currentRound.bodies.getById(this.robotId) // cat
106106
// const target = match.currentRound.bodies.getById(this.actionData.id()) // rat being eaten
107-
const coords = renderUtils.getRenderCoords(src.pos.x, src.pos.y, match.map.dimension, true)
108-
const random1 = ((src.pos.x * 491 + src.pos.y * 603 + match.currentRound.roundNumber * 343) / 100) % 1 // https://xkcd.com/221/
109-
const random2 = ((src.pos.x * 259 + src.pos.y * 429 + match.currentRound.roundNumber * 224) / 100) % 1
110-
const interpolationFactor = match.getInterpolationFactor()
107+
// const coords = renderUtils.getRenderCoords(src.pos.x, src.pos.y, match.map.dimension, true)
108+
// const random1 = ((src.pos.x * 491 + src.pos.y * 603 + match.currentRound.roundNumber * 343) / 100) % 1 // https://xkcd.com/221/
109+
// const random2 = ((src.pos.x * 259 + src.pos.y * 429 + match.currentRound.roundNumber * 224) / 100) % 1
110+
// const interpolationFactor = match.getInterpolationFactor()
111111

112112
// ctx.save()
113113
// ctx.globalAlpha = 0.5 - 0.5 * interpolationFactor * interpolationFactor
@@ -133,6 +133,8 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
133133
const srcBody = match.currentRound.bodies.getById(this.robotId)
134134
const dstBody = match.currentRound.bodies.getById(this.actionData.id())
135135

136+
if (!dstBody) return
137+
136138
const from = srcBody.getInterpolatedCoords(match)
137139
const to = dstBody.getInterpolatedCoords(match)
138140

@@ -192,8 +194,11 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
192194

193195
if (target.beingCarried) {
194196
// drop the target
195-
const carrier = round.bodies.getById(target.carrierRobot!)
196-
carrier.carriedRobot = undefined
197+
// const carrier = round.bodies.getById(target.carrierRobot!)
198+
if(target.carrierRobot !== undefined) {
199+
const carrier = round.bodies.getById(target.carrierRobot)
200+
carrier.carriedRobot = undefined
201+
}
197202
target.size = 1
198203
target.beingCarried = false
199204
target.carrierRobot = undefined
@@ -358,6 +363,8 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
358363
const srcBody = match.currentRound.bodies.getById(this.robotId)
359364
const targetBody = match.currentRound.bodies.getById(this.actionData.id())
360365

366+
if (!targetBody) return
367+
361368
const from = srcBody.getInterpolatedCoords(match)
362369
const to = targetBody.getInterpolatedCoords(match)
363370

@@ -562,26 +569,27 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
562569
[schema.Action.ThrowRat]: class ThrowRatAction extends Action<schema.ThrowRat> {
563570
apply(round: Round): void {
564571
// maybe move rat to target loc
565-
const body = round.bodies.getById(this.robotId)
572+
const body = round.bodies.getById(this.actionData.id())
566573
const endLoc = round.map.indexToLocation(this.actionData.loc())
567-
if( body.carriedRobot !== undefined ) {
568-
const carrier = round.bodies.getById(body.carriedRobot)
574+
if( body.carrierRobot !== undefined && round.bodies.hasId(body.carrierRobot)) {
575+
const carrier = round.bodies.getById(body.carrierRobot)
569576
carrier.carriedRobot = undefined
570577
}
571578
body.carrierRobot = undefined
572579
body.beingCarried = false
573580
body.size = 1
574-
body.pos = { ...endLoc }
581+
// body.pos = { ...endLoc }
575582
}
576583
draw(match: Match, ctx: CanvasRenderingContext2D): void {
577-
const body = match.currentRound.bodies.getById(this.robotId)
584+
if( !match.currentRound.bodies.hasId(this.actionData.id()) ) return
585+
const body = match.currentRound.bodies.getById(this.actionData.id())
578586
const pos = body.getInterpolatedCoords(match)
579587
const coords = renderUtils.getRenderCoords(pos.x, pos.y, match.map.dimension, true)
580588
const interp = match.getInterpolationFactor()
581589

582590
const from = pos
583591
const to = match.currentRound.map.indexToLocation(this.actionData.loc())
584-
console.log('throw from', from, 'to', to)
592+
585593
const dx = to.x - from.x
586594
const dy = to.y - from.y
587595
const mag = Math.hypot(dx, dy)
@@ -698,6 +706,8 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
698706
const src = round.bodies.getById(this.robotId)
699707
const target = round.bodies.getById(this.actionData.id())
700708

709+
if (!target) return
710+
701711
const damage = this.actionData.damage()
702712
target.hp = Math.max(target.hp - damage, 0)
703713
}

client/src/playback/Bodies.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ export default class Bodies {
214214
body.pos = { x: turn.x(), y: turn.y() }
215215
body.direction = turn.dir()
216216
body.hp = Math.max(turn.health(), 0)
217+
body.cheese = turn.cheese()
217218
body.moveCooldown = turn.moveCooldown()
218219
body.actionCooldown = turn.actionCooldown()
219220
body.turningCooldown = turn.turningCooldown()
@@ -434,10 +435,8 @@ export class Body {
434435
const OFFSET = { x: .35, y: 0 } // to center the rat on the tile
435436
const ratnapped = this.robotType === schema.RobotType.RAT && this.beingCarried
436437

437-
if(ratnapped) this.pos.x += OFFSET.x
438438
const pos = this.getInterpolatedCoords(match)
439-
if(ratnapped) this.pos.x -= OFFSET.x
440-
439+
441440
const renderCoords = renderUtils.getRenderCoords(pos.x, pos.y, match.currentRound.map.staticMap.dimension)
442441

443442
if (this.robotType == schema.RobotType.CAT) {
@@ -521,18 +520,22 @@ export class Body {
521520
const maxX = Math.min(location.x + ceiledRadius, match.map.width - 1)
522521
const maxY = Math.min(location.y + ceiledRadius, match.map.height - 1)
523522

524-
const coords: Vector[] = [location]
523+
const coords: Vector[] = []
524+
525525
const halfFOV = fov / 2
526526
if (direction == 0) {
527527
return coords
528528
}
529529

530+
const OFFSET = this.robotType === schema.RobotType.CAT ? {x: 0.5, y: 0.5} : {x: 0, y: 0}
531+
const center = {x: location.x + OFFSET.x, y: location.y + OFFSET.y}
532+
530533
const directionRad = (directionAngles[direction] * Math.PI) / 180
531534

532535
for (let x = minX; x <= maxX; x++) {
533536
for (let y = minY; y <= maxY; y++) {
534-
const dx = x - location.x
535-
const dy = y - location.y
537+
const dx = x - center.x
538+
const dy = y - center.y
536539
if (dx * dx + dy * dy <= radius) {
537540
const angleToPoint = Math.atan2(dy, dx)
538541
let angleDiff = angleToPoint - directionRad

0 commit comments

Comments
 (0)