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  
  Sidescrolling Plattforms  (Read 674 times)
0 Members and 1 Guest are viewing this topic.
Offline Zushii

Senior Newbie





« Posted 2011-03-22 21:14:10 »

Hello.

As Plattforms I use lines. the lines are horizontal at any given height.

      ----------
O
=======================

O : player
= : ground (also line)
- : plattform

Now I used to place a rectangle around the player and ask if the line intersects the rectangle, but this led to the player just touching the plattform and immediatly being placed on the plattform. even if he wanted to walk beneath it and it wasn't very high.

So I tried telling him, to only place the player on the plattform if the Y-Axis value was the same as the Y-Axis value of the line.

Code:


Rectangle r3 = player.getBounds();

      for (int j = 1; j<boxes.size(); j++) {
         Line2D linie = (Line2D) boxes.get(j).makeLine2D();
         
         if (r3.intersectsLine(linie) && player.getY()+player.getImage().getHeight(null) ==  linie.getY1() ) {
            lineIntersected = true; //its a global boolean
            player.setDy(0);         //stop falling
            player.setY(linie.getY1()-player.getImage().getHeight(null)); //place player on plattform
            player.setCurrentY( (int) linie.getY1());                             //this is just for animations, so it knows where to place them
            
         } else if (!r3.intersectsLine(linie) && lineIntersected) {
            lineIntersected = false;
            
            player.setDy(-1); // move down (falling)
         }
         
         
         
         
      }


This is part of my CheckCollision routine.

It's total bullox and only works half ways if I delete the "else if". Can anybody help me? Maybe you got a better idea how to make plattforms. they need to be placeable where I want them.


I'd be so very greatful Cheesy
Offline Kieran Newland

Senior Newbie





« Reply #1 - Posted 2011-03-22 21:23:25 »

I think the problem here is that you are checking if you have intercepted the line, moved to your position and then checked the line to see if it has been intercepted again when you remove the else if. I would make a variable that holds the answer if the line is intercepted and use that for both if statements.
Offline Karmington

Senior Duke


Medals: 1
Projects: 1


Co-op Freak


« Reply #2 - Posted 2011-03-23 00:54:25 »

jumping upwards, the moment you collide you are teleported to the top.
right now the platform tells the player where the player is.

player should just be a rectangle floating in space, until it gets gravity or movement commands or bumps into stuff.

the idea is to split it up more :

the player is continually affected by gravity Dy - his natural state is to fall
but, If there is floor under the player, he stays where he ( collides and ) stays on the platform
otherwise gravity takes place and he is dropping

you could for example test only the bottom of the player box downwards, to check whether the feet hit ground.
the collision tells you where the ground is, and the player accepts that he is not falling anymore

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Zushii

Senior Newbie





« Reply #3 - Posted 2011-03-23 10:23:43 »

Okay. I changed that the plattforms tell the player where he is.
Also moved around some of the code.


Now he always falls. But stops falling if he is told to. But then falls again when leaving a plattform.

It works now Smiley

Thanks for the tipps. Cheesy
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 (36 views)
2014-10-17 03:59:02

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

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

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

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

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

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

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

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

BurntPizza (77 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!