How sense the object ?
Author |
Message |
AntoxicatedDevil78
|
Posted: Thu Nov 29, 2012 11:09 am Post subject: How sense the object ? |
|
|
What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
I am trying to create a game that senses when an object flies by.
What is the problem you are having?
<Answer Here>
I can't fine a command that would sense the colour/ object?
Describe what you have tried to solve this problem
<Answer Here>
Searched around, went into turings help reference, didn't understand it.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
drawbox (120,120,maxx-120,maxy-120, 1)
var x,y :int
x:= maxx div 2
y:= maxy div 2
loop
drawfilloval (x,y ,12,12,110)
drawfilloval (x,y,12,12,0)
x := x +1
end loop
Turing: |
<Add your code here>
|
Please specify what version of Turing you are using
<Answer Here>
4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Panphobia
|
Posted: Thu Nov 29, 2012 2:25 pm Post subject: RE:How sense the object ? |
|
|
Just check the surrounding block for changes in colour. |
|
|
|
|
|
Tony
|
Posted: Thu Nov 29, 2012 3:17 pm Post subject: RE:How sense the object ? |
|
|
Math.Distance
Of course this will only give you the distance between 2 points, so you might have to figure out checking of what points will be enough to give you a good answer. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Panphobia
|
Posted: Thu Nov 29, 2012 7:15 pm Post subject: RE:How sense the object ? |
|
|
Yes as Tony said you could do that or just do something like var distance: int
distance := (x+x1)^2-(y+y1)^2
and whenever this point is moving and the closer it gets or when it passes over you do a certain thing, I think this is what Tony was trying to show you with Math.Distance |
|
|
|
|
|
AntoxicatedDevil78
|
Posted: Fri Nov 30, 2012 9:59 am Post subject: Re: How sense the object ? |
|
|
That helped, but I need it to move in every direction now.
drawbox (120, 120, maxx - 120, maxy - 120, 1)
var x, y : int
x := maxx div 2
y := maxy div 2
loop
drawfilloval (x, y, 12, 12, 110)
delay (10)
drawfilloval (x, y, 12, 12, 0)
x := x + 1
y := y + 1
if x >= (maxx - 135) then
loop
x := x - 1
y := y + 1
drawfilloval (x, y, 12, 12, 110)
delay (10)
drawfilloval (x, y, 12, 12, 0)
if y >= (maxy - 135) then
loop
y := y - 1
x := x - 1
drawfilloval (x, y, 12, 12, 110)
delay (10)
drawfilloval (x, y, 12, 12, 0)
exit when y <= 135
exit when x <= 135
end loop
end if
exit when x <= 135
end loop
end if
if y >= (maxy - 135) then
loop
y := y - 1
x := x + 1
drawfilloval (x, y, 12, 12, 110)
delay (10)
drawfilloval (x, y, 12, 12, 0)
exit when y <= 135
if x <= (maxx - 135)then
loop
x := x - 1
y := y - 1
exit when y <= 135
exit when x <= 135
end loop
end if
end loop
end if
end loop
Quote: |
|
|
|
|
|
Panphobia
|
Posted: Fri Nov 30, 2012 10:36 am Post subject: RE:How sense the object ? |
|
|
what exactly is the purpose of your program? |
|
|
|
|
|
AntoxicatedDevil78
|
Posted: Sat Dec 01, 2012 2:52 pm Post subject: Re: How sense the object ? |
|
|
I'm trying to make the ball bounce, then make it bounce within the rectangle, then have it dodge an object in the rectangle |
|
|
|
|
|
Panphobia
|
Posted: Sat Dec 01, 2012 4:41 pm Post subject: Re: How sense the object ? |
|
|
Ok so get the x,y coords for all 4 points and do something like this, code: | if ballY >= yHighRect then
ballY-=1
if ballY <= yLowRect then
ballY+=1
if ballX >= xRightRect then
ballX-=1
if ballX <= xLeftRect then
ballX +=1
| you could tweak this pseudocode to make it bounce all around, but that is the general way i was taught in grade 11, of course this is all in a loop, so it will keep going, that is for the bouncing, however, you could use this also to make it dodge it, you could make another if to see if they are occupying the same space, and then move the ball xy in a different direction |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|