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 / 2D retro game collision and basic physics HELP PLEASE!!!

Author
Message
Starshyne Emir
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location: Porto Alegre, southern Brazil
Posted: 13th May 2019 18:19
I need some simple ideas for a 2D platformer.
How can I make a good collision system for the player and enemy sprites? I won't use moving platforms, so I believe it should be simpler, but I need something that I can apply for both player and enemies. How can I apply gravity and detect when the character jumps and hits a wall or the ceiling?

No code needed, if you give me ideas I'd be grateful.

Ah, and how can I make a 2D level bigger than the screen? I don't know how to scroll it! Backgrounds are easy to scroll, but I don't know how to move the game field left, right, up or down.

Well, thanks. I know my question isn't so specific, but I believe someone will find a way to help me with my issue.
God is real - except if declared as integer.
Xarcolt
16
Years of Service
User Offline
Joined: 29th Sep 2007
Location:
Posted: 14th May 2019 10:14
ACK I want to help but I'm currently developing something that doesn't do the scrolling bit so I can feel I graduated to that x.x; I know there's sprite collision commands that you can use in conjunction with their coordinates to create accurate player/monster/other readjustment. Short from that (if you're not using assets and just the internal draw commands or something) I would guess you would store every single coordinate in a variable that gets moved instead of the "screen" so the screen can appear to be in motion. It sounds like a headache though so.. I'm probably not the best to answer. Still wanted to say hi though!
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 14th May 2019 14:35
Search the forums for 2D maps / 2d mapping / Tile Maps / Map Collision etc etc as it's all been done before

PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
Starshyne Emir
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location: Porto Alegre, southern Brazil
Posted: 14th May 2019 15:22
I woke up this morning with the answer.
It is becoming common for me to dream with algorithmic solutions, and this one came directly from the realms of dreams.

I'll make a 2D array with the size of the amount of tiles I'll use to build the level.
Then, every loop I'll check the position of all entities I want to apply physics to and then I'll interpolate this position to retrieve the position in that grid the sprite is - dividing the screen position by the sprite size and correcting the result, obviously.
Then, I'll check the adjacent positions in the grid to check if they are walls or empty spaces. If the grid tile below the current position is a wall, I can stop applying gravity. If the tile in the direction of the sprite movement is a wall, I can stop moving it. If the tile above the current sprite position is a wall, I can stop accelerating it up when jumping and so on.
I believe this is the best solution and the fastest in processing time, since I'll use static screens to produce the game world - like old ATARI games - and the sprites will have a very limited space to move on.
What do you think? I am becoming good in sleeping and programming at the same time, hehehehe.
God is real - except if declared as integer.
Xarcolt
16
Years of Service
User Offline
Joined: 29th Sep 2007
Location:
Posted: 15th May 2019 01:49
Quote: "What do you think? I am becoming good in sleeping and programming at the same time, hehehehe. "

I like it xD

Login to post a reply

Server time is: 2024-03-28 13:20:56
Your offset time is: 2024-03-28 13:20:56