Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (604) Games in Android Showcase (171) games submitted by our members Games in WIP (653) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Best collision pixel perfect system EVER, without physics (T_T)  (Read 3290 times) 0 Members and 1 Guest are viewing this topic.
iox

Junior Newbie

 « Posted 2013-03-29 17:15:11 »

Sup, community, I'm newbie. I'm creating a game with elements of classic platformer (Mario, etc...) on Slick2D. I made a pixel perfect, quick and simple system collision, I think. You can download and try for yourself. But I have some problems with physics (jump, gravity, acceleration). I learned a lot of stuff, soo... and I have no idea how it works. Please, help! T__T

iox

Junior Newbie

 « Reply #1 - Posted 2013-03-29 17:20:12 »

Oh, sorry...

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17 `// CHECKcollides(Level level) {   boolean result = false;      // TOP      if (is_tile_solid(x+1, y, level)) result = true;      if (is_tile_solid(x+w-2, y, level)) result = true;      // BOTTOM      if (is_tile_solid(x+1, y+h-1, level)) result = true;      if (is_tile_solid(x+w-2, y+h-1, level)) result = true;      // LEFT      if (is_tile_solid(x, y+1, level)) result = true;      if (is_tile_solid(x, y+h-2, level)) result = true;      // RIGHT      if (is_tile_solid(x+w-1, y+1, level)) result = true;      if (is_tile_solid(x+w-1, y+h-2, level)) result = true;   return result;}`

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19 `// MOVE ENTITYvoid move(Level level, int delta) {   float axs = Math.abs(xs);   float ays = Math.abs(ys);   float max = ays;   if (axs > ays) { max = axs; }   float xstep = xs/max;   float ystep = ys/max;   float axstep = Math.abs(xstep);   float aystep = Math.abs(ystep);   while (axs > 0 || ays > 0) {      x += xstep;      if (collides(level)) { x -= xstep; }      y += ystep;      if (collides(level)) { y -= ystep; }      axs -= axstep;      ays -= aystep;   }}`

 1  2  3  4  5  6  7  8  9  10 `// COLLISIONboolean is_tile_solid(float xpos, float ypos, Level level) {   int i = (int) ((xpos) / Level.tilesize);   int j = (int) ((ypos) / Level.tilesize);    if (i >= 0 && i < level.getMapWidth() && j >= 0 && j < level.getMapHeight()) {      if ( level.getMap().getTileId(i, j, Cnst.COLLISION) == Cnst.SOLID ) return true;      else return false;   }   return true;}`

Opiop
 « Reply #2 - Posted 2013-03-29 22:22:54 »

First, what specifically is your problem? No one can help you if you don't actually tell us what is wrong. Second, you know you just gave out the source code to your game right? On your website, you need to actually export the .jar file instead of giving us your workspace.

Sammidysam
 « Reply #3 - Posted 2013-03-29 22:40:45 »

If you are using Slick2D you could use Rectangles for collision.  They're pretty simple and easy to use.
tyeeeee1
 « Reply #4 - Posted 2013-03-29 23:27:57 »

First, what specifically is your problem? No one can help you if you don't actually tell us what is wrong. Second, you know you just gave out the source code to your game right? On your website, you need to actually export the .jar file instead of giving us your workspace.

I believe that this post was just to show off the code that he wrote. I've based this conclusion off of the topic title.
Opiop
 « Reply #5 - Posted 2013-03-29 23:35:28 »

First, what specifically is your problem? No one can help you if you don't actually tell us what is wrong. Second, you know you just gave out the source code to your game right? On your website, you need to actually export the .jar file instead of giving us your workspace.

I believe that this post was just to show off the code that he wrote. I've based this conclusion off of the topic title.

Ah I feel stupid now. OP, sorry for the criticism!

matheus23

JGO Kernel

Medals: 122
Projects: 3

You think about my Avatar right now!

 « Reply #6 - Posted 2013-03-29 23:40:26 »

I believe that this post was just to show off the code that he wrote. I've based this conclusion off of the topic title.

But I think he's still looking for help:

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Axeman

Senior Devvie

Medals: 7

 « Reply #7 - Posted 2013-03-30 00:35:20 »

But I have some problems with physics (jump, gravity, acceleration). I learned a lot of stuff, soo... and I have no idea how it works. Please, help! T__T

Check this out: http://www.java-gaming.org/topics/how-to-start-with-lwjgl-physics/29112/view.html

ItÂ´s got a couple of really good links where you can read up on game physics.
relminator
 « Reply #8 - Posted 2013-03-30 10:53:38 »

You know this:

 1  2  3  4  5  6  7  8  9  10  11 `  // COLLISION   boolean is_tile_solid(float xpos, float ypos, Level level) {   int i = (int) ((xpos) / Level.tilesize);   int j = (int) ((ypos) / Level.tilesize);    if (i >= 0 && i < level.getMapWidth() && j >= 0 && j < level.getMapHeight()) {      if ( level.getMap().getTileId(i, j, Cnst.COLLISION) == Cnst.SOLID ) return true;      else return false;   }   return true;}`

This isn't a pixel-perfect test right?

Unless your map itself is made of game pixels which is quite a memory hog.

iox

Junior Newbie

 « Reply #9 - Posted 2013-03-30 20:51:59 »

Sorry, that is not expressed. I need a pseudocode of jump & gravity.

matheus23

JGO Kernel

Medals: 122
Projects: 3

You think about my Avatar right now!

 « Reply #10 - Posted 2013-03-30 22:24:27 »

Sorry, that is not expressed. I need a pseudocode of jump & gravity.

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
iox

Junior Newbie

 « Reply #11 - Posted 2013-03-30 22:37:01 »

Okay.jpg
I apologize for the stupid question.

wreed12345

JGO Knight

Medals: 25
Projects: 2
Exp: 2 years

http://linebylinecoding.blogspot.com/

 « Reply #12 - Posted 2013-03-30 22:39:13 »

http://www.java-gaming.org/topics/making-a-sprite-jump/28350/msg/257412/view.html
definitely check that out! I asked a similar question about jumping / gravity

matheus23

JGO Kernel

Medals: 122
Projects: 3

You think about my Avatar right now!

 « Reply #13 - Posted 2013-03-30 22:48:08 »

http://www.java-gaming.org/topics/making-a-sprite-jump/28350/msg/257412/view.html
definitely check that out! I asked a similar question about jumping / gravity

Ha ha. Exactly what i was originally thinking Tod post, but couldn't find it

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
iox

Junior Newbie

 « Reply #14 - Posted 2013-03-30 22:55:02 »

http://www.java-gaming.org/topics/making-a-sprite-jump/28350/msg/257412/view.html
definitely check that out! I asked a similar question about jumping / gravity
Thanx! When I'm done, I'll share source code.