python - 如何让演员在 y 轴上移动?
问题描述
我在 TigerJython (Python) 中编写 Jump&Run 程序。我实现了公式,所以演员跳起来(当按下向上按钮时),然后演员应该由于重力而自动下降。演员应该只在 y 轴上移动(因为平台在移动),所以 x 轴的值为 1。我真的尝试了很多东西,但这个 Jumpman 不想移动。
# Jump & Run
from gturtle import *
from gamegrid import *
import math
from random import randint
from time import sleep
# ----------classJumpman-----------
class Jumpman(Actor):
def __init__(self):
Actor.__init__(self, "jumpman.gif")
self.speed = speed
self.dt = 0.005 * getSimulationPeriod()
def reset(self):
self.px = self.getX()
self.py = self.getY()
self.vx = 1
self.vy = self.speed * math.sin(math.radians(self.getDirection()))
def act(self):
self.vy = self.vy + g * self.dt
self.px = 1
self.py = self.py + self.vy * self.dt
self.setLocation(Location(int(self.px), int(self.py)))
self.setDirection(math.degrees(math.atan2(self.vy, self.vx)))
def collide(self, actor1, actor2):
self.setY(465)
return 0
# ----------classPlaforms----------
class Platform(Actor):
def __init__(self, path):
Actor.__init__(self, path)
def act(self):
self.move()
def generatePlatforms():
#var = randint(1,4)
#var_c = var
platform = Platform("platforms/" + str(randint(1,4)) + ".jpg")
jumpman.addCollisionActor(platform)
addActor(platform, Location(1600, 500), 180)
# ----------------------------------
def onKeyRepeated(keyCode):
if keyCode == 38:
jumpman.setDirection(jumpman.getDirection()+5)
g = 9.81
# GameGrid
makeGameGrid(1280, 720, 1, None, "retro.jpg", False)#, keyRepeated = onKeyRepeated)
jumpman = Jumpman()
addActor(jumpman, Location(400, 480), 90)
setSimulationPeriod(30)
show()
doRun()
while True:
generatePlatforms()
sleep(2)
解决方案
推荐阅读
- sql - sqlite INNER JOIN 仅当数据
- laravel - Ngrok / Laravel5 / Homestead - 发布/登录时出现 500 内部服务器错误
- c - 互斥锁和解锁的一些解释
- python - Java 网关进程在向驱动程序发送其端口号之前退出
- c# - C# - 获取当前公共 IP 地址
- matlab - 获取图中连接组件的节点索引(matlab)
- javascript - 如何使用 React JS 将 json api 中的所有值显示到单个下拉列表中?
- dart - Flutter Camera 插件错误 - 在 null 上调用了 getter 'height'
- android - Android Studio调试清除应用程序数据但再次运行应用程序时数据没有被删除?
- java - 如何使用 Grunt 将 jar 文件复制到 WEB-INF/lib