Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
map 2 map
#1
Whats the easiest way to get from one map to another...like through a door or something. Do i have to hardcode it like

Code:
if (playerx,playery)=whatever AND map%=45 then
       playerx=2  
       playery=34
       map%=46
end if

for every door? Or is there an easier way to do.
Reply
#2
I hope you're using bitmaps...

Let's say this is your map (21x15):
Code:
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1
1,2,1,1,1,1,1,1,1,1,1,1,1,1,3,3,1,2,2,2,1
1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,1
1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,1
1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,1
1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,3,2,2,2,1
1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,1
1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,1
1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,1
1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,1
1,2,1,1,1,1,3,3,1,1,1,1,1,1,1,1,1,1,1,3,1
1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1 = Wall
2 = Floor
3 = Door


And this is your array:

[syntax="qbasic"]dim shared Map(1 to 21, 1 to 15)[/syntax]
Then you'll READ it to the Map-array like this:

[syntax="qbasic"]
for y = 1 to 21
for x = 1 to 15
read Map(x, y)
next x
next y
[/syntax]

Later place this in your code:

[syntax="qbasic"]
for y = 1 to 21
for x = 1 to 15
if Map(x, y) = 1 then put(x*15, y*13), WallTile, pset
if Map(x, y) = 2 then put(x*15,y*13), FloorTile, pset
if Map(x, y) = 3 then put(x*15,y*13), DoorTile, pset
next x
next y
[/syntax]

Replace the spritenames by your own sprites, and multiply x and y by their sizes (as you can see: mine are 15x13)

To move (pseudo code):
Code:
If inkey = up AND Up <> 1 then PlayerMove = up
'and so on :)

Hope it's clear Smile
Reply
#3
HQSneaker, that was not what this guy was asking Tongue you put a lot of effort on the post, though.

This guy has several maps that are interconnected and he's asking for a way to save lines when doing the checks to change maps.

I would use a data type to make the checks automatic. You can do it in 100 ways, I can suggest you this one which is the first one that has came to mind.

First you define a type:

Code:
TYPE DoorType
   map1 AS INTEGER
   x1 AS INTEGER
   y1 AS INTEGER
   map2 AS INTEGER
   x2 AS INTEGER
   y2 AS INTEGER
END TYPE

CONST NumOfDoors = 100
DIM Doors(NumOfDoors) AS DoorType

This way, if you have a door at map 45, location (10, 4) that connects with map 46, location (2,34) you just have an array member with these values:

Code:
Doors(i%).map1 = 45
Doors(i%).x1 = 10
Doors(i%).y1 = 4
Doors(i%).map2=46
Doors(i%).x2 = 2
Doors(i%).y2 = 34

You can assign those values from a file or DATA statements or the way you want. Once you have the array full of door connections, you can use a simple loop to check:

Code:
FOR i%=0 TO NumOfDoors

   IF map% = Doors(i%).map1 AND playerX% = Doors(i%).x1 AND playerY% = Doors(i%).y1 THEN
      map% = Doors(i%).map2
      playerX% = Doors(i%).x2
      playerY% = Doors(i%).y2
      EXIT FOR
   ENDIF

   ' And the way around, if doors are bi directional
   ' (remove if doors just have 1 direction)

   IF map% = Doors(i%).map2 AND playerX% = Doors(i%).x2 AND playerY% = Doors(i%).y2 THEN
      map% = Doors(i%).map1
      playerX% = Doors(i%).x1
      playerY% = Doors(i%).y1
      EXIT FOR
   ENDIF

NEXT i%
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#4
Quote:HQSneaker, that was not what this guy was asking Tongue you put a lot of effort on the post, though.

Crap, why me? Tongue
Reply
#5
Save it for the next one. I'm sure than in less than 1 week you can repost the whole thing for someone asking for bitmapped graphics Smile
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#6
Good idea, will do Tongue ...you can copy/paste too if you like, otherwise you'll have to type the whole thing out :roll:
Reply
#7
Ahh...i get it thanx so much
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)