本文整理汇总了Python中engine.Engine.update_position方法的典型用法代码示例。如果您正苦于以下问题:Python Engine.update_position方法的具体用法?Python Engine.update_position怎么用?Python Engine.update_position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类engine.Engine
的用法示例。
在下文中一共展示了Engine.update_position方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: App
# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import update_position [as 别名]
class App():
def __init__(self):
self.root = tk.Tk()
self.e = Engine()
self.e.update_position(0, 0, 0, 0, 0, 0)
self.canvas = tk.Canvas(self.root, width=canvas_width, height=canvas_height)
self.canvas.pack()
self.speed_up = self.speed_right = self.speed_forward = self.speed_alpha = self.speed_beta = self.speed_gamma = 0
self.root.focus_set()
self.root.bind("<KeyPress>", self.key_down)
self.root.bind("<KeyRelease>", self.key_up)
self.last_time = time.time()
self.update_clock()
self.root.mainloop()
def update_clock(self):
deltat = time.time() - self.last_time
self.last_time = time.time()
self.e.move(deltat * speed * self.speed_forward, deltat * speed * self.speed_up, deltat * speed * self.speed_right)
self.e.rotate(deltat * rot_speed * self.speed_alpha, deltat * rot_speed * self.speed_beta, deltat * rot_speed * self.speed_gamma)
self.canvas.delete('all')
self.canvas.create_text(30, 10, text='FPS: ' + str(int(1/deltat)))
self.draw_cube(2, 5, -0.5, 0.5, -0.5, 0.5, 'red')
self.draw_cube(3.45, 3.55, 0.5, 0.6, -0.05, 0.05, 'red')
self.draw_poly([[2, -0.5, -0.5], [2, -0.5, 0.5], [5, -0.5, 0.5], [5, -0.5, -0.5]], 'red')
#self.draw_cube(5, 7, 3, 1, -1, 1)
#world.draw(self.canvas)
self.root.after(1, self.update_clock)
def draw_poly(self, p, color=None):
allCoords = []
for i in p:
a = self.e.get_2d_point(*i)
allCoords.append(self.screen_pos_x(a[0]))
allCoords.append(self.screen_pos_y(a[1]))
if color:
self.canvas.create_polygon(*allCoords, fill=color)
else:
self.canvas.create_polygon(*allCoords)
def draw_cube(self, x1, x2, y1, y2, z1, z2, color=None):
self.draw_poly([[x1, y1, z1], [x2, y1, z1], [x2, y2, z1], [x1, y2, z1]], color)
self.draw_poly([[x1, y1, z2], [x2, y1, z2], [x2, y2, z2], [x1, y2, z2]], color)
self.draw_poly([[x1, y2, z2], [x2, y2, z2], [x2, y2, z1], [x1, y2, z1]], color)
self.draw_poly([[x1, y2, z2], [x2, y2, z2], [x2, y2, z2], [x1, y2, z2]], color)
# self.draw_line([x1, y1, z1], [x2, y1, z1])
# self.draw_line([x1, y1, z1], [x1, y2, z1])
# self.draw_line([x1, y1, z1], [x1, y1, z2])
#
# self.draw_line([x2, y2, z1], [x1, y2, z1])
# self.draw_line([x2, y2, z1], [x2, y1, z1])
# self.draw_line([x2, y2, z1], [x2, y2, z2])
#
# self.draw_line([x2, y1, z2], [x1, y1, z2])
# self.draw_line([x2, y1, z2], [x2, y2, z2])
# self.draw_line([x2, y1, z2], [x2, y1, z1])
#
# self.draw_line([x1, y2, z2], [x2, y2, z2])
# self.draw_line([x1, y2, z2], [x1, y1, z2])
# self.draw_line([x1, y2, z2], [x1, y2, z1])
def draw_line(self, start3, end3):
start2 = self.e.get_2d_point(start3[0], start3[1], start3[2])
end2 = self.e.get_2d_point(end3[0], end3[1], end3[2])
self.canvas.create_line(self.screen_pos_x(start2[0]), self.screen_pos_y(start2[1]), self.screen_pos_x(end2[0]), self.screen_pos_y(end2[1]), fill="#476042")
def screen_pos_x(self, x):
return x*zoom+canvas_width/2
def screen_pos_y(self, x):
return x*zoom+canvas_height/2
def key_down(self, event):
if event.keycode == 852087:
self.speed_forward = 1
elif event.keycode == 65651:
self.speed_forward = -1
elif event.keycode == 131172:
self.speed_right = 1
elif event.keycode == 97:
self.speed_right = -1
elif event.keycode == 131074:
self.speed_up = 1
elif event.keycode == 3211296:
self.speed_up = -1
elif event.keycode == 5636148:
self.speed_alpha = 1
elif event.keycode == 5767222:
self.speed_alpha = -1
elif event.keycode == 5505074:
self.speed_beta = -1
elif event.keycode == 5963832:
self.speed_beta = 1
elif event.keycode == 5832759:
self.speed_gamma = 1
elif event.keycode == 6029369:
self.speed_gamma = -1
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import update_position [as 别名]
class App:
def __init__(self):
self.root = tk.Tk()
self.canvas = tk.Canvas(self.root, width=canvas_width, height=canvas_height)
self.canvas.pack()
self.e = Engine(self.canvas, canvas_width, canvas_height)
self.e.update_position(0, 2, 0, 0, 0)
self.speed_up = self.speed_right = self.speed_forward = self.alpha = self.beta = 0
self.accel_right = self.accel_forward = 0
self.block_x = self.block_z = self.block_y = 0
self.target_block_x = self.target_block_y = self.target_block_z = 0
self.block_state = 0
self.block_dist = 3
self.block_dist_speed = self.block_dist_accel = 0
self.jumped = self.block_marked = False
self.mouse_start_x = self.mouse_start_y = 0
self.root.focus_set()
self.root.bind("<KeyPress>", self.key_down)
self.root.bind("<KeyRelease>", self.key_up)
self.root.bind("<Button-1>", self.mouse_down)
self.root.bind("<B1-Motion>", self.mouse_moved)
self.load()
self.last_time = time.time()
self.update_clock()
self.root.mainloop()
def load(self):
if os.path.isfile('save.p'):
data = pickle.load(open("save.p", "rb"))
self.e.world = data[0]
self.e.x = data[1]
self.e.y = data[2]
self.e.z = data[3]
self.e.alpha = data[4]
self.e.beta = data[5]
self.block_marked = data[6]
self.block_x = data[7]
self.block_y = data[8]
self.block_z = data[9]
self.block_state = data[10]
self.block_dist = data[11]
def save(self):
data = [self.e.world, self.e.x, self.e.y, self.e.z, self.e.alpha, self.e.beta, self.block_marked, self.block_x,
self.block_y, self.block_z, self.block_state, self.block_dist]
pickle.dump(data, open("save.p", "wb"))
def update_clock(self):
delta_t = time.time() - self.last_time
self.last_time = time.time()
self.block_marked = False
if self.block_state == 0:
for i in range(5):
x = self.e.x + self.e.player_wx * i
y = self.e.y + self.e.player_wy * i
z = self.e.z + self.e.player_wz * i
if self.e.block_exists(x, y, z):
self.block_marked = True
self.target_block_x = round(x)
self.target_block_y = round(y)
self.target_block_z = round(z)
break
if self.block_state == 1:
self.target_block_x = self.e.x + self.e.player_wx * self.block_dist
self.target_block_y = self.e.y + self.e.player_wy * self.block_dist
self.target_block_z = self.e.z + self.e.player_wz * self.block_dist
elif self.block_state == 2:
self.target_block_x = round(self.block_x)
self.target_block_y = round(self.block_y)
self.target_block_z = round(self.block_z)
self.block_state = 3
new_block_x = self.block_x + (self.target_block_x - self.block_x) / 2 * delta_t * 15
new_block_y = self.block_y + (self.target_block_y - self.block_y) / 2 * delta_t * 15
new_block_z = self.block_z + (self.target_block_z - self.block_z) / 2 * delta_t * 15
if not (
self.e.block_exists(new_block_x + 0.5, self.block_y, self.block_z) or self.e.block_exists(
new_block_x - 0.5,
self.block_y,
self.block_z)):
self.block_x = new_block_x
else:
self.block_x = round(new_block_x)
if not (self.e.block_exists(self.block_x, new_block_y + 0.5, self.block_z) or self.e.block_exists(self.block_x,
new_block_y - 0.5,
self.block_z)):
self.block_y = new_block_y
else:
self.block_y = round(new_block_y)
if not (self.e.block_exists(self.block_x, self.block_y, new_block_z + 0.5) or self.e.block_exists(self.block_x,
self.block_y,
new_block_z - 0.5)):
self.block_z = new_block_z
#.........这里部分代码省略.........