Domanda

I think I need some incentive on how to make this, I'm not really experienced in general platforming game mechanics...

Anyway, my player figure has this up to now:

movePlayer = proc p -> do
    let gravity = 100
    sx <- keySpeed GLFW.LEFT GLFW.RIGHT 500 -< ()
    dy <- integralLim_ collision 0 -< (gravity, p)
    dx <- integralLim_ collision 0 -< (sx, p)
    returnA -< (sx, sy)
    where
        keySpeed k1 k2 s = onKey k1 (-s) <|> onKey k2 s <|> pure 0
        collision = undefined -- collision with the world

With gravity, the player object slowly falls down until there is something to stand on. Of course, the next step is to add jumping, in a sin curve... what is a simple way to add it using netwire? One that can also be have further collision detecting added to it?

I just have no idea where to begin with this one.

È stato utile?

Soluzione

First of all note that integrals work for tuples:

(x, y) <- integralLim_ f (x0, y0) -< ((dx, dy), w)

Now consider that gravity is an acceleration value. You can easily add it to other acceleration values:

gravity = pure (0, -9.8)
jump    = pure (0, 1000) . holdFor 0.1 (keyPressed space) <|> pure (0, 0)

pos = integralLim_ collision p0 . integral_ v0 . (gravity ^+^ jump)

where p0 is the initial position and v0 the initial velocity.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top