Jump to content
  • Advertisement
Sign in to follow this  

Mario style Side scroller in allegro

This topic is 2155 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all ,

Im new to game programming and just finished my first side shooter using Allegro . 

Now i want to goto something more complex like a mario style side scroller . 

How do I actually go about it   ? In the game I implemented , all the characters and sprites were in one fixed window which didnt move . How do I do a dynammically moving screen in which sprites come as the player moves forward. Do I simply check the x-axis value and spawn characters based on it or is there some other more elegant method ? 

Any help would be appreciated 


Share this post

Link to post
Share on other sites

You need to add a camera position. Just an x/y position, which you subtract from the position of sprites and backgrounds before drawing them.


In your current game, if you have a sprite at position (50, 100), it will be drawn right there on the screen. But if the camera position is, say, (30, 0), then you subtract it from the sprite position before drawing, thus drawing the sprite at position (20, 100). That is, moved left on the screen, because the camera is moved right in the world. Then you can place enemies anywhere you want in the world, far away from position 0, and the player can walk out there and find them.


Normally you want the camera to follow the player, with the player centered on the screen, so set it to (playerX - halfScreenWidth, playerY - halfScreenY). Although you might check if the results are negative, and if so, set to 0. Depends on whether your background drawing code can deal with negative positions.


Are you currently using a tile based background system, or just blitting a bitmap to the screen before drawing sprites?


Oh, and here's a little Mario style game I whipped up in a 2 day coding frenzy for a little competition a few years ago. It uses Allegro, but I wrote my own drawing code just cause I like to do that instead of using library blit functions. But the usage of them should be pretty much the same.



Edited by DekuTree64

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!