Java-Gaming.org Hi !
Featured games (88)
games approved by the League of Dukes
Games in Showcase (679)
Games in Android Showcase (194)
games submitted by our members
Games in WIP (732)
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  
  Ladder System bugs.  (Read 382 times)
0 Members and 1 Guest are viewing this topic.
Offline CTucker1327
« Posted 2013-12-14 22:18:35 »

So, I'm attempting to write a Ladder System using Tiled Maps anyway, i'm using Dermetfans collision from his tutorial series, but I've edited it a bit.

Here's the code that matters

1  
2  
3  
4  
5  
6  
7  
8  
private void handleMovement(float delta) 
   {
      // apply gravity
      gravityMultiplier = 1f;
      if(!((ladderBelow() || ladderAbove())))
      {
         velocity.y -= gravity * delta;
      }



1  
2  
3  
4  
private boolean isLadder(float x, float y) {
      Cell cell = interactiveLayer.getCell((int) (x / interactiveLayer.getTileWidth()), (int) (y / interactiveLayer.getTileHeight()));
      return cell != null && cell.getTile() != null && cell.getTile().getProperties().containsKey("ladder");
   }



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  
   private boolean ladderBelow() {
      for(float step = 0; step < playerSprite.getRegionWidth(); step += collisionLayer.getTileWidth() / 2)
         if((isLadder(getX() + step, getY())))
            return true;
      return false;
   }
   
   private boolean ladderAbove() {
      for(float step = 0; step < playerSprite.getRegionWidth(); step += collisionLayer.getTileWidth() / 2)
         if(isLadder(getX() + step, getY() + playerSprite.getRegionHeight()))
            return true;
      return false;
   }

   public boolean collidesBottom() {
      for(float step = 0; step < playerSprite.getRegionWidth(); step += collisionLayer.getTileWidth() / 2) {
         if(isCellBlocked(getX() + step, getY())) {
            if(ladderBelow()) {
               if(velocity.y < 0 && !Gdx.input.isKeyPressed(Keys.S))
                  return true;
               else
                  return false;
            }
            return true;
         }
      }
      return false;
   }




1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
@Override
   public boolean keyDown(int keycode) {
      switch(keycode) {
      case Keys.W:
         if(canJump) {
            velocity.y = playerSpeed / 1.8f;
            canJump = false;
         }
         break;
      case Keys.A:
         velocity.x = -playerSpeed;
         isMoving = true;
         break;
      case Keys.D:
         velocity.x = playerSpeed;
         isMoving = true;
         break;
      case Keys.S:
         velocity.y = -playerSpeed;
         isMoving = true;
         break;
      }
      return true;
   }



Basically, when I get to a ladder, and i tap W or D it flies all the way down it, I guess because it's checking to see if there's collision and it says no, so the velocity is never set back to 0, and in turn just multiplies until I hit something with collision? (My guess)

If I tap W, I fly up the ladder, and then "jump" off the top of it, before landing back ontop of the ladder, (But I'm standing ontop of the ladder block, instead of just on the block in general, like I should be. It's hard to explain, so I have it uploaded for you guys) --  Download: https://www.mediafire.com/?h4j943is7uvat5h
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 
Hydroque (16 views)
2016-05-26 14:45:46

Mac70 (38 views)
2016-05-24 21:16:33

theagentd (42 views)
2016-05-14 18:38:35

theagentd (76 views)
2016-05-10 22:37:41

theagentd (82 views)
2016-05-10 22:33:46

IanParcs (110 views)
2016-04-18 14:18:53

KaiHH (106 views)
2016-04-18 08:35:41

KaiHH (130 views)
2016-04-15 12:43:58

theagentd (134 views)
2016-04-14 02:16:17

theagentd (157 views)
2016-04-14 02:15:43
FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50
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!