Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Grid collision
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Flikerator




PostPosted: Tue Mar 15, 2005 3:19 pm   Post subject: 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 Wink

code:
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).

code:
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 Wink

If anyone wants to see the movement just say so and ill post it.
Sponsor
Sponsor
Sponsor
sponsor
ssr




PostPosted: Tue Mar 15, 2005 6:38 pm   Post subject: (No subject)

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




PostPosted: Tue Mar 15, 2005 7:06 pm   Post subject: (No subject)

code:
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




PostPosted: Wed Mar 16, 2005 7:50 am   Post subject: (No subject)

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?
Flikerator




PostPosted: Wed Mar 16, 2005 11:41 am   Post subject: (No subject)

ssr wrote:
code:
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 ^^;

Quote:
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][Movement stopped. But really everything will either take up 100 or 0. Fire will take up 0 but will cause damage if you step on it. I have other ideas for fire too but that will wait..

In each square (or block) 100 units can fit in it. If its over 100 then it cannot go there. Im not sure how I would do that, ill read that link and edit this post..

What do you mean by a linked list? string+string?

EDIT;

I read that. You sent me there last time lolz. How would I do that in Turing though? Make the invisible grid and if you are in it then the unit of that grid goes up 100 (thats your unit size) if something else is there then you cannot go there. Here is a prog, all you need to do is make the grid invisible and have a value of each block Wink

code:

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




PostPosted: Wed Mar 16, 2005 1:50 pm   Post subject: (No subject)

lololol
Rolling Eyes Rolling Eyes
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
Very Happy
Flikerator




PostPosted: Wed Mar 16, 2005 2:16 pm   Post subject: (No subject)

ssr wrote:
lololol
Rolling Eyes Rolling Eyes
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
Very Happy

Read collision detection in tutorials Rolling Eyes
Cervantes




PostPosted: Wed Mar 16, 2005 6:54 pm   Post subject: (No subject)

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!
Sponsor
Sponsor
Sponsor
sponsor
Flikerator




PostPosted: Wed Mar 16, 2005 7:36 pm   Post subject: (No subject)

But you still havn't showed me how to do it in Turing ><
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: