
-----------------------------------
Flikerator
Tue Mar 15, 2005 3:19 pm

Grid collision
-----------------------------------
Alright I was working on it before, but I droped it due to the competition. If anyone knows how to do grid collision could you help me out?

My game will have you charcter and he moves around. There is an invisible grid. When he is in a certain section then he is "in" that part of the grid. If and object is "in" a grid he is about to enter then he is stopped and cannot move there. This will help me because I can make "red" areas (places with buildings) in each area. If he is going to step into a red area, he won't be able to.

This will help make the program smoother with green areas (Creatures) that move around and change there grid. I know it can be down, I just don't know how to do it ;)

colourback (black)
cls
for x : 0 .. maxx by 10
    for y : 0 .. maxy by 10
        Draw.Dot (x, y, brightgreen)
    end for
end for

That is kinda what it looks like (You won't see it when you play though, so no whatdotcolour).

for x : 0 .. maxx by 10
    for y : 0 .. maxy by 10
        if Rand.Int (1, 100) = 1 then
            Draw.FillBox (x + 1, y + 1, x + 9, y + 9, red)
        end if
        Draw.Dot (x, y, black)
    end for
end for

And for an example of squares filled. Just cause im that bored ;)

If anyone wants to see the movement just say so and ill post it.

-----------------------------------
ssr
Tue Mar 15, 2005 6:38 pm


-----------------------------------
well I think u should post ur code...
anyway
I would make an array and record the position of the squares, and then if a dot is in that area, it will stop... 8)

-----------------------------------
ssr
Tue Mar 15, 2005 7:06 pm


-----------------------------------
View.Set ("offscreenonly")
var x, y := 315
var x1,y1:int
var speed := 1
var key : array char of boolean
var ra := 5
var rr := 100
x1:=Rand.Int(1,100) 
y1:=Rand.Int(1,100) 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
%drawfillbox (x1,y1,x1+rr,y1+rr,yellow)
    Input.KeyDown (key)
    if key (KEY_UP_ARROW)
            then
        y += speed
    end if
    if key (KEY_DOWN_ARROW)
            then
        y -= speed
    end if
    if key (KEY_LEFT_ARROW)
            then
        x -= speed
    end if
    if key (KEY_RIGHT_ARROW)
            then
        x += speed
    end if 
    if x + ra = x1 and y > y1 and y < y1 + rr then x-=speed
    end if
    if x - ra = (x1 + rr) and y > y1  and y < (y1 + rr) then x+=speed
    end if
    if y + ra = y1 and x > x1 and x < x1 + rr then y-=speed
    end if
    if y - ra = y1 +rr and x > x1 and x < x1 +rr then y+=speed
    end if
    drawfilloval (x, y, ra, ra, brightred)
    View.Update
    cls
end loop
hopefully this is what u r looking for
just one square, but u can increase the # of squares, and restrictions
u can see the square if u delte teh "%" in the code
 8)

-----------------------------------
Cervantes
Wed Mar 16, 2005 7:50 am


-----------------------------------
ssr: You can go inside the yellow box if you approach it from one of it's corners.
And, that's not what he's looking for.  He's looking to do [url=http://freespace.virgin.net/hugo.elias/models/m_colide.htm]this.
Flikerator: First, try to decide which way you're going to store the block's information.  Do you have a finite number of things that can be in any one grid, or do you not know how many could be in any one grid square?  
Actually, on that note: how does one make a linked list?

-----------------------------------
Flikerator
Wed Mar 16, 2005 11:41 am


-----------------------------------
View.Set ("offscreenonly")
var x, y := 315
var x1,y1:int
var speed := 1
var key : array char of boolean
var ra := 5
var rr := 100
x1:=Rand.Int(1,100) 
y1:=Rand.Int(1,100) 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
%drawfillbox (x1,y1,x1+rr,y1+rr,yellow)
    Input.KeyDown (key)
    if key (KEY_UP_ARROW)
            then
        y += speed
    end if
    if key (KEY_DOWN_ARROW)
            then
        y -= speed
    end if
    if key (KEY_LEFT_ARROW)
            then
        x -= speed
    end if
    if key (KEY_RIGHT_ARROW)
            then
        x += speed
    end if 
    if x + ra = x1 and y > y1 and y < y1 + rr then x-=speed
    end if
    if x - ra = (x1 + rr) and y > y1  and y < (y1 + rr) then x+=speed
    end if
    if y + ra = y1 and x > x1 and x < x1 + rr then y-=speed
    end if
    if y - ra = y1 +rr and x > x1 and x < x1 +rr then y+=speed
    end if
    drawfilloval (x, y, ra, ra, brightred)
    View.Update
    cls
end loop
hopefully this is what u r looking for
just one square, but u can increase the # of squares, and restrictions
u can see the square if u delte teh "%" in the code
 8)

Thats not what I was looking for, but thanks anyway ^^;

ssr: You can go inside the yellow box if you approach it from one of it's corners. 
And, that's not what he's looking for. He's looking to do this. 
Flikerator: First, try to decide which way you're going to store the block's information. Do you have a finite number of things that can be in any one grid, or do you not know how many could be in any one grid square? 
Actually, on that note: how does one make a linked list?

I guess I could do each block has a space of 100. If a certain colour is there it adds a certain amount to the block. If it is 101 or greater then it cannot be done]
View.Set ("offscreenonly,position:center;center,graphics:667,467")
colourback (black)
cls
proc back
    cls
    for x : 3 .. maxx by 10
        for y : 3 .. maxy by 10
            Draw.Dot (x, y, brightgreen)
        end for
    end for
end back

var x, y : int := 13
var speed := 5
Draw.FillBox (x, y, x + 15, y + 15, green)

var ch : array char of boolean

loop
    Input.KeyDown (ch)
    if ch ('s') and y - speed - 1 > 0 or ch (KEY_DOWN_ARROW) and y - speed - 1 > 0 then
        y := y - speed
    end if
    if ch ('w') and y + speed + 17 < maxy or ch (KEY_UP_ARROW) and y + speed + 17 < maxy then
        y := y + speed
    end if
    if ch ('a') or ch (KEY_LEFT_ARROW) then
        x := x - speed
    end if
    if ch ('d') or ch (KEY_RIGHT_ARROW) then
        x := x + speed
    end if
    Draw.FillBox (x, y, x + 15, y + 15, green)
    View.Update
    back
    delay (2)
end loop


-----------------------------------
ssr
Wed Mar 16, 2005 1:50 pm


-----------------------------------
lololol
 :roll:  :roll: 
ok then
anyway ya I know that u can go in,is there any way to pervent it?
I mean it happens in whatdotcolor, I know y, but dont want to calculate the distance adn all that, ok now, 
is there another way to make collusion detection
 :D

-----------------------------------
Flikerator
Wed Mar 16, 2005 2:16 pm


-----------------------------------
lololol
 :roll:  :roll: 
ok then
anyway ya I know that u can go in,is there any way to pervent it?
I mean it happens in whatdotcolor, I know y, but dont want to calculate the distance adn all that, ok now, 
is there another way to make collusion detection
 :D
Read collision detection in tutorials  :roll:

-----------------------------------
Cervantes
Wed Mar 16, 2005 6:54 pm


-----------------------------------
Flikerator: You're missing one part of the grid collision idea.  If two circles are determined to both be at least partially in the same grid square, they MIGHT be touching.  Or they might not.  If, in fact, the two circles are both determined to be in the same square (partially, at least), then use whatever method of collision detection to determine if they have collided.  If you're using circles (or somehing closely resembling a circle) use the distance formula and the sum of the two radii.  
The whole point of this is to save the processor from doing thousands of distance formulas, or worse if you were using, say, irregular 3D entities.  
As for linked lists, I can only guess that it's a bunch of information linked together in a linear fashion (using pointers?).  But that's just a guess.  Silly me, I can't help but think of it as a chain.  Or, if we add another dimension, it becomes chain mail armour!
Aah, someone save me!

-----------------------------------
Flikerator
Wed Mar 16, 2005 7:36 pm


-----------------------------------
But you still havn't showed me how to do it in Turing ><
