Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Scroller game mechanics  (Read 1389 times)
0 Members and 1 Guest are viewing this topic.
Offline AppleSauce
« Posted 2014-05-11 20:58:49 »

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.


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

 
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  Tongue
Offline Jacob Pickens
« Reply #1 - Posted 2014-05-11 22:46:40 »

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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
public void update() {
     EveryEntitesY += gravityAmount;
}

//In the player

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


This would look really jumpy though. Tongue
Offline AppleSauce
« Reply #2 - Posted 2014-05-11 22:50:37 »



1  
2  
3  
4  
5  
6  
7  
8  
9  
public void update() {
     EveryEntitesY += gravityAmount;
}

//In the player

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


This would look really jumpy though. Tongue

Thanks and I could try to fix it up a bit.
Quote
I would most likely use JBox2D its a physics engine from the start. Only problem is that it's pretty complicated.

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?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline AppleSauce
« Reply #3 - Posted 2014-05-12 03:04:52 »

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
1  
float translate_x = 0;


In my while loop I call these methods
1  
2  
3  
4  
5  
6  
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)
1  
2  
3  
4  
5  
6  
7  
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?
Offline AppleSauce
« Reply #4 - Posted 2014-05-12 18:15:43 »

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

Senior Member


Medals: 2
Projects: 1
Exp: 1 year


¬..¬


« Reply #5 - Posted 2014-05-12 20:28:32 »

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

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


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

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.
Offline AppleSauce
« Reply #6 - Posted 2014-05-13 00:26:35 »

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

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


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

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.  Grin
Offline JPG2000

Junior Newbie





« Reply #7 - Posted 2014-07-02 04:35:34 »

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 Tongue


Offline Rayexar

Junior Member


Medals: 2
Exp: 5 years



« Reply #8 - Posted 2014-08-14 10:12:06 »

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.
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (41 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!