Posted: 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
Tony
Posted: Fri Sep 05, 2008 11:11 am Post subject: RE:Wall Help
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: 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
Posted: 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
Posted: 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
Posted: Mon Sep 08, 2008 11:07 am Post subject: RE:Wall Help
If you used a tile system yes
S_Grimm
Posted: 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
Warchamp7
Posted: 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
Creating collisions with the white areas
Insectoid
Posted: 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
Posted: 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
Posted: 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
Posted: 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 :arraycharofboolean var movement :int:=1 procedure bound
if x1 +20=50and y2 -20 <= 200and y2 >= 50then%account for the box's size, offset the variable by size of the box
x1 := x1 - movement
x2 := x2 - movement
endif
if x1 =150and y1 <= 200and y1 >= 50then
x1 := x1 + movement
x2 := x2 + movement
endif end bound