1

我正在创建一个游戏,用户必须更快地点击屏幕才能让他们在游戏中走得更快,但是我遇到了一些问题。我已经制作了游戏,因此它会根据用户的最后一次点击和他们当前的点击计算每分钟的点击次数,但是这种方法似乎很生涩并且效果不佳。我也想不出另一种方法来做到这一点,所以当他们根本不点击时,它会变慢。

我将如何为游戏创建这种机制,其中用户点击得越快,游戏进行得越快,如果他们根本不点击它就会减速停止。

谢谢

这是我到目前为止的一个片段,计算用户的每分钟点击次数 (TPM)。(这是在触摸方法中)。我目前正在将 TPM 传递给一个更新方法,该方法在每次更新时将背景移动 TPM/100(它以 30FPS 运行)

 if (thisTouch == 0 || lastTouch == 0) {
            Log.d("info","First Touch");
            thisTouch = lastTouch = System.currentTimeMillis();
        } else {
            Log.d("d","touch");
            thisTouch = System.currentTimeMillis();

            long difference = thisTouch - lastTouch;

            TPM = (int)((1000*60)/difference);

            lastTouch = thisTouch;
        }

我想知道如何更改此设置,以便游戏在点击更快时加速,然后在他们不触摸屏幕时减慢。

4

3 回答 3

1

也许你可以做这样的事情:

  • 创建一个 PriorityQueue<Long>
  • 每当用户点击屏幕时,将 (currentTime + someTimeOut) 添加到队列中
  • 每当您要检查当前速度(例如队列大小)时,首先删除所有元素> currentTime。

当然,如果您执行此类操作,请不要忘记添加适当的线程安全措施。

于 2012-07-17T13:40:19.607 回答
0

Your general approach is pretty much the only way to do it, it just needs some fine tuning.

Keep a general TapsPerTime variable. With each new tap you register, do not replace the TapsPerTime, but calculate a new, weighted value:

TapsPerTime = (TapsPerTime * X) + (MeasureTapsPerTime * (1-X))

The factor X you need to find empirically (by trying out what works best for you). The general idea here is that each measurement will only nudge the used value a bit into the right direction.

Also, if you do not detect a tap for a set amount of time, simply update the TapsPerTime with the same formula, but use 0 (zero) for MeasureTapsPerTime. So if the user does not do anything the value goes down.

于 2012-07-17T13:45:28.283 回答
0

不要成为“那个人”,但听起来你目前的每分钟点击数计划非常好,但实施得很糟糕。但是,我强烈建议您使用较小的时间量,例如每三秒点击一次,因为游戏通常节奏很快,并且必须等待整整一分钟才能看到您的角色加速或减速可能会产生延迟感。

或者,您可以使用某种形式的加速度,每次点击屏幕时都会增加到最大限制,并且随着时间的推移会随着不点击屏幕而减小。

现在我看到你用一些代码更新了你的问题,我想指出点击是触摸,从屏幕上释放不一定是触摸。老实说,我从您的代码中不知道您是否对此进行补偿,因此这可能是您的一些问题的根源。

最后,对于游戏开发算法和理论,您可能希望查看此 StackExchange 站点:https ://gamedev.stackexchange.com/

听起来您已经非常接近让您的游戏以您想要的方式感受,祝您好运!

于 2012-07-17T13:38:29.243 回答