Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 1486 times)
0 Members and 1 Guest are viewing this topic.
Offline Zushii

Senior Newbie

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


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


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.


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 Devvie

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  

EgonOlsen (79 views)
2018-06-10 19:43:48

EgonOlsen (59 views)
2018-06-10 19:43:44

EgonOlsen (78 views)
2018-06-10 19:43:20

DesertCoockie (261 views)
2018-05-13 18:23:11

nelsongames (159 views)
2018-04-24 18:15:36

nelsongames (158 views)
2018-04-24 18:14:32

ivj94 (901 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (813 views)
2018-03-24 14:43:53

Solater (177 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

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