Coder Social home page Coder Social logo

Entities don't move about slw HOT 9 CLOSED

towerofnix avatar towerofnix commented on August 15, 2024
Entities don't move

from slw.

Comments (9)

towerofnix avatar towerofnix commented on August 15, 2024 1

So I guess xv is getting reset to 0 every tick, once it's touched the ground, before xv is actually used?

from slw.

towerofnix avatar towerofnix commented on August 15, 2024 1

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
  }
}

from slw.

towerofnix avatar towerofnix commented on August 15, 2024

Pretty sure that's on top of the block still. The real issue is the mushroom block isn't moving!

from slw.

nanaian avatar nanaian commented on August 15, 2024

That's what I meant 📦

from slw.

towerofnix avatar towerofnix commented on August 15, 2024

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..?

from slw.

towerofnix avatar towerofnix commented on August 15, 2024

PS I don't know entirely how that constructor call works lol

from slw.

nanaian avatar nanaian commented on August 15, 2024

It does have xv when it's created- it jumps across. As soon as it hits the ground, however, it stops..

from slw.

towerofnix avatar towerofnix commented on August 15, 2024

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.

from slw.

towerofnix avatar towerofnix commented on August 15, 2024

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....

from slw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.