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.

DarkBASIC Professional Discussion / Tile-based Platformer

Author
Message
Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 30th Dec 2011 21:31
I have a total of three questions I hope someone can answer (or help me reach a conclusion on).

1) Can someone explain to me how a tilemap editor works? Mainly, how saving and loading/reading a tile map would work. (yeah, I want to make a tile map to use in my platformer)

2) Assuming I use line/circle collision, what might be the best arrangement (assuming my character is 1x2 tiles (x,y)) for me to place the collision points? Thus far I have about 6 or 7 points (circles about 4 pixels in diameter) located on the sides of my character. I can always add more points or use a different method of collision if the idea's present. (not sprite collision, not flexible enough)

3) I have my array variables created and set before the beginnings of my various loops. Assuming I leave the loop (say, go from the main game to the main menu) and reenter the game from the beginning without closing the program, should the variables reset, or must they be undim'ed, redimed, and then reset? With some of my projects in the past, My game works just fine but when I exit and reenter the game, some parts of the game don't work. (parts that require the arrayed variables)



Since I have three ?'s please put a number for the ? at the beginning of your post so things don't get confusing. (with the different questions and answers and whatnot)
If I need to restate anything, please tell me,
I don't need any code, yet it's always appreciated if it's there,
And I thank you all very much for your input .
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 30th Dec 2011 21:50
1 and 2 can be answered by getting eXtends


Quote: "
5) Perfect Pixel Sprite Collision

With the eXtends plugin you can perform pixel perfect collision between 2 sprites. You can also collect the amount of pixels that collide with each sprite. To show you how it works a small "Snail in the Labyrinth" game, highly inspired by the old Sega Master System, is included as a demonstration sample.
"

http://www.thegamecreators.com/?m=view_product&id=2080

For three I suggest looking at some tuts on Arrays and there are a few flating around very recently... set thread show per page to 100 and you can see the most recent threads in your profile settings.

Hope tis helped...

Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 30th Dec 2011 22:20
1) I can somewhat understand saving them but I want to know "How" to load and read them. I wanna know how to get my program to read the maps from files into the arrays because, currently, I've been using data labels to make and read them.

2) I already have eXtends (though I finally thought to look at the commands just now). I need for my whole sprite to not collide with tiles. I'm using multiple points so I can set certain flags on and off for my player (whether it can jump or not or if my character is colliding with a wall.), and so I can make sure my player's covered because if a circle's too large, it'll hit tiles when it shouldn't. (example) I want point 1 to detect the floor and I want points 2, 3, and 4 to detect whether I'm touching walls or a ceiling or not. When I used whole sprite collisions, my character could only detect one form of collision, at least, not without making multiple collision arrays.

And about 3) I'll take another look around but my question still stands for now.

You did help me a bit MrValentine. Thanks

I used to be the Great Mighty Poo until...
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 30th Dec 2011 22:48
1 - I forgot I have eXtends lol wll check the demo game t see if tey used arrays and how if tey did use them...

2- ignore 1 [was writing this reading your post at the same time lol]
Did you not look a the pizel perfect collisions? or is it that what uses those circles you mentioned?

3- yup keep us posted here

Glad I could help in any way, small or big alays appreciate appreciation thank you too

I see you are fairly new, So probably did what I did and bought a majority of the official plugins haha I only got time recently after a whole year to look into DBP... last year was a rollercoaster...

Nice to meet you and see you around on the forums some more in future as well and also Seasons Greetings and Happy New Year

Hope these questions get some resolution soon!

Daniel TGC
Retired Moderator
19
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 31st Dec 2011 01:51
Quote: "1) Can someone explain to me how a tilemap editor works? Mainly, how saving and loading/reading a tile map would work. (yeah, I want to make a tile map to use in my platformer)"


When I create 2D tile based games I work with a colour coded background layer. The actual tiles themselves are loaded on top of that. It works in the same way physics shapes do, you get an invisable layer you calculate collision and triggers with, while adding the visuals on top of it for the user to see. For example, standard ground can be blue, damage zones can be red, health zones green, trigger zones yellow, etc etc. You can do this in memblocks, which is good because you don't have to update the visual data to the screen until you want too and they are pretty fast to work with.

SO like I say, just treat it as two layers. A basic colourmapped layer that identifies specific tile properties, and a second visual layer that holds the animation and visuals you desire.

Quote: "2) Assuming I use line/circle collision, what might be the best arrangement (assuming my character is 1x2 tiles (x,y)) for me to place the collision points? Thus far I have about 6 or 7 points (circles about 4 pixels in diameter) located on the sides of my character. I can always add more points or use a different method of collision if the idea's present. (not sprite collision, not flexible enough)"


If you use the colour map system I suggested before then this is all pretty mute as you're working directly with the zone data used in memory blocks.

Quote: "3) I have my array variables created and set before the beginnings of my various loops. Assuming I leave the loop (say, go from the main game to the main menu) and reenter the game from the beginning without closing the program, should the variables reset, or must they be undim'ed, redimed, and then reset? With some of my projects in the past, My game works just fine but when I exit and reenter the game, some parts of the game don't work. (parts that require the arrayed variables)
"


I've never needed to undim something before but you can if you wish too. If I need to clear an array I either write 0's to it's whole index, or rebuild the data I need based on the level I'm loading. It really depends how you setup your data. Experiment, find out what works best for you.
Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 31st Dec 2011 15:02
1) I apologize, I should've elaborated a bit more. I understand about using different layers and such. My question is, more accurately, how would I save the map after I've put which tiles I want where (in the editor) and how would I load them (via the file) into my game?



I want to use a tile editor to break away from typing it like this because it takes a lot of unnessecary time when I tile map editor could mass produce these much faster. (if I'm not mistaken) Once I have the file, how do I read it?



2) I'm using the circle/line collision in conjunction with the collision layers. For example, all of my 1 tiles are completely solid thus the player can pass through them upward, downward, leftward, or right...ward (are the last two real words?) If I had a 2 tile, I could pass through upward but not downward. (0 tiles are just air) However, my question is, how do you guys think I should arrange them? Right now, I have three on the left and right sides and one on the bottom and I forgot to make one for the top... Maybe I should put two in each corner? (The points on the sides detect for horizontal collision and the top and bottom for vertical collision.)



And for 3) I've probably just flubbed up somewhere and need to be a bit more careful about my variables huh? Thanks for that advice And thank you for your help thus far guys!

I used to be the Great Mighty Poo until...
Agent
21
Years of Service
User Offline
Joined: 7th Sep 2004
Location: Sydney, Australia
Posted: 1st Jan 2012 07:27
1) I thought you stated your question fairly succinctly, but everyone seems to misconstruing it To me, it looks like you're asking how to create a file on the disk containing the tile information, and how to load it back into your game for use by the engine.

Here is an abridged version of the loadmap() function from my RTS game, Starstrike. You'll be able to use this code to learn how to make a modified version for your own purposes:



It's the first FOR...NEXT nested loop that will interest you. This is where I load values from the file that equate to the contents of your DATA statements. I also have a second loop that loads the units on the map from a second section of the same file. You can keep loading 'types' of data from the file repeatedly (like where your enemy monsters are on the map, or where your powerups and pickups are) before you close the file.

In order to create a file that can be read by this code, you'll need to manually populate a file with the contents of your data statements, or better yet, create a map editor that allows you to place tiles on the map, and then save the file to disk by using the opposite commands to my example (open to write, write byte, etc).



2) In Solodor, I've used the following system for collision detection with the environment:

When the character is moving, say, to the right, I check the topright and bottomright corners of the sprite. For each of those corners, I turn their exact coordinates into tile coordinates. For example, if tiles are 32x32 in size, and the corner of the sprite is located at (71, 34) then that corner is within tile coordinate (3, 2). Then I check my tile array to see if the tile in that location is passable. If it's not, I disallow the rightward movement. If it is, I move on to check the other corner. If they're both passable, I allow progress in that direction.

This method does allow one step into an impassable tile, but generally there's deadspace around the edges of the player sprite anyway, which compensates for this.


3) I like this term: 'Flubbed up'. Lol. Yes, I'd say you've flubbed up somewhere. Be sure that you're clearing the contents of all your variables that have an impact on the game. If things aren't performing correctly on the second playthrough then you've almost certainly got residual information in one of your variables that wasn't cleared since the first playthrough.

Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 1st Jan 2012 15:11
1) I've only had experience loading text from a .txt file so I really wasn't sure. All the tile x and y position's numbers must be written and read as bytes correct? Everything would be written in a linear manner? If I write every tile x and y position to the file, they must be read exactly as they were written write? And if I include what type of tile it is right after it's individual position then (once again) it must be read from the file EXACTLY as written? If so, I think I understand now.


2) I'm not entirely sure how to doi it the way you said but I have a circle/line collision system that should be able to accomplish that. (the collision's only slow if I actually show the lines) I set the radii of the circles to 1 or 2 and place the points around my character (I'll use 2 in each corner now)



3) Try using that term in conversation, you may get some strange reactions (Thank you all for helping me close question 3!)


Also, Happy New Year everyone! I shall spend part of my day sleeping cause drunk guys were playing with fireworks outside in the street til... 10 minutes ago, so I got no sleep... I'll understand more when I wake up.

I used to be the Great Mighty Poo until...
Agent
21
Years of Service
User Offline
Joined: 7th Sep 2004
Location: Sydney, Australia
Posted: 2nd Jan 2012 06:29
Quote: "they must be read exactly as they were written write?"


Yes, that's write Lol at typo.

Anything you write to a file using this technique must be read back in precisely the same order it was written. You can write tilex, tiley, tiletype, tilepassable, tilealpha, tilediffuse, and anything the hell else you want to write, all in plaintext the way you're used to, as long as when you read it back in by your program, you read it precisely the same way you wrote it. I generally code my write function first, then copypaste it into a read function, changing all the WRITEs to READs.

You don't have to write coordinates as bytes (READ BYTE/WRITE BYTE). I recommend you write coordinates as integers (READ FILE/WRITE FILE), as they will always be whole numbers and you may have maps bigger than 256x256 (which will be your maximum if you write bytes for coordinates). For any value that will never be negative and will never be greater than 256, use bytes. Any other value should be an int where possible, and a float where it's not (READ FLOAT/WRITE FLOAT). You can use strings (READ STRING/WRITE STRING) for text. All values except bytes can be hand-typed into a text file to be read by your program, as long as you're careful with your input and don't make any typos or formatting errors.

Your collision detection system seems a little strange. There's no need to create any actual circles or points. You just need to know where those points would be, and check whether or not the tile in that location is passable. I think you're doing it the complex, hard, unnecessary way, but if you're learning something from it then proceed!

I don't think I will ever use the word 'flubbed' in the real world, but thanks anyway

Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 2nd Jan 2012 07:49
I understand now

It only seems complicated (my collision system). It doesn't make anything visible, it's math collision. Though, if I were to show the lines it kills the fps like a slug in the dead sea. With one point, for example, I can track collisions with floors and such. I tried learning the other way but I lost interest/didn't understand it.

And I used that word today 5 times and I got the funniest double takes ever lol.

Once again, thanks to all who have helped me to reach my current conclusions about my questions!

I used to be the Great Mighty Poo until...
Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 7th Jan 2012 14:41 Edited at: 10th Jan 2012 23:18
Okay, I must be doing something glaringly wrong here but I now have another problem. I've written my tilemap editor and I can, of course place and reset my tiles. I'll make my editor a bit more sophisticated once I can figure out why I'm unable to save/load data from the files it's supposed to make.



A bit of assistance please? Everytime I load the files, all of the tiles reset to 0 (the default image) even though I saved a previous file. Also, I've tried opening the dat file and it doesn't show anything, it's just a blank file. (even though I tried saving stuff to it)

Thank you much.


~(A bit later)~
Okay, turns out I'm unable to save anything or something. I've tried saving things like strings or variables but I'm unable to load them. I think it has to do with the way I've saved them but I don't know what it is (I used the same function above and tried .dat, .txt, and other random letters). I seem to be able to insert loaded things back into my program but none of my files have anything on them when I save them. Anybody see anything wrong with my save code?


I'm gonna repost this under a more relevant title.
http://forum.thegamecreators.com/?m=forum_view&t=193308&b=1

I used to be the Great Mighty Poo until...

Login to post a reply

Server time is: 2026-07-10 00:42:49
Your offset time is: 2026-07-10 00:42:49