Closed bates64 closed 7 years ago
Pretty sure that's on top of the block still. The real issue is the mushroom block isn't moving!
That's what I meant :package:
Mushroom just runs Powerup's constructor with the arguments passed to its own constructor.
Here's the constructor for Powerup:
constructor(game: SLW, x: number = 0, y: number = 0, xv: number = 1)
And here's the line that's constructing Mushroom:
const [x, y] = this.game.level.getAbsolutePosition([this.x, this.y])
let shroom = new Mushroom(this.game, x, 0)
In that case the xv
defaults to 1
, so it should be moving.. I wonder if xv
is getting reset (or slowed down too quickly) somewhere..?
PS I don't know entirely how that constructor call works lol
It does have xv
when it's created- it jumps across. As soon as it hits the ground, however, it stops..
So I guess xv
is getting reset to 0 every tick, once it's touched the ground, before xv
is actually used?
Think of it like this:
/* Do Y-velocity handling stuff.. */
// (An equivalent to) this happens once the mushroom
// has touched the ground, and on every tick after the
// mushroom's touched the ground:
this.xv = 0
/* Okay, done doing Y-velocity handling stuff.. */
/* Do X-velocity handling stuff.. */
// Huh, this.xv is 0, so don't do anything!
if (this.xv) {
// whatever
}
/* Okay, done doing X-velocity handling stuff. */
xv
gets reset every onUpdate
before the player is moved horizontally. Once it gets to the step of moving the player horizontally, xv
is 0 and therefore it won't move horizontally.
Of course the question is why this doesn't effect the player sprite, and why it does effect the mushroom sprite - I assume it's because of a bad Y position....
Okay, the issue is this.collides()
is being used instead of some left/right wall detection - I assume collides
is detecting the floor..
edit: relevant code:
for (let i = 0; i < Math.abs(xv); i++) {
this.x += v
if (this.collides()) {
this.x -= v
if (stop) this.xv = 0
}
}