autocam off : hide mouse sync on : sync rate 60 type obj_Satellite ` the sprite index and image num, img ` the local "origin" x, y ` the distance from the local origin dist ` angle to move object away from the origin angle endtype ` quick reference colors global black : black = rgb(0, 0, 0) global white : white = rgb(255, 255, 255) global red : red = rgb(255, 0, 0) global green : green = rgb(0, 255, 0) global blue : blue = rgb(0, 0, 255) global yellow : yellow = rgb(255, 255, 0) global magenta: magenta= rgb(255, 0, 255) global cyan : cyan = rgb(0, 255, 255) global orange : orange = rgb(255, 128, 0) global purple : purple = rgb(128, 0, 255) ` set up rotation tables dim rSpinner(200) dim lSpinner(200) dim bounder(200) dim orbit(200) as obj_Satellite global rIndex = 0 global lIndex = 0 global bIndex = 0 global oIndex = 0 ` make all the sprites makeShip() makeBackdrop() makeEnemy1() makeEnemy2() makeEnemy3() makeEnemy4() makeBullet() ` starting location and movement vectors for the player's ship x = 320 y = 400 dx = 0 dy = 0 ` create the sprite for the player's ship sprite 1, x, y, 1 offset sprite 1, 32, 32 ` starting rotation angle for rSpinners, lSpinners and orbiting sprites angle = 0 ` starting rotation angle and "change of angle" (delta angle) for bounding objects (oscillate back and forth) dB = 1 bAngle = 0 ` beginning sprite offset to use (1 being the player's ship) sprOffset = 2 sprOffset = createEnemy1(sprOffset, 48, 64) sprOffset = createEnemy1(sprOffset, 96, 128) sprOffset = createEnemy1(sprOffset, 48, 192) sprOffset = createEnemy1(sprOffset, 96, 256) sprOffset = createEnemy2(sprOffset, 192, 192) sprOffset = createEnemy2(sprOffset, 288, 96) sprOffset = createEnemy3(sprOffset, 395, 100) sprOffset = createEnemy3(sprOffset, 360, 200) sprOffset = createEnemy4(sprOffset, 545, 100) sprOffset = createEnemy4(sprOffset, 500, 200) sprOffset = createBullets(sprOffset, 320, 350) do ` draw the player's ship sprite 1, x, y, 1 ` scroll the background texture to give the illusion of movement scroll object texture 1, 0, -0.003 ` handle player movement while restricting them to the lower half of the screen if ((upkey() = 1) and (y > 272)) dy = -1 else dy = 0 endif if ((downkey() = 1) and (y < 448)) then dy = 1 if ((leftkey() = 1) and (x > 32)) dx = -1 else dx = 0 endif if ((rightkey() = 1) and (x < 607)) then dx = 1 ` update the (x, y) coordinates used to position the player's sprite x = x + dx y = y + dy ` handle the orbiting sprites for i = 0 to oIndex-1 tangle = wrapvalue(angle + orbit(i).angle) tx = orbit(i).x + (cos(tangle) * orbit(i).dist) ty = orbit(i).y + (sin(tangle) * orbit(i).dist) sprite orbit(i).num, tx, ty, orbit(i).img next i ` handle the rotation of all the enemy sprites for i = 0 to rIndex-1 rotate sprite rSpinner(i), angle next i for i = 0 to lIndex-1 rotate sprite lSpinner(i), 360 - angle next i for i = 0 to bIndex-1 rotate sprite bounder(i), wrapValue(bAngle) next i angle = wrapvalue(angle + 1) if (bAngle < -45) or (bAngle > 45) dB = 0 - dB endif bAngle = bAngle + dB sync loop end ` simple floodfill function to fill in the various shapes function floodfill(x, y, old, new) color = point(x, y) if (color = old) ink new, 0 dot x, y floodfill(x, y-1, old, new) floodfill(x, y+1, old, new) floodfill(x-1, y, old, new) floodfill(x+1, y, old, new) endif endfunction function makeShip() create bitmap 1, 65, 65 set current bitmap 1 ink blue, 0 ` create the wings of the ship circle 10, 30, 10 circle 54, 30, 10 ` create the back of the ship (draw 2 circles to correct a problem I noticed in the fill) circle 32, 29, 32 circle 32, 30, 32 ` block out what we don't need ink 0, 0 box 0, 0, 65, 32 ` draw the front of the ship ink blue, 0 line 28, 0, 21, 32 line 36, 0, 43, 32 line 28, 0, 36, 0 ` fill in the ship floodfill(32, 32, 0, blue) get image 1, 0, 0, 65, 65 set current bitmap 0 delete bitmap 1 endfunction function makeBackdrop() create bitmap 1, 640, 480 set current bitmap 1 ` since rgb(0, 0, 0) is drawn transparent, use rgb(1, 1, 1) to hide the blue screen ink rgb(1, 1, 1), 0 box 0, 0, 640, 480 ` sprinkle the background with single point stars for i = 1 to 320 dot rnd(640), rnd(480), rgb(32 + rnd(64), 32 + rnd(64), 32 + rnd(64)) next i ` add some larger stars to the background for i = 1 to 80 drawStar(rnd(640), rnd(480), rgb(64 + rnd(128), 64 + rnd(128), 64 + rnd(128))) next i get image 2, 0, 0, 640, 480 ` create a plane for our backdrop and texture it with the image we just made make object plain 1, 640, 480 texture object 1, 2 position object 1, -0.5, 0.5, 400 set current bitmap 0 delete bitmap 1 endfunction ` makes a crude star to decorate our backdrop function drawStar(x, y, color) h = (rnd(2) * 2) + 3 h2 = h / 2 w = h - 2 w2 = w / 2 ink color, 0 line x, y - h2, x, y + h2 line x - w2, y, x + w2, y endfunction function makeEnemy1() create bitmap 1, 17, 17 set current bitmap 1 ink green, 0 box 0, 0, 17, 17 get image 3, 0, 0, 16, 16 ink 0, 0 box 0, 0, 17, 17 ink green, 0 circle 4, 4, 4 get image 4, 0, 0, 9, 9 set current bitmap 0 delete bitmap 1 endfunction function makeEnemy2() create bitmap 1, 129, 17 set current bitmap 1 ink red, 0 circle 8, 8, 8 circle 120, 8, 8 line 17, 6, 112, 6 line 17, 10, 112, 10 floodfill(8, 8, 0, red) floodfill(120, 8, 0, red) get image 5, 0, 0, 129, 17 set current bitmap 0 delete bitmap 1 endfunction function makeEnemy3() create bitmap 1, 96, 96 set current bitmap 1 ink orange, 0 line 32, 32, 96, 32 line 32, 32, 64, 90 line 96, 32, 64, 90 dot 64, 90 box 0, 0, 8, 8 floodfill(64, 64, 0, orange) ink 0, 0 circle 64, 32, 10 circle 46, 62, 10 circle 82, 62, 10 floodfill(55, 62, orange, 0) floodfill(74, 62, orange, 0) floodfill(64, 34, orange, 0) ` the following four lines take care of some artifacts that I couldn't figure out ` -- namely, some lines that weren't getting removed by my floodfill function ` comment them out to see what I mean line 32, 32, 96, 32 line 32, 32, 64, 90 line 96, 32, 64, 90 dot 64, 90 get image 6, 32, 32, 96, 96 get image 7, 0, 0, 8, 8 set current bitmap 0 delete bitmap 1 endfunction function makeEnemy4() create bitmap 1, 65, 65 set current bitmap 1 ink purple, 0 circle 32, 32, 32 floodfill(32, 32, 0, purple) ink 0, 0 circle 32, 0, 10 circle 32, 65, 10 circle 0, 32, 10 circle 65, 32, 10 floodfill(32, 2, purple, 0) floodfill(32, 63, purple, 0) floodfill(2, 32, purple, 0) floodfill(63, 32, purple, 0) get image 8, 0, 0, 65, 65 get image 9, 28, 28, 36, 36 set current bitmap 0 delete bitmap 1 endfunction function makeBullet() create bitmap 1, 8, 8 set current bitmap 1 ink red, 0 box 0, 2, 6, 4 box 2, 0, 4, 6 ink yellow, 0 box 2, 2, 4, 4 get image 10, 0, 0, 7, 7 set current bitmap 0 delete bitmap 1 endfunction function createEnemy1(sprOffset, x, y) sprite sprOffset, x, y, 3 offset sprite sprOffset, 8, 8 rSpinner(rIndex) = sprOffset : inc rIndex inc sprOffset sprite sprOffset, x, y, 4 offset sprite sprOffset, 4, -10 rSpinner(rIndex) = sprOffset : inc rIndex inc sprOffset sprite sprOffset, x, y, 4 offset sprite sprOffset, 4, 19 rSpinner(rIndex) = sprOffset : inc rIndex inc sprOffset sprite sprOffset, x, y, 4 offset sprite sprOffset, -10, 4 rSpinner(rIndex) = sprOffset : inc rIndex inc sprOffset sprite sprOffset, x, y, 4 offset sprite sprOffset, 19, 4 rSpinner(rIndex) = sprOffset : inc rIndex inc sprOffset endfunction sprOffset function createEnemy2(sprOffset, x, y) sprite sprOffset, x, y, 5 offset sprite sprOffset, 64, 8 ` rSpinner(rIndex) = sprOffset : inc rIndex bounder(bIndex) = sprOffset : inc bIndex inc sprOffset endfunction sprOffset function createEnemy3(sprOffset, x, y) sprite sprOffset, x, y, 6 offset sprite sprOffset, 32, 32 inc sprOffset sprite sprOffset, x, y - 35, 7 offset sprite sprOffset, 4, 4 bounder(bIndex) = sprOffset : inc bIndex inc sprOffset sprite sprOffset, x - 20, y, 7 offset sprite sprOffset, 4, 4 lSpinner(lIndex) = sprOffset : inc lIndex inc sprOffset sprite sprOffset, x + 20, y, 7 offset sprite sprOffset, 4, 4 rSpinner(rIndex) = sprOffset : inc rIndex inc sprOffset endfunction sprOffset function createEnemy4(sprOffset, x, y) sprite sprOffset, x, y, 8 offset sprite sprOffset, 32, 32 rSpinner(rIndex) = sprOffset : inc rIndex inc sprOffset sprite sprOffset, x, y, 9 offset sprite sprOffset, 4, 4 lSpinner(lIndex) = sprOffset : inc lIndex orbit(oIndex).num = sprOffset orbit(oIndex).img = 9 orbit(oIndex).x = x orbit(oIndex).y = y orbit(oIndex).dist = 35 orbit(oIndex).angle = 0 inc oIndex inc sprOffset ` sprite sprOffset, x, y+35, 9 sprite sprOffset, x, y, 9 offset sprite sprOffset, 4, 4 lSpinner(lIndex) = sprOffset : inc lIndex orbit(oIndex).num = sprOffset orbit(oIndex).img = 9 orbit(oIndex).x = x orbit(oIndex).y = y orbit(oIndex).dist = 35 orbit(oIndex).angle = 90 inc oIndex inc sprOffset ` sprite sprOffset, x-35, y, 9 sprite sprOffset, x, y, 9 offset sprite sprOffset, 4, 4 lSpinner(lIndex) = sprOffset : inc lIndex orbit(oIndex).num = sprOffset orbit(oIndex).img = 9 orbit(oIndex).x = x orbit(oIndex).y = y orbit(oIndex).dist = 35 orbit(oIndex).angle = 180 inc oIndex inc sprOffset ` sprite sprOffset, x+35, y, 9 sprite sprOffset, x, y, 9 offset sprite sprOffset, 4, 4 lSpinner(lIndex) = sprOffset : inc lIndex orbit(oIndex).num = sprOffset orbit(oIndex).img = 9 orbit(oIndex).x = x orbit(oIndex).y = y orbit(oIndex).dist = 35 orbit(oIndex).angle = 270 inc oIndex inc sprOffset endfunction sprOffset function createBullets(sprOffset, x, y) offset = 5 for i = 1 to 1 sprite sprOffset, x - offset, y, 10 offset sprite sprOffset, 2, 2 rSpinner(rIndex) = sprOffset : inc rIndex inc sprOffset sprite sprOffset, x + offset, y, 10 offset sprite sprOffset, 2, 2 lSpinner(lIndex) = sprOffset : inc lIndex inc sprOffset next i endfunction sprOffset