Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (734)
Games in Android Showcase (222)
games submitted by our members
Games in WIP (811)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 2 [3] 4 5 ... 10
 21 
 on: 2017-08-19 15:00:49 
Started by otoomey - Last post by otoomey
I am writing a hud for a project, and because I want to do some complex drawing I want to use a powerful 2D rendering library (like Java2D). My idea is to draw into the BufferedImage whenever the UI needs to update, then take the pixel data from the bufferedimage and bind it into an OpenGL texture buffer. I can then draw the texture on top of my game every frame.

Am I insane? -> yes. But is it really crazier then drawing 2D stuff in OpenGL?

The part that I need help with specifically is transferring the bufferedimage data into the texture buffer. I am using LWJGL.

 22 
 on: 2017-08-19 14:23:35 
Started by cygnus - Last post by otoomey
If you use BufferedImages then Java2D can hardware accelerate your images, making drawing much MUCH faster (Basically java2D puts your image onto the Graphics card). If you use pixel arrays then you lose this optimization.

 23 
 on: 2017-08-19 08:39:41 
Started by pavul - Last post by orangepascal
there's no need to check all tiles every time Smiley

maybe this example helps you get there:

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  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
public final static void example()
{
   int tilex;
   int tileY;

   // sprite horizontal position+speed+width
   int x=24;
   int xSpeed=2;
   int width=16;   // can be any size
   
   // sprite vertical position+speed+height
   int y=64;
   int ySpeed=2;
   int height=16; // can be any size
   
   x+=xSpeed;
   
   // for horizontal movement I usually take the waste-height of my character
   // and check on that..  99% of the time that works, in some case you might want to test at the feet or head height
   // remember, this is for horizontal movement, we aren't testing vertical collisions yet!
   tileY = (y + (height / 2) / 16);
   
   // which direction are we moving in?
   if (xSpeed>0)
   {
      // moving to the right, so check if our right edge hits a wall
      tileX = (x+w) / 16;  // we divide our sprite's right-edge by 16 since our tiles are 16x16 pixels wide
     
      if (tilemap[tileX + (tileY * tilemapwidth)] == solidtile)
      {
         // we hit a solid tile!
         // so correct our position, obviously we couldn't move this far to the right
         // we reset the player on the left edge of the tile we just hit, minus the player's width
         x = (tileX * 16) - width;
      }
   }
   else if (xSpeed<0)
   {
      // moving to the left, so check if our left edge hits a wall
      tileX = (x / 16);  // we divide our sprite's left-edge by 16 since our tiles are 16x16 pixels wide
     
      if (tilemap[tileX + (tileY * tilemapwidth)] == solidtile)
      {
         // we hit a solid tile!
         // so correct our position, obviously we couldn't move this far to the left
         // we reset the player on the right edge of the tile we just hit
         x = (tileX * 16)+16;
      }      
   }
}




Now write a function to do vertical testing, almost the same way, except for the Y-axis Smiley

If you have that up and running, you might want to improve your checking by making the vertical function check not on the sprite's-xAxis-center, but on both the left and right foot.. but don't worry about that too much for now, just try get this up and running!


oh and in case you need some live example, here's one of my opensource projects:
https://bitbucket.org/orangepixel/planet-busters

 24 
 on: 2017-08-19 03:14:13 
Started by pavul - Last post by pavul

simply i cannot do gravity correctly, i have the next things:

( Sprite ) player width:24, height;32

array of tiles:
0 means free
1 means solid tile ( it will  make collision with this )
tile width and height are 16 px

 int [] tileColisionMap = {
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
   
     0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0   
     };


on the update loop i have the next things
{
input : i can move the sprite 2 pixels left and other 2 pixels right

//process gravity for the player
// jump value = 5 &
jumpvalue = -5;
 jumpValue += gravity;
 gravity = 0.37f;           
   
         //every tick the jump get a limit
                if( jumpValue >= jumpForce )
                {
                    jumpValue = jumpForce;
                }
            y += jumpValue;



//after set gravity im checking a collision against each solid tile
//defined in above array

 //this check tile colision against player
                       //basically is puting the solid tiles of the whole level
                       //enemies, usable objects and players may check this colisions
                       if( Collision.getInstance().checkColsionTile(
                       player,
                       tileColisionMap,
                       columns,
                       rows,
                       tileWidth,
                       tileHeigth ).equals( Config.COLISION_BOTTOM ) )
                       {
                             player.setJump( false );
//                             player.setY( player.getY( ) - player.getJumpValue() );
                             System.out.println("::: inside collision "+player.getY() );
                       }//




}


inside that method we have the next code:


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  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
public  String checkColsionTile(Sprite spr,
                int[] colisionMap,
                int cols,
                int rows,
                int tileWidth,
                int tileHeight)
        {
            String side= Config.COLISION_NONE;
            String aux="";
            if(cols <=0 || rows <= 0)
            {
                //arrojar excepcion aqui
            return side;
            }
       
        int mapIndex = 0;
        int totalTiles = cols * rows;
       
        int tilewidth = tileWidth;
        int tileHeigth = tileHeight;
     
      //for de renglones
         for( int i = 0;i < rows; i++ )
            {
                int tiley = i * tileHeigth;
           
                    //for de columnas
                    for( int j = 0 ; j < cols ; j++ )
                    {
                       
                       
                   //@TODO check here if the tile to compute is
                    //near the sprite to collide, to avoid extra process...
                       
                       
                    if( colisionMap[ mapIndex ] == 1)
                     {
                         int tilex = j * tilewidth;
                         
                        side = blockRectangle(spr, tilex, tiley, tilewidth,tileHeigth);
                        if (side.equals(Config.COLISION_BOTTOM))
                        {
                        aux=Config.COLISION_BOTTOM;
                        }
                     
                     }//if validacion si se checa colision
                 
                      if( mapIndex < totalTiles )
                      mapIndex++;
                     
                     
                    }//for cols
            }//for rows
     
//          System.out.println("-checkColsionTile se regreso SIDE: "+side);
       
          if(!aux.equals(""))
          {
          side=aux;
          }
         
          return side;
        }//checkcolisiontile
       


public String blockRectangle(Sprite s1,int x, int y, int width,int height)
   {
            int halfWidth = width / 2;
            int halfHeigth = height / 2;
            int centerX = x + halfWidth;
            int centerY = y + halfHeigth;
           
      String side = Config.COLISION_NONE;        
               
                //get distance vectors
      float vx=s1.getCenterX()-centerX;
      float vy=s1.getCenterY()-centerY;
     
               
      float combinedHalfWidth = s1.getHalfWidth()+halfWidth;
      float combinedHalfHeight = s1.getHalfHeight()+halfHeigth;
           
               
                //collision on x axis
                if( Math.abs(vx) < combinedHalfWidth )
      {
                    //collision on y axis
         if(Math.abs(vy) < combinedHalfHeight)
         {
                           
                            //collision made
                           
            float overlapX=combinedHalfWidth-Math.abs(vx);
            float overlapY=combinedHalfHeight-Math.abs(vy);
     
                            if( overlapX < overlapY )
                                    {
               
               if( vx > 0 )
               {
                                            s1.setX( s1.getX()+overlapX );
                                            return Config.COLISION_LEFT;
               }
               else
               {
                                            s1.setX( s1.getX()-overlapX );
                                            return Config.COLISION_RIGHT;
               }

                                    }//
                                else
   
            {

                                    if( vy > 0 )
               {
                                            s1.setY( s1.getY()+overlapY );
                                            return Config.COLISION_TOP;
                                        }
                                    else
               {
                                           s1.setY( s1.getY()  - overlapY );
                                            return Config.COLISION_BOTTOM;
               }

            }
             


         }//height

                       
      }//width
               
      return side;
     
   }//colision con rectangulos, pero    
       



that collision tile method is supposed to check bottom collision and to put the sprite in the correct place ( must align the player along solid tile )


but the error is that the sprite is stuck when i want to move left
































 25 
 on: 2017-08-18 22:36:30 
Started by Gilmok - Last post by Gilmok
Pathfinding is a large topic as it takes up a large amount of CPU so I wanted to just talk about some things I've been doing to speed up pathfinding for an RTS game I am making.

We all know and love A*, but we do not love its speed.  We know that A* is n^2 over the number of nodes that it expands.  The only thing you can do at this point is seek to reduce the n.

I began with Jump Point search, looking carefully at what points were jump points and which were not.  I found that tiles next to convex corners became my jump points.  My tiles use 4 borders passage (tiles are not just open-closed but have open or closed openings on each of the 4 sides), so some other points also became jump points.  I wrote a function to calculate when a tile gains and loses jump point status based on which of its borders are open.  Now instead of a graph consisting of every tile it just consisted of these jump points.  I built a navmesh of these, which is updated every time a tile gains or loses jump point status.

For a faster jump point search, all tiles have a distance value in all 8 directions to either a wall or a jump point.  Testing adjacency involves dividing the path into diagonal and straight line components and comparing distances (as opposed to walking to each tile and seeing if you hit a wall).  This required me to write methods to update each tile distance whenever a wall or jump point was placed and/or removed.

At this point pathfinding has 2 major costs: finding the isovist (which is the list of jump points that the starting location is adjacent to), and finding the path.  I started with a bi-directional search but I found that finding the isovist was about the same cost as finding the path, so I went back to single direction.  Also, I often have a situation where the starting point is adjacent to hundreds of other points but only few of them actually yield a good path.

To improve the starting point situation,  I divided each point's list of adjacent points into 8 wedges, like a pie.  Every time I expand a node, instead of fully expanding it, I just expand the wedge that contains the best angle to the end point.  As I ran out of nodes in that wedge, I would move around to surrounding wedges.  Now, the A* algorithm works by costing each adjacent node, putting each node into the open list, and selecting the best to expand.  I found that wedging didn't get better performance until I only costed the nodes in the wedge.  This means that I won't always get the best path.  However, my testing shows that the deviance from the best path is usually very small on sparse graphs (0.04 tiles on average) while cutting pathfinding time by a factor of 4. 

I also did try to tackle finding the isovist faster.  The naive approach is to just test the adjacency of each jump point to the starting point.  I also began this other, more involved approach using Formations.

Each jump point on the map is next to a formation (which is an obstacle - think of a rock formation).  To get the formation that a jump point is next to you need to trace out the formation from the navmesh.  To do that you start at a point and use the 8 distance markers in each tile to trace around the edges of the formation until you return to your starting point.

Now that you have all the formations traced out, you can draw a box around them.   This formation list is updated every time you update your graph.

To get the staring point's isovist, cast a beam in all 8 directions.  To cast a beam up, for example, you need the up-right and up-left distances in the tile.  The start of the beam is the tile's x minus the up-right distance, and the beam's width is the up-right distance plus the up-left distance.  Cast this beam up to the top edge of the map (draw a box).  Find all formations that lie in that box, then sort them according to their bottom edges.  Create a bit field containing the visibility lanes in the beam, then eliminate the visibility lanes of each formation in the list.  Record the formations that did hit (and eliminate) visibility lanes.

Repeat the above process for all 8 directions, adding only unique formations.  Then test the adjacency of each point in only the formations you found.

My initial run of this process was quite slow, namely because I was testing the beam against each formation.  My CS program didn't have a class in computational geometry.  After further research I have read about using interval trees, which could be a promising approach to test the collisions between each formation and beam.

Congratualtions for reading this far.  Perhaps you can benefit from my journey in climbing the pathfinding Mt. Everest.

 26 
 on: 2017-08-18 19:38:36 
Started by alphacoder - Last post by FabulousFellini
I think you should do this:  Use straight java to create pong.  That will give you practice with java and how it works.  Then, create pong again using either JavaFx or LibGDX, whichever you prefer, so you can learn about that.  Then, make a 2d platform type game with what you prefer, because if you didn't like JavaFx, you can try LibGDX and you will have a better understanding of what it's doing based off your previous awt/javafx/libgdx knowledge.  Then, try your MMO.

 27 
 on: 2017-08-18 18:29:25 
Started by BurntPizza - Last post by philfrei
Congratulations ra4king!

This week I settled on trying to polish the FM Theremin I wrote a while back, to get it up to a quality where I might post it on itch.io. So far, have made improvements to the GUI, including making panels resizable (giving more "playing" room when the control panel is not needed), and an easier-understand checkbox for whether the "expression" attribute controlled by a slider is a fixed value (independent of Y-axis location) or ranges with the mouse Y position.

I've been slowed down a bit with implementing a decision to eliminate Nyquist aliasing. Am working out a way to automatically scale back the amplitude of the modulator (source of overtones in FM) that takes into consideration the frequency and the degree of modulator feedback. Had to spend time manually listening and charting the frequencies where aliasing kicks in for various modulator Index and Feedback settings, and then on working out good equations/algorithms to fit the data points. It is close to working--last attempt covers the endpoints well but "sags" in the middle. I suspect fixing it is a matter of changing the point at which I reference the data which can be either linear or exponential depending on the stage of the calculation. (E.g., midi notes, piano notes are linear, but the Hz value doubles every 12 steps--do we calculate using the Hz or the midi values?)

Am reminded how important it is as a programmer to learn math for sequences, series and curve-fitting polynomials, as having this handier in memory would have made this much easier to do.

 28 
 on: 2017-08-18 15:53:38 
Started by alphacoder - Last post by pavul
Hello! First post.

1. First of all I wanna ask you guys (I am newb, beware) if would you code a game in Java without using any game engine or thats absolutely stupid idea.

2. Secondly, what do you think about JavaFX for gaming? I know theres libgdx but thats third party.

3. Do you think its possible to create single player game and then change it for MMORPG? Or I will need to start from a scratch while creating MMORPG? Which way is less troublesome?

Thank you!


1.- if you use a game engine will help you to create a game faster without know much about how things work internally, once u are decided to create a game using pure java you will learn how things works and how and most probably you will learn.
2.- javaFx for gaming is ok, if you want to create PC game, libgdx is to create the game for diferent platforms, but using JavaFx will help you to understand how java works and how games can be crated
3.- it is possible but is not recomented when you don't know how to create games, after you have been created a game you have to learn about networks and protocols and after that read a lot of how to crate them, online game is far more difficult.

 29 
 on: 2017-08-18 15:01:07 
Started by pavul - Last post by pavul
yeah no need to do this with Box2D Smiley  it's terrifying to me to see how many people just use box2d for all the simple stuff, that's overkill on math!

this article has good info on any collision detection in platforms:
https://www.gamedev.net/articles/programming/general-and-gameplay-programming/the-guide-to-implementing-2d-platformers-r2936

one extra tip I would give: The order is important, so make sure to do one-direction at a time. 
in code that means:

1. move X to new location
2. detect horizontal walls  (if moved into a wall, revert to correct location in front of wall)
3. move Y to new location
4. detect vertical walls (and correct if needed)

a problem often seen with new devs is doing this:

1. move X,Y to new location
2. detect horizontal walls
3. detect vertical walls

which makes a lot of little bugs happen like suddenly jumping a few pixels, or moving half into tiles, etc.

but most is explained in that article Smiley


you know what, now you mention that is what is happening, im moving two axis instead of one, and actually that is happening because the collision is first evaluation X axis and then Y( it get stuck when I move that on left ), and actually I have like a week seesking the correct way to implement that, lets see you article and thanks so much @orangepascal

 30 
 on: 2017-08-18 13:50:56 
Started by alphacoder - Last post by KaiHH
Array elements inside a byte[] array occupy 1 byte and are 1-byte aligned.
The alignment of class members can be analyzed quickly via OpenJDK JOL.
For the following class declaration:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
class A {
    byte a;
    byte b;
    byte c;
    int d;
    byte e;
    int f;
    float g;
    long h;
    long i;
}

it outputs on a 1.8_141 64-bit HotSpot JVM:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
# Running 64-bit HotSpot VM.
# Using compressed oop with 3-bit shift.
# Using compressed klass with 3-bit shift.
# Objects are 8 bytes aligned.
# Field sizes by type: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]
# Array element sizes: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]

test.Align$A object internals:
 OFFSET  SIZE    TYPE DESCRIPTION                               VALUE
      0    12         (object header)                           N/A
     12     4     int A.d                                       N/A
     16     8    long A.h                                       N/A
     24     8    long A.i                                       N/A
     32     4     int A.f                                       N/A
     36     4   float A.g                                       N/A
     40     1    byte A.a                                       N/A
     41     1    byte A.b                                       N/A
     42     1    byte A.c                                       N/A
     43     1    byte A.e                                       N/A
     44     4         (loss due to the next object alignment)
Instance size: 48 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total

So you can indeed save storage by using byte fields, but it is delicate, since you also have to take care to end your class fields on a 8-byte boundary (for a 64-bit JVM which uses compressed oops). So if your class consists of only 1 byte field it'll occupy exactly as much memory as if you had 1 int field, to make it end on the 16-byte boundary.

So in the end: It is not worth the trouble.

Pages: 1 2 [3] 4 5 ... 10
 
cybrmynd (41 views)
2017-08-02 12:28:51

cybrmynd (57 views)
2017-08-02 12:19:43

cybrmynd (66 views)
2017-08-02 12:18:09

Sralse (79 views)
2017-07-25 17:13:48

Archive (502 views)
2017-04-27 17:45:51

buddyBro (650 views)
2017-04-05 03:38:00

CopyableCougar4 (1136 views)
2017-03-24 15:39:42

theagentd (1137 views)
2017-03-24 15:32:08

Rule (1114 views)
2017-03-19 12:43:22

Rule (1091 views)
2017-03-19 12:42:17
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

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!