<jupyter_start><jupyter_text>Spaceship 3DThis Jupyter notebook demonstrates making a simple 3d game with Jupylet. Run the notebook and click the game canvas once it shows up to bring it into focus and then use the arrows and keys W, A, S, D, SHIFT, ALT and CAPSLOCK to control the camera or the moon.* Moon textures are by [NASA](https://svs.gsfc.nasa.gov/4720).  * Nebula sky was generated with [spacescape](https://github.com/petrocket/spacescape) by <NAME>.  * Alien texture is from [TextureHaven](https://texturehaven.com/textures/).* Eye texture is from [Flickr](https://www.flickr.com/photos/filterforge/33680912465/in/photostream/) stated as CC BY 2.0.<jupyter_code>import math
import sys
import os
sys.path.insert(0, os.path.abspath('./..'))
from jupylet.sprite import Sprite
from jupylet.label import Label
from jupylet.app import App
app = App()
stars = Sprite('images/stars.png', scale=2.5)
alien = Sprite('images/alien.png', scale=0.5)
ship = Sprite('images/ship1.png', x=app.width/2, y=app.height/2, scale=0.5)
moon = Sprite('images/moon.png', x=app.width-70, y=app.height-70, scale=0.5)
circle = Sprite('images/yellow-circle.png', width=184)
circle.opacity = 0.
label = Label('hello, world', color='cyan', font_size=32, x=10, y=10)
vx = 0
vy = 0

up = 0
left = 0
right = 0
@app.run_me_every(1/120)
def update_ship(ct, dt):
    
    global vx, vy

    if left:
        ship.angle += 192 * dt
        
    if right:
        ship.angle -= 192 * dt
        
    if up:
        vx += 3 * math.cos((90 + ship.angle) / 180 * math.pi)
        vy += 3 * math.sin((90 - ship.angle) / 180 * math.pi)

    ship.x += vx * dt
    ship.y += vy * dt
    
    ship.wrap_position(app.width, app.height)
    
    if len(ship.collisions_with(alien)) > 0:
        circle.opacity = 0.5
    else:
        circle.opacity = 0.0
@app.run_me_every(1/48)
def rotate(ct, dt):
    
    alien.angle += 64 * dt
@app.event
def mouse_position_event(x, y, dx, dy):
    
    alien.x = x
    alien.y = y
    
    circle.x = x
    circle.y = y    
@app.event
def key_event(key, action, modifiers):
    
    global up, left, right
    
    keys = app.window.keys
    
    if action == keys.ACTION_PRESS:

        if key == keys.UP:
            ship.image = 'images/ship2.png'
            up = True

        if key == keys.LEFT:
            left = True

        if key == keys.RIGHT:
            right = True

    if action == keys.ACTION_RELEASE:
    
        if key == keys.UP:
            ship.image = 'images/ship1.png'
            up = False

        if key == keys.LEFT:
            left = False

        if key == keys.RIGHT:
            right = False
@app.event
def render(ct, dt):
    
    app.window.clear()
    
    stars.draw()
    moon.draw()

    circle.draw()
    alien.draw()
    ship.draw()
    
    label.draw()
app.run()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup