Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  Game Development / Newbie & Debugging Questions / Calculating rotated points of a rectangle on: 2013-10-31 18:01:30
Hello, I am using vertex buffers to draw this at the moment, but for some reason after the program is launched, the thing that is being drawn appears in the top left corner (close to 0,0) when it is supposed to be at (100,100). The sprite is being rotated around a point Center (a Vector 2), and the Center is being set to (X + (width of sprite)/2) and (Y + (height of sprite/2)) every time the x or y of the sprite is being changed. When I made it so that the rotation (which up until this point had been set at 0) increased every frame, the sprite seemed to rotate around a point close to (0,0). Is there a way I am calculating the new position wrong? Ty for any help!

Position is a Vector 3 by the way and although a Z is in there I am only doing 2D things right now

here is code for calculating verticies:
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  
float x, y;
         float cosRot = FMath.Cos(Rotation);
         float sinRot = FMath.Sin(Rotation);
         
         // Point 1 - top left
        x = Position.X - Center.X;
         y = Position.Y - Center.Y;
         vertices[0]=(float)(x*cosRot - y*sinRot);   // x0
        vertices[1]=(float)(x*sinRot + y*cosRot);   // y0
        vertices[2]=Position.Z;                  // z0
       
         // Point 2 - bottom left
        x = Position.X - Center.X;
         y = (Position.Y + height) - Center.Y;
         vertices[3]=(float)(x*cosRot - y*sinRot);   // x1
        vertices[4]=(float)(x*sinRot + y*cosRot);// y1
        vertices[5]=Position.Z;                  // z1
       
         // Point 3 - top right
        x = (Position.X + width) - Center.X;
         y = Position.Y - Center.Y;
         vertices[6]=(float)(x*cosRot - y*sinRot);   // x2
        vertices[7]=(float)(x*sinRot + y*cosRot);      // y2
        vertices[8]=Position.Z;                     // z2
       
         // Point 4 - bottom right
        x = (Position.X + width) - Center.X;
         y = (Position.Y + height) - Center.Y;
         vertices[9]=(float)(x*cosRot - y*sinRot);   // x3
        vertices[10]=(float)(x*sinRot + y*cosRot);// y3
        vertices[11]=Position.Z;               // z3
2  Game Development / Newbie & Debugging Questions / How to reflect an angle on: 2013-08-03 22:18:58
This may be more of a math question, think of how the ball ricochets off the walls and paddles in pong or brick breaker, I can see that the new angle is equal to the angle that it came in at, but when you have to do it in a unit circle, I can't figure out how to mathematically figure it out. Can someone explain how? TY for any help!
3  Game Development / Newbie & Debugging Questions / How to divy things up using threads on: 2013-04-12 05:10:36
I'm sorry if this is a re-ask, but when trying to separate actions into threads, what should you consider, the only thing i can think of is that every variable affected, assuming this is a new thread not the main one running the game loop, must be declared volitile. Is that all that need to be done? and should the game update loop and render loop be on separate threads? ty for all help.
4  Game Development / Newbie & Debugging Questions / Render off screen on: 2013-04-12 05:05:29
I'm not sure exactly how to phrase a search for this, but I don't understand how, java2D at least, handles this aspect of rendering or if it does at all. If you tell it to render an object wholly outside, or even partially outside, does it save itself the cpu and not render it at all? I mean the way I understand it, every one of those draw methods affects some matrix of pixels (I think of it as a 2D array), and then the show method is called and it is shown on the screen, is that correct?
5  Game Development / Newbie & Debugging Questions / making a new resized image at runtime on: 2013-03-30 16:17:00
Before now I have had a scale for each image loaded that would scale the coordinate grid in the render method, but it occurred to me that this could be a drain of cpu power, so I was wondering how to save a new resized version of a particular image at runtime. TY for any help!
6  Game Development / Newbie & Debugging Questions / Re: lan games in java on: 2013-01-31 08:59:37
I chose the wrong wording, the server program does not crash (i.e. close?), it freezes, i have to open up task manager to shut the thing off.
7  Game Development / Newbie & Debugging Questions / lan games in java on: 2013-01-31 07:22:57
Just wondering if anyone would know a good tutorial for lan networks in java, I understand sockets and the like, as well as the whole concept of doing say collision detection on one computer and sending the updated data to all the clients, but the only actual server and client java program I could find a tutorial for creates a server that crashes immediately after the client disconnects, I don't understand the (coding) difference between the tutorial he showed and a lan network program, or even whether or not his was already lan to begin with. Any tutorials or help would be nice, ty

here is the code for that tutorial I found:
server:
http://pastebin.com/r9AdU2BY

client and dataPackage:
http://pastebin.com/ahgRRhtW
8  Game Development / Newbie & Debugging Questions / Re: Multiplayer top down shooter on: 2013-01-19 18:28:47
makes sense... so say when someone presses the button to shoot, should that player send a series of varriables or IDs needed to create the object on the server, or create the object and send it to the server (is that possible?), I assume the former, so after the server has the object(s), does it send the data for ALL of those objects to every player, or just ones that have changed?
9  Game Development / Newbie & Debugging Questions / Multiplayer top down shooter on: 2013-01-19 17:49:46
As the title said, I am trying to make a multiplayer top down shooter, I get the gist of the client server model and java sockets, but I am unsure as exactly where to put them... What I mean is, a single player starts a server, then after every one links to it, what exactly should be sent to each player. Does every player only send their location to the server, location of any projectiles they fire, the ID of an enemy if they hit it? If someone has a link to a tutorial or something on the subject pls tell me. THX for ANY help!
10  Game Development / Newbie & Debugging Questions / Re: adjusting points for rotation on: 2013-01-14 21:08:57
I wanted to be able to have the sword about 30 degrees to the right of where the character is facing, then after the mouse is clicked the sword swings around 90 degrees in the leftward direction. What I have in that bit of code is what I thought would work for a stationary sword, but it doesn't stay stationary (as I described in the previous post).
11  Game Development / Newbie & Debugging Questions / Re: adjusting points for rotation on: 2013-01-14 10:06:30
Rotation matricies seem to be what I was looking for, but when I try to implement them (at the moment the sword is just a line), I just see the sword rotating from what looks like 90 degrees to 180 degress as fast as it can, and the sword itself is much longer than it should be, this is what pertains to the sword in the game loop:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
//test is the game character, who is holding the sword
       double subx = test.getXloc();
        double suby = test.getYloc();
        playerCenterX = test.getXloc() + (test.getWidth()/2);
        playerCenterY = test.getYloc() + (test.getHeight()/2);
        if(cooldown > 0)
            cooldown--;        
        playerRot = Math.atan2(mouseY - playerCenterY, mouseX - playerCenterX);
        swordRot1 = playerRot;
        subx = sword.getX1();
        suby = sword.getY1();
        sword.setLine(subx*Math.cos(swordRot)-suby*Math.sin(swordRot),subx*Math.sin(swordRot)+suby*Math.cos(swordRot),sword.getX2(),sword.getY2());
12  Game Development / Newbie & Debugging Questions / adjusting points for rotation on: 2013-01-01 02:37:12
_________
|________| *   <-- pretend that is a rectangle and the * behind it is the point, if the rectangle is rotated about the point, how do you know what its new coordinates are?
13  Game Development / Newbie & Debugging Questions / Re: which is faster? on: 2012-12-31 22:08:47
I read over that thread a bit, I love the idea of checking within a set rectangular grid, but it becomes a lot more complicated when you try to deal with sprites along the edges of any rectangle in the grid, because a single sprite can be in up to 4 at once (if its in the midddle of them)...
14  Game Development / Newbie & Debugging Questions / which is faster? on: 2012-12-31 08:48:45
For collision detection, I can either find out whether or not 2 sprites are in the same rectangular areas (up to 4, since they can be on the edge) at the same time before doing collision detection, or simply check every sprite on the entire map every time. Can anyone tell me which they think would be optimum, or rather at what point (as in after how every many collision detections need to take place) does this start saving speed? Also which is faster == or >,<,<=, and >=?
15  Game Development / Newbie & Debugging Questions / Re: Enemy rotation and following wonky... on: 2012-11-30 06:51:16
I get how to do that, I usually do something along these lines:

if(subb.getCenterX()>=sube.getX()&&subb.getCenterX()<=(sube.getX()+sube.getWidth())&&subb.getCenterY()>=sube.getY()&&subb.getCenterY()<=(sube.getY()+sube.getHeight()))

which is just checking whether or not a point is within a rectangular area, but I know methods that check whether or not, for example, a circle and rectangle intersect. I have no idea how they check within the area of a circle like that as well as other irregular shapes.
16  Game Development / Newbie & Debugging Questions / Re: Enemy rotation and following wonky... on: 2012-11-27 09:53:53
I need to brand STUPID in big bold letters on my forehead, ty for finding that. While I'm here though do you know of a way to rotate the rectangles points, because it is only rotated when its drawn and this doesn't work for hit detection, heck even if i knew how to rotate the 4 corners of the rectangle I wouldn't know of a method to check whether or not something is within that area...
17  Game Development / Newbie & Debugging Questions / Enemy rotation and following wonky... on: 2012-11-27 07:51:04
Attempting to make enemies turn and follow player, but they all seem to... I'm not sure, they rotate in the general direction of the player, but at times they go off on their own. The way I organized my classes is horrendous, but I wanted to throw something together to test and see if I could do something like this... apparently not.

I'm Posting the whole code here:
 http://pastebin.java-gaming.org/b5fd1362b3f

but I know it has to be something wrong with the rotation I use, here is where I update the enemies:
1  
2  
3  
4  
5  
6  
7  
for(Move sube: enemies)
        {
            //set rotation
           sube.setRot(Math.atan2(playerCenterY - sube.getCenterY(), playerCenterX - sube.getCenterY()));
            sube.setXloc(sube.getX() + (ENEMY_SPEED * Math.cos(sube.getRot())));
            sube.setYloc(sube.getY() + (ENEMY_SPEED * Math.sin(sube.getRot())));
        }


Am I calculating the rotation wrong? any help is appreciated
18  Game Development / Newbie & Debugging Questions / fast algorithms on: 2012-09-10 08:36:26
Ok I have a situation where one character must test whether they collide with any other characters or debris, so far I have done this by testing whether or not the characters rectangle intersects another character or debris' rectangle. As you can imagine this will become very big as more characters are added into a game, so I wonder if there is an algorithm that would handle this more effectively? Any kind of link to a site or book that has other algorithms useful to game development would be nice as well.

Ty for any and all help.
19  Game Development / Newbie & Debugging Questions / Re: double buffering fail... on: 2012-07-27 06:02:49
Descended Rupture actually extended regular frame (no swing at all) I was paranoid about the EDT so I didn't use swing at all... Also I tried adding a (1,1) grid layout to the frame (DescendedRupture) then added the base panel, base.getWidth() still returned 0, I tried setting its layout to null (just in case, even though I think it is null by default) then adding the base panel, and using base.setBounds(), no matter what I set its width and height to in setBounds, base.getWidth() still returned 0. I don't know what to make of it, but thankfully I could get around it because a canvas was on top of base, and its getWidth() and getHeight() methods worked.
20  Game Development / Newbie & Debugging Questions / Re: double buffering fail... on: 2012-07-25 00:28:29
THANK YOU FOR FINDING THAT!?!!!!!!  Grin Grin Grin Grin It actually paints now, THANK U SOOO MUCH!

holy crap 0_0 it does, why does base.getWidth() return 0... I have another class called GPanel that uses that method (it extends panel) and while inside GPanel (this.getWidth()) the method returns correctly, but then when its used in another class (and base.getWidth() is called) it returns 0. Why the heck does it do that?
21  Discussions / General Discussions / Re: Populated IRC on: 2012-07-24 22:07:31
The question I am trying to answer has been on the forum for several days, I get that people don't want to dig through my code, I'm not going to ask (just give the option), but there are a series of questions about how I formatted my code that would be easier to address in a chat.

PS here is where my question was http://www.java-gaming.org/topics/double-buffering-fail/26902/view.html

also teletubo, that forum is much more populated, but its supposed to be for lwjgl, so when I ask about pure java stuff like double buffering most people aren't willing to answer (understandably so), Also Ironically enough I found out about this forum from that channel... How do I get to the ##java irc channel?
22  Discussions / General Discussions / Populated IRC on: 2012-07-24 21:48:15
I know the site has its own IRC channel, but I was wondering if anyone could tell me what time it is generally... active? Its just I haven't seen more then two people besides me on there the last couple of times I logged in, and I was wondering if it was always like this? If so could anyone tell me a more active IRC channel? Ty for any help.
23  Game Development / Newbie & Debugging Questions / double buffering fail... on: 2012-07-20 18:08:05
Ok... I was attempting to make a 2D game, but for some odd reason double buffering isn't working. I have used it in several other programs and set it up the same way here, but here it doesn't work. In the other programs the code was shorter and only one or two Images were being loaded. This program loads all the images at launch, adds all componets, sets up double buffering, but right after this I tell it to change the canvas background color to blue, screen stays white. I tell it to run the game loop (which at this point only paints parts of the background) and it does nothing. I checked with a println() to see if the Images finished loading (they did), so i just don't know why it wont work. the code is here: http://pastebin.com/h1T4beYW

If your unwilling to look through the whole code (understandable its long), pls just tell me any Ideas you have on what might cause double buffering to not work. pls feel free to correct me if I'm doing anything horridly ineffecient or unneccesary (because I'm sure I have), Ty for any help.
24  Game Development / Newbie & Debugging Questions / Re: null pointer exception (with rectangles) on: 2012-07-17 16:49:03
ah your right, I had forgotten that....Ty
25  Game Development / Newbie & Debugging Questions / null pointer exception (with rectangles) on: 2012-07-17 16:35:52
I have allways assumed that this exception occurs when memory is not allocated for an array before it is used. Now after I added the code that alocated the memory where it was needed, it still threw the exception, so I added lines 7-15 to this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
public void setOutline(int aniID, int x, int y, int w, int h)
    {
        xloc = x;
        yloc = y;
        width[aniID] = w;
        height[aniID] = h;
        try
        {
            outline[aniID].setRect(x,y,w,h);
        }
        catch(NullPointerException exc)
        {
            outline = new Rectangle[width.length];
            outline[aniID].setRect(x,y,w,h);
        }
    }


and lo and behold it is still throwing the same exception (now coming from line 14) after memory was allocated on the previous line. How is this happening, Ty for any help?
26  Game Development / Newbie & Debugging Questions / Re: Array out of bounds error on: 2012-07-12 20:41:11
ok ultroman, I tried something almost exactly like the code in post 14, it still threw the exception... but it may have been the way I did it, I was on stupid pills that day. Also, those casts are very... unnecessary, but the whole code was just so I could learn active rendering, and see how well i could do with AI. I learned enough to improve it quite a bit (I hope), I really missused inheritance when I made the Blue/RedStick classes. Ty all for the help!!
27  Game Development / Newbie & Debugging Questions / Re: transparent colors on: 2012-07-11 18:05:08
ok fine rectangles, anyway ra4king you were right. I never knew that saving as a jpg ment you had no alpha layer, which is why photoshop didn't work... ty
28  Game Development / Newbie & Debugging Questions / Re: Array out of bounds error on: 2012-07-11 14:25:13
I only have 1 thread, and the method isDead() is:
1  
2  
3  
4  
public boolean isDead()
    {
        return dead;
    }


I don't have the foggiest idea of why it isn't working. I commented out the code and the error stopped, so I know it is coming from there.
29  Game Development / Newbie & Debugging Questions / Re: adding image to Button (non-swing) on: 2012-07-11 14:18:57
aww man, I was afraid I was going to have to do that... Do you think it will slow the program down if I do it that way?
30  Game Development / Newbie & Debugging Questions / transparent colors on: 2012-07-11 12:45:31
You know how every image in java (or anywhere else) has to be square? You have some kind of background in the places where you didn't draw (white or otherwise), so how do you turn that transparent/opaque in java? I tried drawing the image in photoshop with an opaque background, and it was still drawn white. Then google showed me this (found at http://stackoverflow.com/questions/665406/how-to-make-a-color-transparent-in-a-bufferedimage-and-save-as-png):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public Image transformGrayToTransparency(BufferedImage image)   
    {    
        ImageFilter filter = new RGBImageFilter()    
        {      
            public final int filterRGB(int x, int y, int rgb)      
            {        
                return (rgb << 8) & 0xFF000000;      
            }    
        };      
        ImageProducer ip = new FilteredImageSource(image.getSource(), filter);    
        return Toolkit.getDefaultToolkit().createImage(ip);  
    }


What I really don’t understand is lines 5-8, namely the return statement, because 1) I don’t understand its logic or the purpose of that hexadecimal number, and 2) how is rgb 1 integer? If there is a simpler way to do what I need without the use of this code, please tell me.
Pages: [1] 2
 

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

The first screenshot will be displayed as a thumbnail.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (19 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!