URGENT Collision Detection help
Author |
Message |
adrian123
|
Posted: Tue Jan 17, 2012 11:16 pm Post subject: URGENT Collision Detection help |
|
|
What is it you are trying to achieve?
So I'm stuck with collision detection on my program (it's a copter-esque game that involves controlling a flying mario and dodging bullet bills that come towards you).
What is the problem you are having?
I am not sure if my code is correct beacuse my collision is not working. Does anyone know how to fix it? I have copied the whole code. The object collision statement is near the end of the code.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
setscreen ("graphics: 900;600, position:center;center, nocursor, offscreenonly, nobuttonbar")
var counter : int := 0
var titlefont, font1, smallerfont : int
font1 := Font.New ("Calibri:30")
titlefont := Font.New ("Calibri:60")
smallerfont := Font.New ("Calibri:45")
var w1, w2, button : int
var y : int := 650 div 2
var highscore : int := 0
var bulletbill, marioup, mariodown, bulletbillbg : int
bulletbillbg := Pic.FileNew ("bulletbillbg.bmp")
bulletbill := Pic.FileNew ("bulletbill.bmp")
marioup := Pic.FileNew ("mariouptest.gif")
mariodown := Pic.FileNew ("mariodown.gif")
var bulletbillx : int := 900
var bulletbilly := Rand.Int (120, 400)
var bulletbillbgy := Rand.Int (120, 400)
var bulletbillbgx : int := - 100
%CollisionVaribles
var mariox1, marioy1, mariox2, marioy2 : int
var bulletbillx1, bulletbilly1, bulletbillx2, bulletbilly2 : int
mariox1 := 40
marioy1 := 40
mariox2 := mariox1 + Pic.Width (marioup )
marioy2 := marioy1 + Pic.Height (marioup )
bulletbillx1 := 40
bulletbilly1 := 40
bulletbillx2 := bulletbillx1 + Pic.Width (bulletbill )
bulletbilly2 := bulletbilly1 + Pic.Height (bulletbill )
put ""
Font.Draw ("Press any key to start!", 100, 350, titlefont, black)
Font.Draw ("Game by Adrian Lau", 200, 250, smallerfont, black)
Input.Pause
cls
loop
Pic.ScreenLoad ("bg.bmp", 0, 0, picCopy)
Pic.Draw (bulletbillbg, bulletbillbgx, bulletbillbgy, picMerge)
bulletbillbgx := bulletbillbgx + 10
if bulletbillbgx >= 950 then
bulletbillbgx := - 100
bulletbillbgy := Rand.Int (120, 400)
end if
Pic.Draw (bulletbill, bulletbillx, bulletbilly, picMerge)
bulletbillx := bulletbillx - 12
if bulletbillx <= - 100 then
bulletbillx := maxx
bulletbilly := Rand.Int (120, 400)
end if
Mouse.Where (w1, w2, button )
if button = 1 then
y + = 3
Pic.Draw (marioup, 30, y, picMerge)
View.Update
else
y - = 4
Pic.Draw (marioup, 30, y, picMerge)
View.Update
end if
Font.Draw ("Score:", 15, 45, font1, black)
counter := counter + 1
Font.Draw (intstr (counter ), 120, 45, font1, black)
View.Update
Font.Draw ("Highscore:", 620, 45, font1, black)
View.Update
if y >= 440 then
delay (500)
cls
Font.Draw ("You went ", 230, 300, smallerfont, black)
Font.Draw (intstr (counter ), 470, 300, smallerfont, black)
Font.Draw (" km. ", 585, 300, smallerfont, black)
exit
end if
if y <= 103 then
delay (500)
cls
Font.Draw ("You went ", 230, 300, smallerfont, black)
Font.Draw (intstr (counter ), 470, 300, smallerfont, black)
Font.Draw (" km. ", 585, 300, smallerfont, black)
exit
end if
loop
if mariox1 < bulletbillx2 and mariox2 > bulletbilly1 and marioy1 < bulletbilly2 and marioy2 > bulletbilly1 then
exit
end if
end loop
end loop
|
Please specify what version of Turing you are using
4.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dreadnought
|
Posted: Wed Jan 18, 2012 1:32 am Post subject: Re: URGENT Collision Detection help |
|
|
Your "collision variables" are never updated, so you can't check collision with them since they don't actually store the position of the objects. |
|
|
|
|
|
|
|