Need help with collision detection cant figure it out
Author |
Message |
UnTiteled
|
Posted: Thu Jan 14, 2010 3:04 pm Post subject: Need help with collision detection cant figure it out |
|
|
What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
i am simpy trying to make collision detection. i am trying to make it that when the bad guy (or good guy) gets hit health subtracts
(sorry for the code not being organized)
What is the problem you are having?
<Answer Here>
I cant understand how to do collisions
Describe what you have tried to solve this problem
<Answer Here>
reading over tutorials
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
const GROUND_HEIGHT := 120
const RUN_SPEED := 10
const JUMP_SPEED := 30
const GRAVITY := 2
var manfig1 := Pic.FileNew ("stand.gif")
var manfig2 := Pic.FileNew ("face.gif")
var monsterfig2 := Pic.FileNew ("monster_face.gif")
var monster := Pic.FileNew ("monster.gif")
var ypos := 750
var xpos := 150
var chars : array char of boolean
var position := 1000
var posx, posy : int
var velx, vely : real
posx := 20
velx := 0
posy := 400
vely := 0
colourback (70)
cls
locate (15, 20)
put "___________.__"
locate (16, 20)
put "\\__ ___/| |__ ____ "
locate (17, 20)
put " | | | | \\_/ __ \\ "
locate (18, 20)
put " | | | Y \\ ___/ "
locate (19, 20)
put " |____| |___| /\\___ >"
locate (20, 20)
put " \\/ \\/ "
locate (21, 20)
put " _____ .__ .__ .__ __ "
locate (22, 20)
put " / _ \\ | | ____ | |__ ____ _____ |__| _______/ |_ "
locate (23, 20)
put " / /_\\ \\| | _/ ___\\| | \\_/ __ \\ / \\| |/ ___/\\ __\\"
locate (24, 20)
put "/ | \\ |_\\ \\___| Y \\ ___/| Y Y \\ |\\___ \\ | | "
locate (25, 20)
put "\\____|__ /____/\\___ >___| /\\___ >__|_| /__/____ > |__| "
locate (26, 20)
put " \\/ \\/ \\/ \\/ \\/ \\/ "
put "Instructions: Move with the 'up, down, left, and right buttons', shoot with the space bar"
put ""
put "On the first day, God created the Heavens and The earth..."
put "On the sixth day, God created the creatures of the earth, and with them"
put "came a soul devouring beast, once the humans were put on the earth, so"
put "did the demon start to hunt for souls"
put ""
put "your quest iss to defeat these demons and save the world from darkness"
put "hit any key to begin"
Input.Pause
colourback (white)
colour (white)
cls
locate (16, 20)
colour (black)
put " _______________"
locate (17, 20)
put "|prepare |"
locate (18, 20)
put "|to |"
locate (19, 20)
put "|be destroyed. |"
locate (20, 20)
put "| ______________|"
locate (21, 20)
put "|/"
Pic.Draw (manfig2, 120, 240, picMerge)
Pic.Draw (manfig1, 50, 50, picMerge)
drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)
locate (41, 10)
put "hit any key to continue"
Input.Pause
locate (16, 90)
put " _______________"
locate (17, 90)
put "| |"
locate (18, 90)
put "|GRAAAWWWWRRRRR |"
locate (19, 90)
put "|______________ |"
locate (20, 90)
put " |/"
Pic.Draw (monsterfig2, 790, 250, picMerge)
locate (41, 10)
Pic.Draw (monster, position, 60, picMerge)
View.Set ("offscreenonly")
loop
colour (black)
colourback (white)
cls
locate (16, 20)
put " _______________"
locate (17, 20)
put "|prepare |"
locate (18, 20)
put "|to |"
locate (19, 20)
put "|be destroyed. |"
locate (20, 20)
put "| ______________|"
locate (21, 20)
put "|/"
Pic.Draw (manfig2, 120, 240, picMerge)
Pic.Draw (manfig1, 50, 50, picMerge)
drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)
locate (41, 10)
locate (16, 90)
put " _______________"
locate (17, 90)
put "| |"
locate (18, 90)
put "|GRAAAWWWWRRRRR |"
locate (19, 90)
put "|______________ |"
locate (20, 90)
put " |/"
Pic.Draw (monsterfig2, 790, 250, picMerge)
locate (41, 10)
Pic.Draw (monster, position, 60, picMerge)
position := position - 1
delay (15)
View.Update
cls
exit when position = 750
end loop
locate (5, 50)
put "press s to start..."
Input.Pause
var pic2 := Pic.FileNew ("darkblast.gif")
var monster2 := Pic.FileNew ("monster.gif")
var pic := Pic.FileNew ("fireball2.gif")
View.Set ("offscreen")
loop
loop
Input.KeyDown (chars )
if chars ('q') then
exit
end if
if chars (KEY_LEFT_ARROW) then
velx := -RUN_SPEED
elsif chars (KEY_RIGHT_ARROW) then
velx := RUN_SPEED
else
velx := 0
end if
if chars (KEY_UP_ARROW) and posy = GROUND_HEIGHT then
vely := JUMP_SPEED
end if
var y := posx
var x := posy
Pic.Draw (monster2, 750, 60, picMerge)
Pic.Draw (pic2, ypos, xpos, picMerge)
ypos := ypos - 1
delay (3)
if ypos = - 80 then
ypos := 750
exit
end if
Input.KeyDown (chars )
if chars (' ') then
loop
Input.KeyDown (chars )
if chars ('q') then
exit
end if
if chars (KEY_LEFT_ARROW) then
velx := -RUN_SPEED
elsif chars (KEY_RIGHT_ARROW) then
velx := RUN_SPEED
else
velx := 0
end if
if chars (KEY_UP_ARROW) and posy = GROUND_HEIGHT then
vely := JUMP_SPEED
end if
Pic.Draw (manfig1, posx, posy, picMerge)
drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)
vely - = GRAVITY
posx + = round (velx )
posy + = round (vely )
if posy < GROUND_HEIGHT then
posy := GROUND_HEIGHT
vely := 0
end if
delay (35)
View.Update
cls
if posx < 0 then
posx := - 1
elsif posx > 600 then
posx := 600
end if
Pic.Draw (pic, y, x, picMerge)
y + = 5
if y > 760 then
y := - 10
exit
end if
Pic.Draw (monster2, 750, 60, picMerge)
Pic.Draw (pic2, ypos, xpos, picMerge)
ypos := ypos - 1
delay (3)
if ypos = - 80 then
ypos := 750
end if
var hp := 100
var hp2 := 100
locate (2, 1)
put "health: ", hp, "/100"
locate (2, 110)
put "health: ", hp2, "/100"
if y >= posx
then
hp := hp - 10
end if
if y > 751
and x > 261
then
hp2 := hp2 - 10
end if
end loop
end if
ypos := ypos - 1
delay (3)
if ypos = - 80 then
ypos := 750
end if
vely - = GRAVITY
posx + = round (velx )
posy + = round (vely )
if posy < GROUND_HEIGHT then
posy := GROUND_HEIGHT
vely := 0
end if
Pic.Draw (manfig1, posx, posy, picMerge)
drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)
delay (35)
if posx < 0 then
posx := - 1
elsif posx > 600 then
posx := 600
end if
View.Update
cls
var hp := 100
var hp2 := 100
locate (2, 1)
put "health: ", hp, "/100"
locate (2, 110)
put "health: ", hp2, "/100"
if y >= posx
then
hp := hp - 10
end if
if y > 751
and x > 261
then
hp2 := hp2 - 10
end if
end loop
ypos := ypos - 1
delay (3)
if ypos = - 80 then
ypos := 750
end if
var hp := 100
var hp2 := 100
locate (2, 1)
put "health: ", hp, "/100"
locate (2, 110)
put "health: ", hp2, "/100"
var y := posx
var x := posy
if y >= posx
then
hp := hp - 10
end if
var y2 := posx
var x2 := posy
if y2 > 751
and x2 > 261
then
hp2 := hp2 - 10
end if
locate (2, 1)
put "health: ", hp, "/100"
locate (2, 110)
put "health: ", hp2, "/100"
end loop
|
Please specify what version of Turing you are using
<Answer Here>
4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
UnTiteled
|
Posted: Thu Jan 14, 2010 3:15 pm Post subject: RE:Need help with collision detection cant figure it out |
|
|
i just realized that the code is screwed up a little bit and can you also tell me if i am outputting the healt (hp) out right? |
|
|
|
|
|
TerranceN
|
Posted: Thu Jan 14, 2010 3:55 pm Post subject: Re: Need help with collision detection cant figure it out |
|
|
Did you see this tutorial? Collision Detection by richcash |
|
|
|
|
|
UnTiteled
|
Posted: Thu Jan 14, 2010 4:17 pm Post subject: RE:Need help with collision detection cant figure it out |
|
|
mhm |
|
|
|
|
|
TerranceN
|
Posted: Thu Jan 14, 2010 5:11 pm Post subject: RE:Need help with collision detection cant figure it out |
|
|
Well then what exactly don't you understand? You might want to re-read that tutorial slowly, cause I think that tutorial explains collision quite clearly (and how to use it with pictures too). |
|
|
|
|
|
UnTiteled
|
Posted: Thu Jan 14, 2010 9:31 pm Post subject: RE:Need help with collision detection cant figure it out |
|
|
ya i think i understand it
plus mi code is screwed up a little bit |
|
|
|
|
|
|
|