Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (113)
games submitted by our members
Games in WIP (562)
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  
  Best collision pixel perfect system EVER, without physics (T_T)  (Read 2341 times)
0 Members and 1 Guest are viewing this topic.
Offline 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

Hello, %username%!
Offline 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  
// CHECK
collides(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 ENTITY
void 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  
// 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;
}

Hello, %username%!
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« 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.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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.
Offline 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.
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


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

Offline matheus23

JGO Kernel


Medals: 107
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:
Please, help! T__T

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

Senior Member


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.
Offline 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.

Offline iox

Junior Newbie





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

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

Hello, %username%!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Kernel


Medals: 107
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.
https://www.google.de/search?q=platformer+jump+gravity+site%3Ajava-gaming.org

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

Junior Newbie





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

Okay.jpg
I apologize for the stupid question.

Hello, %username%!
Offline wreed12345

JGO Knight


Medals: 24
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

Offline matheus23

JGO Kernel


Medals: 107
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 Cheesy

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline 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.

Hello, %username%!
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.

Dwinin (15 views)
2014-09-12 09:08:26

Norakomi (45 views)
2014-09-10 13:57:51

TehJavaDev (57 views)
2014-09-10 06:39:09

Tekkerue (26 views)
2014-09-09 02:24:56

mitcheeb (49 views)
2014-09-08 06:06:29

BurntPizza (33 views)
2014-09-07 01:13:42

Longarmx (19 views)
2014-09-07 01:12:14

Longarmx (21 views)
2014-09-07 01:11:22

Longarmx (20 views)
2014-09-07 01:10:19

mitcheeb (30 views)
2014-09-04 23:08:59
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!