如何使汽车pygame具有制动功能

时间:2018-10-29 22:36:49

标签: python pygame game-physics

我是python的新手,我想知道如何通过按空格键使汽车具有制动功能。我已经放置了一些控件来使汽车向左和向右前进以及向后行驶,但是减速是我需要使用空格键进行的操作。我不知道是否需要我的代码才能回答这个问题,但还是这样。

谢谢

In [1]: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:import time
import numpy as np
import tensorflow as tf

t = time.time()
for i in range(400):
    a = np.random.uniform(0,1,(1000,2000))
print("np.random.uniform: {} seconds".format(time.time() - t))

t = time.time()
for i in range(400):
    a = np.random.random((1000,2000))
print("np.random.random:  {} seconds".format(time.time() - t))

sess = tf.Session()
t = time.time()
for i in range(400):
    a = sess.run(tf.random_uniform((1000,2000),dtype=tf.float64))
print("tf.random_uniform: {} seconds".format(time.time() - t))::::::::::::::::::
:--
np.random.uniform: 11.066569805145264 seconds
np.random.random:  9.299575090408325 seconds
2018-10-29 18:34:58.612160: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2018-10-29 18:34:58.612191: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2018-10-29 18:34:58.612210: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
tf.random_uniform: 16.619441747665405 seconds

1 个答案:

答案 0 :(得分:1)

只需添加一个self.k_break属性,在玩家休息时将其设置为True,然后在大于0的情况下减小self.speed,在小于0的情况下增大。{ {1}}和max,使其停止在0。

min