a mario like game

Started by Hardcoal, February 22, 2018, 04:27:54

Previous topic - Next topic

Hardcoal

Hi.. a rookie question..
when you want to make a scroll game like mario bros ..
how exactly do you do the collision?

A) do you use physics engine?
B) Non physical engine?
C) You create your own collision system

I will be glad to see a simple code for a collision game in blitmax if possible..

Thanks and God bless..
Code

Qube

2D Mario games would not of used any physics engines as they would of been a complete system hog. A lot of modern newbie coders automatically dive on 2D physics for 2D platform games ( for obvious reasons ) but 99% fail as they just assume that the physics engine will handle all the jumping / gravity and collisions without any work on their side. 2D physics only works well on a 2D platformer when you know how to code a 2D platformer. There are no super simple shortcuts to skip the core hard work.

I can't state exactly how Mario worked but I'm pretty sure it was pretty much all tile based calculations with offsets and perhaps even distance between x1 / y1, x2 / y2.
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

Hardcoal

i know that physics is not the right approach ,, although i try to adapt some way using it..
but blitz3d collisions should do the trick..
I dont mind programing my own collision system..
i am just interested to hear about different approaches of collisions methods on this type of games..
Code

Qube

I really wouldn't go down the physics route for a 2D platform game. I think you'd end up coding way too many work arounds to accommodate the reactions. I do think you'd be better off controlling the world as you want it to be.

As already mentioned regarding collisions there aren't really many methods. Disregarding a whole physics engine then you're just left with tlle based with offset, distance based and of course pixel collision. Very few do pixel perfect collision these days
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

iWasAdam

original mario games are based on single 2d screen of data.
scrolling was done by shifting the screen and drawing the next column of tiles
redraw was hidden by wider borders at the sides

There were a lot of custom hardware tricks used, to make a static screen look like it was scrolling.

Derron

There are literally 100s of side scrolling tutorials on the web.

Basically you check if you collide with a tile - if you collide with a tile you could do the better collision detection (eg. for slopes).
"Mario" would have basic gravity applied everytime, jumping brings in "upwards force". Then it is pure math ...


http://higherorderfun.com/blog/2012/05/20/the-guide-to-implementing-2d-platformers/
or
https://gamedevelopment.tutsplus.com/tutorials/basic-2d-platformer-physics-part-7-slopes-groundwork--cms-28472


bye
Ron

RemiD

#6
i would do a 2 passes collisions detection :
the screen would be divided in tiles (square areas)


;before moving the entity, store its old position
;depending on its movement vector, calculate the new position
;check if turningmoving entity will be in an area having "obstacles tiles" (or you could use radiuses and a distance check)
;if yes
;check if the outline (pixels) of the turningmoving entity intersects with the outline (pixels) of the obstacle
;if yes
  ;move it back at its original position and do a unit by unit (pixel by pixel) movement before the 2 outlines (pixels) intersect to find the appropriate repositionning position and collision point
;if no
  ;position the turningmoving at the new position
;if no
;position the turningmoving at the new position


for a turningmoving entity which is moving fast, you will have to check for a possible collision with an obstacle in all the tiles around the vector from oldposition to newposition, to prevent the turningmoving entity to go through obstacles...

iWasAdam

Similar to what RemiD said.
I wrote a mario-like game a few decades back. It used a tile based grid.

You just need to check the current tile you are on/near. The same for any enemies.

Think of a tile as:
no contents - can move
blocked contents - movement is blocked - check that dropping/falling wont put you inside this tile!
various diagonals - same as blocked, but you can occupy part of the tile - this can be extended to automatic sliding in a certain direction

This first test would be blocked and non-blocked tiles (don't even start without getting this working 100% first)

Hardcoal

#8
I still want to experiment with physics as well..
but thanks for all the tips..
I've being and still is, busy more on the editor.. than on making games :)

I can do 100 times the same thing until i get it right.. if i have a good mood.
I dont give up so easy if at all.

For Example, I've built like 10 times map editors and everytime i learn something new..
I willing to sacrifice experiments.. as long as I get what I want..

Thats one reason I came to the conclusion that IDE's arnt so Efficient as I want them to be..

I've seen some IDE's that Do some of the things I desire..
Like a collapsed remarks Section on B4A IDE.. for Android..
So some people do think like I do..
But I know you can do much more..

I'm trying various methods because eventually I Do want to make Games

Im trying direct approach without and Editor Framework..
And also simultaneously trying other methods.. and Concepts..
Its like a research as well..

I just really hope something will come out of it eventually..




Code