Tutorial: Alien Alley Arcade Game
Write a fun space shooter arcade game where you control a spaceship and shoot alien enemies coming at you. Keep moving to shoot.
Source Code
'-------------------------------------------------
' Source code for demo game: Alien Alley
' Original game concept & graphics: Dave Roberts (1994)
'-------------------------------------------------
DIM title, alien, status, planet AS IMAGE
DIM player, shot1, shot2, explo AS IMAGE ' Player
DIM ship1, ship2, ship3, explo1, explo2, explo3, laser1, laser2, laser3 AS IMAGE ' Enemies
DIM credits, barScore AS TEXT
DIM health1, health2, health3, health4, health5 AS RECTANGLE
DIM btnStart AS BUTTON
DIM score AS INTEGER: score = 0
DIM lives AS INTEGER: lives = 6
DIM isOver AS BOOLEAN: isOver = FALSE
' Music & background.
MUSIC "space_voyage"
BGIMAGE "alien_bg", "move-left", 3
planet = IMAGE "alien_planet", (0,0), "hide"
' Define main screen.
title = IMAGE "alien_logo", (_MIDDLEX, 30), "fade-in", 1000
credits = TEXT "Credits:\noriginal game by Dave Roberts (1994)\nremake by D2Soft Technologies (2024)", (_MIDDLEX, 550), "console", 18, #ffffff, "fade-in", 1000
alien = IMAGE "alien_greenman", (550, 400), "fade-in", 1000
btnStart = BUTTON "alien_button", "start", (_MIDDLEX, 450), "console", 30, #FCFC00, "fade-in", 1000
ANIM btnStart, "scale", 100, 90
' Define player.
player = IMAGE "alien_player", (_MIDDLEX, 640) ' Hide at bottom of screen.
shot1 = IMAGE "alien_shot", (0,0), "offscreen"
shot2 = IMAGE "alien_shot", (0,0), "offscreen"
explo = IMAGE "alien_explo", (0,0), "hide"
' Define enemies.
ship1 = IMAGE "alien_ship", (0,0), "hide"
ship2 = IMAGE "alien_ship", (0,0), "hide"
ship3 = IMAGE "alien_ship", (0,0), "hide"
explo1 = IMAGE "alien_explo", (0,0), "hide"
explo2 = IMAGE "alien_explo", (0,0), "hide"
explo3 = IMAGE "alien_explo", (0,0), "hide"
laser1 = IMAGE "alien_shot2", (0,0), "offscreen"
laser2 = IMAGE "alien_shot2", (0,0), "offscreen"
laser3 = IMAGE "alien_shot2", (0,0), "offscreen"
' Define interface.
status = IMAGE "alien_status", (0, 580), "hide"
barScore = TEXT "0", (480, 599), "console", 20, #FFFFFF, "hide"
health1 = RECT (192, 600)-(192+16, 620), #07F717, "hide"
health2 = RECT (192+16, 600)-(192+32, 620), #07F717, "hide" ' Each bloc is 16 pixels.
health3 = RECT (192+32, 600)-(192+48, 620), #07F717, "hide"
health4 = RECT (192+48, 600)-(192+64, 620), #07F717, "hide"
health5 = RECT (192+64, 600)-(192+80, 620), #07F717, "hide"
' Define events.
DRAG player, (0,100)-(640,640-60) ' Define player zone, don't go over status bar.
ON PRESS player, playerClick
ON DRAG player, playerClick
ON CLICK btnStart, startGame
' Set collisions.
ON COLLIDE ship1, shot1, shotShip1
ON COLLIDE ship1, shot2, shotShip2
ON COLLIDE ship1, player, destroyBoth
ON COLLIDE ship2, shot1, shotShip1
ON COLLIDE ship2, shot2, shotShip2
ON COLLIDE ship2, player, destroyBoth
ON COLLIDE ship3, shot1, shotShip1
ON COLLIDE ship3, shot2, shotShip2
ON COLLIDE ship3, player, destroyBoth
ON COLLIDE laser1, player, shotPlayer
ON COLLIDE laser2, player, shotPlayer
ON COLLIDE laser3, player, shotPlayer
'--------------------- SUBs ---------------------
SUB startGame
HIDE btnStart
SOUND "click"
HIDE title, "fade-out", 1000
HIDE credits, "fade-out", 1000
HIDE alien, "fade-out", 1000
WAIT
MUSIC "space_dream"
SHOW status, "fade-in", 1000
SHOW barScore, "fade-in", 1000
BGCOLOR #A385F7
BGIMAGE "alien_bg2", "move-down", 10
WAIT
MOVE player, (_MIDDLEX, 500), 1000
WAIT
SHOW health1, "fade-in", 250
SOUND "blop", "no-wait"
WAIT
SHOW health2, "fade-in", 250
SOUND "blop", "no-wait"
WAIT
SHOW health3, "fade-in", 250
SOUND "blop", "no-wait"
WAIT
SHOW health4, "fade-in", 250
SOUND "blop", "no-wait"
WAIT
SHOW health5, "fade-in", 250
SOUND "blop", "no-wait"
WAIT
TIMER 500, spawn1
TIMER 500, spawn2
TIMER 500, spawn3
TIMER 500, showPlanet
TIMER 500, shootLaser1
TIMER 700, shootLaser2
TIMER 900, shootLaser3
END SUB
SUB playerClick
sound "laser"
SHOW shot1
SHOW shot2
MOVE shot1, (POSX(player)+5, POSY(player))
MOVE shot2, (POSX(player)+50, POSY(player))
MOVE shot1, "out-up", 500
MOVE shot2, "out-up", 500
END SUB
SUB spawn1
IF NOT VISIBLE(ship1) THEN
MOVE ship1, (RND(0, 640-64), -62) ' Move ship back at top of screen.
SHOW ship1
MOVE ship1, (RND(0, 640-64), 640), RND(4000, 8000) ' Ship attacks.
WAIT
HIDE ship1
END IF
END SUB
SUB spawn2
IF NOT VISIBLE(ship2) THEN
MOVE ship2, (RND(0, 640-64), -62) ' Move ship back at top of screen.
SHOW ship2
MOVE ship2, (RND(0, 640-64), 640), RND(4000, 8000)
WAIT
HIDE ship2
END IF
END SUB
SUB spawn3
IF NOT VISIBLE(ship3) THEN
MOVE ship3, (RND(0, 640-64), -62) ' Move ship back at top of screen.
SHOW ship3
MOVE ship3, (RND(0, 640-64), 640), RND(4000, 8000)
WAIT
HIDE ship3
END IF
END SUB
'TODO: could improve by using _OBJECT2 into shotShip to hide to proper shot.
SUB shotShip1
HIDE shot1
shotShip
END SUB
SUB shotShip2
HIDE shot2
shotShip
END SUB
SUB shotShip
SOUND "explosion", "no-wait"
IF _OBJECT = ship1 THEN
explode1
END IF
IF _OBJECT = ship2 THEN
explode2
END IF
IF _OBJECT = ship3 THEN
explode3
END IF
incScore
END SUB
SUB explode1
STOP ANIM ship1
MOVE explo1, (POSX(ship1), POSY(ship1))
SHOW explo1
HIDE ship1
SLEEP 300
HIDE explo1
END SUB
SUB explode2
STOP ANIM ship2
MOVE explo2, (POSX(ship2), POSY(ship2))
SHOW explo2
HIDE ship2
SLEEP 300
HIDE explo2
END SUB
SUB explode3
STOP ANIM ship3
MOVE explo3, (POSX(ship3), POSY(ship3))
SHOW explo3
HIDE ship3
SLEEP 300
HIDE explo3
END SUB
SUB shootLaser1
IF VISIBLE(ship1) AND POSY(ship1) > 10 AND NOT isOver THEN
sound "laser2"
SHOW laser1
MOVE laser1, (POSX(ship1)+28, POSY(ship1)+66)
MOVE laser1, "out-down", 1500
END IF
END SUB
SUB shootLaser2
IF VISIBLE(ship2) AND POSY(ship2) > 10 AND NOT isOver THEN
sound "laser2"
SHOW laser2
MOVE laser2, (POSX(ship2)+28, POSY(ship2)+66)
MOVE laser2, "out-down", 1500
END IF
END SUB
SUB shootLaser3
IF VISIBLE(ship3) AND POSY(ship3) > 10 AND NOT isOver THEN
sound "laser2"
SHOW laser3
MOVE laser3, (POSX(ship3)+28, POSY(ship3)+66)
MOVE laser3, "out-down", 1500
END IF
END SUB
SUB shotPlayer
HIDE _OBJECT
ANIM player, "blink", 200, 3
lives = lives - 1
updateLives
IF lives > 0 THEN
SOUND "hit", "no-wait"
ELSE
destroyPlayer
END IF
END SUB
SUB destroyPlayer
isOver = TRUE
STOP DRAG player
SOUND "explosion", "no-wait"
MOVE explo, (POSX(player), POSY(player))
SHOW explo
HIDE player
SLEEP 300
HIDE explo
SLEEP 1000
gameOver
END SUB
SUB destroyBoth
destroyPlayer
shotShip
END SUB
SUB incScore
IF NOT isOver THEN
score = score + 10
SET TEXT barScore, STR(score)
END IF
END SUB
SUB showPlanet
MOVE planet, (RND(0, 640-64), -100)
SHOW planet
MOVE planet, "out-down", 13000
END SUB
SUB updateLives
IF lives = 5 THEN
HIDE health5
END IF
IF lives = 4 THEN
HIDE health4
END IF
IF lives = 3 THEN
HIDE health3
END IF
IF lives = 2 THEN
HIDE health2
END IF
IF lives = 1 THEN
HIDE health1
END IF
END SUB
SUB gameOver
MUSIC "game_over"
TEXT "Your final score: " + STR(score), (_MIDDLEX, _MIDDLEY), "console", 30, #FFFFFF
SLEEP 4000
RELOAD
END SUB
Go back to list of Tutorials.