TILE-BASED GAME HELP....
I''m creating a mario type side-scroller game. Here''s my problem:
I''m not sure how to create moving platforms in the game. I know that there is probably a really easy explanation for this, but I''m kind of new to these types of games. First, i thought that i could use the background tiles and just keep changing the platform tiles up or down a row. But then i realized that because the tiles are 32x32, it wouldnt look good since they could only move 32 pixels at a time ( it would look really choppy). Please help me.
p.s. i''m talking about the ones like in Super Mario 3, (the ones that move along a black line)
thanks
You need to offset the sprite for your platform. Draw the background and then draw the platform at whatever position you need.
Several billion trillion tons of superhot exploding hydrogen nuclei rose slowly above the horizon and managed to look small, cold and slightly damp.-The Hitchhiker's Guide to the Galaxy by Douglas Adams
To move the platform, interpolate its position.
The function excpects an array for Platforms somewhere, each of them having some variables for:
Time - Time since creation of the platform.
x, y - Current coordinates of the platform.
Waypoints - Array of waypoints the platform moves to.
NumWPs - Number of Waypoints in the array.
This code is kept simple: The Platform always takes 100 loops to go from one waypoint to another, not taking into account the distance. (Wether the next waypoint is 50 pixels away or 1000, the platform will take 100 loops). You may want to make Platform.time a float and increase it by 1/100 of the distance between the two waypoints. Or insert a speed variable to replace the above 1/100 with speed/1000 or so.
Anyway, interpolation is just linear, using
newpos = source + ((target - source) / 100 * percentage_of_way_traveled);
for interpolation.
-Markus-
class CMoverWP { int m_nX; int m_nY; inline void SetPos(int x, int y) { m_nX = x; m_nY = y; }};//Platform[0].Waypoints = new CMoverWP[3];Platform[0].Waypoints[0].SetPos(100, 100);Platform[0].Waypoints[1].SetPos(150, 20);Platform[0].Waypoints[2].SetPos(200, 20);//void MovePlatforms() { int wp1, wp2; int x, y;// wp1 = Platform[0].CurrentWP; wp2 = Platform[0].CurrentWP + 1; if(wp2 > Platform[0].NumWPs) wp2 = 0;// x = (Platform[0].Waypoints[wp2].x - Platform[0].Waypoints[wp1].x); y = (Platform[0].Waypoints[wp2].y - Platform[0].Waypoints[wp1].y);// Platform[0].x = Platform[0].Waypoints[wp1].x) + (x * 100 / Platform[0].time); Platform[0].y = Platform[0].Waypoints[wp1].y) + (y * 100 / Platform[0].time); Platform[0].time++;// return;}
The function excpects an array for Platforms somewhere, each of them having some variables for:
Time - Time since creation of the platform.
x, y - Current coordinates of the platform.
Waypoints - Array of waypoints the platform moves to.
NumWPs - Number of Waypoints in the array.
This code is kept simple: The Platform always takes 100 loops to go from one waypoint to another, not taking into account the distance. (Wether the next waypoint is 50 pixels away or 1000, the platform will take 100 loops). You may want to make Platform.time a float and increase it by 1/100 of the distance between the two waypoints. Or insert a speed variable to replace the above 1/100 with speed/1000 or so.
Anyway, interpolation is just linear, using
newpos = source + ((target - source) / 100 * percentage_of_way_traveled);
for interpolation.
-Markus-
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement