Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2
1  Java Game APIs & Engines / Java 2D / Re: Slick2D, play sound at location on: 2013-04-07 19:49:31
but it isn't what I expected.

That not really descriptive.

playAt(x, y, z)  does EXACTLY what you want.
make sure your sound files are MONO or it simply wont work
Care to explain how the method works? What the parameters mean? The method is very poorly documented.
2  Java Game APIs & Engines / Java 2D / Re: Translating XNA method to Slick2D on: 2013-04-04 00:08:01
Do I really need to learn linear algebra? That would require a background of math to, which I dont have.
I checked the Slick2D api and I found a few interesting things but I am stuck at the first line in the method body:
Matrix transformAToB = transformA * Matrix.Invert(transformB);
How do I translate this?

The real problem is that since Slick uses OpenGL for rendering, you won't have access to the color data without performing a copy from GPU to CPU (which can be slow).
Dont worry about that.
3  Java Game APIs & Engines / Java 2D / Translating XNA method to Slick2D on: 2013-04-03 23:04:59
There is a method by Microsoft which perform a pixel perfect collision detection on two sprites. The special thing about this function is that it supports rotations!
Here is the method:

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  
        /// <summary>
       /// Determines if there is overlap of the non-transparent pixels between two
       /// sprites.
       /// </summary>
       /// <param name="transformA">World transform of the first sprite.</param>
       /// <param name="widthA">Width of the first sprite's texture.</param>
       /// <param name="heightA">Height of the first sprite's texture.</param>
       /// <param name="dataA">Pixel color data of the first sprite.</param>
       /// <param name="transformB">World transform of the second sprite.</param>
       /// <param name="widthB">Width of the second sprite's texture.</param>
       /// <param name="heightB">Height of the second sprite's texture.</param>
       /// <param name="dataB">Pixel color data of the second sprite.</param>
       /// <returns>True if non-transparent pixels overlap; false otherwise</returns>
       public static bool IntersectPixels(
                            Matrix transformA, int widthA, int heightA, Color[] dataA,
                            Matrix transformB, int widthB, int heightB, Color[] dataB)
        {
            // Calculate a matrix which transforms from A's local space into
           // world space and then into B's local space
           Matrix transformAToB = transformA * Matrix.Invert(transformB);

            // When a point moves in A's local space, it moves in B's local space with a
           // fixed direction and distance proportional to the movement in A.
           // This algorithm steps through A one pixel at a time along A's X and Y axes
           // Calculate the analogous steps in B:
           Vector2 stepX = Vector2.TransformNormal(Vector2.UnitX, transformAToB);
            Vector2 stepY = Vector2.TransformNormal(Vector2.UnitY, transformAToB);

            // Calculate the top left corner of A in B's local space
           // This variable will be reused to keep track of the start of each row
           Vector2 yPosInB = Vector2.Transform(Vector2.Zero, transformAToB);

            // For each row of pixels in A
           for (int yA = 0; yA < heightA; yA++)
            {
                // Start at the beginning of the row
               Vector2 posInB = yPosInB;

                // For each pixel in this row
               for (int xA = 0; xA < widthA; xA++)
                {
                    // Round to the nearest pixel
                   int xB = (int)Math.Round(posInB.X);
                    int yB = (int)Math.Round(posInB.Y);

                    // If the pixel lies within the bounds of B
                   if (0 <= xB && xB < widthB &&
                        0 <= yB && yB < heightB)
                    {
                        // Get the colors of the overlapping pixels
                       Color colorA = dataA[xA + yA * widthA];
                        Color colorB = dataB[xB + yB * widthB];

                        // If both pixels are not completely transparent,
                       if (colorA.A != 0 && colorB.A != 0)
                        {
                            // then an intersection has been found
                           return true;
                        }
                    }

                    // Move to the next pixel in the row
                   posInB += stepX;
                }

                // Move to the next row
               yPosInB += stepY;
            }

            // No intersection found
           return false;
        }

I am familiar with java so I can translate most of the code myself. width, height and color data I have access to so we dont have to worry about them.
It is the Matrix and Transform classes that confuse me. What is their equivalence in Slick2D? Also, in my game, the rotation of the images is stored as an float.
4  Java Game APIs & Engines / Java 2D / Re: Slick2D, play sound at location on: 2013-03-14 20:39:02
Sound System jPCT supports binding Listener to Camera, thats what I am looking for, right?
5  Java Game APIs & Engines / Java 2D / Slick2D, play sound at location on: 2013-03-14 19:07:48
So, I need help with an algorithm for my 2D Game.
 
Say entity AA is emitting a sound. The strength of the emitting sound is determined by the distance between AA and BB(this could be the main character).
The further away they are, the weaker the sound is. The max distance(pass this distance and the sound volume is 0) is of course customizable.
The volume setting can be from 0.0 to 1.0.
 
Where and when to do these checks is not a problem. I know my engine and I can resolve that. How to check it is the problem.

There is a method in Slick2Ds Sound class called playAt(x, y, z) but it isn't what I expected.

Maybe there already is a way to implement this with Slick2D?
6  Games Center / Showcase / Re: Flesh Boy alpha on: 2013-03-10 22:52:50
And you are using Java 7 to launch this?
7  Games Center / Showcase / Re: Flesh Boy alpha on: 2013-03-10 15:01:42
Thanks for the info.
Please try this one and report back:

http://www.speedyshare.com/XTY8s/OS-Flesh-Boy-Alpha-Mac.rar
8  Games Center / Showcase / Re: Flesh Boy alpha on: 2013-03-10 12:31:14
Added Linux and Mac.
Please check if they work.

If someone need Solaris, hollar!
9  Games Center / Showcase / Flesh Boy alpha on: 2013-03-09 16:54:24
This is a public release of my latest project. I am hoping people will download it and give me some feedback.

Open Source Fleh Boy is a 2d game with a simple concept, you finish a stage by reaching goal. You have a bunch enemies, a time limit and loads of hindrance trying to stop you from reaching there.

Flesh Boy is heavily inspired by Super Meat Boy, N+ and NReality.

Here is an ingame image:



You are that red guy doing a wall slide.

In this release, I wont be showing any features. Instead, I am releasing a test map where you can check and feel the controller.

I am mostly looking for controller feedback, but any type of feedback is appreciated:
- Do you like the controller? Why?
- Would you want to play a game with a controller like this?
- Bugs?
- Other thoughts?

Download:
http://www.gamedev.net/topic/639987-os-flesh-boy-alpha/

Usage:
Extract the content from the rar, launch the executable file.

You need java 7 to run this.
10  Java Game APIs & Engines / Java 2D / Re: Obtain pixel from Image(Slick2D) on: 2013-01-23 18:22:13
I am trying to create a fast pixel-perfect function. The only thing making it ineffective is grabbing the pixels from the Image.
I have made a piss solution, by associating every image with an int[][] array(that represent all the pixels in the image). This array is initiated at loading screen. The results performance wise is fantastic. But it turns my code into a mess, killing the readability. And its not working with rotation.
11  Java Game APIs & Engines / Java 2D / Obtain pixel from Image(Slick2D) on: 2013-01-23 11:32:59
Using image.getColor is afaik performance killer. Is there any other options? Take note that this option should be compatible with rotated images.
12  Java Game APIs & Engines / Java 2D / Re: Adding a trailer behind a missile on: 2013-01-08 02:22:45
ra4king: That lime-green circle is the target. The other dark-greyed-green-line is the smoke, which is incorrectly placed.
But never mind that. I solved it, but a new problem occurred.

I see the problem. This line:
stage.append(trailer.getClone(x, y + realHeight));
This just adds the trailer to the game, it does not render it. That happens later, when the rotation is restored to normal.

So I thought, I use g.renderAnimation instead of stage.append, so I can render it on the method where the rotation is taking place. The trailer is just an graphical effect anyway, with no properties.
I quickly succeed to get the trailer where I wanted.
However, I am getting erroneous results with drawAnimation(org.newdawn.slick.Animation).
It seems like multiple animations that use the very same Image object can not be present at the same time.
Even if I am calling drawAnimation every frame, only one animation is seeable. That is not the only problem, the graphic context is not rendering all frames in the animation. Yepp, for some reason, it is skipping some frames, making it look like it is blinking.
Can anyone explain this?
13  Java Game APIs & Engines / Java 2D / Re: Adding a trailer behind a missile on: 2013-01-07 18:16:19
The green thing is the target.

14  Java Game APIs & Engines / Java 2D / Re: Adding a trailer behind a missile on: 2013-01-07 04:24:31
the trailer is a bit off.
Also, the rotation is insignificant. It the position(i e behind the rocket) that is important.
15  Java Game APIs & Engines / Java 2D / Adding a trailer behind a missile on: 2013-01-06 22:45:02
I know how to add a trailer behind a missile, but I am having trouble getting the right coordinates, the trailer is a bit off.
So, first, I rotate the image so it is facing the target and render it:

1  
2  
3  
4  
float rotation = (float) getAngle(x, y, targetX, targetY);
         
g.rotate(x, y, rotation + 90);
g.drawImage(missile, x, y);


Then, I try to render the trailer behind the missile like this:

1  
2  
3  
4  
5  
if(trailer != null)
{
   g.rotate(x, y + realHeight, rotation + 90);
   stage.append(trailer.getClone(x, y + realHeight));
}

And finally, I make the rotation normal:
Quote
g.rotate(0, 0, 0);

Obviously this doesn't work.
Any one have any idea?
16  Java Game APIs & Engines / Java 2D / Re: Draw a laser(Slick2D) on: 2013-01-06 19:14:34
That laser fx thing gave me an idea. I just draw multiple lines(graphics.drawLine) with smaller strokes and different color on the same coordinates. That would make it look like a real laser.
17  Java Game APIs & Engines / Java 2D / Draw a laser(Slick2D) on: 2013-01-06 02:47:02
I want to render a laser. I could just use graphics.drawLine, but that would draw a plain single colored line.
I want to add some effect. Is there a way to do this?
18  Java Game APIs & Engines / Java 2D / Re: Save/load in java game with Slick2D on: 2013-01-02 19:55:18
I doubt class exists. How is that nonexistent class suppose to know what to save? How is it suppose to know about the variables your games uses when they did not exist when that nonexistent class was developed?
What you have to do, is that when the Save button is pressed, you save all the stats of the game, the health, the position of all the units etc.
19  Java Game APIs & Engines / Java 2D / Re: quickest most effecient way to darken/lighten image on the fly? on: 2012-12-30 19:11:53
I advise you to stay away from Java2D when creating games. Java2D spend more time rendering than for example Slick2D does and, having fps such as 60 or higher is going to cause lag because Java2D can not render so many times per frame. So what is going to happen that it is going to skip rendering some frames, making the game look laggy, but in reality it is just rendering operation that are being aborted. Note that this do not happen on all computers, but you wanna make a game that looks the same on all computer, right?
20  Java Game APIs & Engines / Java 2D / Re: Use drawLine to render a bullet(Slick2D). on: 2012-12-28 22:40:10
I know how to use translate. May I ask how I calculate the rotation variable?
21  Java Game APIs & Engines / Java 2D / Re: Use drawLine to render a bullet(Slick2D). on: 2012-12-28 22:23:50
A gun fire at target. The projectile is traveling towards the target. I want to create a bullet effect, which would start at the projectiles x and y coordinate, and end... exactly where? I cant just use the projectiles x and y + 10(which would be the length of the bullet) because then would the bullet always be a vertical line rather than a rotated line.

I cant figure out how to get a correctly rotated line.
22  Java Game APIs & Engines / Java 2D / Use drawLine to render a bullet(Slick2D). on: 2012-12-28 22:11:06
I have the coordinates for the weapon object, which is fire at the target object, which I also have the coordinates to.
I am trying to create a bullet effect.
I tried some stuff out, but they didnt work as expected ingame.
23  Java Game APIs & Engines / Java 2D / Re: Pixel perfect collision detection on: 2012-12-25 22:29:02
Your implementation is identical to the this one:
http://www.gamedev.net/topic/329033-pixel-perfect-collision-detection/#entry3131661
However, the one above is faster yours, I think.
Why dont you have return true rather than bool = true? It is just useless cycles.

May I ask how exact your method is? The one I just linked, is always two pixels "late".
24  Java Game APIs & Engines / Java 2D / Re: Beginnings of a Slick2D weather class on: 2012-12-22 15:15:34
this would attract more people if you actually provided some images on how this would look in game.
25  Java Game APIs & Engines / Java 2D / Re: Apply AffineTransform to Slick2D? on: 2012-12-21 20:31:23
I do not think that will be a good idea. I am trying to archive what I explained here:
http://www.java-gaming.org/topics/make-the-stage-move-when-the-main-character-move/27970/view.html
Afaik, this can only be done with AffineTransform.
26  Java Game APIs & Engines / Java 2D / Apply AffineTransform to Slick2D? on: 2012-12-21 20:20:43
With, Java2D, I did like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
   @Override
   public void draw(Graphics2D g)
   {      
      AffineTransform transformer = new AffineTransform();
      transformer.translate(-(Math.min(stage.width-stage.visibleWidth,   Math.max(0, main.posX - stage.visibleWidth  / 2))),
                            -(Math.min(stage.height-stage.visibleHeight, Math.max(0, main.posY - stage.visibleHeight / 2))));
      g.setTransform(transformer);
   //...
  }

This works perfect.
I tried similar in Slick2D:
   
1  
2  
3  
4  
5  
6  
7  
@Override
   public void render(GameContainer gc, Graphics g) throws SlickException
   {
      g.translate(-(Math.min(stage.width-stage.visibleWidth,   Math.max(0, main.posX - stage.visibleWidth  / 2))),
                  -(Math.min(stage.height-stage.visibleHeight, Math.max(0, main.posY - stage.visibleHeight / 2))));
   //...
  }


This however, did not work at all. The result was that every thing in the window was black.
How do I fix this?


EDIT: This was an mistake by me. translate works fine for slick2d
27  Java Game APIs & Engines / Java 2D / Re: Pixel perfect collision detection on: 2012-12-19 21:47:00
Is it safe to assume the sprites won't be scaled in anyway? As in their drawn size matches the image size? Or do you want help with sprites possibly being scaled as well...
The spriates wont be scaled in any way after they are loaded for the first time.

I must ask, why are you doing it this way? is this a learning experience? cause it would be a lot easier to just get some pre-existing code thats already in java.
I cant find any pixel perfect code written in java, so I have to translate this C++ code.
28  Java Game APIs & Engines / Java 2D / Pixel perfect collision detection on: 2012-12-18 23:28:30
I want to translate a C++ function I found on the net. Here is the C++ code:
// Full object-to-object pixel-level collision detector:
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  
short int Sprite_Collide(sprite_ptr object1, sprite_ptr object2) {
 
    int left1, left2, over_left;
    int right1, right2, over_right;
    int top1, top2, over_top;
    int bottom1, bottom2, over_bottom;
    int over_width, over_height;
    int i, j;
    unsigned char *pixel1, *pixel2;
 
    left1 = object1->x;
    left2 = object2->x;
    right1 = object1->x + object1->width;
    right2 = object2->x + object2->width;
    top1 = object1->y;
    top2 = object2->y;
    bottom1 = object1->y + object1->height;
    bottom2 = object2->y + object2->height;
 
 
    // Trivial rejections:
   if (bottom1 < top2) return(0);
    if (top1 > bottom2) return(0);
   
    if (right1 < left2) return(0);
    if (left1 > right2) return(0);
 
 
    // Ok, compute the rectangle of overlap:
   if (bottom1 > bottom2) over_bottom = bottom2;
    else over_bottom = bottom1;
 
    if (top1 < top2) over_top = top2;
    else over_top = top1;
 
    if (right1 > right2) over_right = right2;
    else over_right = right1;
 
    if (left1 < left2) over_left = left2;
    else over_left = left1;
 
 
    // Now compute starting offsets into both objects' bitmaps:
   i = ((over_top - object1\1->y) * object1->width) + over_left;
    pixel1 = object1->frames[object1->curr_frame] + i;
 
    j = ((over_top - object2->y) * object2->width) + over_left;
    pixel2 = object2->frames[object2->curr_frame] + j;
 
   
    // Now start scanning the whole rectangle of overlap,
   // checking the corresponding pixel of each object's
   // bitmap to see if they're both non-zero:

    for (i=0; i < over_height; I++) {
        for (j=0; j < over_width; j++) {
            if (*pixel1 > 0) && (*pixel2 > 0) return(1);
            pixel1++;
            pixel2++;
        }
        pixel1 += (object1->width - over_width);
        pixel2 += (object2->width - over_width);
    }
 
 
    // Worst case!  We scanned through the whole darn rectangle of overlap
   // and couldn't find a single colliding pixel!

    return(0);
 
};


I understand most of the code. I get lost at line 45 and downwards.
Some help?
PS I am using BufferedImage, and the getRGB methods are extremely slow. I am thinking to store all the colors in an int array, that is initialized before the game starts.
29  Java Game APIs & Engines / Java 2D / Re: Slick2d advantages? on: 2012-12-18 20:22:40
Well, I am not that convinced to use Slick2D. I am not creating a high performance game anyway. However, my game looks laggy on my laptop for some odd reson(it is not really laggy as the fps is locked at 66. Its more like an graphical glitch), which is why I am considering switching to Slick2D.
30  Java Game APIs & Engines / Java 2D / Slick2d advantages? on: 2012-12-18 02:33:31
Do Slick2D have advantages over Swing? Example, do it interfere with the native system better than Swing do? Why is it better than Swing?
Isint Slick2D just a modified Swing window?
Pages: [1] 2
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (88 views)
2013-05-17 21:29:12

alaslipknot (96 views)
2013-05-16 21:24:48

gouessej (128 views)
2013-05-16 00:53:38

gouessej (123 views)
2013-05-16 00:17:58

theagentd (131 views)
2013-05-15 15:01:13

theagentd (119 views)
2013-05-15 15:00:54

StreetDoggy (161 views)
2013-05-14 15:56:26

kutucuk (184 views)
2013-05-12 17:10:36

kutucuk (185 views)
2013-05-12 15:36:09

UnluckyDevil (191 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.291 seconds with 20 queries.