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

Username:   Password: 
 RegisterRegister   
 Wall Help
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Boiq




PostPosted: Fri Sep 05, 2008 10:45 am   Post subject: Wall Help

Okay, i'm currently working on a game programmed by Turing.

I recently added some basic graphic walls using 'drawfillbox'. I have an animated object that is being controll, so how would I make it so when it runs into the wall it stops rather then going through it.

All help would be appreciated to guide me onto the right path, thanks.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Sep 05, 2008 11:11 am   Post subject: RE:Wall Help

Figure out where the wall is.

On paper. With math.

You already have the numbers -- you are using them to draw the wall in the first place. Although it might be easier to exploit arrays (think tiles) and write a general solution once than having to hard-code every block location (that gets messy).

Posted Image, might have been reduced in size. Click Image to view fullscreen.
(not really a wall, but it's semi-relevant)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Insectoid




PostPosted: Fri Sep 05, 2008 12:46 pm   Post subject: RE:Wall Help

Sorry, tony, I know you love paper and math, but I can't help but give a link of my own.

Tutorial!
S_Grimm




PostPosted: Mon Sep 08, 2008 10:36 am   Post subject: RE:Wall Help

if y location of box is greater than y location of top wall, then y := y -1
Warchamp7




PostPosted: Mon Sep 08, 2008 11:02 am   Post subject: Re: RE:Wall Help

A\V @ Mon Sep 08, 2008 10:36 am wrote:
if y location of box is greater than y location of top wall, then y := y -1


1. He's talking about blocks not a roof

2. That wouldn't work if he moves more than 1 pixel every loop which is likely unless that loop is 1


Collisions in turing are not a simple task if you're still getting your bearings. You'll need to have collision checks between the object you control and anything that can restrict it's movement. Now if you only had two objects it's not too difficult but with more it becomes a little more daunting.

Unless you know how to use arrays effectively it won't be fun tracking multiple collisions : /
Boiq




PostPosted: Mon Sep 08, 2008 11:06 am   Post subject: RE:Wall Help

Okay, i'm starting to understand a bit.

And yes i'm talking about a collosion with the walls. Isn't it kinda binary, like 0's for path, 1's for walls, 2 for your character, etc?
Warchamp7




PostPosted: Mon Sep 08, 2008 11:07 am   Post subject: RE:Wall Help

If you used a tile system yes
S_Grimm




PostPosted: Mon Sep 08, 2008 11:43 am   Post subject: Re: Wall Help

This is whant you want to do right?
sorry asbout the rough code. I need to fix the top and right boundries


code:

var x, y : int := 30 %starting position of box
var x1, y1 : int := 40
var move := 5 %change this variable to change movement
var key : array char of boolean
procedure bound
    if (x >= 300) then
        x := x - move
        x1 := x1 - move
    end if
    if x <= 20 then
        x := x + move
        x1 := x1 + move
    end if
    if (y >= 300) then
        y := y - move
        y1 := y1 - move
    end if
    if y <= 20 then
        y := y + move
        y1 := y1 + move
    end if
end bound
procedure movement
    Input.KeyDown (key)
    if key (KEY_UP_ARROW) then
        y := y + move
        y1 := y1 + move
    end if
    if key (KEY_RIGHT_ARROW) then
        x := x + move
        x1 := x1 + move
    end if
    if key (KEY_LEFT_ARROW) then
        x := x - move
        x1 := x1 - move
    end if
    if key (KEY_DOWN_ARROW) then
        y := y - move
        y1 := y1 - move
    end if
end movement

View.Set ("offscreenonly")
loop
Draw.FillBox (20, 20, 300, 300, black)
    Draw.FillBox (x, y, x1, y1, red)
    bound
    movement   
    View.Update
end loop
Sponsor
Sponsor
Sponsor
sponsor
Warchamp7




PostPosted: Mon Sep 08, 2008 11:57 am   Post subject: RE:Wall Help

If he's doing a top down then that seems right, though once again you're just doing outer boundaries.

I think he's looking for collisions with a block.

So for example using your rough code
Posted Image, might have been reduced in size. Click Image to view fullscreen.

Creating collisions with the white areas
Insectoid




PostPosted: Mon Sep 08, 2008 3:34 pm   Post subject: RE:Wall Help

Outer boundaries? That's what you wanted? That's easy.

In pseudocode,

if the right button is pressed and the X value is less then maxx, incease X by 1.
S_Grimm




PostPosted: Tue Sep 09, 2008 6:41 pm   Post subject: RE:Wall Help

ok so you want the code to look like :
if x location of figure = right edge of box, then x := x - movement pixels
end if
for a specific size of box where you need to go over it also:
if x location of figure is = right edge of box and y location of figure is >= bottom of box and y location <= top of box then
x := x - movement pixels
end if
Warchamp7




PostPosted: Wed Sep 10, 2008 7:43 am   Post subject: Re: RE:Wall Help

A\V @ Tue Sep 09, 2008 6:41 pm wrote:
ok so you want the code to look like :
if x location of figure = right edge of box, then x := x - movement pixels
end if
for a specific size of box where you need to go over it also:
if x location of figure is = right edge of box and y location of figure is >= bottom of box and y location <= top of box then
x := x - movement pixels

end if


If I read that right, you just made the character only move if it's INSIDE the box touching the right side of it.
S_Grimm




PostPosted: Wed Sep 10, 2008 9:37 am   Post subject: Re: Wall Help

Warchamp, Here is an example of the conde. you cannot move the red box through the side of the white box. (you can still move through the top and bottom though. i wrote this really fast.

Turing:

setscreen ("offscreenonly")
var x1, y1 : int := 300
var x2, y2 : int := 320
var key : array char of boolean
var movement : int := 1
procedure bound
if x1 +20 = 50 and y2 -20 <= 200 and y2 >= 50 then %account for the box's size, offset the variable by size of the box
x1 := x1 - movement
x2 := x2 - movement
end if
if x1 = 150 and y1 <= 200 and y1 >= 50 then
x1 := x1 + movement
x2 := x2 + movement
end if
end bound

loop
View.Update
Draw.FillBox (0, 0, maxx, maxy, black)
Draw.FillBox (50, 50, 150, 200, white)
Draw.FillBox (x1,y1,x2,y2, red)
    Input.KeyDown (key)
    if key (KEY_UP_ARROW) then
        y1 := y1 + movement
        y2 := y2 + movement
    end if
    if key (KEY_RIGHT_ARROW) then
        x1 := x1 + movement
        x2 := x2 + movement
    end if
    if key (KEY_LEFT_ARROW) then
        x1 := x1 - movement
        x2 := x2 - movement
    end if
    if key (KEY_DOWN_ARROW) then
        y1 := y1 - movement
        y2 := y2 - movement
    end if
bound
end loop
Warchamp7




PostPosted: Wed Sep 10, 2008 11:38 am   Post subject: Re: Wall Help

Quote:
if x location of figure is = right edge of box and y location of figure is >= bottom of box and y location <= top of box then
x := x - movement pixels


code:
if x1 + 20 = 50 and y2 -20 <= 200 and y2 >= 50 then


As I pretty much said, this only works if he is perfectly at 50.

What happens if the speed is 4? It's good to make an area to check for collisions. A literal hitbox.

Posted Image, might have been reduced in size. Click Image to view fullscreen.
isaiahk9




PostPosted: Thu Sep 11, 2008 12:00 pm   Post subject: RE:Wall Help

One of the easiest ways I've found is just like this :

if the user clicks "move right" and characterx < x coordinate of the right side of the wall and character x > x coordinate of the left side then

the character can move any direction

else

the character can only move left.

Kind of confusing the way I wrote it, but basically your character cannot go in the area that is designated wall.
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 2  [ 26 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: