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

Username:   Password: 
 RegisterRegister   
 Tiles + Collision need help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Rewrite




PostPosted: Sat Jan 22, 2005 11:48 pm   Post subject: Tiles + Collision need help

Hey short time reader, first time poster to these forums. I've recently picked up on turing and am currently compiling a game of my own. But being a newbie I've run into some problems that I was hoping some of the pros of this forum could help me out with.
Like many NES games before I was hoping to create my game using the tile system. So far I've been successful in creating a program that takes in a txt file and converts it into tiles, and than a character that moves around on that screen and scales the map. Although my problem lies in the fact that I cannot figure out how collision would work, so if someone could provide some insite onto the subject I would greatly appreciate it Very Happy

Here is what I have worked on as of now. (heres to hoping the code html works)

code:


setscreen ("graphics:500;400,offscreenonly")
View.Set ("noecho")

var playerx : int := maxx div 2
var playery : int := maxy div 2

var changex : int := 0
var changey : int := 0

var maptownstartx : int := 0
var maptownstarty : int := 0

var tilenumber : int := 30
var stream : int
var size : int := 36

open : stream, "003.map", get

var pictures : array 1 .. size, 1 .. size of int

var pic1 : int := Pic.FileNew ("001.bmp")
var pic2 : int := Pic.FileNew ("002.bmp")
var pic3 : int := Pic.FileNew ("003.bmp")
var pic4 : int := Pic.FileNew ("004.bmp")
var pic5 : int := Pic.FileNew ("005.bmp")
var pic6 : int := Pic.FileNew ("006.bmp")
var pic7 : int := Pic.FileNew ("007.bmp")
var pic8 : int := Pic.FileNew ("008.bmp")
var pic9 : int := Pic.FileNew ("009.bmp")
var pic10 : int := Pic.FileNew ("010.bmp")

var playerdown1 : int := Pic.FileNew ("walkdown1.bmp")
var playerdown2 : int := Pic.FileNew ("walkdown2.bmp")
var playerup1 : int := Pic.FileNew ("walkup1.bmp")
var playerup2 : int := Pic.FileNew ("walkup2.bmp")
var playerright1 : int := Pic.FileNew ("walkright1.bmp")
var playerright2 : int := Pic.FileNew ("walkright2.bmp")
var playerleft1 : int := Pic.FileNew ("walkleft1.bmp")
var playerleft2 : int := Pic.FileNew ("walkleft2.bmp")

for i : 1 .. size
    get : stream, skip
    exit when eof (stream)
    for j : 1 .. size
        get : stream, pictures (i, j)
    end for
end for

close : stream

procedure maptown
for i : 1 .. size
    for j : 1 .. size
        if pictures (i, j) = 001 then
            Pic.Draw (pic1, Pic.Width (pic1) * (j - 1 + changex), maxx - Pic.Height (pic1) * (i + 3 + changey), picCopy)
        elsif pictures (i, j) = 002 then
            Pic.Draw (pic2, Pic.Width (pic2) * (j - 1 + changex), maxx - Pic.Height (pic2) * (i + 3 + changey), picCopy)
        elsif pictures (i, j) = 003 then
            Pic.Draw (pic3, Pic.Width (pic3) * (j - 1 + changex), maxx - Pic.Height (pic3) * (i + 3 + changey), picCopy)
        elsif pictures (i, j) = 004 then
            Pic.Draw (pic4, Pic.Width (pic4) * (j - 1 + changex), maxx - Pic.Height (pic4) * (i + 3 + changey), picCopy)
        elsif pictures (i, j) = 005 then
            Pic.Draw (pic5, Pic.Width (pic5) * (j - 1 + changex), maxx - Pic.Height (pic5) * (i + 3 + changey), picCopy)
        elsif pictures (i, j) = 006 then
            Pic.Draw (pic6, Pic.Width (pic6) * (j - 1 + changex), maxx - Pic.Height (pic6) * (i + 3 + changey), picCopy)
        elsif pictures (i, j) = 007 then
            Pic.Draw (pic7, Pic.Width (pic7) * (j - 1 + changex), maxx - Pic.Height (pic7) * (i + 3 + changey), picCopy)
        elsif pictures (i, j) = 008 then
            Pic.Draw (pic8, Pic.Width (pic8) * (j - 1 + changex), maxx - Pic.Height (pic8) * (i + 3 + changey), picCopy)
        elsif pictures (i, j) = 009 then
            Pic.Draw (pic9, Pic.Width (pic9) * (j - 1 + changex), maxx - Pic.Height (pic9) * (i + 3 + changey), picCopy)
        elsif pictures (i, j) = 010 then
            Pic.Draw (pic10, Pic.Width (pic10) * (j - 1 + changex), maxx - Pic.Height (pic10) * (i + 3 + changey), picCopy)
       
        end if
    end for
end for
end maptown

procedure walk (down1, down2, funx, funy : int)

    Draw.Cls
    Time.Delay (150)
    maptown
    Pic.Draw (down2, funx, funy, picMerge)
    View.Update
    Draw.Cls

    Time.Delay (150)
    maptown %
    Pic.Draw (down1, funx, funy, picMerge)
    View.Update

end walk

procedure playgame

    var chars : array char of boolean

    loop

        Input.KeyDown (chars)
       
if chars (KEY_UP_ARROW) then
 changey += 1
 walk (playerup1, playerup2, playerx, playery)
   
elsif chars (KEY_RIGHT_ARROW) then
changex -= 1
walk (playerright1, playerright2, playerx, playery)
       
elsif chars (KEY_LEFT_ARROW) then
            changex += 1
            walk (playerleft1, playerleft2, playerx, playery)


        elsif chars (KEY_DOWN_ARROW) then
            changey -= 1
            walk (playerdown1, playerdown2, playerx, playery)

        end if 

    end loop
end playgame

playgame

Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun Jan 23, 2005 12:11 am   Post subject: (No subject)

it is quite simple.

you just have to validate move procedures. Let me explain:

first you move your character vertually. Such as calcualte the new position your character will move to and save that to a temp variable. You then check the tile type that is in that location. If it's something you don't want your character to walk on (water, wall, etc), your validation returns false and you don't move the character.
Rewrite




PostPosted: Sun Jan 23, 2005 4:59 pm   Post subject: (No subject)

Thanks, I can understand the whole theory behind tiles and why it works. But what I'm having trouble with is Pic.Draw files colliding with other Pic.Draw files. I've seen plently of tutorials on Draw.Boxs or whatever colliding with each other, but not Pic.Draws and bmps hitting each other, and I don't know about this 'whatdotcolor' system, but I doubt it would work properly for multicolor tiles (if stone steps and stonewalls of a bmp are the same grey how does turing know how to collid with the stonegrey wall and not the stonegrey ground?)
TheXploder




PostPosted: Sun Jan 23, 2005 5:16 pm   Post subject: (No subject)

Whatdot colour will not work for sure. Now the concept with tiles is to make a 2d array and for each 0 in the 2d array place a grass tile lets say and for a 1 a wall. So the spacing of the tiles doesn't matter, what matters is where the object is located on the map.

2 is the players location..

1111
1201
1001
1001
1111

so then to make a check...

code:

if key (right) and map (playerx + 1, playery) = 0 then
      //move right
end if
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  [ 4 Posts ]
Jump to:   


Style:  
Search: