Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Game Mechanics / Re: Stopping from a jump on: 2012-03-28 15:11:46
That's clear. Thank you a lot for your replys. I think it's all right for the moment.
You and _Riven (on IRC) helped me a lot. Thank you again!
2  Game Development / Game Mechanics / Re: Stopping from a jump on: 2012-03-28 14:02:12
Is it a good thing to implement the frame management inside a State object?

I mean...

When the player jumps, the jump animation is needed. When the player falls, the fall animation is needed. The jump and fall animation are 4-5 frames long. I wonder if it is a good thing to encapsulate the frame-changing mechanism inside the State object. The State interface will be like this:

1  
2  
3  
4  
5  
6  
7  
public interface State {
   void enter();  
   void process();
   void exit();  
   void onInputEvent();  
   BufferedImage getCurrentFrame();
}


Is this a violation of the State Pattern?
3  Game Development / Game Mechanics / Re: Stopping from a jump on: 2012-03-28 11:38:17
Look up for finite state machines or keep asking  Smiley

I googled up "finite state machines" and now I'm asking. Smiley (dear administrator, smileys in this site are ugly Sad)
I found some examples on how to implement finite state machines in Java, but how can I implement them in a game? Can you (or someone else) give me a 10-lines example for the states JUMPING, FALLING, LANDED, please?

--------
EDIT:

I mean an example of finite state machine coded into classes.
4  Game Development / Game Mechanics / Re: Stopping from a jump on: 2012-03-28 07:38:43
* You could set up a state machine for this, with states for MOVING, STOPPING, FALLING, etc. instead of numerous if-statements

This is an interesting point. Can you elaborate more on that?

* Do collision checking with the environment instead using coordinates.

This is my first game and the coordinates check was for testing purposes. Clearly I will implement collision detection with environment objects.
5  Game Development / Game Mechanics / Re: Stopping from a jump on: 2012-03-28 04:40:13
@Antiharpist Thank you for the reply. This is the code I written. It works for now.

These are the enums:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
   private static enum XMovement {
      MOVING, STOPPING, STOPPED;
   }
   
   private static enum YMovement {
      JUMPING, FALLING, LANDED;
   }
   
   private XMovement xMovement = XMovement.STOPPED;
   private YMovement yMovement = YMovement.LANDED;


I had to break the _jumpAnimator in two pieces:
  • The first is named _jumpAnimator and it calculates the y position from the beginning to the vertex of the parabola;
  • The second is named _fallAnimator and it calculates the y position from the vertex of the parabola to the end.

This is the code of interest in the tick() method.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
      if (_controls.getKey(Controls.JUMP_BUTTON).isDown)
         if (yMovement == YMovement.LANDED) {
            yMovement = YMovement.JUMPING;
            _jumpAnimator = new JumpAnimator(JUMP_DURATION, JUMP_HEIGHT, position.y);
         }
     
      if (yMovement == YMovement.FALLING) {
         _fallAnimator.tick();
         position.y = _fallAnimator.getValue();
      }
     
      if (yMovement == YMovement.JUMPING) {
         _jumpAnimator.tick();
         position.y = _jumpAnimator.getValue();
         
         if (_jumpAnimator.finished()) {
            _fallAnimator = new FallAnimator(JUMP_DURATION, JUMP_HEIGHT, position.y);
            yMovement = YMovement.FALLING;
         }
      }
     
      if (yMovement == YMovement.FALLING) {
         /* For testing the ground is at y = 200 */
         if (position.y >= 200) /* This is ugly. The fall animator returns double values and it's hard that the value returned it's equal to 200.00 */
            position.y = 200;
            yMovement = YMovement.LANDED;
      }


It works, but I don't think it's what that can be said beautiful code.
Every comment/suggestion is appreciated. I want to make good code first.
6  Game Development / Game Play & Game Design / Re: SUI on: 2012-03-27 15:45:45
From a JFrame constructor call:

1  
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

7  Game Development / Game Mechanics / Re: Stopping from a jump on: 2012-03-27 11:03:18
Well, at the moment the if statement is not very nice. But here it is:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public void tick() {
      [ some code ]
     
      if (_status == JUMPING) {
         jumpAnimator.tick();
         position.y = jumpAnimator.getValue();
      }

      /* check if the player reached the bottom */
      if (position.y >= (int) 512 * 3 / 4 - 32) {
         _status = STOPPED;
      }
   }


Where 512 * 3 / 4 is the height of the screen and 32 is the height of the player.
8  Game Development / Game Mechanics / Re: Stopping from a jump on: 2012-03-27 11:00:43
If you mean

1  
2  
3  
4  
5  
6  
      if (_status == JUMPING) {
         jumpAnimator.tick();
         position.y = jumpAnimator.getValue();
      } else if (/* reached the bottom */) {
         _status = STOPPED;
      }


It doesn't work. It doesn't change the state to STOPPED.
9  Game Development / Game Mechanics / Stopping from a jump on: 2012-03-27 10:34:36
Hi, this is my first post here.
I'm developing my own 2D platform game. I'm only at the beginning. Now I'm trying to make the player jump.
The jump itself works fine but I'm not able to stop the player. Here is some code:

1  
2  
3  
4  
5  
6  
7  
8  
   public void tick() {
      [ some code ]
     
      if (_status == JUMPING) {
         jumpAnimator.tick();
         position.y = jumpAnimator.getValue();
      }
   }


jumpAnimator is an object that calculates the current y position. It works very well and the jump follows a realistic curve.
I want the player jumping, falling and when he reaches the bottom of the screen, stopping.
To stop the jump my idea was to set the _status variable to STOPPED when the player reaches the bottom of the screen.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public void tick() {
      [ some code ]
     
      if (_status == JUMPING) {
         jumpAnimator.tick();
         position.y = jumpAnimator.getValue();
      }

      if ( /*reached the bottom*/ ) {
         _status = STOPPED;
      }
   }


If I add those lines, the player won't jump anymore because he starts to jump and immediately set his _status to STOPPED.

Any idea?
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

Dwinin (28 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (73 views)
2014-09-10 06:39:09

Tekkerue (37 views)
2014-09-09 02:24:56

mitcheeb (57 views)
2014-09-08 06:06:29

BurntPizza (44 views)
2014-09-07 01:13:42

Longarmx (27 views)
2014-09-07 01:12:14

Longarmx (34 views)
2014-09-07 01:11:22

Longarmx (34 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
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!