Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Collsion Detection Help For My Game
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
The Lone Ranger




PostPosted: Wed Dec 16, 2009 5:00 pm   Post subject: Re: Collsion Detection Help For My Game

Where exactly would that go in my collision procedure.
Sponsor
Sponsor
Sponsor
sponsor
TheGuardian001




PostPosted: Wed Dec 16, 2009 9:58 pm   Post subject: Re: Collsion Detection Help For My Game

Depends on when you want it to exit. Presumably sometime between when hit is set and the end of the procedure.
The Lone Ranger




PostPosted: Thu Dec 17, 2009 11:43 am   Post subject: Re: Collsion Detection Help For My Game

I put exit when hit into my program,but it still doesn't work.

I feel like I've tried everything to make this collision work, could you please offer me some more help.
mirhagk




PostPosted: Thu Dec 17, 2009 1:26 pm   Post subject: RE:Collsion Detection Help For My Game

you need to put the exit when code in all the loops you have (so that it will exit all the loops once it's hit)
The Lone Ranger




PostPosted: Thu Dec 17, 2009 7:58 pm   Post subject: Re: Collsion Detection Help For My Game

Thank you so much for that.

I am almost done my collisions, I have some of it working but I still need a little bit more help. The program ends when it says there is a collision, but the collision occurs before the asteroid and the ship touch.
Here is the code,

% Mohammad Malik and Ronny Blanco
% The Asteroid Game
% December 1st, 2009

View.Set ("graphics:640,427")

% The variables for our program
var name : string
var chars : array char of boolean
var pic : int := Pic.FileNew ("F:\\images2.jpg")
var backGround : int := Pic.FileNew ("F:\\back.jpg")
var asteroid : int := Pic.FileNew ("F:\\Asteroid.jpg")
var x, y : int
var x2, y2 : int

const ship := "x"

colorback (black)
% The values of x, y, x2, and y2
x := 10
y := 10

x2 := 100
y2 := 100
var hit : boolean := false
% The procedure to play music
procedure DoMusic
loop
Music.PlayFile ("E:\\pathetic.WAV") % This is the music file
end loop
end DoMusic


put "INSTRUCTIONS"
put "To play this game you must use the left and right arrow keys to move your space ship, and dodge the falling asteroids."
put "Good Luck!"
put "Please input your name: " ..
get name
cls


proc collision (x : int, y : int, w : int, h : int, x1 : int, y1 : int, w1 : int, h1 : int)
locate (1, 1)
if x1 - x <= 70 and y1 - 73 - y < 65 then
hit := true
end if
Text.Locate (1, 1)
put hit
end collision


% The process to make the asteroids fall
process downFall
loop
exit when hit = true

randint (x2, 0, 600) % This randomizes the x position of the asteroid

for decreasing i : maxy .. 0 by 20
% This command draws the asteroids
Pic.Draw (asteroid, x2, i, picCopy)
delay (100)
cls
if i <= 20 then

delay (10)

end if

end for

end loop

end downFall

fork downFall


loop
exit when hit = true
%This command draws the background
Pic.Draw (backGround, 0, 0, picCopy)
exit when hit
if backGround = 0 then
put "Unable to load JPEG: ", Error.LastMsg
end if


% The call to the DoMusic procedure
Music.PlayFile ("DoMusic")


% This loop is for the controls in the game
loop
collision (x, y, 70, 73, x2, y2, 158, 72)
exit when hit = true
Input.KeyDown (chars)
if chars (KEY_RIGHT_ARROW) then %If the right arrow key is pressed, then the space ship will move to the right
x := x + 5
elsif chars (KEY_LEFT_ARROW) then %If the left arrow key is pressed, then the space ship will move to the left
x := x - 5
end if
% This error message displays if the picture is unable to load
if pic = 0 then
put "Unable to load JPEG: ", Error.LastMsg
end if
% This is the command to draw the space ship
Pic.Draw (pic, x, y, picCopy)
delay (10)
end loop

end loop

It's definetly got something to do with my collision procedure, but I just can't figure out what, could you please help me?
mirhagk




PostPosted: Thu Dec 17, 2009 11:22 pm   Post subject: RE:Collsion Detection Help For My Game

Use Math.Distance (enter two points and it returns the distance between the two of them).

Your collision detection is a little unreliable
The Lone Ranger




PostPosted: Fri Dec 18, 2009 10:26 am   Post subject: Re: Collsion Detection Help For My Game

YES! I have finally finshed my collsions! The game is not perfect, but at least I finshed on the deadline, thanks for all your help guys.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 22 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: