Im wondering how tio work projectile collision detection. I've got collsion detection for the characters working, but the projectile collision isnt. Could anybody help me out?
"Blast" is the projectile, here's my code.
Turing: |
%Music
process BgmSound
loop
Music.PlayFile ("music.mp3")
end loop
end BgmSound
fork BgmSound
View.Set ("title:Space Survival")
var mDamage, hp, Enemyhp : int
var mypic1 : int := Pic.FileNew ("StrikerRight.bmp")
var mypic2 : int := Pic.FileNew ("Enemy.bmp")
var blast : int := Pic.FileNew ("Blast.bmp")
var CharacterX : array 1 .. 2 of int
var CharacterY : array 1 .. 2 of int
var MonsterX : array 1 .. 2 of int
var MonsterY : array 1 .. 2 of int
var blastX : array 1 .. 2 of int
var blastY : array 1 .. 2 of int
var chars : array char of boolean
var shoot : boolean := false
View.Set ("offscreenonly, graphics:650;410")
CharacterX (1) := 50 % Characters X value (Horizontal Axis)
CharacterY (1) := 50 % Characters Y value (Verticle Axis
CharacterX (2) := 0
CharacterY (2) := 0
MonsterX (1) := 550 % Monsters X value (Horizontal Axis)
MonsterY (1) := 200 % Monsters Y value (Verticle Axis)
MonsterX (2) := 0
MonsterY (2) := 0
blastX (1) := CharacterX (1) + 11
blastY (1) := CharacterY (1) + 11
blastX (2) := 0
blastY (2) := 0
hp := 500
Enemyhp := 2
const Speed := 5
MonsterX (2) := MonsterX (1) + Pic.Width (mypic2 )
MonsterY (2) := MonsterY (1) + Pic.Height (mypic2 )
blastX (2) := blastX (1) + Pic.Width (blast )
blastY (2) := blastY (1) + Pic.Height (blast )
loop
drawfillbox (1, 1, maxx, maxx, black)
drawfillbox (5, 384, hp + 5, 384, red) %Hp bars
drawfillbox (5, 385, hp + 5, 385, red) %Hp bars
drawfillbox (5, 386, hp + 5, 386, red) %Hp bars
drawfillbox (5, 387, hp + 5, 387, red) %Hp bars
drawfillbox (5, 388, hp + 5, 388, red) %Hp bars
drawfillbox (5, 389, hp + 5, 389, red) %Hp bars
drawfillbox (5, 390, hp + 5, 390, red) %Hp bars
drawfillbox (5, 391, hp + 5, 391, red) %Hp bars
drawfillbox (5, 392, hp + 5, 392, red) %Hp bars
drawfillbox (5, 393, hp + 5, 393, red) %Hp bars
drawfillbox (5, 394, hp + 5, 394, red) %Hp bars
drawfillbox (5, 395, hp + 5, 395, red) %Hp bars
drawfillbox (5, 396, hp + 5, 396, red) %Hp bars
drawfillbox (5, 397, hp + 5, 397, red) %Hp bars
drawfillbox (5, 398, hp + 5, 398, red) %Hp bars
drawfillbox (5, 399, hp + 5, 399, red) %Hp bars
%Collision Detection
if CharacterX (2) > MonsterX (1) and CharacterX (1) < MonsterX (2) and CharacterY (2) > MonsterY (1) and CharacterY (1) < MonsterY (2) and hp > 0 then
hp := hp - 2
end if
Input.KeyDown (chars )
if chars (KEY_UP_ARROW) and hp > 0 then
CharacterY (1) + = Speed
blastX (1) := CharacterX (1) + 11
blastY (1) := CharacterY (1) + 11
if CharacterX (2) > MonsterX (1) and CharacterX (1) < MonsterX (2) and CharacterY (2) > MonsterY (1) and CharacterY (1) < MonsterY (2) and hp > 0 then
hp := hp - 2
end if
CharacterY (2) := CharacterY (1) + Pic.Height (mypic1 )
if CharacterY (1) + Pic.Height (mypic1 ) >= maxy then
CharacterY (1) := maxy - Pic.Height (mypic1 )
end if
end if
if chars (KEY_RIGHT_ARROW) and hp > 0 then
CharacterX (1) + = Speed
blastX (1) := CharacterX (1) + 11
blastY (1) := CharacterY (1) + 11
if CharacterX (2) > MonsterX (1) and CharacterX (1) < MonsterX (2) and CharacterY (2) > MonsterY (1) and CharacterY (1) < MonsterY (2) and hp > 0 then
hp := hp - 2
end if
CharacterX (2) := CharacterX (1) + Pic.Width (mypic1 )
if CharacterX (1) + Pic.Width (mypic1 ) >= maxx then
CharacterX (1) := maxx - Pic.Width (mypic1 )
end if
end if
if chars (KEY_LEFT_ARROW) and hp > 0 then
CharacterX (1) - = Speed
blastX (1) := CharacterX (1) + 11
blastY (1) := CharacterY (1) + 11
if CharacterX (2) > MonsterX (1) and CharacterX (1) < MonsterX (2) and CharacterY (2) > MonsterY (1) and CharacterY (1) < MonsterY (2) and hp > 0 then
hp := hp - 2
end if
CharacterX (2) := CharacterX (1) + Pic.Width (mypic1 )
if CharacterX (1) <= 0 then
CharacterX (1) := 0
end if
end if
if chars (KEY_DOWN_ARROW) and hp > 0 then
CharacterY (1) - = Speed
blastX (1) := CharacterX (1) + 11
blastY (1) := CharacterY (1) + 11
if CharacterX (2) > MonsterX (1) and CharacterX (1) < MonsterX (2) and CharacterY (2) > MonsterY (1) and CharacterY (1) < MonsterY (2) and hp > 0 then
hp := hp - 2
end if
CharacterY (2) := CharacterY (1) + Pic.Height (mypic1 )
if CharacterY (1) <= 1 then
CharacterY (1) := 1
end if
end if
if chars (' ') then
shoot := true
end if
if shoot = true then
blastX (1) + = 10
Pic.Draw (blast, blastX (1), blastY (1), picMerge)
end if
if blastX (1) >= maxx and hp > 0 then
blastX (1) := CharacterX (1) + 11
blastY (1) := CharacterY (1) + 11
blastX (2) := 0
blastY (2) := 0
shoot := false
if blastX (2) >= MonsterX (1) and blastX (1) <= MonsterX (2) and blastY (2) >= MonsterY (1) and blastY (1) <= MonsterY (2) and hp >= 0 then
hp := hp - 2
end if
end if
if hp <= 0 then
put "You have died" %Hp System
end if
View.Set ("offscreenonly")
Pic.Draw (mypic2, MonsterX (1), MonsterY (1), picMerge) % Enemy
Pic.Draw (mypic1, CharacterX (1), CharacterY (1), picMerge) % Character
View.Update
delay (13)
cls
end loop
|
Right now if it works it should drain my characters hp. If anybody could help me out, it would be greatly appreciated. |