Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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 209 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.

 

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

The first screenshot will be displayed as a thumbnail.

Longarmx (39 views)
2014-10-17 03:59:02

Norakomi (30 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (57 views)
2014-10-14 00:39:48

TehJavaDev (58 views)
2014-10-14 00:35:47

TehJavaDev (48 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!