Sep 16, 2006 11:58
i decided the other day that i was going to learn how to program computer games, cause i was bored and thought it would be amusing. so i downloaded some fairly simple software and wrote a space-invaders sort of game in Basic4GL. here's the code:
dim score, lives, turretx, alienx, alieny, asteroidx, asteroidy
dim bulletx, bullety, bulletOnScreen, i
lives = 3
turretx = 19
alienx = 0
alieny = 12
asteroidx = 20
asteroidy = 0
bulletOnScreen = false
TextMode (TEXT_BUFFERED)
while true
if ScanKeyDown (VK_LEFT) and turretx > 0 then
turretx = turretx - 1
endif
if ScanKeyDown (VK_RIGHT) and turretx < 37 then
turretx = turretx + 1
endif
alienx = alienx + 1
if alienx >37 then
alienx = 0
alieny = rnd () % 22 + 1
endif
asteroidy = asteroidy + 1
if asteroidy >23 then
asteroidx = rnd () % 22 + 1
asteroidy = 0
endif
if bulletOnScreen then
bullety = bullety - 1
if bullety < 1 then
bulletOnScreen = false
endif
else
if ScanKeyDown (VK_SPACE) then
bulletOnScreen = true
bullety = 22
bulletx = turretx + 1
endif
endif
cls
color (255, 255, 255)
locate 0, 0: print "Score=" + score
locate 30, 0: print "Lives=" + lives
color (255, 50, 50)
locate alienx, alieny: print ">O<"
color (150, 150, 150)
locate turretx, 23: print ""
locate asteroidx, asteroidy: print "(o)"
if bulletOnScreen then
color (255, 255, 50)
locate bulletx, bullety: print "!"
endif
if bulletOnScreen and bullety = alieny and bulletx >= alienx and bulletx <= alienx + 2 then
color (255, 255, 100)
for i = 1 to 10
locate alienx, alieny: print "///"
DrawText ()
Sleep (50)
locate alienx, alieny: print "\\\"
DrawText ()
Sleep (50)
next
bulletOnScreen = false
alienx = 0
alieny = rnd () % 22 + 1
score = score + 100
Sleep (1000)
endif
if asteroidy = 23 and turretx >= asteroidx and turretx <= asteroidx + 2 then
for i = 1 to 10
locate turretx, 23: print ">>>"
DrawText ()
Sleep (50)
locate turretx, 23: print "<<<"
DrawText ()
Sleep (50)
next
lives = lives - 1
Sleep (1000)
endif
if lives = -1 then locate 0, 12: print "GAME OVER"
endif
DrawText ()
Sleep (75)
wend
yay, isn't that exciting. ok, it's a lot cooler when you actually play it...