Dont know how to do collission with pictures
Author |
Message |
caldrium
|
Posted: Tue Jan 24, 2006 12:37 pm Post subject: Dont know how to do collission with pictures |
|
|
well i looked at just about all of the collission things, in the collission detection post, i changed all the variables according to what i used, but it still didnt work. If anyone can fill in the spot with code,or tell how to do it, that would be sick. I have turing 4.0.2 if that makes any difference, and this is the last thing i need for my program. Thanks in advance for your help.
P.S. Download the game if you want it to run cause of graphics, or you can just look at my code
P.P.S The spot where im putting the collission is the last for (empty right now) at the bottom.
code: |
var fish, sharkout, level, fishdirection, sprint, score : int
var distance:real
var buttons : array char of boolean
var maxX, maxY : int := 200
var sharkx : array 1 .. 1000 of int
var sharky : array 1 .. 1000 of int
var s : int := 50
level := 1
score := 0
fishdirection := 0
sprint := 500
sharkout := 2
for xx : 1 .. 1000
sharkx (xx) := maxx
end for
for xx : 1 .. 1000
sharky (xx) := 500
end for
setscreen ("offscreenonly")
var sharkPic := Pic.FileNew ("shark.jpg")
var fishPic := Pic.FileNew ("fish.jpg")
var fishPic2 := Pic.FileNew ("fish2.jpg")
Pic.Draw (fishPic, maxX, maxY, picMerge)
proc fishSpawn
randint (fish, (level * 2), 100)
if (fish = 100) then
sharkout := sharkout + 1
for xx : sharkout .. sharkout
randint (sharky (xx), 1, maxy)
Pic.Draw (sharkPic, sharkx (xx), sharky (xx), picMerge)
end for
end if
end fishSpawn
proc scoreBoard
score := score + 10
delay (0)
locate (1, 1)
if score >= 10000 then
score := 0
level := level + 1
end if
put "LEVEL ", level, " " : 23, "SWIM POWER: ", sprint, " " : 13, "NEXT LEVEL(10k): ", score
end scoreBoard
loop
fishSpawn
scoreBoard
Input.KeyDown (buttons)
drawline (550, 0, 550, maxy, 2)
%fishMove
% Draw.FillOval (maxX, maxY, 20, 20, 5)
for xx : 1 .. sharkout
sharkx (xx) := sharkx (xx) - 3
Pic.Draw (sharkPic, sharkx (xx), sharky (xx), picMerge)
end for
if fishdirection = 0 then
Pic.Draw (fishPic, maxX, maxY, picMerge)
else
Pic.Draw (fishPic2, maxX, maxY, picMerge)
end if
View.Update
%FISH MOVEMENT RESTRICTIONS
if (maxX <= -20) then %if you go to far left
maxX := -20 %restrict you from moving further
elsif (maxX >= 440) then %if you try to pass the line
maxX := 440 %restrict you from moving further
end if
if (maxY <= -20) then %if you go to far down
maxY := -20 %restrict you from moving further
elsif (maxY >= 350) then %if you go to far up
maxY := 350 %restrict you from moving further
end if
%FISH MOVEMENT
%NORMAL MOVEMENT
if buttons (KEY_UP_ARROW) then %if the up arrow is pressed
maxY := maxY + 6 %move up
elsif buttons (KEY_DOWN_ARROW) then %if the down arrow is pressed
maxY := maxY - 6 %move down
elsif buttons (KEY_LEFT_ARROW) then %if the left arrow is pressed
maxX := maxX - 6 %move left
fishdirection := 0 %face fish left
elsif buttons (KEY_RIGHT_ARROW) then %if the right arrow is pressed
maxX := maxX + 6 %move right
fishdirection := 1 %face fish right
end if
%SWIM POWER USAGE
if buttons (KEY_SHIFT) and sprint not= 0 then %if they hold shift down
sprint := sprint - 1 %lower their Swim Power
delay (0)
end if
%SWIM POWER MOVEMENT
if buttons (KEY_UP_ARROW) and buttons (KEY_SHIFT) and sprint not= 0 then %if the up arrow +shift key is pressed
maxY := maxY + 9 %move up fast
elsif buttons (KEY_DOWN_ARROW) and buttons (KEY_SHIFT) and sprint not= 0 then %if the down arrow +shift key is pressed
maxY := maxY - 9 %move down fast
elsif buttons (KEY_LEFT_ARROW) and buttons (KEY_SHIFT) and sprint not= 0 then %if the left arrow +shift keyis pressed
maxX := maxX - 9 %move left fast
fishdirection := 0 % face fish left
elsif buttons (KEY_RIGHT_ARROW) and buttons (KEY_SHIFT) and sprint not= 0 then %if the right arrow +shift keyis pressed
maxX := maxX + 9 %move right fast
fishdirection := 1 %face fish right
end if
for xx : 1 .. sharkout %POST COLLISSION HERE
end for
colorback (11) %backround colour
delay (30)
cls
end loop
|
Description: |
|
Download |
Filename: |
FISH GAME.zip |
Filesize: |
9.58 KB |
Downloaded: |
63 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
caldrium
|
Posted: Tue Jan 24, 2006 1:14 pm Post subject: (No subject) |
|
|
i dont think the attachment thing worked. sorry for the 2x post
Description: |
|
Download |
Filename: |
FISH GAME.zip |
Filesize: |
9.58 KB |
Downloaded: |
68 Time(s) |
|
|
|
|
|
|
Albrecd
|
Posted: Tue Jan 24, 2006 2:19 pm Post subject: (No subject) |
|
|
Okay, in order to detect colision:
code: | %For our purposes here, X1 and Y1 will be the coordinates of
%one picture: Pic1, and X2 and Y2 will be the coordinates of the other: Pic2.
if X1 >= X2 and X1 <= X2 + Pic.Width (Pic2) and Y1 >= Y2 and Y1 <= Y2 + Pic.Height (Pic2) then
%whatever you want it to do...
end if |
|
|
|
|
|
|
caldrium
|
Posted: Tue Jan 24, 2006 5:08 pm Post subject: (No subject) |
|
|
hmmn.. it still didnt work :S
i copy+pasted ur thing and plugged in my thing but it still didnt work
btw my
x1 :=maxX
x2:=sharkx(xx) (its in an array, btw i have the if in a for statement)
y1:= maxY
y2:= sharky(xx)
the program still runs so its no variable name error, but when i move right up to them nothing happens
|
|
|
|
|
|
caldrium
|
Posted: Tue Jan 24, 2006 8:23 pm Post subject: (No subject) |
|
|
BUMP :S
|
|
|
|
|
|
MysticVegeta
|
Posted: Wed Jan 25, 2006 6:12 pm Post subject: (No subject) |
|
|
No need to bump after 3 hours.
Anyways, You can always use the distance formula to find distance better 2 co-ordinates in a cartesian plane. Just imagine that the turing output window is the cartesian plane.
code: |
Distance = sqrt ((y2-y1)^2 + (x2-x1)^2) |
|
|
|
|
|
|
caldrium
|
Posted: Wed Jan 25, 2006 7:07 pm Post subject: (No subject) |
|
|
ok cool, so when the collission happens
what would i make distances =?
like if distance = 0
collission :=true (?)
or what would i do
|
|
|
|
|
|
caldrium
|
Posted: Wed Jan 25, 2006 8:37 pm Post subject: (No subject) |
|
|
OH nevermind, i found out my problem
the colission wasnt a proper spot, making it not work. thanks for the help
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|