⏱️ Boucle de jeu temps réel
timer = tick 40ms exécute une boucle à 25 fps directement dans l'état réactif sans nécessiter setInterval ou requestAnimationFrame.
Défendez la grille dans un jeu d’arcade jouable créé avec Rune-Web.
Appuyez sur PLAY NOW, déplacez-vous avec A/D ou les flèches et tirez avec Espace. Les commandes tactiles sont sous le jeu.
Chargement du jeu…
Aucun fichier correspondant.
#!RUNE
import "parts"
@App
name = VectRaiders
version = 1.0
type = REST
port = 3000
@Frontend
type = rune-web
path = %ROOT%
page = space-invaders
@Page/space-invaders
title = VectRaiders
style = invaders
logic = invaders
view:
main .arcade-cabinet:
header .cabinet-header:
h1 .cabinet-title "VECTRAIDERS"
div .stats-bar:
span "SCORE: {score}"
span "LIVES: {lives}"
span "ALIENS: {alien_count}"
div .arena-viewport:
div .game-arena:
div .arena-grid
# Player Cannon
div .player style="left: calc({player.x} * 100% / 480);":
div .player-canon
# Player Lasers
div .bullet <- bullet in bullets:
style = "left: calc({bullet.x} * 100% / 480); top: calc({bullet.y} * 100% / 460);"
# Alien Lasers
div .alien-bullet <- ab in alien_bullets:
style = "left: calc({ab.x} * 100% / 480); top: calc({ab.y} * 100% / 460);"
# Invader Grid
div .alien .type-{alien.type} style="left: calc({alien.x} * 100% / 480); top: calc({alien.y} * 100% / 460); display: {alien.alive ? 'flex' : 'none'};" <- alien in aliens:
"👾"
# Explosions & Particles
div .particle <- p in particles:
style = "left: calc({p.x} * 100% / 480); top: calc({p.y} * 100% / 460); opacity: calc({p.life} / {p.max_life}); width: {p.size}px; height: {p.size}px; background: {p.color};"
# Game State Overlay
if status != "playing":
div .overlay:
h2 .overlay-title "{game_message}"
button .start-btn click=start on_pointerdown=start "PLAY NOW"
# Arcade Controls for Touch and Mouse
div .arcade-controls:
button .ctrl-btn on_pointerdown=startLeft on_pointerup=stopMove on_pointerleave=stopMove click=moveLeft "◀ LEFT"
button .ctrl-btn .fire-btn on_pointerdown=fire click=fire "⚡ FIRE"
button .ctrl-btn on_pointerdown=startRight on_pointerup=stopMove on_pointerleave=stopMove click=moveRight "RIGHT ▶"
p .controls-hint "KEYBOARD: [A / ◀] LEFT • [D / ▶] RIGHT • [SPACE] FIRE"
# Enemy formations and fleet configuration for VectRaiders
@Logic/invaders
state:
local alien_batch = { "x": 50, "start_x": 50 } * 6 inc (x, start_x) by 65
aliens = [
alien with { "y": 40, "start_y": 40, "type": 1 },
alien with { "y": 80, "start_y": 80, "type": 2 },
alien with { "y": 120, "start_y": 120, "type": 3 }
] all { "alive": true }
@Logic/invaders
timer = tick 40ms
keys:
ArrowLeft -> moveLeft
ArrowRight -> moveRight
Space -> fire
KeyA -> moveLeft
KeyD -> moveRight
state:
player = { "x": 220, "y": 420 }
bullets = []
alien_bullets = []
particles = emitter { "life": 14, "friction": 0.92, "size": [3, 5] }
alien_dir = 1
alien_speed = 3
alien_count = 18
move_dir = 0
score = 0
lives = 3
status = "ready"
game_message = "VECTRAIDERS"
action startLeft:
stop when status != "playing"
move_dir = -1
player.x = clamp(player.x - 18, 10, 434)
action startRight:
stop when status != "playing"
move_dir = 1
player.x = clamp(player.x + 18, 10, 434)
action stopMove:
move_dir = 0
action moveLeft:
stop when status != "playing"
player.x = clamp(player.x - 20, 10, 434)
action moveRight:
stop when status != "playing"
player.x = clamp(player.x + 20, 10, 434)
action fire:
stop when status != "playing"
stop when bullets.length >= 3
bullets.push({ "x": player.x + 16, "y": 405, "alive": true })
sound "laser"
action start:
score = 0
lives = 3
alien_count = 18
alien_dir = 1
move_dir = 0
player.x = 220
bullets = []
alien_bullets = []
particles = []
restore aliens
status = "playing"
game_message = ""
music.play "vectraiders"
action tick:
particles.step()
stop when status != "playing"
# Smooth continuous movement when on-screen buttons are pressed
if move_dir < 0:
player.x = clamp(player.x - 12, 10, 434)
if move_dir > 0:
player.x = clamp(player.x + 12, 10, 434)
# 1. Update player bullets
for b in bullets:
b.y -= 12
bullets = bullets.filter it.y > 0 and it.alive
# 2. Update alien bullets
for ab in alien_bullets:
ab.y += 7
alien_bullets = alien_bullets.filter it.y < 460 and it.alive
# 3. Check alien bullet collision with player
for ab in alien_bullets:
if collide(ab, player, 20, 16):
ab.alive = false
lives -= 1
sound "hit"
particles.burst(player.x + 16, player.y + 10, 14, "#00e5ff", 8)
if lives <= 0:
sound "gameover"
music.stop
status = "game_over"
game_message = "GAME OVER"
stop
# 4. Move aliens and detect boundary reversal
change_dir = false
for a in aliens:
if a.alive:
a.x += alien_dir * alien_speed
if a.x > 430 or a.x < 20:
change_dir = true
if a.y > 400:
sound "gameover"
music.stop
status = "game_over"
game_message = "GRID BREACHED! GAME OVER"
stop
if change_dir:
alien_dir = -alien_dir
sound "step"
for a in aliens:
a.y += 16
# 5. Check player bullet collisions with aliens
for b in bullets:
for a in aliens:
if a.alive and b.alive:
if collide(b, a, 22, 18):
a.alive = false
b.alive = false
score += 20
alien_count -= 1
sound "explosion"
particles.burst(a.x + 12, a.y + 10, 10, "#ff2a85", 7)
# 6. Occasional alien return fire
if random(1, 22) == 1:
for a in aliens:
if a.alive and random(1, 5) == 1:
alien_bullets.push({ "x": a.x + 12, "y": a.y + 16, "alive": true })
stop
# 7. Check victory condition
if alien_count <= 0:
sound "victory"
music.stop
status = "victory"
game_message = "VECTOR GRID SAVED! YOU WIN!"
stop
# VectRaiders Arcade Sound & Chiptune Music Engine
@Sound/laser
wave = sawtooth
freq = 880 -> 110
duration = 120ms
volume = 0.25
curve = exponential
@Sound/hit
wave = square
freq = 180 -> 40
duration = 90ms
volume = 0.35
@Sound/explosion
wave = noise
filter = lowpass 800 -> 60
duration = 350ms
volume = 0.45
@Sound/step
wave = square
notes = 110, 98, 87, 82
duration = 80ms
volume = 0.2
@Sound/gameover
wave = sawtooth
sequence = E4:150ms, D4:150ms, C4:250ms, G3:450ms
duration = 600ms
volume = 0.3
@Sound/victory
wave = triangle
sequence = C5:120ms, E5:120ms, G5:120ms, C6:240ms
duration = 600ms
volume = 0.3
@Music/vectraiders
type = 8bit
tempo = 144
loop = true
volume = 0.18
lead:
E4:8 D#4:8 E4:8 B3:8 D4:8 C4:8 A3:4 # Bar 1: Alien theme
E4:8 D#4:8 E4:8 B3:8 D4:8 C4:8 A3:4 # Bar 2: Theme reprise
C4:8 D4:8 E4:8 G4:8 A4:4 G4:4 # Bar 3: Ascending run
E4:8 D4:8 C4:8 B3:8 A3:2 # Bar 4: Minor cadence
bass:
A2:4 E2:4 A2:4 E2:4 # Bar 1: Driving pulse
A2:4 E2:4 A2:4 E2:4 # Bar 2
C3:4 G2:4 C3:4 G2:4 # Bar 3
F2:4 C2:4 E2:4 G#2:4 # Bar 4
drums:
kick:4 snare:4 kick:4 snare:4 # Bar 1
kick:4 snare:4 kick:4 snare:4 # Bar 2
kick:8 hihat:8 snare:4 kick:8 hihat:8 snare:4 # Bar 3: Roll
kick:4 snare:4 kick:4 snare:4 # Bar 4
@Style/invaders
tokens:
neon_green = #00ff88
neon_cyan = #00e5ff
neon_pink = #ff2a85
neon_yellow = #ffd000
cabinet_bg = #0a0d1a
arena_bg = #04060d
card_bg = #0d1124
grid_border = #233554
text_muted = #8892b0
btn_bg = #1a233a
presets:
game-entity:
abs = true
pointer-events = none
arcade-btn:
position = relative
pointer-events = auto
cursor = pointer
touch-action = manipulation
user-select = none
weight = bold
center = xy
transition = all 0.1s ease
rules:
body:
margin = 0
padding = 8px
box-sizing = border-box
background = {cabinet_bg}
.arcade-cabinet:
max-width = min(540px, calc((100svh - 272px) * 480 / 460 + 32px))
width = 100%
box-sizing = border-box
margin = 0 auto
background = {card_bg}
border = 3px solid {neon_green}
round = 16px
padding = 0.75rem
box-shadow = 0 0 35px {neon_green / 25%}, inset 0 0 20px rgba(0, 0, 0, 0.8)
font-family = "Courier New", monospace, sans-serif
color = #ffffff
user-select = none
touch-action = manipulation
# Embedded cabinets size from available width; the host fits their height.
# Using the iframe's viewport height here creates a resize feedback loop.
.rune-embedded-game .arcade-cabinet:
max-width = 540px
.cabinet-header:
text-align = center
margin-bottom = 0.75rem
border-bottom = 2px solid {neon_green / 30%}
padding-bottom = 0.6rem
.cabinet-title:
font-size = 1.75rem
weight = 900
letter-spacing = 4px
color = {neon_green}
text-glow = {neon_green} 10px 20px
margin = 0 0 0.5rem 0
.stats-bar:
display = flex
justify-content = space-between
font-size = 0.95rem
weight = bold
letter-spacing = 2px
color = {neon_cyan}
.stat-label:
color = {text_muted}
# Rendering maps the 480 by 460 game coordinates into this fluid rectangle.
.arena-viewport:
position = relative
container-type = inline-size
display = block
width = 100%
height = auto
aspect = 480 / 460
margin = 0 auto
overflow = hidden
.game-arena:
abs = inset
size = 100%
box-sizing = border-box
background = {arena_bg}
border = 2px solid {grid_border}
round = 8px
overflow = hidden
box-shadow = inset 0 0 40px rgba(0, 0, 0, 0.9)
pointer-events = none
.arena-grid:
use = (game-entity)
abs = 0 0
size = 100%
background-image = linear-gradient({neon_green / 4%} 1px, transparent 1px), linear-gradient(90deg, {neon_green / 4%} 1px, transparent 1px)
background-size = 5% 5.217391%
.player:
use = (game-entity)
bottom = 3.478261%
size = 7.5% 4.347826%
background = {neon_green}
round = 4px 4px 1px 1px
glow = {neon_green} 15px
transition = left 0.04s ease-out
.player-canon:
position = absolute
top = -30%
left = 41.666667%
size = 16.666667% 40%
background = #ffffff
round = 2px
.alien:
use = (game-entity)
size = 5.833333% 4.782609%
round = 4px
center = xy
font-size = clamp(6px, 2.916667cqw, 14px)
weight = bold
transition = top 0.1s linear, left 0.1s linear
.alien.type-1:
background = {neon_pink}
glow = {neon_pink} 10px
color = #ffffff
.alien.type-2:
background = {neon_cyan}
glow = {neon_cyan} 10px
color = {arena_bg}
.alien.type-3:
background = {neon_yellow}
glow = {neon_yellow} 10px
color = {arena_bg}
.bullet:
use = (game-entity)
size = 0.833333% 2.608696%
background = #ffffff
round = 2px
box-shadow = 0 0 8px {neon_cyan}, 0 0 14px #ffffff
.alien-bullet:
use = (game-entity)
size = 0.833333% 2.173913%
background = {neon_pink}
round = 2px
glow = {neon_pink} 8px
.particle:
use = (game-entity)
round = 50%
transform = translate(-50%, -50%)
pointer-events = none
z-index = 15
will-change = transform, opacity
.overlay:
abs = inset
size = 100%
background = {arena_bg / 88%}
center = xy
flex-direction = column
z-index = 20
pointer-events = auto
.overlay-title:
font-size = 1.6rem
weight = 900
letter-spacing = 3px
margin-bottom = 1rem
text-align = center
color = {neon_yellow}
text-glow = {neon_yellow} 15px
padding = 0 1rem
.start-btn:
use = (arcade-btn)
background = {neon_green}
color = {arena_bg}
border = none
padding = 0.85rem 2.25rem
font-size = 1.15rem
letter-spacing = 2px
round = 8px
glow = {neon_green / 60%} 20px
transition = all 0.15s ease
&:hover:
background = #33ffa3
glow = {neon_green / 90%} 30px
transform = scale(1.05)
&:active:
transform = scale(0.97)
.arcade-controls:
position = relative
z-index = 100
display = flex
justify-content = space-between
width = 100%
gap = 0.75rem
margin-top = 1.1rem
box-sizing = border-box
pointer-events = auto
.ctrl-btn:
use = (arcade-btn)
flex = 1
min-height = 54px
background = {btn_bg}
color = {neon_green}
border = 2px solid {grid_border}
padding = 0.75rem 0.5rem
font-size = 1.05rem
round = 8px
&:hover:
border-color = {neon_green}
glow = {neon_green / 30%} 12px
&:active:
background = {neon_green}
color = {arena_bg}
transform = scale(0.95)
&.fire-btn:
flex = 1.4
background = {neon_pink}
color = #ffffff
border-color = {neon_pink}
glow = {neon_pink / 40%} 15px
font-size = 1.2rem
&:hover:
background = #ff4d99
glow = {neon_pink / 70%} 25px
&:active:
background = #ff1a75
transform = scale(0.95)
.controls-hint:
text-align = center
margin-top = 0.75rem
font-size = 0.8rem
color = #64748b
letter-spacing = 1px
responsive:
(max-width: 520px):
.arcade-cabinet:
padding = 0.5rem
margin = 0 auto
border-width = 2px
border-radius = 12px
.cabinet-title:
font-size = 1.35rem
letter-spacing = 2px
.stats-bar:
font-size = 0.8rem
letter-spacing = 1px
.arcade-controls:
gap = 0.4rem
margin-top = 0.6rem
position = relative
z-index = 100
.ctrl-btn:
min-height = 54px
font-size = 1rem
padding = 0.75rem 0.25rem
.ctrl-btn.fire-btn:
flex = 1.3
font-size = 1.15rem
.controls-hint:
font-size = 0.7rem
(max-height: 480px):
.arcade-cabinet:
max-width = min(420px, calc((100svh - 175px) * 480 / 460 + 24px))
padding = 0.5rem
.cabinet-title:
font-size = 1rem
margin-bottom = 0.25rem
.cabinet-header:
margin-bottom = 0.4rem
padding-bottom = 0.4rem
.stats-bar:
font-size = 0.65rem
letter-spacing = 0
.arcade-controls:
margin-top = 0.5rem
gap = 0.25rem
.ctrl-btn:
min-height = 44px
font-size = 0.7rem
padding = 0.5rem 0.1rem
.ctrl-btn.fire-btn:
font-size = 0.75rem
.controls-hint:
display = none
timer = tick 40ms exécute une boucle à 25 fps directement dans l'état réactif sans nécessiter setInterval ou requestAnimationFrame.
keys: associe les touches (ArrowLeft, ArrowRight, Space) directement aux actions avec blocage automatique du défilement navigateur.
collide(bullet, alien, 22, 18) et clamp(x, min, max) offrent des capacités spatiales concises et réutilisables.
La mise à jour des positions des tirs et aliens déclenche un rafraîchissement DOM instantané avec esthétique rétro néon CRT.
⌨️ A / ◀: Gauche • D / ▶: Droite • Espace: Tirer
📱 Touchez et maintenez les boutons d'arcade à l'écran pour glisser et tirer sur mobile et tablette.
Pour exécuter l’exemple complet, installez Vectrune et Git. Clonez le dépôt une fois et conservez le dossier parts avec le fichier principal.
Démarrage rapidegit clone https://github.com/davethomas11/vectrune.git
cd vectruneExécutez ces commandes à la racine du dépôt. Si vous avez déjà une copie, ouvrez simplement un terminal à sa racine.
vectrune examples/games/space_invaders/space_invaders.rune
vectrune examples/games/space_invaders/space_invaders.rune -o html > space_invaders.html