Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Loading a map from a file & collisions

Author
Message
xSpadez
12
Years of Service
User Offline
Joined: 11th Apr 2012
Location: 127.0.0.1
Posted: 12th Apr 2012 05:20
Hello,

I have been reading tutorials/programming basic stuff and have a pretty nice grasp of the basics in DBPro so now I decided to make a game instead of these mini tech demos >_>. Basically the environment, player, baddies, are all keyboard (ASCII) characters. I got movement setup and basic AI + rewards system at the moment, But I want to add the ability to load the maps from text files so I can update them and people can add to the game. The maps are just Asterisks (*) for walls and $ for money, etc etc. Now I'm trying to figure out how to make it as simple as possible to make the map, save and then load when neccesary. So I know I have to load in the same way I saved the data like the coords to the objects and walls. How do I actually make the map and have it save the data? I started with:

DIM Map(20,20) <-- 20x20 map

So each numb is a plot on the grid and holds a character like a wall (*) or another object. How would I go about putting the actual object there and then saving the positions of it since these aren't sprites there just ASCII characters?

Another thing I'm struggling with is collision with the walls/baddies etc. If these were object/sprites I could add collision easily but their not so I guess checking the pixels around the Player and if it goes into a wall it would be a diff color so it checks with POINT command?


Sorry for the long text but I'm just trying to explain best as possible and I really don't know where to start off here.


Thanks,

xSpadez

xSpadez - Like a baws
Lewis999
14
Years of Service
User Offline
Joined: 23rd Oct 2010
Location:
Posted: 12th Apr 2012 19:06
I don't know how to do it exactly like you described, but If the map is on one row (make it how you would normally then delete the "returns") then this should work:



test.txt(in the same folder,must be 20x20(400) characters long):

^all that's on one line, I'm sure It's possible to do it exactly how you said, but I don't know how >.<
Lewis999
14
Years of Service
User Offline
Joined: 23rd Oct 2010
Location:
Posted: 12th Apr 2012 19:43
Sorry for the double post, I couldn't just edit the previous one because it hasn't been verified yet

I just remembered how to load separate rows, can't believe I forgot >.<



Also, I'm bored.
epic loading screen is epic
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 12th Apr 2012 22:11 Edited at: 12th Apr 2012 22:12
Asking how to make the map's a little like asking "How should I draw?". There's only one correct answer and that's "Any darn way that makes you feel comfortable". Here's something I boiled up that will load your map quickly and create a graphical representation old-school-style.

NOTE this line: MapFile$ = "C:\Map.txt"
needs to be changed to point to wherever your map file is before running.



It's crude and ugly but it works

Hope this was what you were looking for.

PS: You can print ASCII characters by modifying the code a little. I just used graphics for the sake of illustration.

Lewis999
14
Years of Service
User Offline
Joined: 23rd Oct 2010
Location:
Posted: 13th Apr 2012 16:13 Edited at: 13th Apr 2012 17:36
nonZero, sorry for being a little off topic, but how do you get syntax highlighting to work in the code snippets? ^^

So this post isn't completely off topic, I'll throw some code that's slightly related to the OP in your face


map.txt:


edit: changed the code a little + put syntax highlighting on
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 13th Apr 2012 17:13
@Lewis999:
[verbose explanation]
It's like so:
"[" + "code lang=dbp" + "]"
without the quotation marks or plusses. Take note of the spaces. I believe the "lang=" can be used to set highlighting for other languages like php, C, etc. Best way to learn if to subscribe to a thread (Enable mailback by checking the box above "Post Message" and then check your email which displays all forum code as raw text. For example, if you've subscribed to this thread already (mailback enabled), this coffee will appear as "[" + "ic:coffee" + "]" in your email (without the +'s and quotes).
[/verbose explanation]

Lewis999
14
Years of Service
User Offline
Joined: 23rd Oct 2010
Location:
Posted: 13th Apr 2012 17:37 Edited at: 13th Apr 2012 17:46
Thanks
I just tried it on the post above and it works fine ^^
also, I think I'm having too much fun with the idea of a tile based rpg, loading the maps from a txt file, at this rate, I'll have map a map editor and dungeon generator within the next hour, and a combat system within 2 >.<

edit: oh, and @xSpadez:
If you're using a tile based system(if it's text based then I'm assuming you are), it's easy . Just store the player co-ordinates as variables and when the player tries to move, check the place he is trying to move into to see if it is a solid block or not. eg:
(where "#" in the map.txt is nothing)
then just position the player at the 2 variables each loop
xSpadez
12
Years of Service
User Offline
Joined: 11th Apr 2012
Location: 127.0.0.1
Posted: 13th Apr 2012 19:54
Wow thanks for all the replies guys. I was away for a while so I didn't get to respond yet. I'm going to try out both examples and edit it a bit to fit. Thank you for helping me








xSpadez - Like a baws

Login to post a reply

Server time is: 2024-11-24 20:16:12
Your offset time is: 2024-11-24 20:16:12