Author Topic: Map Making maybe Editor  (Read 11240 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Map Making maybe Editor
« on: August 15, 2018, 09:49:23 am »
I started working on a Pathfinder function to work with Maps and that got me started on the problem of generating random maps, which further got me thinking about map making and even editors, say for levels. My thoughts have been specially influenced by PMACKAY's cool little game of collecting diamonds without being buried or blocked by rocks. There were points there made by Steve about how to setup a map, use strings or use numbers?

Strings seem more descriptive and I think numbers would have things going faster with one level of calculations removed. ie you have to translate a string to maybe numbers for tile handles.

I think my ultimate goal is an AI Editor that can generate Maps on the fly!

Probably would need maze generation capability. Some sort of image loading routine to tile the map...
 
But for starters, should maps be strings or numbers?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Map Making maybe Editor
« Reply #1 on: August 15, 2018, 07:43:09 pm »
Rule #1 make maps with borders. So you can do all your array processing 1 step in on each side and never have to worry you are out of bounds of the map array.

Marked as best answer by bplus on August 17, 2018, 06:33:51 am

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Map Making maybe Editor
« Reply #2 on: August 17, 2018, 07:57:37 am »
Hi Bplus
what do you think about this little demo on your issue ?
Code: QB64: [Select]
  1. 'STRING  vs NUMBER in MAP
  2. DIM chessboard(1 TO 8, 1 TO 8) AS INTEGER
  3. DIM chessboard2(1 TO 8, 1 TO 8) AS STRING
  4. DIM colore2 AS STRING
  5.  
  6. ' STRING version
  7. n = 0
  8. FOR a = 1 TO 8
  9.     FOR b = 1 TO 8
  10.         n = n + 1
  11.         IF a MOD 2 = 0 THEN
  12.             IF n MOD 2 = 0 THEN colore2 = "GIALLO" ELSE colore2 = "VERDE"
  13.         ELSE
  14.             IF n MOD 2 = 0 THEN colore2 = "VERDE" ELSE colore2 = "GIALLO"
  15.         END IF
  16.         chessboard2(a, b) = colore2
  17. NEXT b, a
  18.  
  19. FOR a = 1 TO 8
  20.     FOR b = 1 TO 8
  21.         'squares 20h x 20l
  22.         IF chessboard2(a, b) = "GIALLO" THEN colore = 14 ELSE colore = 2
  23.         LINE (a * 20, b * 20)-((a * 20) + 20, (b * 20) + 20), colore, BF
  24. NEXT b, a
  25.  
  26.  
  27. LOCATE 24, 1: PRINT "Press a key to see Number Version";
  28.  
  29. 'NUMBER version
  30. n = 0
  31. FOR a = 1 TO 8
  32.     FOR b = 1 TO 8
  33.         n = n + 1
  34.         IF a MOD 2 = 0 THEN
  35.             IF n MOD 2 = 0 THEN colore = 14 ELSE colore = 2
  36.         ELSE
  37.             IF n MOD 2 = 0 THEN colore = 2 ELSE colore = 14
  38.         END IF
  39.         chessboard(a, b) = colore
  40. NEXT b, a
  41.  
  42. FOR a = 1 TO 8
  43.     FOR b = 1 TO 8
  44.         'squares 20h x 20l
  45.         colore = chessboard(a, b)
  46.         LINE (a * 20, b * 20)-((a * 20) + 20, (b * 20) + 20), colore, BF
  47. NEXT b, a
  48.  
  49. LOCATE 24, 1: PRINT "Press a key to see Tricky/Descriptive Number Version";
  50.  
  51. ' using const the code can be more readable
  52.  
  53. CONST GIALLO = 14, VERDE = 2
  54.  
  55. n = 0
  56. FOR a = 1 TO 8
  57.     FOR b = 1 TO 8
  58.         n = n + 1
  59.         IF a MOD 2 = 0 THEN
  60.             IF n MOD 2 = 0 THEN colore = GIALLO ELSE colore = VERDE
  61.         ELSE
  62.             IF n MOD 2 = 0 THEN colore = VERDE ELSE colore = GIALLO
  63.         END IF
  64.         chessboard(a, b) = colore
  65. NEXT b, a
  66.  
  67. FOR a = 1 TO 8
  68.     FOR b = 1 TO 8
  69.         'squares 20h x 20l
  70.         colore = chessboard(a, b)
  71.         LINE (a * 20, b * 20)-((a * 20) + 20, (b * 20) + 20), colore, BF
  72. NEXT b, a
  73.  

as you can see the third option is to use  DESCRETPIVE CONST NAME  for number of the table of value of the map.

Good Coding
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Map Making maybe Editor
« Reply #3 on: August 17, 2018, 10:16:18 am »
I see! Yes! With CONST you get the best of both worlds, fast number and descriptive value names. Thanks!

So next time we do Chess code, we will make Constants for all the Chessmen.

BTW, while looking at your Chess board drawing, I saw maybe an easier way to draw a checkered board.
Code: QB64: [Select]
  1. 'draw checkered board
  2. SCREEN _NEWIMAGE(500, 500, 32)
  3. ' using const so the code can be more readable < great idea!
  4. CONST GOLD = &HFFFF9900, BLACK = &HFF000000, RED = &HFFFF0000, SQ = 50
  5.  
  6. n = 0
  7. LINE (46, 46)-STEP(400 + 4, 400 + 4), GOLD, BF
  8. FOR y = 1 TO 8
  9.     FOR x = 1 TO 8
  10.         n = (n + 1) MOD 2
  11.         IF n MOD 2 THEN colore& = RED ELSE colore& = BLACK
  12.         LINE (x * SQ, y * SQ)-STEP(SQ - 4, SQ - 4), colore&, BF
  13.     NEXT
  14.     n = (n + 1) MOD 2 '< for even amount of squares in a row
  15.  


Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Map Making maybe Editor
« Reply #4 on: August 17, 2018, 02:05:16 pm »
It will be wonderful as soon as I can finish my study about chessprogramming theory...
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Map Making maybe Editor
« Reply #5 on: August 19, 2018, 09:50:32 am »
Rule #2 Make maps so that the action areas are played between 1 and Map Width or Height

DIM MAP(MAPW + 2, MAPH + 2)

So Borders run 0 and Map Width (or Height) + 1 and the MAP constants for Width and Height reflect the actual amount of squares in the action area.

Action area:
For y = 1 to MAPH
For x = 1 to MAPW

I've seen exits placed in the border, why not any where in the action area, the "arena"?

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Map Making maybe Editor
« Reply #6 on: August 19, 2018, 01:04:36 pm »
When it comes to map making, I want my maps to contain a whole lot of my game information, all ready to go, for me.

For example:

Shouldn't a map tell you what tile piece goes in each position?
Shouldn't it tell you if you can walk North, South, East, West, or any of the diagonals?
How about if you can swim it?  Fly it?
Shouldn't a map tell you if a tile has a special effect attached to it, such as Darkness, Spin, or Teleport?
If there's a creature always on the map, shouldn't it tell you where they're at?  What that creature's walking path is?  (Random, Chase direct to hero, One step North, One step West, One step South, One step East, Repeat...)
What a tile contains, and how the character can interact with it?  (Click on it and loot the medical herb which is in the pot at 10,2, Papa's House.)

For my game (Destiny's Child), the map itself contains all this information for me and all the game 'engine' has to do is read the map and then react to all this information.

Say we have a room which looks like the following:

Code: QB64: [Select]
  1. |----|  |----|
  2. |            |
  3. |            |
  4. |            |
  5. --------------
  6.  

With a single glance, you can see where the "walls" would be, which would limit the character's movement, and you can see where the entrance/exit would be.   All we need to do is mark those areas with walls as "unpassable", and then place the teleporter to the main map at the exit.

Code: QB64: [Select]
  1. |----|S1|----|
  2. |            |
  3. |            |
  4. |            |
  5. --------------

So,  a typical map type might look like the following:

TYPE MapInfo
    Walk as _Byte
    Swim as _Byte
    Fly as _Byte
    Tile as Long 'Representing tile and tile set
    Script as Long 'This says while the character walks on this tile, we check special conditions.  (If hero has Gold Key, then Walk and NORTH = TRUE.. He can walk through the locked north door.)
    Monster as Long 'monster icon
    MonsterPath as Long 'Random, Chase, Patrol)
    MonsterScript as Long 'what the monster does when it catches the hero, or if the hero clicks on it.
END TYPE

Notice that my map info contains a "Script" which can be used to set and check various game flags.  Movement via teleport is often through this script, which I identify as a number cooresponding to that room. 

SCRIPT 0001:
Physical Damage 3 'spiked floor
IF hero HAS "Gold Key"  Then
    Walk AND North = TRUE
ELSE
    If Move = North Then
        PopUp "The door is locked; you can not open it at this time."
    END IF
END IF
If Walk = East then
    Teleport to "MainMap0101"
END IF
END SCRIPT


Note, these scripts are attached to the end of the map, so they're loaded when the map is, keeping all of the control information self-contained, and allowing our game 'engine' to just worry about processing these scripts for us.

************************

Just something for you to think about, if you're going to work on a map maker/editor.  I don't know if my way would work for everyone, but it seems the best way for things to work for *me*, at least.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Map Making maybe Editor
« Reply #7 on: August 19, 2018, 03:04:35 pm »
Thanks Steve,

This is exactly the kind of discussion I was hoping to learn from.

I have not made any games with maps but PMACKAY's has inspired me. I hadn't realized that sort of game could offer interesting puzzles to solve ie extracting diamonds from places with falling rocks (don't even mention the monsters (yet)) without getting buried on trapped in a corner.

I did try to help Johnno with a platformmer game but that is about the extent of map games, plenty of board games but no map games.

My interest is theoretical: What is the best foundation to establish for a creating a game using a map?
My hypothesis is if you have that established and a great idea for a game, the game will write itself.

Steve:
Quote
When it comes to map making, I want my maps to contain a whole lot of my game information, all ready to go, for me.

I agree, the map should show what Tile or Drawing might go into each MAP(x, y) location but isn't that it?
Then there would be a legend that translates the map's (x, y) value that represents the object that occupies that space.

Then those objects might need a type that would be part of script as to how they interact.
The map tracks the locations of the objects, the object type determines the behaviors of interaction.

So
DIM MAP(MAPW + 2, MAPH + 2) AS INTEGER (or LONG or _BYTE)  'to represent object type numbers

or
DIM MAP(MAPW + 2, MAPH + 2) AS MAPINFO

?


Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Map Making maybe Editor
« Reply #8 on: August 19, 2018, 03:24:47 pm »
Thanks Steve,

This is exactly the kind of discussion I was hoping to learn from.

I have not made any games with maps but PMACKAY's has inspired me. I hadn't realized that sort of game could offer interesting puzzles to solve ie extracting diamonds from places with falling rocks (don't even mention the monsters (yet)) without getting buried on trapped in a corner.

I did try to help Johnno with a platformmer game but that is about the extent of map games, plenty of board games but no map games.

My interest is theoretical: What is the best foundation to establish for a creating a game using a map?
My hypothesis is if you have that established and a great idea for a game, the game will write itself.

Steve:
Quote
When it comes to map making, I want my maps to contain a whole lot of my game information, all ready to go, for me.

I agree, the map should show what Tile or Drawing might go into each MAP(x, y) location but isn't that it?
Then there would be a legend that translates the map's (x, y) value that represents the object that occupies that space.

Then those objects might need a type that would be part of script as to how they interact.
The map tracks the locations of the objects, the object type determines the behaviors of interaction.

So
DIM MAP(MAPW + 2, MAPH + 2) AS INTEGER (or LONG or _BYTE)  'to represent object type numbers

or
DIM MAP(MAPW + 2, MAPH + 2) AS MAPINFO

?

Years ago, I played around with the RPG Maker software, and it helped me develop my philosophy on what information maps should contain.  Take a look at it here: http://www.rpgmakerweb.com

It's a rather sizeable download, but simple enough to work with once you get it.

The way it basically works is you create the map with the tiles you want, then set scripts for each tile which the character interacts with as they walk upon them.

I'm not that proficient with Ruby (the language RPG Maker uses), but it's a good tool to play around with, just to learn the concept of Script-driven maps...  Then all you have to do is create the game engine as you want it, and any map you make in the future will work with that core engine, allowing creation of extended levels, expansion material, and new content.

*************************

Edit:  The VX Ace version uses Ruby; it seems as if the new RPG Maker MV version uses JavaScript under the hood, but it still works more or less the same.
« Last Edit: August 19, 2018, 03:38:25 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Map Making maybe Editor
« Reply #9 on: August 20, 2018, 09:22:52 am »
Aaha! I was reading Terrie Ritchies tut Task 13 Math Functions:  http://qb64sourcecode.com/Task13.html

And there he described setting up a map with Type as had Steve, and there he showed how passages are made with bit math coded into one number indicating which side gives access / exit to cell.

I was thinking a cell is either wall section or open section depending on tile you assign, you make your maze with wall tiles.

So there is another way to do maze like maps that would need a Type description, but do you have to track the x, y position in the map's type?

But is this just a made up application to show bit wise operation? To me, it seems easier to move player(s) around by checking if the MAP(x, y) location is of wall type or a passage type.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Map Making maybe Editor
« Reply #10 on: August 20, 2018, 12:44:14 pm »
Here's a real quick demo of how I'd normally tend to structure the data for my maps anymore:

Code: QB64: [Select]
  1. TYPE MapInfo 'Let's define a very basic set of map information
  2.     Tile AS _UNSIGNED LONG 'what tile goes in what spot
  3.     Walk AS _UNSIGNED _BYTE 'what directions can the character walk in from that tile
  4.     Fly AS _UNSIGNED _BYTE 'what directions can the character fly in from that tile
  5.     Distance AS _UNSIGNED _BYTE 'How far is it from this tile to where the hero is, in case we need to path a monster to the hero
  6.     Script AS LONG 'To handle any unique occurances on a specific tile
  7.  
  8. TYPE Coordinate
  9.     x AS _BYTE
  10.     y AS _BYTE
  11.  
  12.  
  13. CONST Min = 1, Max = 10 'Map size
  14.  
  15.  
  16. DIM SHARED Map(Min - 1 TO Max + 1, Min - 1 TO Max + 1) AS MapInfo 'The map
  17. DIM SHARED Hero AS Coordinate 'Hero's X/Y Position
  18. DIM SHARED Flags(10) AS _BYTE 'A set of flags which we can use to indicate changes in the game as we play
  19.  
  20. SCREEN _NEWIMAGE(800, 600, 32)
  21.  
  22. 'Define some areas
  23.  
  24. 'First, let's make the whole map walkable and flyable, until we define areas where we can't walk/run
  25. FOR x = Min - 1 TO Max + 1
  26.     FOR y = Min - 1 TO Max + 1
  27.         Map(x, y).Walk = -1
  28.         Map(x, y).Fly = -1
  29.     NEXT
  30.  
  31.  
  32. FOR x = Min - 1 TO Max + 1
  33.     'Create my water
  34.     Map(x, 5).Tile = &HFF0000FF 'Blue tile for water
  35.     Map(x, 5).Walk = 0 'Can't walk on water, unless you're Jesus
  36.  
  37. FOR x = Min - 1 TO Max + 1
  38.     'Then my border
  39.     Map(x, 0).Tile = &HFFFF0000: Map(x, 11).Tile = &HFFFF0000 'Red border for map wall
  40.     Map(0, x).Tile = &HFFFF0000: Map(11, x).Tile = &HFFFF0000
  41.     Map(x, 0).Walk = 0: Map(x, 11).Walk = 0 'can't walk on this tile
  42.     Map(0, x).Walk = 0: Map(11, x).Walk = 0
  43.     Map(0, x).Fly = 0: Map(11, x).Fly = 0 'can't fly here either
  44.     Map(x, 0).Fly = 0: Map(x, 11).Fly = 0
  45.  
  46.  
  47. Map(9, 9).Tile = &HFFFF00FF 'Purple square to mark the exit
  48.  
  49. Map(3, 3).Script = 1 'Find the Angel Wings
  50. Map(9, 9).Script = 2 'Find the Exit
  51.  
  52. Hero.x = 1: Hero.y = 1
  53.  
  54.     _LIMIT 30
  55.     CLS
  56.     DrawMap
  57.     k$ = INKEY$
  58.     IF Flags(1) = 0 THEN 'hero doesn't have the boots yet, so can only walk
  59.         SELECT CASE UCASE$(k$)
  60.             CASE "W": IF Map(Hero.x, Hero.y - 1).Walk THEN Hero.y = Hero.y - 1
  61.             CASE "A": IF Map(Hero.x - 1, Hero.y).Walk THEN Hero.x = Hero.x - 1
  62.             CASE "S": IF Map(Hero.x, Hero.y + 1).Walk THEN Hero.y = Hero.y + 1
  63.             CASE "D": IF Map(Hero.x + 1, Hero.y).Walk THEN Hero.x = Hero.x + 1
  64.         END SELECT
  65.     ELSE 'the hero is now flying
  66.         SELECT CASE UCASE$(k$)
  67.             CASE "W": IF Map(Hero.x, Hero.y - 1).Fly THEN Hero.y = Hero.y - 1
  68.             CASE "A": IF Map(Hero.x - 1, Hero.y).Fly THEN Hero.x = Hero.x - 1
  69.             CASE "S": IF Map(Hero.x, Hero.y + 1).Fly THEN Hero.y = Hero.y + 1
  70.             CASE "D": IF Map(Hero.x + 1, Hero.y).Fly THEN Hero.x = Hero.x + 1
  71.         END SELECT
  72.     END IF
  73.  
  74.     CheckScripts
  75.  
  76.     _DISPLAY
  77. LOOP UNTIL k$ = CHR$(27)
  78.  
  79. SUB DrawMap
  80.  
  81.     FOR x = Min - 1 TO Max + 1
  82.         FOR y = Min - 1 TO Max + 1
  83.             LINE (x * 25 + 25, y * 25 + 25)-STEP(24, 24), Map(x, y).Tile, BF
  84.     NEXT y, x
  85.     COLOR &HFFFFFF00 'Yellow
  86.     _PRINTSTRING (Hero.x * 25 + 25, Hero.y * 25 + 25), CHR$(1)
  87.     IF NOT Flags(1) THEN
  88.         COLOR &HFF00FF00
  89.         _PRINTSTRING (3 * 25 + 25, 3 * 25 + 25), "W"
  90.     END IF
  91.     COLOR -1
  92.  
  93. SUB CheckScripts
  94.     SELECT CASE Map(Hero.x, Hero.y).Script
  95.         CASE 1
  96.             IF Flags(1) = 0 THEN Flags(1) = -1 'hero picks up the Angel Wings!
  97.         CASE 2
  98.             BEEP: BEEP
  99.             _AUTODISPLAY
  100.             CLS
  101.             PRINT "YOU ARE A BIG WINNER!!  WOOT!"
  102.             END
  103.     END SELECT
  104.  

Now, for my game "Destiny's Child", the scripts are self-contained and saved with the maps themselves, and the "game engine" simply parses that information and deals with it as a character walks (or moves) across each tile  (if possible).

For this little "game", the purpose is to move the hero from where they start to the nice purple exit square at the bottom of the screen.  Unfortunately, there's a river which blocks the way, so it's impossible to move all the way there....  The first thing you'll have to do is find the Angel Wings, pick them up, and then proceed to the exit, where you become a big winner!

Movement is simple enough with the WASD keys, and I think this shows a bit of the concept that I was trying to get across above.  With a Map Editor, I could quickly mark the tiles which would contain the redbrick walls, the blue river, and designate which areas are passable via which methods.  Then a quick insertion of "special areas" via the scripts/flags, and all I'd have to do is then run the game through the "engine" which loads it and parses it for us. 

Using the above method, 90% of the game creation process become Map/Tile orientated and self-contained, rather than having to be hard-coded into each "game" itself.   It makes for very quick map creation and very easily allows you to add new levels, maps, content... Whatever you like. 

Anywho...  See if the concept makes a little more sense now.  Maybe it's not the way you'd create a game, but it certainly works exceedingly well for me.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Map Making maybe Editor
« Reply #11 on: August 20, 2018, 02:07:25 pm »
A quick update to make the "Script" a little more stand-alone and the internal routines a little more static with their behavior.

Code: QB64: [Select]
  1. TYPE MapInfo 'Let's define a very basic set of map information
  2.     Tile AS _UNSIGNED LONG 'what tile goes in what spot
  3.     Walk AS _UNSIGNED _BYTE 'what directions can the character walk in from that tile
  4.     Fly AS _UNSIGNED _BYTE 'what directions can the character fly in from that tile
  5.     Distance AS _UNSIGNED _BYTE 'How far is it from this tile to where the hero is, in case we need to path a monster to the hero
  6.     Script AS LONG 'To handle any unique occurances on a specific tile
  7.  
  8. TYPE Coordinate
  9.     x AS _BYTE
  10.     y AS _BYTE
  11.  
  12.  
  13. CONST Min = 1, Max = 10 'Map size
  14.  
  15.  
  16. DIM SHARED Map(Min - 1 TO Max + 1, Min - 1 TO Max + 1) AS MapInfo 'The map
  17. DIM SHARED Hero AS Coordinate 'Hero's X/Y Position
  18. DIM SHARED Flags(10) AS _BYTE 'A set of flags which we can use to indicate changes in the game as we play
  19.  
  20. SCREEN _NEWIMAGE(800, 600, 32)
  21.  
  22. 'Define some areas
  23.  
  24. 'First, let's make the whole map walkable and flyable, until we define areas where we can't walk/run
  25. FOR x = Min - 1 TO Max + 1
  26.     FOR y = Min - 1 TO Max + 1
  27.         Map(x, y).Walk = -1
  28.         Map(x, y).Fly = -1
  29.     NEXT
  30.  
  31.  
  32. FOR x = Min - 1 TO Max + 1
  33.     'Create my water
  34.     Map(x, 5).Tile = &HFF0000FF 'Blue tile for water
  35.     Map(x, 5).Walk = 0 'Can't walk on water, unless you're Jesus
  36.  
  37. FOR x = Min - 1 TO Max + 1
  38.     'Then my border
  39.     Map(x, 0).Tile = &HFFFF0000: Map(x, 11).Tile = &HFFFF0000 'Red border for map wall
  40.     Map(0, x).Tile = &HFFFF0000: Map(11, x).Tile = &HFFFF0000
  41.     Map(x, 0).Walk = 0: Map(x, 11).Walk = 0 'can't walk on this tile
  42.     Map(0, x).Walk = 0: Map(11, x).Walk = 0
  43.     Map(0, x).Fly = 0: Map(11, x).Fly = 0 'can't fly here either
  44.     Map(x, 0).Fly = 0: Map(x, 11).Fly = 0
  45.  
  46.  
  47. Map(3, 3).Tile = 1 'special tile to mark the Angel Wings Icon..
  48. Map(9, 9).Tile = &HFFFF00FF 'Purple square to mark the exit
  49.  
  50. Map(3, 3).Script = 1 'Find the Angel Wings
  51. Map(9, 9).Script = 2 'Find the Exit
  52.  
  53. Hero.x = 1: Hero.y = 1
  54.  
  55.     _LIMIT 30
  56.     CLS
  57.     DrawMap
  58.     k$ = INKEY$
  59.     IF Flags(1) = 0 THEN 'hero doesn't have the boots yet, so can only walk
  60.         SELECT CASE UCASE$(k$)
  61.             CASE "W": IF Map(Hero.x, Hero.y - 1).Walk THEN Hero.y = Hero.y - 1
  62.             CASE "A": IF Map(Hero.x - 1, Hero.y).Walk THEN Hero.x = Hero.x - 1
  63.             CASE "S": IF Map(Hero.x, Hero.y + 1).Walk THEN Hero.y = Hero.y + 1
  64.             CASE "D": IF Map(Hero.x + 1, Hero.y).Walk THEN Hero.x = Hero.x + 1
  65.         END SELECT
  66.     ELSE 'the hero is now flying
  67.         SELECT CASE UCASE$(k$)
  68.             CASE "W": IF Map(Hero.x, Hero.y - 1).Fly THEN Hero.y = Hero.y - 1
  69.             CASE "A": IF Map(Hero.x - 1, Hero.y).Fly THEN Hero.x = Hero.x - 1
  70.             CASE "S": IF Map(Hero.x, Hero.y + 1).Fly THEN Hero.y = Hero.y + 1
  71.             CASE "D": IF Map(Hero.x + 1, Hero.y).Fly THEN Hero.x = Hero.x + 1
  72.         END SELECT
  73.     END IF
  74.  
  75.     CheckScripts
  76.  
  77.     _DISPLAY
  78. LOOP UNTIL k$ = CHR$(27)
  79.  
  80. SUB DrawMap
  81.     'Draw Map
  82.     FOR x = Min - 1 TO Max + 1
  83.         FOR y = Min - 1 TO Max + 1
  84.             IF Map(x, y).Tile = 1 THEN 'Special Tileset for the Wings
  85.                 COLOR &HFF00FF00
  86.                 _PRINTSTRING (3 * x + 25, 3 * y + 25), "W"
  87.             ELSE 'Or the normal tileset of the squares
  88.                 LINE (x * 25 + 25, y * 25 + 25)-STEP(24, 24), Map(x, y).Tile, BF
  89.             END IF
  90.     NEXT y, x
  91.  
  92.     'Draw Hero
  93.     COLOR &HFFFFFF00 'Yellow
  94.     _PRINTSTRING (Hero.x * 25 + 25, Hero.y * 25 + 25), CHR$(1)
  95.     COLOR -1
  96.  
  97. SUB CheckScripts
  98.     SELECT CASE Map(Hero.x, Hero.y).Script
  99.         CASE 1
  100.             IF Flags(1) = 0 THEN
  101.                 Flags(1) = -1
  102.                 Map(3, 3).Tile = 0 'hero picks up the Angel Wings!
  103.             END IF
  104.         CASE 2
  105.             BEEP: BEEP
  106.             _AUTODISPLAY
  107.             CLS
  108.             PRINT "YOU ARE A BIG WINNER!!  WOOT!"
  109.             END
  110.     END SELECT
  111.  

Now, Script 1 behaves a little more like we'd expect a script to work with a game engine.  It sets the flag which says the player has the Angel Wings and can fly, and it changes the map so that the icon no longer displays on it. 

Now, if we want to add a second map, we could simply change Script 2 to load the next map in memory, place the hero in his starting position, and put a new set of wings somewhere else (if we wanted to), to add to the puzzle of "How to get from point A to point B."
« Last Edit: August 20, 2018, 02:15:26 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Map Making maybe Editor
« Reply #12 on: August 20, 2018, 02:33:01 pm »
Thanks Steve,

I do like small examples, I will study this more when I get back from running errands.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Map Making maybe Editor
« Reply #13 on: August 20, 2018, 08:24:33 pm »
Hi Guys
just some thinking about this very interesting talking on MAP, MAP Editor and Game Engine

@Bplus
about the use of bitwise as map
here Terry example
Code: QB64: [Select]
  1. '*
  2. '* Bitwise math demonstration
  3. '*
  4. '* Draws a simple map and allows player to move circle within map
  5. '*
  6.  
  7. '--------------------------------
  8. '- Variable Declaration Section -
  9. '--------------------------------
  10.  
  11. TYPE MAP '             set up map cell structure
  12.     x AS INTEGER '     upper left x coordinate of cell
  13.     y AS INTEGER '     upper left y coordinate of cell
  14.     walls AS INTEGER ' identifies cell walls
  15.  
  16. DIM MAP(4, 4) AS MAP ' create the map array
  17. DIM cx% '              current x cell coordinate of player
  18. DIM cy% '              current y cell coordinate of player
  19. DIM KeyPress$ '        player key presses
  20.  
  21. '----------------------------
  22. '- Main Program Begins Here -
  23. '----------------------------
  24.  
  25. SCREEN _NEWIMAGE(250, 250, 32) '                                  create 250x250 32bit screen
  26. _TITLE "Simple Map" '                                             give window a title
  27. CLS '                                                             clear the screen
  28. DRAWMAP '                                                         draw the map
  29. DO '                                                              MAIN LOOP begins here
  30.     PCOPY 1, 0 '                                                  copy page 1 to current screen
  31.     CIRCLE (MAP(cx%, cy%).x + 24, MAP(cx%, cy%).y + 24), 20, _RGB32(255, 0, 0) ' draw player
  32.     PAINT (MAP(cx%, cy%).x + 24, MAP(cx%, cy%).y + 24), _RGB32(128, 0, 0), _RGB32(255, 0, 0)
  33.     _DISPLAY '                                                    update the screen without flicker
  34.     DO '                                                          KEY INPUT LOOP begins here
  35.         KeyPress$ = INKEY$ '                                      get a key (if any) that player pressed
  36.         _LIMIT 120 '                                              limit loop to 120 times per second
  37.     LOOP UNTIL KeyPress$ <> "" '                                  KEY INPUT LOOP back if no key
  38.     SELECT CASE KeyPress$ '                                       which key was pressed?
  39.         CASE CHR$(27) '                                           the ESC key
  40.             SYSTEM '                                              return to Windows
  41.         CASE CHR$(0) + CHR$(72) '                                 the UP ARROW key
  42.             IF NOT MAP(cx%, cy%).walls AND 1 THEN cy% = cy% - 1 ' move player up if no wall present
  43.         CASE CHR$(0) + CHR$(77) '                                 the RIGHT ARROW key
  44.             IF NOT MAP(cx%, cy%).walls AND 2 THEN cx% = cx% + 1 ' move player right if no wall present
  45.         CASE CHR$(0) + CHR$(80) '                                 the DOWN ARROW key
  46.             IF NOT MAP(cx%, cy%).walls AND 4 THEN cy% = cy% + 1 ' move player down if no wall present
  47.         CASE CHR$(0) + CHR$(75) '                                 the LEFT ARROW key
  48.             IF NOT MAP(cx%, cy%).walls AND 8 THEN cx% = cx% - 1 ' move player left if no wall present
  49.     END SELECT
  50. LOOP '                                                            MAIN LOOP back
  51.  
  52. '-----------------------------------
  53. '- Function and Subroutine section -
  54. '-----------------------------------
  55.  
  56. SUB DRAWMAP ()
  57.  
  58. '*
  59. '* draws a map based on the value of each map cell
  60. '*
  61.  
  62. SHARED MAP() AS MAP ' need access to map array
  63.  
  64. DIM x%, y% '          x,y map coordinates
  65.  
  66. FOR y% = 0 TO 4 '                                                 cycle through map rows
  67.     FOR x% = 0 TO 4 '                                             cycle through map columns
  68.         READ MAP(x%, y%).walls '                                  read wall DATA
  69.         MAP(x%, y%).x = x% * 50 '                                 compute upper left x coordinate of cell
  70.         MAP(x%, y%).y = y% * 50 '                                 compute upper left y coordinate of cell
  71.         IF MAP(x%, y%).walls AND 1 THEN '                         is NORTH wall present?
  72.             LINE (MAP(x%, y%).x, MAP(x%, y%).y)-(MAP(x%, y%).x + 49, MAP(x%, y%).y), _RGB32(255, 255, 255) ' yes, draw it
  73.         END IF
  74.         IF MAP(x%, y%).walls AND 2 THEN '                         is EAST wall present?
  75.             LINE (MAP(x%, y%).x + 49, MAP(x%, y%).y)-(MAP(x%, y%).x + 49, MAP(x%, y%).y + 49), _RGB32(255, 255, 255) ' yes, draw it
  76.         END IF
  77.         IF MAP(x%, y%).walls AND 4 THEN '                         is SOUTH wall present?
  78.             LINE (MAP(x%, y%).x, MAP(x%, y%).y + 49)-(MAP(x%, y%).x + 49, MAP(x%, y%).y + 49), _RGB32(255, 255, 255) ' yes, draw it
  79.         END IF
  80.         IF MAP(x%, y%).walls AND 8 THEN '                         is WEST wall present?
  81.             LINE (MAP(x%, y%).x, MAP(x%, y%).y)-(MAP(x%, y%).x, MAP(x%, y%).y + 49), _RGB32(255, 255, 255) ' yes, draw it
  82.         END IF
  83.     NEXT x%
  84. NEXT y%
  85. PCOPY 0, 1 '                                                      save a copy of the map
  86.  
  87.  
  88. '------------------------
  89. '- Program DATA section -
  90. '------------------------
  91.  
  92. '*
  93. '* Map cell values
  94. '*
  95.  
  96. DATA 11,15,15,11,15,12,5,5,4,3,15,15,15,15,10,11,15,9,5,6,12,5,6,15,15
  97.  

here examples for using in chessprogramming...
 https://chessprogramming.wikispaces.com/General%20Setwise%20Operations
https://chessprogramming.wikispaces.com/Square%20Mapping%20Considerations
https://chessprogramming.wikispaces.com/Bitboards

Quote
But is this just a made up application to show bit wise operation? To me, it seems easier to move player(s) around by checking if the MAP(x, y) location is of wall type or a passage type.

Yes, already the kind of tile set in a single position of map brings information to use with event.... (tile is it already a flag)
but if a tile has different event for different characters and/or different features (magic key, tool, to be a ghost....) how do you manage it ? i.e. what do you think if the wall type has into it a secret acrossing if  the character to pass is hero with magic key, or thief with his tool, or a ghost?

@SMcNeill
Hi Steve your solution  is very interesting and IMHO it can be also combined with bitwise information system....
as soon as I'll post as code my idea to be clearer.


Programming isn't difficult, only it's  consuming time and coffee

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Map Making maybe Editor
« Reply #14 on: August 20, 2018, 09:23:16 pm »
Normally, Tempodibasic, I tend to use bit-values for my maps; I just watered things down for ease-of-concept sharing.  ;)

Normally, I have a set of CONST defined:
CONST North = 1, East = 2, West = 4, South = 8, Up = 16, Down = 32

Then it's a case of defining a map tile (usually with an editor), so that:
Map(1,1).Walk = 3 'From this point the character can walk North or East


And the main advantage of this method??  Uni-directional travel.

Map (10,10).Walk = 1 'Only North is allowed
Map (10, 9).Walk = 2 'Only East is allowed.

So if you walk north from (10,10), you can't just turn around and walk back south from (10,9); you have to continue moving east.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!