0% found this document useful (0 votes)
21 views

Message

The document describes code for a program that allows drawing of buildings and other objects on a screen. It includes procedures for drawing backgrounds, moving a character, shooting fireworks, and customizing colors. Variables are declared for coordinates, colors, and other properties and constants are set for common colors. Procedures are provided to draw elements, erase areas, and animate movements and fireworks.

Uploaded by

Chance Deng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Message

The document describes code for a program that allows drawing of buildings and other objects on a screen. It includes procedures for drawing backgrounds, moving a character, shooting fireworks, and customizing colors. Variables are declared for coordinates, colors, and other properties and constants are set for common colors. Procedures are provided to draw elements, erase areas, and animate movements and fireworks.

Uploaded by

Chance Deng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 13

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Dai, Daniel, 343056610 %


% ICS2O1-2D Mr. J. Lee %
% Date: 24 May 2023 %
% Unit Summative %
% Purpose: Summative Project %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Set Screen Graphics


setscreen ("graphics, nocursor")

% Declaration of Constants
const BLUE := 54
const DARKBLUE := 104
const DARKERGREY := 28
const DARKGREEN := 119
const GREY := 29
const LIGHTBLUE := 53
const PALE := 92
const PEACH := 90
const PINK := 60
const RED := 12
const SKYBLUE := 101
const YELLOW := 44
const HEADER := Font.New ("arial:36:bold")
const TEXT := Font.New ("roboto:12")

% Declaration of Variables
var KeyPress : string (1)
var x1, x2, x3, x4, y1, y2, y3, y4, y5, y6, y7, y8, y9, r1, r2 : int
var EraseColour, FireworkOutline, TorsoColour, FireworkExplode : int
var LegColour, HeadColour, TitleDrawBackgroundColour : int
var DescDrawBackgroundColour, FireworkColour, StartDrawBackgroundColour : int
var ExitTextColour, StarColour, Outline, BuildingColour : int
var BuildingColourShade, FlagPole, Moon, Grass, DrawBackgroundColour : int
var xmouse, ymouse, button : int

% Variable Assignment
y1 := 40
y2 := 100
x1 := maxx div 2 - 35
x2 := maxx div 2 + 35
x3 := maxx div 2 - 20
x4 := maxx div 2 + 20
y3 := 0
y4 := 10
y5 := 30
y6 := 40
y7 := 0
y8 := 40
y9 := 130
r1 := 1
r2 := 1

BuildingColour := GREY
BuildingColourShade := DARKERGREY
DescDrawBackgroundColour := SKYBLUE
DrawBackgroundColour := SKYBLUE
EraseColour := DARKBLUE
ExitTextColour := brightred
FireworkColour := brightred
FireworkExplode := brightred
FireworkOutline := black
FlagPole := GREY
Grass := DARKGREEN
HeadColour := black
LegColour := black
Moon := PALE
Outline := black
StartDrawBackgroundColour := DARKBLUE
StarColour := YELLOW
TitleDrawBackgroundColour := SKYBLUE
TorsoColour := black

% Keybinds
var Left : string := "a"
var Right : string := "d"
var Fire : string := "e"
var Customize : string := "c"

% List Of All The Procedures


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Draw DrawBackground Procedure


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure DrawBackground

% Grass
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawfillbox (0, 0, maxx, 100, Grass)

% Outline between Grass and Buildings


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawline (0, 100, maxx, 100, Outline)

% Flag Pole
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawbox (250, 90, 253, 250, Outline)

drawfillbox (251, 91, 252, 249, FlagPole)

% Canada Flag
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawbox (253, 168 + 30, 340, 218 + 30, Outline)
drawfillbox (254, 169 + 30, 339, 217 + 30, white)
drawfillbox (254, 169 + 30, 274, 217 + 30, brightred)
drawfillbox (319, 169 + 30, 339, 217 + 30, brightred)
drawfillmapleleaf (280, 175 + 30, 315, 215 + 30, brightred)

% Buildings
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Building #1
drawbox (0, 100, 70, 260, Outline)
drawline (60, 270, 70, 260, Outline)
drawline (60, 270, 0, 270, Outline)
drawfill (50, 265, BuildingColour, Outline)
drawfill (30, 200, BuildingColour, Outline)

% Building #2
drawbox (80, 100, 150, 240, Outline)
drawline (140, 250, 70, 250, Outline)
drawline (150, 240, 140, 250, Outline)
drawline (80, 240, 70, 250, Outline)

drawfill (110, 245, BuildingColour, Outline)


drawfill (100, 180, BuildingColour, Outline)

drawfill (75, 185, BuildingColourShade, Outline)

% Building #3
drawbox (160, 100, 230, 280, Outline)

drawline (160, 280, 140, 290, Outline)


drawline (140, 250, 140, 290, Outline)
drawline (210, 290, 230, 280, Outline)
drawline (140, 290, 210, 290, Outline)

drawfill (180, 290, BuildingColour, Outline)


drawfill (200, 180, BuildingColour, Outline)
drawfill (190, 285, BuildingColour, Outline)

drawfill (155, 250, BuildingColourShade, Outline)

% Building #4
drawbox (450, 100, 520, 250, Outline)

drawline (440, 260, 450, 250, Outline)


drawline (440, 260, 440, 100, Outline)
drawline (440, 260, 510, 260, Outline)

drawline (510, 260, 520, 250, Outline)

drawfill (480, 255, BuildingColour, Outline)


drawfill (480, 170, BuildingColour, Outline)

drawfill (445, 190, BuildingColourShade, Outline)

% Building #5
drawline (515, 255, 515, 260, Outline)
drawline (590, 100, 590, 260, Outline)
drawline (515, 260, 590, 260, Outline)

drawline (580, 270, 590, 260, Outline)


drawline (505, 270, 515, 260, Outline)
drawline (505, 270, 580, 270, Outline)
drawline (505, 260, 505, 270, Outline)

drawfill (550, 265, BuildingColour, Outline)


drawfill (570, 180, BuildingColour, Outline)

drawfill (507, 265, BuildingColourShade, Outline)

% Building #6
drawline (620, 100, 620, 230, Outline)
drawline (620, 230, maxx, 230, Outline)
drawline (610, 240, 620, 230, Outline)
drawline (610, 100, 610, 240, Outline)
drawline (610, 240, maxx, 240, Outline)

drawfill (630, 235, BuildingColour, Outline)


drawfill (630, 190, BuildingColour, Outline)

drawfill (615, 170, BuildingColourShade, Outline)

end DrawBackground
% End of Draw DrawBackground Procedure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Procedure to move the character left


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure MoveLeft
drawfillbox (x3, y2, x4, y9, EraseColour)

DrawBackground

x1 := x1 - 10
x2 := x2 - 10
x3 := x3 - 10
x4 := x4 - 10
drawfillbox (x1, y1, x2, y2, TorsoColour)
drawfillbox (x3, y7, x4, y8, LegColour)
drawfillbox (x3, y2, x4, y9, HeadColour)
end MoveLeft
% End of move character left procedure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Move character right procedure


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure MoveRight
DrawBackground
x1 := x1 + 10
x2 := x2 + 10
x3 := x3 + 10
x4 := x4 + 10
drawfillbox (x1, y1, x2, y2, TorsoColour)
drawfillbox (x3, y7, x4, y8, LegColour)
drawfillbox (x3, y2, x4, y9, HeadColour)
end MoveRight
% End of move character right procedure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Draw stars procedure


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure DrawStars

var randomx, randomy, random : int


randint (random, 30, 50)

for i : 20 .. random
randint (randomx, 0, maxx)
randint (randomy, 290, maxy)
drawdot (randomx, randomy, StarColour)
end for
end DrawStars
% End of draw stars procedure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Shoot fireworks procedure


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure ShootFirework
y3 := 50
y4 := 60
y5 := 80
y6 := 90

% Firework going up
for i : 1 .. 10

delay (100)

drawfillbox (x1, y1, x2, y2, TorsoColour)

y3 := y3 + 20
y4 := y4 + 20
y5 := y5 + 20
y6 := y6 + 20
r1 := 1
r2 := 1

drawbox (x2 - 10, y4, x2, y5, FireworkOutline)


drawline (x2 - 5, y3, x2 - 5, y4, FireworkOutline)

drawfillbox (x2 - 9, y4 + 1, x2 - 1, y5 - 1, FireworkColour)

delay (50)

drawbox (x2 - 10, y4, x2, y5, EraseColour)


drawline (x2 - 5, y3, x2 - 5, y4, EraseColour)

drawfill (x2 - 5, y4 + 5, EraseColour, Outline)

DrawBackground

drawfillbox (x1, y1, x2, y2, TorsoColour)


drawfillbox (x3, y7, x4, y8, LegColour)
drawfillbox (x3, y2, x4, y9, HeadColour)

drawfilloval (600, 365, 30, 30, Moon)


Draw.Text ("Press C to customize", 15, 379, TEXT, ExitTextColour)
DrawStars

end for

% Firework explode
DrawBackground
drawfillbox (x1, y1, x2, y2, TorsoColour)
drawfillbox (x3, y7, x4, y8, LegColour)
drawfillbox (x3, y2, x4, y9, HeadColour)

delay (100)
for i : 1 .. 5
drawoval (x2, y6, r1, r2, FireworkExplode)

delay (100)
cls
DrawBackground
drawfillbox (x1, y1, x2, y2, TorsoColour)
drawfillbox (x3, y7, x4, y8, LegColour)
drawfillbox (x3, y2, x4, y9, HeadColour)
r1 := r1 + 5
r2 := r2 + 5

drawfilloval (600, 365, 30, 30, Moon)


Draw.Text ("Press C to customize", 15, 379, TEXT, ExitTextColour)
DrawStars

end for

DrawBackground
drawfillbox (x1, y1, x2, y2, TorsoColour)
drawfillbox (x3, y7, x4, y8, LegColour)
drawfillbox (x3, y2, x4, y9, HeadColour)

end ShootFirework
% End of shoot fireworks procedure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Shoot fireworks procedure


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure CustomFirework
y3 := 50
y4 := 60
y5 := 80
y6 := 90

% Firework going up
for i : 1 .. 10

delay (100)

drawfillbox (x1, y1, x2, y2, TorsoColour)

y3 := y3 + 20
y4 := y4 + 20
y5 := y5 + 20
y6 := y6 + 20
r1 := 1
r2 := 1

drawbox (x2 - 10, y4, x2, y5, FireworkOutline)


drawline (x2 - 5, y3, x2 - 5, y4, FireworkOutline)

drawfillbox (x2 - 9, y4 + 1, x2 - 1, y5 - 1, FireworkColour)

delay (50)
drawbox (x2 - 10, y4, x2, y5, EraseColour)
drawline (x2 - 5, y3, x2 - 5, y4, EraseColour)

drawfill (x2 - 5, y4 + 5, EraseColour, Outline)

DrawBackground

drawfillbox (x1, y1, x2, y2, TorsoColour)


drawfillbox (x3, y7, x4, y8, LegColour)
drawfillbox (x3, y2, x4, y9, HeadColour)

drawfilloval (600, 365, 30, 30, Moon)


DrawStars

end for

% Firework explode
DrawBackground
drawfillbox (x1, y1, x2, y2, TorsoColour)
drawfillbox (x3, y7, x4, y8, LegColour)
drawfillbox (x3, y2, x4, y9, HeadColour)

delay (100)

for i : 1 .. 5
drawoval (x2, y6, r1, r2, FireworkExplode)

delay (100)
cls
DrawBackground
drawfillbox (x1, y1, x2, y2, TorsoColour)
drawfillbox (x3, y7, x4, y8, LegColour)
drawfillbox (x3, y2, x4, y9, HeadColour)
r1 := r1 + 5
r2 := r2 + 5

drawfilloval (600, 365, 30, 30, Moon)


DrawStars

end for

DrawBackground
drawfillbox (x1, y1, x2, y2, TorsoColour)
drawfillbox (x3, y7, x4, y8, LegColour)
drawfillbox (x3, y2, x4, y9, HeadColour)

end CustomFirework
% End of shoot fireworks procedure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% End Of Procedure List


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Start Screen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop

colourback (TitleDrawBackgroundColour)
cls

Font.Draw ("Firework Animation", maxx div 2 - 210, 240, HEADER, black)


Font.Draw ("ICS2O1-2D Mr. J. Lee", maxx div 2 - 75, 200, TEXT, black)
Font.Draw ("Dai, Daniel", maxx div 2 - 40, 160, TEXT, black)
Font.Draw ("343056610", maxx div 2 - 40, 140, TEXT, black)
Font.Draw ("press space to contine", maxx div 2 - 75, 30, TEXT, black)

getch (KeyPress)
if KeyPress = chr (32) then
exit
end if
end loop

% Description Screen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop

colourback (DescDrawBackgroundColour)
cls

Font.Draw ("Description", 0, maxy - 50, HEADER, black)


Font.Draw ("This an animation that will shoot fireworks.", maxx div 2 - 150,
280, TEXT, black)
Font.Draw ("Press and hold the A and D keys to spawn, and move the character
left and right.", maxx div 2 - 270, 260, TEXT, black)
Font.Draw ("To shoot fireworks, tap the E key twice.", maxx div 2 - 150, 240,
TEXT, black)
Font.Draw ("Press C to customize.", maxx div 2 - 60, 220, TEXT, black)
Font.Draw ("press space to contine", maxx div 2 - 75, 30, TEXT, black)

getch (KeyPress)
if KeyPress = chr (32) then % (if spacebar is pressed)
exit
end if
end loop

% Set Screen to Night


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
colourback (StartDrawBackgroundColour)
cls

% Draw Moon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawfilloval (600, 365, 30, 30, Moon)

% Runs DrawBackground procedure


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DrawBackground

% Runs DrawStars procedure


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DrawStars
loop

% Exit to Customize
getch (KeyPress)
if KeyPress = Customize then
exit
end if

% Shoot Firework
if KeyPress = Fire then
ShootFirework
end if

% Move Left
getch (KeyPress)
if KeyPress = Left then
MoveLeft
end if

% Move Right
if KeyPress = Right then
drawfillbox (x3, y2, x4, y9, EraseColour)
MoveRight
end if

end loop

% Customization
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

colourback (white)
cls

% Character Customization
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Get User Input


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Font.Draw ("Choose Head Colour", 0, maxy - 50, HEADER, black)
loop
mousewhere (xmouse, ymouse, button)

% Option 1 (peach)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawfillbox (maxx div 7 * 1, maxy div 2 - 50, maxx div 7 * 2, maxy div 2 + 50,
PEACH)
if xmouse > 77 and xmouse < 154 and ymouse > 149 and ymouse < 249 and button =
1 then
HeadColour := PEACH
cls

exit

end if

% Option 2 (yellow)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawfillbox (maxx div 7 * 3, maxy div 2 - 50, maxx div 7 * 4, maxy div 2 + 50,
YELLOW)
if xmouse > 231 and xmouse < 308 and ymouse > 149 and ymouse < 249 and button =
1 then
HeadColour := YELLOW
cls

exit

end if
% Option 3 (black)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawfillbox (maxx div 7 * 5, maxy div 2 - 50, maxx div 7 * 6, maxy div 2 + 50,
black)
if xmouse > 385 and xmouse < 462 and ymouse > 149 and ymouse < 249 and button =
1 then
HeadColour := black
cls

exit

end if
end loop

delay (200)

% Character Clothes Customization


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Get User Input


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Font.Draw ("Choose Clothes Colour", 0, maxy - 50, HEADER, black)

loop
mousewhere (xmouse, ymouse, button)
View.Update

% Option 1 (BLUE & Black)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawfillbox (maxx div 4 - 35, 160, maxx div 4 + 35, 220, BLUE)
drawfillbox (maxx div 4 - 20, 120, maxx div 4 + 20, 160, black)
drawfillbox (maxx div 4 - 20, 220, maxx div 4 + 20, 250, HeadColour)

if xmouse > 82 and xmouse < 207 and ymouse > 100 and ymouse < 300 and button =
1 then
TorsoColour := brightblue
LegColour := black

cls

exit

end if

% Option 2 (Pink & Black)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawfillbox (maxx div 4 * 2 - 35, 160, maxx div 4 * 2 + 35, 220, PINK)
drawfillbox (maxx div 4 * 2 - 20, 120, maxx div 4 * 2 + 20, 160, black)
drawfillbox (maxx div 4 * 2 - 20, 220, maxx div 4 * 2 + 20, 250, HeadColour)

if xmouse > 258 and xmouse < 382 and ymouse > 100 and ymouse < 300 and button =
1 then
TorsoColour := PINK
LegColour := black

cls

exit

end if

% Option 3 (Black & Black)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawfillbox (maxx div 4 * 3 - 35, 160, maxx div 4 * 3 + 35, 220, black)
drawfillbox (maxx div 4 * 3 - 20, 120, maxx div 4 * 3 + 20, 160, black)
drawfillbox (maxx div 4 * 3 - 20, 220, maxx div 4 * 3 + 20, 250, HeadColour)

if xmouse > 432 and xmouse < 558 and ymouse > 100 and ymouse < 300 and button =
1 then
TorsoColour := black
LegColour := black

cls

exit

end if
end loop
delay (200)

% Firework Customization
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Get User Input


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Font.Draw ("Choose Fireworks Colour", 0, maxy - 50, HEADER, black)
loop
mousewhere (xmouse, ymouse, button)
View.Update

% Red Option
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawfillbox (maxx div 7 * 1, maxy div 2 - 50, maxx div 7 * 2, maxy div 2 + 50,
brightred)
if xmouse > 77 and xmouse < 154 and ymouse > 149 and ymouse < 249 and button =
1 then
FireworkColour := brightred
FireworkExplode := brightred
cls

exit

end if

% Blue Option
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawfillbox (maxx div 7 * 3, maxy div 2 - 50, maxx div 7 * 4, maxy div 2 + 50,
brightblue)
if xmouse > 231 and xmouse < 308 and ymouse > 149 and ymouse < 249 and button =
1 then
FireworkColour := brightblue
FireworkExplode := brightblue
cls

exit

end if

% Yellow Option 3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawfillbox (maxx div 7 * 5, maxy div 2 - 50, maxx div 7 * 6, maxy div 2 + 50,
YELLOW)
if xmouse > 385 and xmouse < 462 and ymouse > 149 and ymouse < 249 and button =
1 then
FireworkColour := YELLOW
FireworkExplode := YELLOW
cls

exit

end if

end loop

delay (200)

% Set Screen to Night


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
colourback (StartDrawBackgroundColour)
cls

% Draw Moon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawfilloval (600, 365, 30, 30, Moon)

% Runs DrawBackground procedure


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DrawBackground

% Runs DrawStars procedure


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DrawStars

loop

% Shoot Firework
if KeyPress = Fire then
CustomFirework
end if

% Move Left
getch (KeyPress)
if KeyPress = Left then
MoveLeft
end if
% Move Right
if KeyPress = Right then
drawfillbox (x3, y2, x4, y9, EraseColour)
MoveRight
end if

end loop

You might also like