Turing Space shooter game-hit detection and scoring problem
Author |
Message |
Will910
|
Posted: Thu Jun 17, 2010 9:16 pm Post subject: Turing Space shooter game-hit detection and scoring problem |
|
|
What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
What is the problem you are having?
<Answer Here>
Describe what you have tried to solve this problem
<Answer Here>
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
[syntax="turing"]
What is it you are trying to achieve?
I am trying to get my program to keep track of the score properly(10 points per hit)
and for the hit detection to work properly.
What is the problem you are having?
The score seems to go up randomly when i fire off to the side of cyclops
Describe what you have tried to solve this problem
I have tried if statements that create an imaginary "Box" around the cyclops but I may have messed it up.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
var x, y, button, buttonupdown : int
var font1, font2, font3, font4 : int
var WinID : int
var lives : int := 0
var points : int := 0
var xcan : int := 0
var num, num1 : int := 0
var yball, xball : int := 0
var lvl : int := 0
var clr, clr1, clr2 : int := 0
var hiscore : int := 0
var code : string
var key : string (1)
var fired : boolean := false
var xc1, xc2, xc3, xc4, xc5, xc6, xc7, xc8, xc9, xc10 : int
var yc1, yc2, yc3, yc4, yc5, yc6, yc7, yc8, yc9, yc10 : int
drawfill (1, 1, 255, 1)
font1 := Font.New ("chiller:32:underline,bold")
font2 := Font.New ("Arial black:24")
font3 := Font.New ("TremorITC TT:32:underline,bold")
font4 := Font.New ("BankGothic Lt BT:32:bold")
Font.Draw ("Beware of the Cyclops", 180, 200, font1, 12)
play ("<ADGEDGDEGDE1>A>")
cls
xcan := 260
xball := xcan
loop
%Title Screen
drawfill (1, 1, 255, 1)
color (14)
colorback (255)
drawbox (200, 370, 440, 320, 12) %start game button
Font.Draw ("Start", 270, 335, font2, 14)
drawbox (200, 230, 440, 180, 12) %Instructions button
Font.Draw ("Instructions", 215, 195, font2, 14)
drawbox (200, 100, 440, 50, 12) %Exit button
Font.Draw ("Exit", 275, 65, font2, 14)
%left cyclops on title screen
drawfilloval (100, 200, 25, 25, 4)
drawfilloval (100, 210, 7, 7, 1)
drawfillarc (100, 190, 15, 10, 180, 0, 0)
drawfillarc (100, 188, 12, 7, 180, 0, 255)
%right cyclops on title screen
drawfilloval (530, 200, 25, 25, 4)
drawfilloval (530, 210, 7, 7, 1)
drawfillarc (530, 190, 15, 10, 180, 0, 0)
drawfillarc (530, 188, 12, 7, 180, 0, 255)
View.Set ("offscreenonly")
buttonwait ("down", x, y, button, buttonupdown )
if x > 200 and x < 440 and y < 230 and y > 180 then
View.Update
cls
drawfill (1, 1, 255, 1)
drawbox (1, 399, 105, 350, 12)
locate (2, 2)
put "Back to menu" ..
Font.Draw ("Instructions", 180, 325, font4, 9)
locate (6, 1)
color (0)
put "Beware of the cyclops is played using the arrow keys, mouse and space bar. The"
put "arrow keys control the movement of your cannon," ..
put " and the spacebar is used to fire the cannon." ..
put " You collect power ups by shooting them out of the sky and killing bosses." ..
put " You also accumulate points for each enemy you shoot down, these " ..
put " points can be used to upgrade your cannon and to buy different projectiles." ..
put " After 3 levels of gameplay you will face a boss, which will be tougher than" ..
put "regular cyclops, but will give a higher point reward."
loop
buttonwait ("down", x, y, button, buttonupdown )
exit when x > 1 and x < 105 and y > 350 and y < 399
end loop
if x > 200 and x < 440 and y < 100 and y > 50 then
exit
end if
elsif x > 200 and x < 440 and y > 320 and y < 370 then
View.Update
cls
%Y co-ordinates for cyclops'
randint (yc1, 400, 600)
randint (yc2, 400, 610)
randint (yc3, 400, 450)
randint (yc4, 500, 600)
randint (yc5, 400, 550)
randint (yc6, 440, 610)
randint (yc7, 550, 610)
randint (yc8, 420, 610)
randint (yc9, 600, 700)
randint (yc10, 400, 440)
%X co-ordinates for cyclops'
randint (xc1, 40, 580)
randint (xc2, 40, 580)
randint (xc3, 40, 580)
randint (xc4, 40, 580)
randint (xc5, 40, 580)
randint (xc6, 40, 580)
randint (xc7, 40, 580)
randint (xc8, 40, 580)
randint (xc9, 40, 580)
randint (xc10, 40, 580)
randint (clr, 1, 255)
randint (clr1, 1, 255)
randint (clr2, 1, 255)
lives := 10
loop
loop
if yball > 400 and fired = true then
fired := false
yball := 0
xball := xcan
num := 0
end if
if fired = true and xball >= xc1 - 15 and xball <= xc1 + 15 and yball + 5 >= yc1 - 15 and yball + 5 <= yc1 + 15 and yball < 390 then
randint (xc1, 30, 580)
randint (yc1, 400, 600)
randint (clr, 1, 255)
randint (clr1, 1, 255)
randint (clr2, 1, 255)
fired := false
yball := 0
xball := xcan
num := 0
points := points + 10
elsif fired = true and xball - 5 >= xc1 - 15 and xball + 5 <= xc1 + 15 and yball < 390 then
randint (xc1, 30, 580)
randint (yc1, 400, 600)
randint (clr, 1, 255)
randint (clr1, 1, 255)
randint (clr2, 1, 255)
fired := false
yball := 0
xball := xcan
num := 0
points := points + 10
elsif fired = true and xball >= xc2 - 15 and xball <= xc2 + 15 and yball + 5 >= yc2 - 15 and yball + 5 <= yc2 + 15 and yball < 390 then
randint (xc1, 30, 580)
randint (yc1, 400, 600)
randint (clr, 1, 255)
randint (clr1, 1, 255)
randint (clr2, 1, 255)
fired := false
yball := 0
xball := xcan
num := 0
points := points + 10
elsif fired = true and xball - 5 >= xc2 - 15 and xball - 5 <= xc2 + 15 and yball < 390 then
randint (xc1, 30, 580)
randint (yc1, 400, 600)
randint (clr, 1, 255)
randint (clr1, 1, 255)
randint (clr2, 1, 255)
fired := false
yball := 0
xball := xcan
num := 0
points := points + 10
elsif fired = true and xball >= xc3 - 15 and xball <= xc3 + 15 and yball + 5 >= yc3 - 15 and yball + 5 <= yc3 + 15 and yball < 390 then
randint (xc1, 30, 580)
randint (yc1, 400, 600)
randint (clr, 1, 255)
randint (clr1, 1, 255)
randint (clr2, 1, 255)
points := points + 10
elsif fired = true and xball - 5 >= xc3 - 15 and xball - 5 <= xc3 + 15 and yball < 390 then
randint (xc1, 30, 580)
randint (yc1, 400, 600)
randint (clr, 1, 255)
randint (clr1, 1, 255)
randint (clr2, 1, 255)
fired := false
yball := 0
xball := xcan
num := 0
points := points + 10
end if
locate (1, 1)
color (12)
put "Points ", points
locate (18, 1)
color (12)
put "Lives: ", lives
drawfilloval (xball + 40, yball + 80, 5, 5, 12)
drawfillbox (xcan, 1, xcan + 60, 30, 8)
drawfillbox (xcan + 30, 30, xcan + 50, 80, 8)
drawfillarc (xcan + 40, 80, 10, 5, 180, 0, 255)
drawfilloval (xc1, yc1, 15, 15, clr )
drawfilloval (xc1, yc1 + 4, 3, 3, clr1 )
drawarc (xc1, yc1 - 3, 4, 3, 180, 0, clr2 )
drawfilloval (xc2, yc2, 15, 15, clr )
drawfilloval (xc2, yc2 + 4, 3, 3, clr1 )
drawarc (xc2, yc2 - 3, 4, 3, 180, 0, clr2 )
drawfilloval (xc3, yc3, 15, 15, clr )
drawfilloval (xc3, yc3 + 4, 3, 3, clr1 )
drawarc (xc3, yc3 - 3, 4, 3, 180, 0, clr2 )
delay (20)
View.Update
drawfilloval (xball + 40, yball + 80, 5, 5, 255)
drawfillbox (xcan, 1, xcan + 60, 30, 255)
drawfillbox (xcan + 30, 30, xcan + 50, 80, 255)
drawfillarc (xcan + 40, 80, 10, 5, 180, 0, 255)
drawfilloval (xc1, yc1, 15, 15, 255)
drawfilloval (xc1, yc1 + 2, 3, 3, 255)
drawarc (xc1, yc1 - 3, 4, 3, 180, 0, 255)
drawfilloval (xc2, yc2, 15, 15, 255)
drawfilloval (xc2, yc2 + 4, 3, 3, 255)
drawarc (xc2, yc2 - 3, 4, 3, 180, 0, 255)
drawfilloval (xc3, yc3, 15, 15, 255)
drawfilloval (xc3, yc3 + 4, 3, 3, 255)
drawarc (xc3, yc3 - 3, 4, 3, 180, 0, 255)
yc1 := yc1 - 1
yc2 := yc2 - 1
yc3 := yc3 - 1
yc4 := yc4 - 1
yc5 := yc5 - 1
yc6 := yc6 - 1
yc7 := yc7 - 1
yc8 := yc8 - 1
yc9 := yc9 - 1
yc10 := yc10 - 1
if hasch then
getch (key ) %get key pressed
num := ord (key )
elsif num = 203 and xcan <= 5 then
xcan := xcan + 0
elsif num = 203 then %left arrow
xcan := xcan - 10
elsif num = 205 and xcan >= 560 then
xcan := xcan + 0
elsif num = 205 then %right arrow
xcan := xcan + 10
elsif num = 32 then
fired := true
yball := yball + 10
num1 := 32
end if
if lives = 0 then
Font.Draw ("GAME OVER:underline,bold", 180, 200, font4, 9)
locate (12, 40)
put "High Score:", hiscore
exit
elsif yc1 < 0 and yc2 < 0 and yc3 < 0 then
randint (xc1, 10, 630)
randint (xc2, 10, 630)
randint (xc3, 10, 630)
randint (yc1, 400, 630)
randint (yc2, 400, 630)
randint (yc3, 400, 630)
randint (clr, 1, 255)
randint (clr1, 1, 255)
randint (clr2, 1, 255)
lives := lives - 1
elsif yc2 < 0 and yc1 < 0 then
randint (xc2, 10, 630)
randint (xc1, 10, 630)
randint (yc1, 400, 630)
randint (yc2, 400, 630)
randint (clr, 1, 255)
randint (clr1, 1, 255)
randint (clr2, 1, 255)
lives := lives - 1
elsif yc3 < 0 and yc2 < 0 then
randint (xc3, 10, 630)
randint (xc2, 10, 630)
randint (yc2, 400, 630)
randint (yc3, 400, 630)
randint (clr, 1, 254)
randint (clr1, 1, 254)
randint (clr2, 1, 254)
lives := lives - 1
elsif yc1 < 0 then
randint (xc1, 10, 630)
randint (yc1, 400, 630)
randint (clr, 1, 255)
randint (clr1, 1, 255)
randint (clr2, 1, 255)
lives := lives - 1
elsif yc2 < 0 then
randint (xc2, 10, 630)
randint (yc2, 400, 630)
randint (clr, 1, 255)
randint (clr1, 1, 255)
randint (clr2, 1, 255)
lives := lives - 1
elsif yc3 < 0 then
randint (xc3, 10, 630)
randint (yc3, 400, 630)
randint (clr, 1, 255)
randint (clr1, 1, 255)
randint (clr2, 1, 255)
lives := lives - 1
end if
if fired = false then
xball := xcan
yball := 0
end if
if fired = true then
yball := yball + 20
end if
end loop
if x >= 200 and x <= 440 and y >= 180 and y <= 230 then
end if
exit
end loop
end if
end loop
WinID := Window.GetActive
Window.Hide (WinID )
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
TokenHerbz
|
Posted: Sun Jun 20, 2010 3:31 pm Post subject: Re: Turing Space shooter game-hit detection and scoring problem |
|
|
go threw and add comments, I don't feel like reading every bit of code.
What you need to do is check your bullet + velocity of bullet to the target + targets velocity. You need to check the pathing from the jump, so your bullet doesn't jump over the target and miss the collision. |
|
|
|
|
|
A.J
|
Posted: Sun Jun 20, 2010 4:07 pm Post subject: RE:Turing Space shooter game-hit detection and scoring problem |
|
|
You forget to update your 'fired' variable after every if statement...look for where you are missing it. |
|
|
|
|
|
|
|