Dojo Defender Session 1 : Cheatsheet
# Déplacer le vaisseau
if keyboard.left and ship.x > 30:
ship.x -= 5
if keyboard.right and ship.x < WIDTH - 30:
ship.x += 5
# Faire apparaître un astéroïde
def spawn_asteroid():
rock = Actor('asteroid_big')
rock.x = random.randint(30, WIDTH - 30)
rock.y = -30
rock.speed = random.uniform(3, 5)
asteroids.append(rock)
# Timer chaque seconde (60 frames)
timer += 1
if timer % 60 == 0:
spawn_asteroid()
# Faire tomber les astéroïdes et les supprimer
for rock in asteroids[:]:
rock.y += rock.speed
if rock.y > HEIGHT + 30:
asteroids.remove(rock)
# Détection de collision
if rock.colliderect(ship) and not invincible:
lives -= 1
# lancer l'explosion
# Jouer l'explosion
explosion.pos = (ship.x, ship.y)
explosion.image = 'explosion_1'
explosion_frame = 1
explosion_timer = 5
explosion_active = True
ship.visible = False
# Écran de game over
if game_over:
screen.draw.text("GAME OVER", center=(WIDTH/2, HEIGHT/2),
color="red", fontsize=60)
# Afficher les vies
screen.draw.text(f"Vies : {lives}", (10, 40), color="red", fontsize=24)