%%%%%%%%%%%%%%%%
% %
%%% JoyPad %%%
% %
%%%%%%%%%%%%%%%%
% Billy Boldt %
%%%% % % % %%%%%
%% Button : ground (y) := orange
setscreen ("graphics:max;max, offscreenonly,nobuttonbar")
colorback (7)
cls
%% Variables %%
drawfillbox (0, 0, maxx, maxy, 7)
var key : array char of boolean
var shipX, shipY : int
shipX := 10
shipY := maxy div 2
var laserX, laserY, hold : array 1 .. 10 of int
var done, laserwait : int := 0 % Tells program when another laser is allowed to fire
var dif : int := 3 % Difference of movement
var level : array 1 .. 10 of int
var barX, barY, meterX, meterY : int
var track : int := 0
var track2 : int := 5
barX := 10
barY := maxy - 10
meterX := 10
meterY := maxy - 10
var stars : int := 100
var starx, stary, sdif : array 1 .. 100 of int
var death : boolean := false
var fig : int := Font.New ("Chiller:72")
var fig2 : int := Font.New ("Wide Latin:38")
for i : 1 .. stars
starx (i) := Rand.Int (1, maxx) %Making a default for the star somewhere on the screen
stary (i) := Rand.Int (1, maxy)
sdif (i) := Rand.Int (2, 7)
end for
for i : 1 .. upper (hold) % Give the lasers initial values
laserX (i) := 0 % Just defaulting everything to zero
laserY (i) := 0
hold (i) := 0
end for
proc moveStars
for i : 1 .. stars
starx (i) -= sdif (i) % Move them to their corresponding speed
drawdot (starx (i), stary (i), white)
if starx (i) < 0 then
starx (i) := maxx
stary (i) := Rand.Int (1, maxy)
sdif (i) := Rand.Int (2, 7)
end if
end for
end moveStars
proc eraseShip
drawfillbox (shipX - 10, shipY, shipX + 50, shipY + 25, 7)
end eraseShip
proc DrawShip
drawfilloval (shipX + 25, shipY + 15, 25, 10, 28)
drawfillbox (shipX - 10, shipY, shipX + 25, shipY + 10, 28)
drawfilloval (shipX + 35, shipY + 20, 7, 3, 1)
drawfillbox (shipX + 27, shipY + 2, shipX + 50, shipY + 4, 23)
drawfillbox (shipX + 25, shipY, shipX + 27, shipY + 5, 23)
end DrawShip
proc Shoot
for i : 1 .. upper (hold)
if hold (i) = 1 then
laserX (i) += dif * 3
drawfillbox (laserX (i) + 51, laserY (i) + 2, laserX (i) + 75, laserY (i) + 4, 9)
if laserX (i) > maxx then % If its greater than the screen then reset it
hold (i) := 0
end if
end if
end for
end Shoot
var rock : array 1 .. 30 of
record
x, y, size, spd, dx : int
end record
for i : 1 .. upper (rock) %The amount in array (which is 100)
rock (i).x := Rand.Int (maxx, maxx + 400)
rock (i).y := Rand.Int (50, maxy - 50)
rock (i).size := Rand.Int (10, 20)
rock (i).spd := round (19 - (rock (i).size) / 1.007) %rock(i).spd must be whole/int so we use round()
if rock (i).spd = 0 then %Checking if the speed is 0
rock (i).spd := 1
end if
end for
var grow, gx, gy, gend : array 1 .. upper (rock) of int %grow: size, gx: x-coord, gy: y-coord, gend: finishes explosion
for i : 1 .. upper (grow) %Making defaults for variables
grow (i) := 0
gend (i) := 0
end for
proc newRock (thing : int) %Created a new asteroid, same material from above
rock (thing).x := Rand.Int (maxx, maxx + 400)
rock (thing).y := Rand.Int (0, maxy)
rock (thing).size := Rand.Int (10, 20)
rock (thing).spd := round (19 - (rock (thing).size) / 1.007) %rock(i).spd must be whole/int so we use round()
if rock (thing).spd = 0 then %Checking if the speed is 0
rock (thing).spd := 1
end if
end newRock
proc asteroids
% Make move
for i : 1 .. upper (rock)
rock (i).x -= rock (i).spd
drawfilloval (rock (i).x, rock (i).y, rock (i).size, rock (i).size, 62) % 43 orange
drawoval (rock (i).x, rock (i).y, rock (i).size, rock (i).size, 37) % 42 For effect
if rock (i).x <= 0 - 25 then % Resets asteroids back when gone off screen
newRock (i)
end if
end for
end asteroids
proc Lose % Game Over
cls
color (12)
locatexy (10, maxy - 10)
Font.Draw ("YOU DIED", maxx div 2 - 170, maxy div 2, fig, 12)
death := true
end Lose
proc LifeMeter
drawbox (barX, barY, barX + 200, barY + 10, 12)
drawfillbox (meterX + 1, meterY + 1, meterX + track2, meterY + 9, 43)
if meterX + track2 > 200 then
Lose
end if
View.Update
track2 += 5
end LifeMeter
proc CrashCheck
for i : 1 .. upper (rock)
if rock (i).x < shipX + 60 and rock (i).x > shipX - 20 and rock (i).y > shipY and rock (i).y < shipY + 25 then
LifeMeter
end if
end for
end CrashCheck
proc Boom (boomx, boomy, current, thing : int)
if thing <= rock (current).size and gend (current) not= -7 then %Red Circle
drawfilloval (boomx, boomy, thing, thing, 12)
if thing <= rock (current).size then
gend (current) := -7 %Just a number, moving onto the yellow/orange
end if
elsif gend (current) = -7 then
drawfilloval (boomx, boomy, rock (current).size, rock (current).size, 12) %red
drawfilloval (boomx, boomy, (thing - rock (current).size) * 2, (thing - rock (current).size) * 2, 43) %orange
drawfilloval (boomx, boomy, thing - rock (current).size, thing - rock (current).size, 14) %yellow
if thing - rock (current).size >= round (rock (current).size / 2) then %Once its too big, its done.
gend (current) := 0
end if
end if
end Boom
var count : int := 0
proc RockHit
for i : 1 .. upper (rock) % Checking Every Rock
for x : 1 .. upper (hold) % Checking Every Laser
for q : 0 .. 24 % Checking Ever Point In Every Laser
if laserY (x) >= rock (i).y - 15 and laserY (x) <= rock (i).y + 15 and laserX (x) + q >= rock (i).x - 10 and laserX (x) + q <= rock (i).x + 10 then
grow (i) := 1 %Starting the growth of the explosion
gx (i) := rock (i).x %Making the x-coord equal to gx (so it can hold onto it)
gy (i) := rock (i).y %Making the y-coord equal to gx (so it can hold onto it)
newRock (i) %Creating a new rock, using 'i' which is the current one shot down
count := count + 1
end if
end for
end for
end for
end RockHit
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc ReAssignValues
for j : 1 .. upper (rock)
for i : 1 .. upper (rock) %The amount in array (which is 100)
rock (i).x := Rand.Int (maxx, maxx + 400)
rock (i).y := Rand.Int (50, maxy - 50)
rock (i).size := Rand.Int (10, 20)
rock (i).spd := round (19 - (rock (i).size) / 1.007) %rock(i).spd must be whole/int so we use round()
if rock (i).spd = 0 then %Checking if the speed is 0
rock (i).spd := 1
end if
grow (i) := 0
gend (i) := 0
end for
end for
end ReAssignValues
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc DrawShipAndShoot
cls
moveStars
Shoot
DrawShip
asteroids
CrashCheck
RockHit
for i : 1 .. upper (grow) %Checking if any asteroids have exploded
if grow (i) > 0 then %Start exploding if they are
grow (i) += 1 %Changing the radius of the explosion
Boom (gx (i), gy (i), i, grow (i)) %Boom (x-coord, y-coord, which asteroid, radius of a'roid)
if gend (i) = 1 then %In the proc 'Boom' we make gend 1 when its finished
grow (i) := 0 %Now we can reset that asteroids explosion for future use
end if
end if
end for
View.Update
end DrawShipAndShoot
proc shoots
for i : 1 .. upper (hold)
if hold (i) = 0 and done = 0 then % If the current laser is free to be shot
laserX (i) := shipX
laserY (i) := shipY
hold (i) := 1 % Making it taken
done := 1 % Telling the program to delay before shooting again
end if
end for
end shoots
var Asteroids : int := Pic.FileNew ("Asteroids.bmp")
loop
Pic.Draw (Asteroids, 0, 0, picMerge)
% Font.Draw ("ASTEROIDS", 40, 400, fig2, 28)
for decreasing i : 28 .. 21
Font.Draw ("ASTEROIDS", 40, 400, fig2, i)
delay (50)
View.Update
end for
for i : 21 .. 28
Font.Draw ("ASTEROIDS", 40, 400, fig2, i)
delay (50)
View.Update
end for
exit when hasch
end loop
Pic.Free (Asteroids)
delay (1000)
proc NextLevel
cls
drawfillbox (0, 0, maxx, maxy, 7)
Font.Draw ("Next Level", 40, 400, fig, 28)
delay (2000)
count := 0
View.Update
end NextLevel
loop
loop
Input.KeyDown (key)
if key (KEY_LEFT_ARROW) and shipX > dif then
eraseShip
shipX -= dif
elsif key (KEY_RIGHT_ARROW) then
eraseShip
shipX += dif
end if
if key (KEY_UP_ARROW) then
eraseShip
shipY += dif
elsif key (KEY_DOWN_ARROW) and shipY > 30 then
eraseShip
shipY -= dif
end if
if key (KEY_TAB) and done = 0 then % If we're allowed to shoot another laser
shoots
end if
if done = 1 and laserwait < 20 then % Waiting untill laserwait is 20
laserwait += 1 % This will make a delay of [20 * (whatever delay is set)] before shooting again
elsif done = 1 and laserwait >= 20 then % Now its ok to shoot, so reset laserwait
laserwait := 0
done := 0
end if
if shipX <= 0 then % Checking for ship bounderies
shipX := 0
elsif shipX >= maxx - 40 then
shipX := maxx - 40
end if
if shipY >= maxy - 30 then
shipY := maxy - 30
end if
DrawShipAndShoot % Draw everything
if death = true then % Once you die, the game is over.
exit
end if
if count = 10 then
ReAssignValues
% delay (1000)
NextLevel
exit
end if
end loop
end loop
|