2

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.

Lanbo
  • 13,437
  • 14
  • 67
  • 141

1 Answers1

2

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.

ertes
  • 4,244
  • 1
  • 16
  • 22
  • Can't really get `pos` to work... what's that in proper arrow notation? – Lanbo Apr 10 '13 at 19:39
  • @LambdaDusk: Sorry, my failure. I forgot the initial position/velocity. Answer edited. – ertes Apr 10 '13 at 19:52
  • This works if I keep the space key pressed. If I just tap it, nothing happens, and keeping it pressed makes the sprite fly. – Lanbo Apr 11 '13 at 17:42