Small Basic: Space Invaders (código)


a1

  1.  ‘ SBace-Invaders-25 – A space invader game in under 25 lines by Davey~Wavey, Nov.2009, for Small Basic.’
  2. ‘ Alien has increasing speed as it descends to increase difficulty, but you also get more score the faster they are!
  3. ‘ You are rated on your score and your hit accuracy. You have 3 lives. Use your mouse to move your rocket and left mousebutton to fire.
  4. ‘ NOTES: This looks more complex than it really is. Instead of defining any variables, I am using the array to handle everything.
  5. ‘                 Unfortunately this means that every time I change a variable, I have to completely rebuild the array, hence the long ‘gamearry’ lines.
  6. ‘                If you compare them though, you’ll see that only one, or maybe two, values change each time.
  7. ‘               To cut down on lines, I’m also using the ElseIf’s to handle the various checks, which means I only need one endif.
  8. ‘               bx, by = bullet x,y.   ax,ay = alien x,y.   adir = alien direction.   aspeed = alien speed.
  9. ‘               The strange ‘1=-1;-1=1’ elements, along with ‘adir’, allow me to simulate a logical ‘NOT’ type function when I need to bounce the alien. (i.e. adir=NOT adir)
  10. ‘ initialise game array and start mouse event handling
  11. gamearry = “1=-1;-1=1;bx=0;by=0;lives=3;ammo=0;score=0;bullet=” + Shapes.AddEllipse(5,10) + “;gun=” + Shapes.AddImage(“http://www.tutorialized.com/upload/(2006.06.21-09:12:44)rocket50x50.jpg”) + “;ax=” + (GraphicsWindow.Width/2) + “;ay=20;adir=-1;aspeed=0.2;alien=” + shapes.AddImage(“http://www.adiumxtras.com/images/thumbs/space_invaders_1_17601_6150_thumb.png”)
  12. GraphicsWindow.MouseDown=fire
  13. While gamearry[“lives”] > 0
  14.   ‘ update alien and bullet positions
  15.   gamearry = “1=-1;-1=1;bx=” + gamearry[“bx”] + “;by=” + (gamearry[“by”] – gamearry[“aspeed”]) +”;lives=” + gamearry[“lives”] +”;ammo=” + gamearry[“ammo”] +”;score=” + gamearry[“score”] +”;bullet=” + gamearry[“bullet”] +”;gun=” + gamearry[“gun”] +”;ax=” + (gamearry[“ax”] + (gamearry[ gamearry[“adir”] ] * gamearry[“aspeed”] )) +”;ay=” + gamearry[“ay”] +”;adir=” + gamearry[“adir”] +”;aspeed=” + gamearry[“aspeed”] +”;alien=” + gamearry[“alien”]
  16.   ‘ move the gun, alien and bullet
  17.   Shapes.Move(gamearry[“gun”], GraphicsWindow.MouseX-25, GraphicsWindow.Height-50)
  18.   Shapes.Animate(gamearry[“alien”], gamearry[“ax”]-25, gamearry[“ay”]-25,0)
  19.   Shapes.Move(gamearry[“bullet”], gamearry[“bx”]-3, gamearry[“by”])
  20.   ‘ bounce the alien at the screen edge (or has it hit player?)
  21.   If ((gamearry[“ax”] < 35) or (gamearry[“ax”] > GraphicsWindow.Width-35)) Then
  22.     ‘ alien has hit edge of screen, so bounce it
  23.     gamearry = “1=-1;-1=1;bx=” + gamearry[“bx”] + “;by=” + gamearry[“by”] +”;lives=” + gamearry[“lives”] +”;ammo=” + gamearry[“ammo”] +”;score=” + gamearry[“score”] +”;bullet=” + gamearry[“bullet”] +”;gun=” + gamearry[“gun”] +”;ax=” + gamearry[“ax”] +”;ay=” + (gamearry[“ay”]+10) +”;adir=” + gamearry[ gamearry[“adir”] ] +”;aspeed=” + (gamearry[“aspeed”]+0.01) +”;alien=” + gamearry[“alien”]
  24.   ElseIf (gamearry[“ay”] >= GraphicsWindow.Height-15) Then
  25.     ‘ alien has reached the bottom – decrease life and reset alien.
  26.     gamearry = “1=-1;-1=1;bx=” + gamearry[“bx”] + “;by=” + gamearry[“by”] +”;lives=” + (gamearry[“lives”]-1) +”;ammo=” + gamearry[“ammo”] +”;score=” + gamearry[“score”] +”;bullet=” + gamearry[“bullet”] +”;gun=” + gamearry[“gun”] +”;ax=” + (GraphicsWindow.Width/2) + “;ay=20;adir=” + gamearry[ gamearry[“adir”] ] +”;aspeed=” + (gamearry[“aspeed”]+0.01) +”;alien=” + gamearry[“alien”]
  27.   ElseIf ( math.abs( math.Floor(gamearry[“bx”]-(gamearry[“ax”])) ) <25 ) and ( math.Abs( Math.Floor( gamearry[“by”]-gamearry[“ay”] ) ) < 10 ) Then
  28.     ‘ bullet has collided with alien – increase score and reset alien
  29.     gamearry = “1=-1;-1=1;bx=” + gamearry[“bx”] + “;by=” + gamearry[“by”] +”;lives=” + gamearry[“lives”] +”;ammo=” + gamearry[“ammo”] +”;score=” + (gamearry[“score”]+Math.Floor((gamearry[“aspeed”]+1)*(gamearry[“aspeed”]+1))) +”;bullet=” + gamearry[“bullet”] +”;gun=” + gamearry[“gun”] +”;ax=” + (GraphicsWindow.Width/2) + “;ay=20;adir=” + gamearry[“adir”] +”;aspeed=” + gamearry[“aspeed”] +”;alien=” + gamearry[“alien”]
  30.   EndIf
  31.   ‘ show status
  32.   GraphicsWindow.Title = “SBace-Invaders-25: SCORE=” + gamearry[“score”] + ”   LIVES=” + gamearry[“lives”]
  33. EndWhile
  34. ‘ Game Over!
  35. GraphicsWindow.ShowMessage (“Well Done, you scored: ” + gamearry[“score”] + ” and your Skill = ” + Math.Floor((gamearry[“score”]/gamearry[“ammo”])*100) + “%”, “<<< G-A-M-E   O-V-E-R >>>         “)
  36. Sub fire
  37.   gamearry = “1=-1;-1=1;bx=” + (GraphicsWindow.mousex) + “;by=” + (GraphicsWindow.Height-45) +”;lives=” + gamearry[“lives”] +”;ammo=” + (gamearry[“ammo”]+1) +”;score=” + gamearry[“score”] +”;bullet=” + gamearry[“bullet”] +”;gun=” + gamearry[“gun”] +”;ax=” + gamearry[“ax”] +”;ay=” + gamearry[“ay”] +”;adir=” + gamearry[“adir”] +”;aspeed=” + gamearry[“aspeed”] +”;alien=” + gamearry[“alien”]
  38. EndSub

(20 lines)
by Davey-Wavey: XDK444

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s