Skip to content

Commit 48e93a8

Browse files
author
Tselote Woldemichael
committed
add animations for ratnap and ratcollision
1 parent 255afb5 commit 48e93a8

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

client/src/playback/Actions.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,32 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
183183
}
184184
},
185185
[schema.Action.RatNap]: class RatNapAction extends Action<schema.RatNap> {
186+
private static readonly OFFSET = { x: -0.35, y: 0 }
186187
apply(round: Round): void {
187188
// move the target onto the source adjust target's size using scale factor
188189
const src = round.bodies.getById(this.robotId)
189190
const target = round.bodies.getById(this.actionData.id()) // rat getting napped
191+
192+
target.lastPos = { ...target.pos }
193+
target.pos = { x: src.pos.x + RatNapAction.OFFSET.x, y: src.pos.y + RatNapAction.OFFSET.y }
194+
target.size = 0.6
190195
}
191196
draw(match: Match, ctx: CanvasRenderingContext2D): void {
192197
//target rat moves onto src rat, circle around carried group thing
193198
const src = match.currentRound.bodies.getById(this.robotId)
194-
const target = match.currentRound.bodies.getById(this.actionData.id()) // rat getting napped
199+
// const target = match.currentRound.bodies.getById(this.actionData.id()) // rat getting napped
200+
201+
const srcCoords = renderUtils.getRenderCoords(src.pos.x, src.pos.y, match.map.dimension, true)
202+
ctx.save()
203+
ctx.shadowBlur = 12
204+
ctx.shadowColor = src.team.color
205+
ctx.beginPath()
206+
ctx.strokeStyle = src.team.color
207+
ctx.globalAlpha = 0.7
208+
ctx.lineWidth = 0.04
209+
ctx.arc(srcCoords.x, srcCoords.y, 0.6, 0, 2 * Math.PI)
210+
ctx.stroke()
211+
ctx.restore()
195212
}
196213
},
197214
[schema.Action.RatCollision]: class RatCollisionAction extends Action<schema.RatCollision> {
@@ -200,6 +217,33 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
200217
const src = match.currentRound.bodies.getById(this.robotId)
201218
const pos = match.map.indexToLocation(this.actionData.loc())
202219
const coords = renderUtils.getRenderCoords(pos.x, pos.y, match.map.dimension, true)
220+
const t = match.getInterpolationFactor()
221+
222+
ctx.save()
223+
// dusty base color that fills the cell and fades out
224+
const baseAlpha = 0.4 * (1 - t)
225+
ctx.fillStyle = `rgba(150,130,110,${baseAlpha})`
226+
ctx.fillRect(coords.x - 0.5, coords.y - 0.5, 1, 1)
227+
228+
// these are the random rocks that fill the cell
229+
const rockCount = 10
230+
for (let i = 0; i < rockCount; i++) {
231+
const rx = coords.x - 0.5 + Math.random() * 1
232+
const ry = coords.y - 0.5 + Math.random() * 1
233+
const size = 0.08 + Math.random() * 0.15
234+
const shade = 90 + Math.floor(Math.random() * 50)
235+
const alpha = 0.7 * (1 - t)
236+
ctx.fillStyle = `rgba(${shade},${shade - 10},${shade - 20},${alpha})`
237+
ctx.fillRect(rx, ry, size, size)
238+
}
239+
240+
// ring outside the cell (also fades out)
241+
ctx.strokeStyle = src.team.color
242+
ctx.globalAlpha = 0.35 * (1 - t)
243+
ctx.lineWidth = 0.04
244+
ctx.strokeRect(coords.x - 0.5, coords.y - 0.5, 1, 1)
245+
ctx.restore()
246+
203247
}
204248
},
205249
[schema.Action.PlaceDirt]: class PlaceDirtAction extends Action<schema.PlaceDirt> {

0 commit comments

Comments
 (0)