setscreen ("graphics:640;480,nocursor")
var shippic : int := Pic.FileNew ("Spaceship.bmp")
var rock1pic : int := Pic.FileNew ("Rock1.bmp")
var rock2pic : int := Pic.FileNew ("Rock2.bmp")
var rock3pic : int := Pic.FileNew ("Rock3.bmp")
var rock4pic : int := Pic.FileNew("Rock4.bmp")
var rock5pic : int := Pic.FileNew("Rock5.bmp")
var boompic : int := Pic.FileNew("Boom.bmp")
var laserpic : int := Pic.FileNew ("Laser.bmp")
var shipxcenter : int := 290
var shipycenter : int := 0
var rock1xcenter : int := Rand.Int (10, 630)
var rock1ycenter : int := maxy + 20
var rock2xcenter : int := Rand.Int (10, 630)
var rock2ycenter : int := maxy + 20
var rock3xcenter : int := Rand.Int (10, 630)
var rock3ycenter : int := maxy + 20
var rock4xcenter : int := Rand.Int (10,630)
var rock4ycenter : int := maxy + 20
var rock5xcenter : int := Rand.Int (10,630)
var rock5ycenter : int := maxy + 20
var boomxcenter : int := 0
var boomycenter : int := 0
var laserxcenter : int :=-10
var laserycenter : int :=-10
var shoot: boolean :=false
var chars : array char of boolean
var key : string(1):=""
var speedofship : int := 10
var font1 : int := Font.New ("comicsans:12")
var score : int := 0
var lives : int := 3
procedure DrawShip (x, y : int)
Pic.Draw (shippic, x, y, picMerge)
end DrawShip
procedure DrawRock (x, y ,rockpic: int)
Pic.Draw (rockpic, x, y, picMerge)
end DrawRock
procedure DrawBoom(x,y :int)
Pic.Draw(boompic,x,y,picMerge)
end DrawBoom
procedure DrawLaser (x, y : int)
Pic.Draw (laserpic, x, y, picMerge)
end DrawLaser
DrawShip (shipxcenter, shipycenter)
procedure Collision(X1:int,Y1:int,var X2:int,var Y2:int,pic1:int,pic2:int)
if X1+Pic.Width(pic1)/2>X2-Pic.Width(pic2)/2 and X1-Pic.Width(pic1)/2<X2+Pic.Width(pic2)/2 and Y1+Pic.Width(pic1)>Y2-Pic.Width(pic2)/2 and Y1-Pic.Width(pic1)/2<Y2+Pic.Width(pic2)/2 then
boomxcenter:=X2
boomycenter:=Y2
DrawBoom(boomxcenter,boomycenter)
X2 := Rand.Int (10,630)
Y2 := maxy + 20
lives:=lives-1
end if
end Collision
loop
Input.KeyDown (chars)
View.Update
View.Set ("offscreenonly")
cls
Font.Draw ("Score: ", 10, 465, font1, 7)
Font.Draw (intstr (score), 70, 465, font1, 7)
Font.Draw ("Lives: ", 500, 465, font1, 7)
Font.Draw (intstr (lives), 560, 465, font1, 7)
if hasch then
getch(key)
end if
if shoot=true then
laserycenter:=laserycenter+20
end if
if chars (chr(ORD_SPACE)) and laserxcenter=-10 and laserycenter=-10 then
laserxcenter:=shipxcenter+27
laserycenter:=shipycenter+97
shoot:=true
end if
DrawLaser(laserxcenter,laserycenter)
if laserycenter>=maxy+10 then
laserxcenter:=-10
laserycenter:=-10
shoot:=false
end if
if chars (KEY_UP_ARROW) then
shipycenter := shipycenter + speedofship
end if
if chars (KEY_RIGHT_ARROW) then
shipxcenter := shipxcenter + speedofship
end if
if chars (KEY_LEFT_ARROW) then
shipxcenter := shipxcenter - speedofship
end if
if chars (KEY_DOWN_ARROW) then
shipycenter := shipycenter - speedofship
end if
DrawShip (shipxcenter, shipycenter)
if shipxcenter <= 1 then
shipxcenter := 1
end if
if shipxcenter >= maxx - Pic.Width (shippic) then
shipxcenter := maxx - Pic.Width (shippic)
end if
if shipycenter <= 1 then
shipycenter := 1
end if
if shipycenter >= maxy - Pic.Height (shippic) then
shipycenter := maxy - Pic.Height (shippic)
end if
DrawRock (rock1xcenter, rock1ycenter,rock1pic)
rock1ycenter := rock1ycenter - 1
if rock1ycenter <= 0 then
rock1xcenter := Rand.Int (10, 630)
rock1ycenter := maxy + 20
end if
DrawRock (rock2xcenter, rock2ycenter,rock2pic)
rock2ycenter := rock2ycenter - 2
if rock2ycenter <= 0 then
rock2xcenter := Rand.Int (10, 630)
rock2ycenter := maxy + 20
end if
DrawRock (rock3xcenter, rock3ycenter,rock3pic)
rock3ycenter := rock3ycenter - 3
if rock3ycenter <= 0 then
rock3xcenter := Rand.Int (10, 630)
rock3ycenter := maxy + 20
end if
DrawRock (rock4xcenter, rock4ycenter,rock4pic)
rock4ycenter := rock4ycenter - 4
if rock4ycenter <= 0 then
rock4xcenter := Rand.Int (10, 630)
rock4ycenter := maxy + 20
end if
DrawRock (rock5xcenter, rock5ycenter,rock5pic)
rock5ycenter := rock5ycenter - 5
if rock5ycenter <= 0 then
rock5xcenter := Rand.Int (10, 630)
rock5ycenter := maxy + 20
end if
Collision(shipxcenter,shipycenter,rock1xcenter,rock1ycenter,shippic,rock1pic)
Collision(shipxcenter,shipycenter,rock2xcenter,rock2ycenter,shippic,rock2pic)
Collision(shipxcenter,shipycenter,rock3xcenter,rock3ycenter,shippic,rock3pic)
Collision(shipxcenter,shipycenter,rock4xcenter,rock4ycenter,shippic,rock4pic)
Collision(shipxcenter,shipycenter,rock5xcenter,rock5ycenter,shippic,rock5pic)
if laserxcenter+Pic.Width(laserpic)/2>rock1xcenter-Pic.Width(rock1pic)/2 and laserxcenter-Pic.Width(laserpic)/2<rock1xcenter+Pic.Width(rock1pic)/2 and laserycenter+Pic.Width(laserpic)>rock1ycenter-Pic.Width(rock1pic)/2 and laserycenter-Pic.Width(laserpic)/2<rock1ycenter+Pic.Width(rock1pic)/2 then
boomxcenter:=rock1xcenter
boomycenter:=rock1ycenter
DrawBoom(boomxcenter,boomycenter)
rock1xcenter := Rand.Int (10, 630)
rock1ycenter := maxy + 20
score:=score+1
end if
if laserxcenter+Pic.Width(laserpic)/2>rock2xcenter-Pic.Width(rock2pic)/2 and laserxcenter-Pic.Width(laserpic)/2<rock2xcenter+Pic.Width(rock2pic)/2 and laserycenter+Pic.Width(laserpic)>rock2ycenter-Pic.Width(rock2pic)/2 and laserycenter-Pic.Width(laserpic)/2<rock2ycenter+Pic.Width(rock2pic)/2 then
boomxcenter:=rock2xcenter
boomycenter:=rock2ycenter
DrawBoom(boomxcenter,boomycenter)
rock2xcenter := Rand.Int (10, 630)
rock2ycenter := maxy + 20
score:=score+1
end if
if laserxcenter+Pic.Width(laserpic)/2>rock3xcenter-Pic.Width(rock3pic)/2 and laserxcenter-Pic.Width(laserpic)/2<rock3xcenter+Pic.Width(rock3pic)/2 and laserycenter+Pic.Width(laserpic)>rock3ycenter-Pic.Width(rock3pic)/2 and laserycenter-Pic.Width(laserpic)/2<rock3ycenter+Pic.Width(rock3pic)/2 then
boomxcenter:=rock3xcenter
boomycenter:=rock3ycenter
DrawBoom(boomxcenter,boomycenter)
rock3xcenter := Rand.Int (10, 630)
rock3ycenter := maxy + 20
score:=score+1
end if
if laserxcenter+Pic.Width(laserpic)/2>rock4xcenter-Pic.Width(rock4pic)/2 and laserxcenter-Pic.Width(laserpic)/2<rock4xcenter+Pic.Width(rock4pic)/2 and laserycenter+Pic.Width(laserpic)>rock4ycenter-Pic.Width(rock4pic)/2 and laserycenter-Pic.Width(laserpic)/2<rock4ycenter+Pic.Width(rock4pic)/2 then
boomxcenter:=rock4xcenter
boomycenter:=rock4ycenter
DrawBoom(boomxcenter,boomycenter)
rock4xcenter := Rand.Int (10, 630)
rock4ycenter := maxy + 20
score:=score+1
end if
if laserxcenter+Pic.Width(laserpic)/2>rock5xcenter-Pic.Width(rock5pic)/2 and laserxcenter-Pic.Width(laserpic)/2<rock5xcenter+Pic.Width(rock5pic)/2 and laserycenter+Pic.Width(laserpic)>rock5ycenter-Pic.Width(rock5pic)/2 and laserycenter-Pic.Width(laserpic)/2<rock5ycenter+Pic.Width(rock5pic)/2 then
boomxcenter:=rock5xcenter
boomycenter:=rock5ycenter
DrawBoom(boomxcenter,boomycenter)
rock5xcenter := Rand.Int (10, 630)
rock5ycenter := maxy + 20
score:=score+1
end if
exit when lives=0 or score=20
end loop
cls
if lives<=0 then
Font.Draw ("Game Over! ", 320, 240, font1, 7)
elsif score>=20 then
Font.Draw ("You Win! ", 320, 240, font1, 7)
end if
|