Final Project immediate help Please!!! due January 16th
Author |
Message |
Shainman
|
Posted: Sun Jan 13, 2008 7:13 pm Post subject: Final Project immediate help Please!!! due January 16th |
|
|
I'm almost done my final project for my grade 9 computer class. My final project was to create a game of my choice so i created City Jumper. I have almost all of my program complete, but i ran into a big problem, I dont know how to do collision detection. the stickfigure jumps over the buildings (bmp files) that have a border around them (only the first level has borders). I really don't know how to make it so that when the stick figure hits the buildings he looses a life and has to start over. This is my code, any help is really appreciated.
%Ariel Shain
%Ms. Dyke
%January 9, 2008
%This Program will let you play a game called City Jumper.
%You play as a little man who jumps over buildings to get to the end of the level.
%There are a total of 10 level that you have to complete.
%You will have 3 lives to try and finish the game.
%Imports GUI so buttons can be created
import GUI
%Declaration Section
var pictureID : int
var name : string
var key : string (1) := "0"
var mainWin : int := Window.Open ("position:250;200,graphics:400;400") %Draws the main Window.
var lives : int := 3
var level : int := 1
var x : int := 5
var quitBtn, playBtn, menuBtn, helpBtn, yesBtn, noBtn, nextBtn, backBtn : int := 0
var bigHouse : int := Pic.FileNew ("big house.bmp") %finds document
var smallHouse : int := Pic.FileNew ("small house.bmp") %finds document
var skyDome : int := Pic.FileNew ("SkyDome.bmp") %finds document
var cnTower : int := Pic.FileNew ("CN tower.bmp") %finds document
%Program Title
procedure title
cls
pictureID := Pic.FileNew ("ISP title2.bmp") %finds document
Pic.Draw (pictureID, 20, 307, picMerge) %draw picture (program title)
locate (10, 1)
end title
%Pause Program
procedure pauseProgram
var reply : string (1)
put ""
put "Press any key to continue...."
getch (reply)
end pauseProgram
%Program Introduction
procedure introduction
title
GUI.Show (menuBtn) %Shows Menu Button
GUI.Hide (playBtn) %Hides play Button
GUI.Hide (quitBtn) %Hides quit Button
GUI.Hide (helpBtn) %Hides instructions Button
GUI.Hide (yesBtn) %Hides yes Button
GUI.Hide (noBtn) %Hides no Button
GUI.Hide (nextBtn) %Hides next button
GUI.Hide (backBtn) %Hides back button
locate (7, 1)
%Start of introduction story
put "Since the beginning of time people have told great"
put "stories about a magical piece of wood. It was said"
put "that it was created by the great magician Merlin."
put "This board was capable of flying above the ground."
put "The rider would push off the ground, and jump over"
put "buildings."
put ""
put "One bright day Timmy Robinson was looking through"
put "his junk in the attic, when he came upon an orange"
put "skateboard. This one looked incredible, so Timmy "
put "went outside to take it for a ride. When he tried"
put "to do an Ollie, he jumped high, and flew over his"
put "house. Thus the great City Jumper was born. Timmy"
put "journeyed to Canada, and after many months came to"
put "Toronto. He is now having a fun jumping adventure"
put "in the city."
%End of introduction story
end introduction
%Error Window
procedure drawErrorWindow
var winID2 := Window.Open ("position:250;400,graphics:200;100") %draws second (error) window
%Window.Show (winID2)
%Window.SetActive (winID2)
put "Your name must be between"
put "3 and 10 characters long."
put ""
put "Press any key to continue" ..
loop
exit when hasch
end loop
Window.Close (winID2)
end drawErrorWindow
%Main Menu
procedure mainMenu
title
GUI.Show (playBtn) %Shows Menu Button
GUI.Show (helpBtn) %Shows Menu Button
GUI.Show (quitBtn) %Shows Menu Button
GUI.Hide (menuBtn) %Hides menu Button
end mainMenu
%User Input
procedure userInput
title
locate (8, 1)
put "Please enter your name: " ..
get name
if length (name) < 3 or length (name) > 10 then
drawErrorWindow
userInput
end if
end userInput
%Program Display
process displayMovement
%draws character and moves him across the screen
loop
exit when lives < 0 or level > 10 or x > 930
if not (key = chr (203) or key = chr (205)) then
x := x + 1
drawfillbox (29 + x, 0, 65 + x, 65, 7)
drawfilloval (50 + x, 55, 10, 10, 42)
drawline (50 + x, 55, 50 + x, 25, 42)
drawline (50 + x, 25, 40 + x, 10, 42)
drawline (50 + x, 25, 60 + x, 10, 42)
drawline (35 + x, 40, 65 + x, 40, 42)
drawline (30 + x, 10, 70 + x, 10, 42)
drawfilloval (40 + x, 5, 5, 5, 42)
drawfilloval (60 + x, 5, 5, 5, 42)
drawfilloval (40 + x, 5, 2, 2, 1)
drawfilloval (60 + x, 5, 2, 2, 1)
delay (5)
end if
end loop
cls
end displayMovement
%Program Display
%objects in game
process objects
fork displayMovement
loop
if level = 1 then
Pic.Draw (bigHouse, 200, 0, picCopy) %draw picture (big building)
Pic.Draw (smallHouse, 500, 0, picCopy) %draw picture (small building)
Pic.Draw (smallHouse, 840, 0, picCopy) %draw picture (small building)
drawbox (199, 0, 253, 75, 21)
drawbox (499, 0, 541, 33, 21)
drawbox (839, 0, 881, 33, 21)
elsif level = 2 then
Pic.Draw (smallHouse, 200, 0, picCopy) %draw picture (big building)
Pic.Draw (smallHouse, 400, 0, picCopy) %draw picture (big building)
Pic.Draw (smallHouse, 437, 0, picCopy) %draw picture (big building)
Pic.Draw (cnTower, 800, 0, picCopy) %draw picture (CN tower)
elsif level = 3 then
Pic.Draw (bigHouse, 200, 0, picCopy) %draw picture (big building)
Pic.Draw (cnTower, 400, 0, picCopy) %draw picture (CN tower)
Pic.Draw (skyDome, 600, 0, picCopy) %draw picture (Sky Dome)
elsif level = 4 then
Pic.Draw (smallHouse, 200, 0, picCopy) %draw picture (small building)
Pic.Draw (smallHouse, 330, 0, picCopy) %draw picture (small building)
Pic.Draw (bigHouse, 460, 0, picCopy) %draw picture (small building)
Pic.Draw (smallHouse, 650, 0, picCopy) %draw picture (small building)
Pic.Draw (bigHouse, 780, 0, picCopy) %draw picture (small building)
elsif level = 5 then
Pic.Draw (cnTower, 150, 0, picCopy) %draw picture (CN tower)
Pic.Draw (skyDome, 310, 0, picCopy) %draw picture (Sky Dome)
Pic.Draw (bigHouse, 650, 0, picCopy) %draw picture (small building)
Pic.Draw (smallHouse, 700, 0, picCopy) %draw picture (small building)
end if
if x > 930 then
level := level + 1
x := 5
cls
GUI.SetBackgroundColor (7)
end if
exit when lives < 0 or level > 10
end loop
end objects
%Program Display
%programming of keys for jumps
procedure jumps
userInput
cls
var playWin := Window.Open ("position:6;300,graphics:1000;300") %draws third (game) window
setscreen ("nocursor") %sets new screen up
GUI.SetBackgroundColor (7)
Window.Hide (mainWin)
%fork displayMovement
fork objects
loop
getch (key)
if key = chr (203) and x < 930 then
for a : 0 .. 7
drawfillbox (15 + x + a ** 2, -20 + a * 15, 70 + x + a ** 2, 65 + a * 15, 7)
drawfilloval (50 + x + a ** 2, 55 + a * 15, 10, 10, 42)
drawline (50 + x + a ** 2, 55 + a * 15, 50 + x + a ** 2, 25 + a * 15, 42)
drawline (50 + x + a ** 2, 25 + a * 15, 40 + x + a ** 2, 10 + a * 15, 42)
drawline (50 + x + a ** 2, 25 + a * 15, 60 + x + a ** 2, 10 + a * 15, 42)
drawline (35 + x + a ** 2, 40 + a * 15, 65 + x + a ** 2, 40 + a * 15, 42)
drawline (30 + x + a ** 2, 10 + a * 15, 70 + x + a ** 2, 10 + a * 15, 42)
drawfilloval (40 + x + a ** 2, 5 + a * 15, 5, 5, 42)
drawfilloval (60 + x + a ** 2, 5 + a * 15, 5, 5, 42)
drawfilloval (40 + x + a ** 2, 5 + a * 15, 2, 2, 1)
drawfilloval (60 + x + a ** 2, 5 + a * 15, 2, 2, 1)
delay (75)
end for
for decreasing a : 7 .. 0
drawfillbox (115 + x - a ** 2, 0 + a * 15, 175 + x - a ** 2, 90 + a * 15, 7)
drawfilloval (153 + x - a ** 2, 55 + a * 15, 10, 10, 42)
drawline (153 + x - a ** 2, 55 + a * 15, 153 + x - a ** 2, 25 + a * 15, 42)
drawline (153 + x - a ** 2, 25 + a * 15, 143 + x - a ** 2, 10 + a * 15, 42)
drawline (153 + x - a ** 2, 25 + a * 15, 163 + x - a ** 2, 10 + a * 15, 42)
drawline (138 + x - a ** 2, 40 + a * 15, 168 + x - a ** 2, 40 + a * 15, 42)
drawline (133 + x - a ** 2, 10 + a * 15, 173 + x - a ** 2, 10 + a * 15, 42)
drawfilloval (143 + x - a ** 2, 5 + a * 15, 5, 5, 42)
drawfilloval (163 + x - a ** 2, 5 + a * 15, 5, 5, 42)
drawfilloval (143 + x - a ** 2, 5 + a * 15, 2, 2, 1)
drawfilloval (163 + x - a ** 2, 5 + a * 15, 2, 2, 1)
delay (75)
end for
x := x + 103
elsif key = chr (205) and x < 930 then
for a : 0 .. 9
drawfillbox (10 + x + a ** 2, -20 + a * 15, 70 + x + a ** 2, 65 + a * 15, 7)
drawfilloval (50 + x + a ** 2, 55 + a * 15, 10, 10, 42)
drawline (50 + x + a ** 2, 55 + a * 15, 50 + x + a ** 2, 25 + a * 15, 42)
drawline (50 + x + a ** 2, 25 + a * 15, 40 + x + a ** 2, 10 + a * 15, 42)
drawline (50 + x + a ** 2, 25 + a * 15, 60 + x + a ** 2, 10 + a * 15, 42)
drawline (35 + x + a ** 2, 40 + a * 15, 65 + x + a ** 2, 40 + a * 15, 42)
drawline (30 + x + a ** 2, 10 + a * 15, 70 + x + a ** 2, 10 + a * 15, 42)
drawfilloval (40 + x + a ** 2, 5 + a * 15, 5, 5, 42)
drawfilloval (60 + x + a ** 2, 5 + a * 15, 5, 5, 42)
drawfilloval (40 + x + a ** 2, 5 + a * 15, 2, 2, 1)
drawfilloval (60 + x + a ** 2, 5 + a * 15, 2, 2, 1)
delay (75)
end for
for decreasing a : 9 .. 0
drawfillbox (190 + x - a ** 2, 0 + a * 15, 250 + x - a ** 2, 90 + a * 15, 7)
drawfilloval (228 + x - a ** 2, 55 + a * 15, 10, 10, 42)
drawline (228 + x - a ** 2, 55 + a * 15, 228 + x - a ** 2, 25 + a * 15, 42)
drawline (228 + x - a ** 2, 25 + a * 15, 218 + x - a ** 2, 10 + a * 15, 42)
drawline (228 + x - a ** 2, 25 + a * 15, 238 + x - a ** 2, 10 + a * 15, 42)
drawline (213 + x - a ** 2, 40 + a * 15, 243 + x - a ** 2, 40 + a * 15, 42)
drawline (208 + x - a ** 2, 10 + a * 15, 248 + x - a ** 2, 10 + a * 15, 42)
drawfilloval (218 + x - a ** 2, 5 + a * 15, 5, 5, 42)
drawfilloval (238 + x - a ** 2, 5 + a * 15, 5, 5, 42)
drawfilloval (218 + x - a ** 2, 5 + a * 15, 2, 2, 1)
drawfilloval (238 + x - a ** 2, 5 + a * 15, 2, 2, 1)
delay (75)
end for
x := x + 178
end if
key := "0"
exit when lives < 0 or level > 10
end loop
delay (1000)
Window.Hide (playWin)
Window.Show (mainWin)
Window.SetActive (mainWin)
mainMenu
end jumps
%Instructions
procedure instructions
title
GUI.Show (nextBtn) %Shows menu button
GUI.Hide (playBtn) %Hides play Button
GUI.Hide (quitBtn) %Hides quit Button
GUI.Hide (helpBtn) %Hides instructions Button
%Start of instructions
locate (7, 1)
put "Objective: In City Jumper you are Timmy Robinson."
locate (8, 12)
put "You must jump over all of the objects"
locate (9, 12)
put "in the levels to continue to the next."
locate (10, 12)
put "You only have 3 lives in the whole game"
put ""
put "Controls: The left arrow key: small jump."
locate (13, 11)
put "The right arrow key: big jump."
%End of instructions
locate (21, 12)
put "small jump big jump" %Captions for picture
pictureID := Pic.FileNew ("Arrow Keys.bmp") %finds document
Pic.Draw (pictureID, 125, 90, picMerge) %draw picture (arrow keys)
end instructions
procedure instructions2
title
GUI.Show (menuBtn) %Shows menu button
GUI.Show (backBtn) %Shows back button
GUI.Hide (nextBtn) %Hides next button
locate (7, 1)
put "Regular buildings are easy to jump over. They have"
put "no special features. However, some buildings have"
put "security features. Timmy's skateboard allows Timmy"
put "him to see the building's laser system. The laser"
put "system protects the buildings from intruders. You"
put "have to jump over the lasers to continue jumping."
put "The lasers appear red."
locate (20, 4)
put "Regular Building Special Building with"
locate (21, 36)
put "lasers"
Pic.Draw (bigHouse, 73, 100, picCopy) %draw picture (big building)
Pic.Draw (cnTower, 281, 100, picCopy) %draw picture (CN tower)
end instructions2
%Confirm Quit
procedure confirmQuit
title
GUI.Show (yesBtn) %Shows yes Button
GUI.Show (noBtn) %Shows no Button
GUI.Hide (menuBtn) %Hides menu Button
GUI.Hide (backBtn) %Hides back button
locate (8, 1)
put "Are you sure you want to leave?"
pictureID := Pic.FileNew ("Question Mark.bmp") %finds document
Pic.Draw (pictureID, 97, 0, picMerge) %draw picture (question mark)
end confirmQuit
%Goodbye
procedure goodBye
title
locate (8, 1)
put "Thank you for playing City Jumper."
put "Play again soon."
locate (11, 27)
put "Programmer: Ariel Shain"
pictureID := Pic.FileNew ("Happy Face.bmp") %finds document
Pic.Draw (pictureID, 95, 0, picMerge) %draw picture (happy face)
delay (3000) %delays the end of the program so user could read what is written
Window.Hide (mainWin) %Closes window
Pic.Free (pictureID) %Releases picture from memory
Pic.Free (bigHouse) %Releases picture from memory
Pic.Free (smallHouse) %Releases picture from memory
Pic.Free (cnTower) %Releases picture from memory
Pic.Free (skyDome) %Releases picture from memory
end goodBye
playBtn := GUI.CreateButtonFull (100, 250, 200, "Play", jumps, 0, '^P', false)
helpBtn := GUI.CreateButtonFull (100, 200, 200, "Instructions", instructions, 0, '^I', false)
menuBtn := GUI.CreateButtonFull (100, 10, 200, "Menu", mainMenu, 0, '^M', false)
quitBtn := GUI.CreateButtonFull (100, 150, 200, "Quit", confirmQuit, 0, KEY_ESC, false)
yesBtn := GUI.CreateButtonFull (150, 220, 50, "Yes", GUI.Quit, 0, 'y', false)
noBtn := GUI.CreateButtonFull (200, 220, 50, "No", mainMenu, 0, 'n', false)
nextBtn := GUI.CreateButtonFull (345, 10, 0, "Next", instructions2, 0, '^N', false)
backBtn := GUI.CreateButtonFull (0, 10, 0, "Back", instructions, 0, 'B', false)
%Main Program
introduction
loop
exit when GUI.ProcessEvent
end loop
goodBye
%End of Program |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
yusong
|
Posted: Sun Jan 13, 2008 7:18 pm Post subject: RE:Final Project immediate help Please!!! due January 16th |
|
|
Turing: |
if box1_x2 > box2_x1 and box1_x1 < box2_x2 and box1_y2 > box2_y1 and box1_y1 < box2_y2 then
put "They have collided!"
exit
end if
|
For Rectangular Collision
If you want Circular Collision
Turing: |
distance_between_centres := sqrt ((circle_ 2_x - circle_ 1_x ) ** 2 + (circle_ 2_y - circle_ 1_y ) ** 2)
if distance_between_centres <= circle_ 1_radius + circle_ 2_radius then
put "The circles have collided!"
exit
end if
|
Thank you richcash for your awesome tutorial on collision, which has helped me a lot. |
|
|
|
|
![](images/spacer.gif) |
Shainman
|
Posted: Sun Jan 13, 2008 9:03 pm Post subject: Re: Final Project immediate help Please!!! due January 16th |
|
|
what if i need to do collision detection between a cirlce and a box? like if i need to know when a circle has touched a box. |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
Shainman
|
Posted: Sun Jan 13, 2008 9:51 pm Post subject: Re: Final Project immediate help Please!!! due January 16th |
|
|
wow that actually helped ( the paper thing) thanks Tony!!! ![Very Happy Very Happy](images/smiles/icon_biggrin.gif) |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Sun Jan 13, 2008 10:10 pm Post subject: RE:Final Project immediate help Please!!! due January 16th |
|
|
no problem! I knew I was writing all that stuff for a reason ![Wink Wink](http://compsci.ca/v3/images/smiles/icon_wink.gif) |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
questionableninja
![](http://compsci.ca/v3/uploads/user_avatars/19359017854744a68482b5a.jpg)
|
Posted: Sun Jan 13, 2008 10:13 pm Post subject: Re: Final Project immediate help Please!!! due January 16th |
|
|
WTH all my teacher lets us do is stupid projects that are no fun at all like making a pargraph out of 3 files like WTF is that maaaan you are so lcuky *sigh* ![Evil or Very Mad Evil or Very Mad](http://compsci.ca/v3/images/smiles/icon_evil.gif) |
|
|
|
|
![](images/spacer.gif) |
StealthArcher
![](http://compsci.ca/v3/uploads/user_avatars/18949255664b176c4f1481b.jpg)
|
Posted: Sun Jan 13, 2008 10:15 pm Post subject: RE:Final Project immediate help Please!!! due January 16th |
|
|
Coherent posts are your friend, friend. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|