haskell - Netwire 中的跳跃机制

标签 haskell reactive-programming frp arrows netwire

我认为我需要一些关于如何做到这一点的激励,我在一般平台游戏机制方面并没有真正的经验......

无论如何,到目前为止我的玩家人物是这样的:

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

重力的作用下,玩家物体会慢慢下落,直到有东西可以站立。当然,下一步是在 sin 曲线中添加跳跃...使用 netwire 添加它的简单方法是什么?还可以添加进一步的碰撞检测吗?

我只是不知道从哪里开始。

最佳答案

首先请注意,积分适用于元组:

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

现在考虑重力是一个加速度值。您可以轻松地将其添加到其他加速度值:

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)

其中,p0 是初始位置,v0 是初始速度。

关于haskell - Netwire 中的跳跃机制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15930082/

相关文章:

haskell - Haskell 中的惰性笛卡尔积

javascript - 如何在 React Js 中设置匹配密码

vb.net - .NET 确定控件的值已更改并最终确定

haskell - 为什么响应式(Reactive)香蕉中没有从非事件构建事件的函数?

PostgreSQL Simple 在一个元组中最多只支持 10 个变量,但我需要更多

haskell - 当使用 Aeson 解析 JSON 时,为什么 Maybe 在类型参数中会受到不同的处理?

java - webflux spring boot 应用程序的过滤器,返回 ResponseEntity<?>

angularjs - RxJS 并与 Angular 1 一起使用

haskell - 箭头 FRP 中的连续信号切换

eclipse - 无法安装 EclipseFP,因为无法安装 scion-browser,因为无法安装 terminfo