const NUM_OF_BLOCKS := 100 % this is needed throughout most of prog
procedure Block_Start (var X, Y : array 1 .. NUM_OF_BLOCKS of int)
var YR : nat := maxy - 45
var XR : nat := 15
for Block : 1 .. NUM_OF_BLOCKS
if XR + 30 > maxx then
YR := YR - 30
XR := 1
end if
X (Block) := XR
Y (Block) := YR
XR := XR + 30
end for
end Block_Start
procedure Pause
var P : char
P := getchar
end Pause
%sound effect(s)
process Bump_Sound (Frequency, Length : int)
sound (Frequency, Length)
end Bump_Sound
%%%MAIN%%%%%%%
%VARS AND CONSTANTS
const B_C := 7 % background colour (7 is black)
const SIZE := 40 % size of paddle / 2
const COLOUR_OF_PLAYER := 0 % paddle's colour
const SPEED_OF_P := 4 % paddle's speed
const SIZE_OF_BALL := 3 % radius of the ball
const MAX_LEVELS := 3 % number of levels
% Set up screen
setscreen ("graphics:max,max,nobuttonbar,offscreenonly")
const MID_X := maxx div 2
const MID_Y := maxy div 2
var HitCount : int
var NumberOfHits : array 1 .. NUM_OF_BLOCKS of nat1
var Hit : array 1 .. NUM_OF_BLOCKS of boolean % draw block or not
var XB, YB : array 1 .. NUM_OF_BLOCKS of int % co-ordinates for each block
var COfB : array 1 .. NUM_OF_BLOCKS of int % the color of each block
% each block
var XP, YP : int % co-ordinates for the player's paddle
var X, Y : int % the co-orninates of the ball
var DX, DY : int1 % the direction that the ball is moving in
% ball if the ball hits a puck
var BallsLeft : int % the number of balls the user still has
var Key : array char of boolean % input key var
var Serve : boolean % used to see if ball should move or not
var Score : int % user's score (oviously)
% level var
var Level : int
% display fonts
var Font1 : int := Font.New ("Avenida LET:30")
var Font2 : int := Font.New ("Avenida LET:50")
var IntToString : string % used for puting numbers into a string so
% that the Font.Draw command will work with them
%initilization of vars
Score := 0
Level := 1
BallsLeft := 3
colorback (B_C)
cls
% Tittle screen
Font.Draw ("Block Buster!", 100, 300, Font2, 12)
Font.Draw (" (Press any key to resume)", MID_X - 200, 100, Font1, 12)
Font.Draw (" (Made by Peter)", MID_X - 200, 1, Font1, 12)
View.Update
Pause
cls
color (0)
put "The point of this game is to hit all the blocks with your ball."
put "You bounce the ball around with your paddel."
put "To clear a level make all the blocks disapear."
put " The higher you get in levels the more hits it will take" ..
put " for a block to vanish."
put ""
put "Controls: "
put "Left : Left arrow key"
put "Right : right arrow key"
put "Pause : enter"
put "serve ball : spacebar"
put ""
put "Press any key to continue"
View.Update
Pause
loop
HitCount := 0
Serve := false
%player
XP := MID_X
YP := 10
%ball
X := MID_X
Y := YP + SIZE_OF_BALL + 1
DX := SPEED_OF_P - 2
DY := SPEED_OF_P + 1
% block stuff
Block_Start (XB, YB) % co-ordinates
for Index : 1 .. NUM_OF_BLOCKS
loop
randint (COfB (Index), 1, 15)
exit when COfB (Index) not= B_C
end loop
Hit (Index) := false
NumberOfHits (Index) := 0
end for
BallsLeft := 3
loop
cls % clear screen
%player movement
Input.KeyDown (Key)
if Key (KEY_RIGHT_ARROW) or XP - SIZE < 1 then
XP := XP + SPEED_OF_P % move right
end if
if Key (KEY_LEFT_ARROW) or XP + SIZE > maxx then
XP := XP - SPEED_OF_P % move left
end if
% this next section is for ball movement and bouncing
if Serve = true then
% bouncing
if X < 1 or X > maxx then
DX := -DX
fork Bump_Sound (100, 100)
end if
if Y > maxy then
DY := -DY
fork Bump_Sound (100, 100)
end if
if Y <= 1 then
Serve := false
Y := YP + SIZE_OF_BALL + 1
DY := SPEED_OF_P + 1
BallsLeft := BallsLeft - 1
end if
% movement
X := X + DX
Y := Y + DY
% ball interaction with paddle
if X < XP + SIZE and X > XP - SIZE and Y - SIZE_OF_BALL < 10 then
DY := -DY
fork Bump_Sound (100, 100)
end if
else
% player Serve
if Serve = false and Key (' ') then
Serve := true
end if
% ball follows player if it is't served
if Serve = false then
X := XP
end if
end if
%drawblocks and block ball colision
for Index : 1 .. NUM_OF_BLOCKS
if Hit (Index) = false then
drawfillbox (XB (Index) - 15, YB (Index) - 15, XB (Index) + 15,
YB (Index) + 15, COfB (Index))
drawbox (XB (Index) - 15, YB (Index) - 15, XB (Index) + 15,
YB (Index) + 15, B_C)
% collision
if X > XB (Index) - 15 and X < XB (Index) - 13 and
Y > YB (Index) - 15 and Y < YB (Index) + 15 then
NumberOfHits (Index) := NumberOfHits (Index) + 1
if NumberOfHits (Index) >= Level then
Score := Score + 1
Hit (Index) := true
HitCount := HitCount + 1
end if
DX := -DX
fork Bump_Sound (100, 100)
elsif X > XB (Index) + 13 and X < XB (Index) + 15 and
Y > YB (Index) - 15 and Y < YB (Index) + 15 then
Score := Score + 1
NumberOfHits (Index) := NumberOfHits (Index) + 1
if NumberOfHits (Index) >= Level then
HitCount := HitCount + 1
Hit (Index) := true
end if
DX := -DX
fork Bump_Sound (100, 100)
elsif X > XB (Index) - 15 and X < XB (Index) + 15 and
Y > YB (Index) - 15 and Y < YB (Index) - 10 then
Score := Score + 1
NumberOfHits (Index) := NumberOfHits (Index) + 1
if NumberOfHits (Index) >= Level then
HitCount := HitCount + 1
Hit (Index) := true
end if
fork Bump_Sound (100, 100)
DY := -DY
elsif X > XB (Index) - 15 and X < XB (Index) + 15 and
Y > YB (Index) + 10 and Y < YB (Index) + 15 then
NumberOfHits (Index) := NumberOfHits (Index) + 1
Score := Score + 1
if NumberOfHits (Index) >= Level then
HitCount := HitCount + 1
Hit (Index) := true
end if
DY := -DY
fork Bump_Sound (100, 100)
end if
end if
end for
% drawplayer
drawfillbox (XP - SIZE, 10, XP + SIZE, 3, COLOUR_OF_PLAYER)
% draw ball
drawfilloval (X, Y, SIZE_OF_BALL, SIZE_OF_BALL, COLOUR_OF_PLAYER)
% Output stats
IntToString := intstr (Score)
Font.Draw ("Score: " + IntToString, 1, maxy - 30, Font1, 12)
IntToString := intstr (BallsLeft)
Font.Draw ("Balls Left: " + IntToString, 200, maxy - 30, Font1, 12)
IntToString := intstr (Level)
Font.Draw ("Level: " + IntToString, 400, maxy - 30, Font1, 12)
exit when BallsLeft < 0 or HitCount = NUM_OF_BLOCKS
if Key (KEY_ENTER) then
Font.Draw ("Paused (Press any key to resume)", MID_X - 200, 100,
Font1, 12)
View.Update
Pause
end if
View.Update
end loop
exit when Level >= MAX_LEVELS or BallsLeft < 0
Level := Level + 1
end loop
cls
if BallsLeft < 0 then
Font.Draw ("You Lose!", 100, 100, Font2, 12)
else
Font.Draw ("You Win!", 100, 100, Font2, 12)
end if
|