Show Posts
|
|
Pages: [1]
|
|
1
|
Game Development / Game Mechanics / Bullet Angles
|
on: 2011-05-26 23:20:56
|
Well, geometry has finally become of use in my life, too bad I rarely payed attention in that class  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: 
|
|
|
|
|
3
|
Game Development / Newbie & Debugging Questions / Re: Actual Size of a JFrame?
|
on: 2011-05-24 04: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 02:47:25
|
Why when I do: 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 20: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 21: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 JDialog(Frame owner) Will explain what I am trying to say?
|
|
|
|
|
8
|
Game Development / Newbie & Debugging Questions / Re: How to make a button close a GUI?
|
on: 2011-05-13 20: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 20: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!  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 19: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  Now, onto the jumping and falling physics... Dare I make a thread in java2d already? 
|
|
|
|
|
11
|
Game Development / Newbie & Debugging Questions / Re: Restrict size of a JComponent
|
on: 2011-05-12 14: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 
|
|
|
|
|
12
|
Game Development / Newbie & Debugging Questions / Re: Restrict size of a JComponent
|
on: 2011-05-12 04: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
|
|
|
|
|
14
|
Game Development / Newbie & Debugging Questions / Restrict size of a JComponent
|
on: 2011-05-12 01: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
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|