Scroller game mechanics

I just released my first game with an actual objective and would like to start another project along with it. I have never really made any type of sidescroller game. Only in Slick2D witth thenewboston’s tutorial. Anyways, How would a simple sidescroller work like Mario.

https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcR396HTkFSabZMXWmOmKLemShF_bPA3LnsPylrYcYsUvD5nVym9tQ

Once I get the hang of that, I want to move on to a multidirectional scroller like The Legends Of Zelda(Big fan).

http://t0.gstatic.com/images?q=tbn:ANd9GcQN5ClXOKGdufr-ayHLI9CmQeed_D9f0QYo-dPtwGCotkCWQ5oM

I have an idea of how to make one with different rooms that don’t scroll. Here’s an example of what I mean.

This would just be a screen size level and each room(yellow rectangle) would take you to another room. Maybe some kind of array of strings for each level?

Okay, besides the scrolling aspect of the game, how would gravity work? I made some kind of gravity simulator for testing, but I think every time you jump your velocity y increases until you hit the floor(or collision platform).

Finally, I’d like to ask, what is the best book you guys have used as a game development resource. Something that explains more on game mechanics.

Thanks, and happy coding :stuck_out_tongue:

I would most likely use JBox2D its a physics engine from the start. Only problem is that it’s pretty complicated. So, you could do something like this:


public void update() {
     EveryEntitesY += gravityAmount;
}

//In the player

public void jump() {
     playerX -= gravityAmount + 13;
}

This would look really jumpy though. :stuck_out_tongue:

Thanks and I could try to fix it up a bit.

Is JBox2D a usable library or just a game engine? If it is a game engine are you telling me to somehow use it with LWJGL or make the game separately with it?

I saw a tutorial that helped me with it. Now I’m trying to understand why my rectangle moves the opposite direction.

I have a float for translation

float translate_x = 0;

In my while loop I call these methods

glTranslatef(translate_x, 0, 0);


			if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
				translate_x += 5;
			}

This is the rectangle I’m drawing(I did use glpush and pop)

glColor3f(250, 0, 0);
			glBegin(GL_QUADS);
			glVertex2i(400, 400); // Upper-left
			glVertex2i(450, 400); // Upper-right
			glVertex2i(450, 450); // Bottom-right
			glVertex2i(400, 450); // Bottom-left
			glEnd();

Whenever I press down on d, the rectangle moves the opsite direction or where I want it to move. Why so?

If any of you have made a sidescroller game, would you use camera movement to move the screen or the translation?

This could be because your projection is wrong. Like flipped around, if you could post your ‘Opengl setup’ I could check that.

I move the camera, if you have other movement going on independent from the scrolling, for example it only scrolls when you are near the edge then moving the camera is easier, instead of working out the new translation, but if you want the ‘player’ on the same part of the screen constantly then you can just translate.

Thanks, I figured out how to center the player with translate, but camera sounds a bit smoother. I’ll probably apply it once I learn some more camera functions. ;D

Hello,

I just completed code for stopping the camera to scroll when it reaches the map bounds. Firstly, here’s how I do the camera in rendering:

graphics.drawImage (image, x-xCamera, y-yCamera, null);

Do this for your rendering method for players, tiles* anything you want to scroll.

This Is very simple. If you set the xCamera to 30, everything would be drawn 30 pixels to the left.

Alright, so that’s the camera. He’s how to center the camera on the screen:

public boolean stop = false;

if (stop) return: //if stop is true camera want scroll

xCamera = player.x - (screenWidth / 2);
yCamera = player.y - (screenHeight / 2);

Run these on your update tick.

If you ever want the camera to stop, simply make stop = true.

To stop the camera from scrolling below the x of 0, simply:

if (cameraX <0) cameraX = 0;

Same for max map, but check if the cameraX + screen width Is less then map max.

I hope this helps :wink:

Btw this is mainly for a top down legend of zwlda type gams, but it’ll work for 2d. Also respond with any questipns :stuck_out_tongue:

It’s pretty easy using Libgdx with Tiled maps and Box2D after you set up the Camera and Box2d world. Just keep centering the camera on the player’s position for scrolling. Let box2d handle all the physics.