Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (736)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (813)
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  
  How to make a little fight jump?  (Read 665 times)
0 Members and 1 Guest are viewing this topic.
Offline Kyokai

Junior Newbie





« Posted 2017-05-14 10:46:53 »

 Grin Hi,

I'm doing a Little Fighter style game and I'm having trouble with the jump.

I have the following code:
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  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
public class Jump{
   
   MainGame game;
   Rectangle player, shadown;    //Rectangle of shadown and player
   boolean inJump = false;         //Stop jump
   float positionY;                     // Position of the character
   float velocityY;                     // Velocity of the character
   float gravity = -450f;            // How strong is gravity
        float initialJump = 0;

   public Jump(MainGame game, Rectangle player, Rectangle shadow) {
      super();
      this.game = game;
      this.player = player;
      this.shadow = shadow;
   }
   
   
   public void upgrade(float delta){
     
      if (inJump) {
         
         if(positionY <= initialJump){
            stop();
         } else {
            player.setPosition(player.x, positionY);
            positionY += velocityY * 0.02f;      // Apply vertical velocity to X position
             velocityY += gravity * 0.02f;        // Apply gravity to vertical velocity  
         }
         
         
      }

         
      game.debugRender.begin(ShapeType.Filled);
      game.debugRender.setColor(Color.GREEN);
      game.debugRender.rect(player.x,player.y, player.width, player.height);
      game.debugRender.setColor(Color.BLACK);
      game.debugRender.rect(sombra.x, sombra.y, sombra.width, sombra.height);
      game.debugRender.end();
         
     
   }

   public void OnJumpKeyPressed()
   {
      if (inJump != true) {
         initialJump = shadown.y + sombra.height;     //Position the start of the jump on the platform / rectangle, shadow              
         positionY = player.getY() + 1;                      //Initial positionY
         emPulo = true;                //Started jump
         velocityY = 300.0f;           //Give a vertical boost to the players velocity to start jump  
      }
     
     
   }
   
   
   //Para o pulo
   void stop(){
        inJump= false;
       velocityX = 0;        
       player.setPosition(player.x, inicialPulo);
   }


This works well on a fixed platform, But my platform moves, In case my platform is the shadow.


I'm trying to make this jump:
Quote
The shadow platform walks up and the jump follows


My projec testt xD
Quote

 Smiley thank for help  Grin

Offline Kyokai

Junior Newbie





« Reply #1 - Posted 2017-05-21 13:50:38 »

 Angry I already got it, thank you very much.
Pages: [1]
  ignore  |  Print  
 
 

 
cybrmynd (138 views)
2017-08-02 12:28:51

cybrmynd (158 views)
2017-08-02 12:19:43

cybrmynd (153 views)
2017-08-02 12:18:09

Sralse (168 views)
2017-07-25 17:13:48

Archive (646 views)
2017-04-27 17:45:51

buddyBro (766 views)
2017-04-05 03:38:00

CopyableCougar4 (1300 views)
2017-03-24 15:39:42

theagentd (1264 views)
2017-03-24 15:32:08

Rule (1237 views)
2017-03-19 12:43:22

Rule (1312 views)
2017-03-19 12:42:17
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!