super mario hill-problem..

Hi, this is my first post at this amazing forum :slight_smile:
I’m making a supermario clone just for fun… It’s fullscreen (640x480) and is based on 32px tiles…

So far the hero ‘detects ground’ whenever the tile is ground. However I want to be able to make hills / slopes to make the game a little less square… How can I do this? I’m thinking that instead of checking if the tile is ground or not, I can somehow check if it’s transparent or not at a certain x,y location?

edit: I meant to put this under the noobies-category… sorry… =)

I’ve never done this, but it does seem interesting so I’ll throw out some ideas. One thing you could do is store a slope with each tile and scale your player’s velocity based on that slope. So for instance, a flat tile that you walk on top of would have a slope of zero and a tile that slopes at a 45 degree angle would have slope 1. So you could do something like:

(avoid dividing by zero)
if(tileSlope != 0)
playerSpeed = playerSpeed/(2*tileSlope);
else
//restore the original player speed

Then you have the problem of needing to change the direction of his movement so it matches the slope. If you are moving your characters using a speed scalar value and a velocity normalized vector, then you just need the velocity vector to match the slope of the tile:

velocity.x = 1-slope;
velocity.y = slope;

and if you aren’t already moving your characters this way, you may want to do it like this:

player.x += velocity.xplayerSpeeddelta (if its a time based game).

You could also represent the collision bounds of the tile using java.awt.geom.Area and figure out the slope and where to place the character on each tile from there. If you are still interested in checking for transparent pixels, I believe you could do this:

int pixelColor = bufferedImage.getRGB(x, y);
boolean isTransparent = (pixelColor & 0xff000000)== 0 ? true : false;

assuming bufferedImage is the BufferedImage representing your tile.

another thing would be which direction your travelling as to know if to slow you down (going uphill) or speed you up (going down hill)

a way i was thinking of doing it myself (as im just using a simple map array and checking on values of the tiles to tell me what they are (ie first 100 tiles for EG are background, 100-15 say are walkable/wall types etc etc)

what I was planning on doing for some diagonals was to say have a couple for the each slope direction, then when we read the tile value for our collision, is to see if its a slope, then depending on the direction were moving, is to either erduce or increase the players speed and then move him accordingly in the appropriate diagonal direction. (hope you understood all that as I sometimes find it hard to describe what it is im getting at! :-/)

edit: just realised its basically what was just said above :-[ ::slight_smile:

Testing for tile transparency is kind of ugly. Instead, I think you should maintain a int[32] companion array for each type of tile that contains height values. This even allow you to do some cool effects like outdoor tiles where mario’s feet are slightly hidden behing grass or such things.

ok, i’ll drop the transparent pixel way… storing a slope for each tile is a good idea, thanks for tips :slight_smile: