Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (553)
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]
1  Game Development / Game Mechanics / Bullet Angles on: 2011-05-26 21:20:56
Well, geometry has finally become of use in my life, too bad I rarely payed attention in that class  Grin


So I have a character, lets call him bob.  Bob is inside of a 100 x 100 window, the center of bobs body is at (50, 50), hence he is in the middle of the screen.

The mouse position can be put anywhere around bob in this window, and we want to calculate the angle at which the mouse is in relationship 0 - 360 degrees.

Just like a unit circle (yay calc!)

I have been using Math.atan, but it only gives angles -90 - 90, is there a way to calculate these angles in relationship to a horizontal-radian line pointing to the right?

This may expain better:

2  Game Development / Newbie & Debugging Questions / Re: Actual Size of a JFrame? on: 2011-05-24 03:45:55
How about running this code after calling setVisible(true):
1  
2  
Insets i = frame.getInsets();
frame.setSize(width+i.right+i.left,height+i.bottom+i.top);


Genius, thanks!  You should add me on AIM or skype, I seem to run into you a lot Cheesy
3  Game Development / Newbie & Debugging Questions / Re: Actual Size of a JFrame? on: 2011-05-24 02:20:38
Call setPreferredSize on the component embedded in the JFrame instead of the JFrame itself.

Then call JFrame.pack().

I tried that and it didn't work =/

I want it to be exact so if they game were ever to go fullscreen it wouldn't have weird offsets, and I feel like it should fit to the size I specify.  Stupid swing.
4  Game Development / Newbie & Debugging Questions / Actual Size of a JFrame? on: 2011-05-24 00:47:25
Why when I do:

Quote
gameFrame.setPreferredSize(new Dimension(800, 600));

It gives me a frame about 10 pixels less on the left and the right :/

I have done setSize method as well to no prevail.

How can I fix this so the graphics component embedded in the JFrame is actually 800 x 600

5  Game Development / Game Mechanics / Collision Detection For My Game on: 2011-05-20 18:02:24
Hey guys, so I have a game I am developing which is a 2d sidescroller.  I have an arraylist of all elements in the world and they have a location object attatched to each of them.

Each tile is 24 x 24 pixels, the character is 24 x 48 characters.

I have developed an object called "Location" which keeps track of all objects x and y's.

For instance, I can say player.getLocation().getX() to get where it is on the X axis, same for Y.

I want the player to be able to move left, right, and jump.  I have the jumping physics worked out, but collision detection is just being a pain. 

Currently, in my Location class I have a class called overlaps(Location otherLoc), so I can say like

1  
if(player.overlaps(elements.get(i).getLocation())


And loop through, brute force checking every single object on the screen and seeing if it overlaps.

My overlaps method is as follows, I beleive it is written wrong but I have written it about 4 times to I am a little fed up with it, maybe you can figure it out.

Note:  Datastore.TILE_SIZE = 24.

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  
   public boolean overlaps(Location _toCompare)
   {
      if((((this.getX() >= _toCompare.getX()) &&
         (this.getX() <= (_toCompare.getX() + Datastore.TILE_SIZE)) &&
         (this.getY() <= (_toCompare.getY())) &&  
         (this.getY() >= (_toCompare.getY() + Datastore.TILE_SIZE)))) ||
         
        (((this.getX() + Datastore.TILE_SIZE) >= (_toCompare.getX()) &&      
         (this.getX() + Datastore.TILE_SIZE) <= (_toCompare.getX() + Datastore.TILE_SIZE) &&
         this.getY() <= (_toCompare.getY()) &&  
         this.getY() >= (_toCompare.getY() + Datastore.TILE_SIZE))) ||
         
         ((this.getX() >= _toCompare.getX() &&      
         this.getX() <= (_toCompare.getX() + Datastore.TILE_SIZE) &&
         (this.getY() + Datastore.TILE_SIZE) >= (_toCompare.getY()) &&  
         (this.getY() + Datastore.TILE_SIZE) <= (_toCompare.getY() + Datastore.TILE_SIZE))) ||        
         
        (((this.getX() + Datastore.TILE_SIZE) >= _toCompare.getX() &&      
         (this.getX() + Datastore.TILE_SIZE) <= (_toCompare.getX() + Datastore.TILE_SIZE) &&
         (this.getY() + Datastore.TILE_SIZE) >= (_toCompare.getY()) &&  
         (this.getY() + Datastore.TILE_SIZE) <= (_toCompare.getY() + Datastore.TILE_SIZE))))
      {
         return true;
      } else {
         return false;
      }
   }
/code]
6  Game Development / Newbie & Debugging Questions / Re: How to make a button close a GUI? on: 2011-05-13 19:58:53
You're missing my point... But I'm not the one to argue, so I'll just let it be.

I am recommending this because with using multiple JFrames, especially if you are retreiving information, you have to use static variables to give one jframe access to another jframe's variables.
Not true.

As said, it highly depends on the quality of your code. If your code requires you to connect JFrames with static variables, then it shows you have a problem structuring your UI classes in an Object Oriented way. I develop in Swing for intranet applications these days, and I only use static for constants.

Perhaps the constructor
Quote
JDialog(Frame owner)
Will explain what I am trying to say?
7  Game Development / Newbie & Debugging Questions / Re: If statements comparing a string to a string? (a = "text" doesn't work) on: 2011-05-13 18:18:32
Sorry, I meant in object.  We all make typos  Cool

Quote
Not true, sometimes you have to check if an object is null (and calling equals() on a null object will throw an exception), or you want to see if two objects are just the same references.

But by calling .equals(), whether you are checking if it is null or not or if it is just a reference, you still must use .equals for situations dealing with objects... All I am saying.
8  Game Development / Newbie & Debugging Questions / Re: How to make a button close a GUI? on: 2011-05-13 18:14:07
I am recommending this because with using multiple JFrames, especially if you are retreiving information, you have to use static variables to give one jframe access to another jframe's variables.  I never said it didn't work, it's just not practical.  With dialogs, you can instantiate a dialog from a jframe class and easily pull information from it.

ToXSiK
9  Game Development / Newbie & Debugging Questions / Re: How to make a button close a GUI? on: 2011-05-13 18:01:22
Also, it's never safe to be initializing multiple JFrames within the same program, especially if you want them to be able to "Talk".  For your situation, I would really recommend initializing your JFrame, do setVisible(false);, and then use a JDialog component to get the login information.  If it's correct, poof!  the JFrame is visible, if not, well say wrong password or something!  Cheesy

I tried making an application using JFrames that when certain buttons were pushed spawned more JFrames, but it's just a bad idea and without the use of static variables, it's really hard to get them to communicate.


Here is a really good tut on working with very basic Dialog boxes, just make one to grab the login information.

http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html


10  Game Development / Newbie & Debugging Questions / Re: Restrict size of a JComponent on: 2011-05-13 17:55:08
GridBagLayout is really good, but when you give it control of your panels, it does what it pleases to them.  BoxLayout was nice because I can set the buttons/components to align through setLayout(BorderLayout.X_AXIS) and everything was sized appropriately and looked nice.  Also, I feel like adding rigid spaces in Panels are heavily under-used.  I used them a lot this time and with that you can really make your GUI look nice =)

I will post a picture of it when I get back to the house of it, so you guys can see what you helped me accomplish  Grin

Now, onto the jumping and falling physics... Dare I make a thread in java2d already?   Cool
11  Game Development / Newbie & Debugging Questions / Re: Restrict size of a JComponent on: 2011-05-12 12:21:28
hehe I meant to type "will", but I like the guesses!  =)

And I have to agree with you, swing has so much potential but its complexity turns many people away (It turned me away at first, I was just using netbeans little "GUI for making a GUI", but it is not very customizable and felt clunky to me). 

Anyways, another question, what is your favorite layout manager?  I started with GridBagLayout, but with BoxLayout you can specify component sizes and the will usually abide to them (Except for my custom component) >.<

Curious to hear  Yawn
12  Game Development / Newbie & Debugging Questions / Re: Restrict size of a JComponent on: 2011-05-12 02:29:01
Hey guys, thanks for the replies.  I figured it out finally, I had the component inside of a BoxLayout panel and BoxLayout likes to resize components like mine without asking >:{  So anyways, if anyone else has this problem, here's the fix.

Add it to a JPanel with no formatting and add your component to that (the panel will not resize it).

Also in your component constructor you must put
1  
this.setPreferredSize(new Dimension(x, y));

 
Like you guys said above for it to only display that much.
Thanks for the responses guys, only java forum I got replies to so far ^_^  We probably be back here soon XP
13  Game Development / Newbie & Debugging Questions / Re: If statements comparing a string to a string? (a = "text" doesn't work) on: 2011-05-11 23:08:08
Like they said above.  I just wanted to throw in there that Object.equals(otherObj) is used when comparing OBJECTS.  == is used ONLY when comparing primitive data types (float, int, byte, etc.).  Every time you use a java object class, you will have the .equals method available (Since they all implement Comparable - Look into doing this if you want to make you're own .equals method).

ToXSiK  Cool
14  Game Development / Newbie & Debugging Questions / Restrict size of a JComponent on: 2011-05-11 23:02:59
Title says it all.  I have an object class that I have created that extends JComponent.  When I add is to a JFrame, I want the size to be limited to only a certain area.  I am overriding the paintComponent method to display my graphics for my game. 

Also, the JFrame is BIGGER than the component, so I cannot simply force the component to abide by the frame size.

Thanks!

ToXSiK

PS, Hey Everyone!  My first post!  xP
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (24 views)
2014-08-22 19:31:30

atombrot (34 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (28 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (27 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (33 views)
2014-08-08 02:01:56

Norakomi (42 views)
2014-08-06 19:49:38
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!