Nov-29-2017, 03:08 AM
Hi, I want to do a spaceship that I can control with the arrows on the keyboard. For now I'm able to make it rotate on itself with the left and the right arrow, but I want to make it go in the direction that the ship is facing. For now, all I can do is make it go up and down, but on one axis.
My code look like this:
My code look like this:
import pyglet
fenetre = pyglet.window.Window(700, 700, 'Lost')
fusee_img = pyglet.image.load('player1-ConvertImage.jpg')
fusee_img.anchor_x = fusee_img.width
fusee_img.anchor_y = fusee_img.height
fusee = pyglet.sprite.Sprite(fusee_img, x=100, y=100)
keys = pyglet.window.key.KeyStateHandler()
def update(dt):
fenetre.push_handlers(keys)
left = keys[pyglet.window.key.LEFT]
right = keys[pyglet.window.key.RIGHT]
up = keys[pyglet.window.key.UP]
down = keys[pyglet.window.key.DOWN]
if up and down:
None
elif up:
fusee.y += (dt * 100)
elif down:
fusee.y -= dt * 100
if right and left:
None
elif right:
fusee.rotation += dt * 300
elif left:
fusee.rotation -= dt * 300
pyglet.clock.schedule_interval(update, 1 / 120.0)
@fenetre.event
def on_draw():
fenetre.clear()
fusee.draw()
pyglet.app.run()
