Show Posts
|
|
Pages: [1] 2 3 ... 5
|
|
1
|
Game Development / Shared Code / Re: Key Buffer!
|
on: 2010-09-17 01:49:11
|
@Nate "It would be better to use a circular buffer rather than shifting all the keys." I don't quite understand this. what do you mean "circular buffer?"
1 2 3 4 5 6 7 8
| public void keyPressed(int keyNum){ key[num] = keyNum; num++; ticks = 0; if(num >= key.length){ num = 0; } } |
Your buffer would start at num and circle around the end of the array back to num-1.
|
|
|
|
|
4
|
Java Game APIs & Engines / JOGL Development / OpenGL image flip / coordinate system question
|
on: 2010-09-11 01:21:26
|
|
Basically, I am being forced to use OpenGL to do my drawing (by a 3rd party application that I cannot avoid), and I am being handed a byte buffer containing an image that constantly changes that I need to paint on the screen.
The issue I am having is that the origin (0,0) for OpenGL is in the lower left corner of the screen while the origin for the image is in the upper left. When I paint it the way I have been drawing the png files I am loading from disk, the image is flipped vertically.
I have attempted glScalef(width, -height, 0), but nothing draws. I have attempted using glOrtho to move the origin for OpenGL, which works for all of the lines/polygons I am drawing, but not for the images. In order to get the images to display after the glOrtho manipulation, I have to call glScalef(width, -height, 0) and then the image is still upside down.
I am still very new to OpenGL, can anyone point me towards a solution?
Thanks, Tim
|
|
|
|
|
6
|
Game Development / Game Play & Game Design / Re: Fighting Game Health Bars
|
on: 2010-06-09 03:39:07
|
|
I would draw a filled rectangle for each one, with one dimension (width or height) being related to the current health of that player. ie: if max health is 100, and player one is at 100 health, you would draw/fill a rectangle 5 pixels high and 100 pixels wide. If player one's health is at 75, you would only draw a rectangle 75 pixels wide.
Make sense?
If max health is variable and you only have a fixed space to display the bar, you will need to do a little math to calculate the ratio. Max health bar width divided by max health multiplied by current health to get the width of the health bar. ie: 250 current health, 500 max health, 100 pixels max health bar width 100/500 = 0.2 0.2 * 250 = 50 pixels wide for current health
|
|
|
|
|
9
|
Java Game APIs & Engines / JOGL Development / Re: new to OpenGL, could use some help
|
on: 2010-06-02 19:25:06
|
|
I appreciate the response, but I have attempted to use both of those (I *really* have no clue what I am doing here)
My attempt to use glViewPort resulted in all my images being scaled down to the size of the viewport instead of being clipped, and glScissor doesn't appear to do anything.
I am working within another application's OpenGL context and when it is done drawing, I get a callback letting me know it is safe for me to draw.
|
|
|
|
|
10
|
Java Game APIs & Engines / JOGL Development / new to OpenGL, could use some help
|
on: 2010-06-02 19:03:39
|
Basically, I am being forced to use OpenGL to do my drawing (by a 3rd party application that I cannot avoid). I need to be able to draw in image from a png file. I need to be able to rotate that image. Both of these, I have working. What I need help with it figuring out how to clip the image. Basically, the image is large and I want to have a small viewport with the image moving/rotating inside it. The viewport would stay fixed (a small square) and the image I am drawing would pan/rotate behind the viewport square and be clipped to fit within the viewport square (I hope that made sense) I am currently loading the file and drawing the image as a texture as follows: (I modified example code to get to here, so please let me know if I am doing this part incorrectly as well) 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
| m_imageList = gl.glGenLists(1); gl.glNewList(m_imageList, gl.GL_COMPILE); gl.glPushMatrix(); gl.glTranslatef(-0.5, -0.5, 0.0); gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE); gl.glEnable(gl.GL_TEXTURE_2D); gl.glBindTexture(gl.GL_TEXTURE_2D, textureID); gl.glBegin(gl.GL_QUADS); gl.glTexCoord2f(0.0, 0.0); gl.glVertex2f(0.0, 0.0); gl.glTexCoord2f(1.0, 0.0); gl.glVertex2f(1.0, 0.0); gl.glTexCoord2f(1.0, 1.0); gl.glVertex2f(1.0, 1.0); gl.glTexCoord2f(0.0, 1.0); gl.glVertex2f(0.0, 1.0); gl.glEnd(); gl.glPopMatrix(); gl.glEndList();
gl.glPushMatrix(); gl.glLoadIdentity(); gl.glPushMatrix(); gl.glTranslate(x, y, 0.0); gl.glScalef(256.0, 32.0, 0.0); gl.glColor4f(1.0, 1.0, 1.0, 0.5); gl.glCallList(m_imageList); gl.glPopMatrix(); |
|
|
|
|
|
14
|
Game Development / Newbie & Debugging Questions / Re: some questions
|
on: 2010-04-19 14:14:18
|
Yep, I got that, class, or enum.
But how the hell do you swap from intro screen to game play mode without a function pointer?!?!?!?
One possibility would be to have a base class to handle drawing and the game logic, then derive new classes for intro screen and game play. You have a reference to the current active "game screen" object and call the drawing and logic methods on that in your game loop. When the state changes, you just change the active "game screen".
|
|
|
|
|
15
|
Game Development / Newbie & Debugging Questions / Re: java.util.ConcurrentModificationException
|
on: 2010-04-16 02:06:29
|
Perhaps I am missing the point...but...
It looks to me like it is not a threading issue at all. It looks to me like he is removing an element from the data structure he is using in his for loop definition. That will cause concurrent mod exceptions for sure.
Change your loop to build a stack of actors to remove when you go through your loop. Then, afterward, remove the stack from your first data structure.
I agree, and suggest using an Iterator as it can safely remove an element while traversing the list. 1 2 3 4 5 6
| for (Iterator<Actor> iterator = lActors.iterator(); iterator.hasNext();) { Actor a = iterator.next(); if (a.getHealth() <= 0) { iterator.remove(); } } |
|
|
|
|
|
16
|
Java Game APIs & Engines / Java 2D / Re: Frame vs. Applet
|
on: 2010-04-15 14:50:11
|
These are the methods I use, it will run either as an applet or a standalone application. If this isn't a good way to do it, hopefully, someone else will offer improvements. 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
| public class GameApplet extends Applet {
private static JFrame parentFrame=null; private static boolean blnApplet = false; private static int frameWidth; private static int frameHeight;
public GameApplet() { super(); enableEvents(AWTEvent.MOUSE_EVENT_MASK); enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK); enableEvents(AWTEvent.KEY_EVENT_MASK); blnApplet = true; }
public GameApplet(JFrame f) { this(); parentFrame = f; initialized = false; blnApplet = false; }
public void init() { blnApplet = true; }
public void destroy() { }
public void reset() { ... Initialize game objects here, load images, etc. ... initialized = true; }
public void start() { new Thread() { public void run() { render(); ... game loop goes here ... if (!blnApplet) { System.exit(0); } } }.start(); }
public void stop() { }
public void render() { if (initialized) { ... draw on gDisplay here ... Graphics g; try { g = this.getGraphics(); if (g != null) { g.drawImage(imgDisplay, 0, 0, null); g.dispose(); } } catch (Exception e) { } } }
public void update(Graphics g) { paint(g); }
public void addNotify() { super.addNotify(); GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); DisplayMode displayMode = device.getDisplayMode(); frameWidth = displayMode.getWidth(); frameHeight = displayMode.getHeight(); frameWidth = 800; frameHeight = 600; if (!blnApplet && parentFrame != null) { parentFrame.setSize(parentFrame.getInsets().left + parentFrame.getInsets().right + frameWidth, parentFrame.getInsets().top + parentFrame.getInsets().bottom + frameHeight); } imgDisplay = createImage(frameWidth, frameHeight); gDisplay = imgDisplay.getGraphics(); reset(); }
public static void main(String[] args) { GameFrame frame = new GameFrame(gameName); GameApplet game = new GameApplet(frame); frame.add("Center", game); frame.setUndecorated(true); frame.setIgnoreRepaint(true); frame.setVisible(true); game.start(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| public class GameFrame extends JFrame { public GameFrame(String str) { super (str); enableEvents(AWTEvent.WINDOW_EVENT_MASK); }
protected void processEvent(AWTEvent evt) { switch (evt.getID()) { case WindowEvent.WINDOW_CLOSING: dispose(); System.exit(0); default: super.processEvent(evt); } } } |
|
|
|
|
|
17
|
Game Development / Newbie & Debugging Questions / Re: creating a random path
|
on: 2010-04-05 03:41:20
|
|
Sounds like you just need to work on your heuristics. You don't want a completely random walk, you want to guide it a bit. Basically, pick a random starting position along one side. Pick a direction to be facing. Then, your choices are to walk forward and add to the path, or turn. You can't do two turns in a row. You can only turn after walking for at least two. You can't walk onto the existing path. If you get into a case where you cannot perform a legal move and you have not reached the goal point on the other side, you need to discard the path and start over
You can adjust the weight of the random between walking and turning to get lots of straight segments or lots of twisty segments.
|
|
|
|
|
19
|
Game Development / Game Mechanics / Re: Realistic missile speed relative to ship velocity
|
on: 2010-03-17 22:49:18
|
Is it some kind of homework and all the class will pop here?
My thread wasn't homework, I am waaay to old for that. It looks like you are working in degrees, the java sin/cos methods work in radians. How are you populating your lookup tables? When I fire, I do the following: 1 2 3 4 5 6
| GameVector shotV = new GameVector(shipObj.velocity); GameVector shotV2 = new GameVector(); shotV2.setAngle(Math.toRadians(angle)); shotV2.setLength(shotSpeed); shotV2 = shotV.add(shotV2); shot.setThrust(shotV2.angle, shotV2.length); |
In my vector class, I do the addition as follows: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public GameVector(double x, double y) { setPosition(x, y); } public void setPosition(double x, double y) { this.x = x; this.y = y; angle = Math.atan2(y, x); length = Math.sqrt(x*x+y*y); } public GameVector add(GameVector v) { return new GameVector(x+v.x, y+v.y); } public void setAngle(double angle) { setPolar(angle, this.length); } public void setLength(double length) { setPolar(angle, length); } public void setPolar(double angle, double length) { this.angle = angle; this.length = length; x = Math.cos(angle)*length; y = Math.sin(angle)*length; } |
EDIT - including the setAngle and setLength methods from my vector class
|
|
|
|
|
20
|
Game Development / Game Mechanics / Re: Physics of shooting
|
on: 2010-03-09 20:32:18
|
|
Actually, it was still behaving a little off, I needed to use the result of the vector addition. Just add the two vectors and the new vector is the shot vector. I could have sworn I had tried that first, but I must not have.
@DemonPants, no issues with firing backwards relative to ship movement. While it is true that shot will be moving in the same direction as the ship if the ship is traveling faster than the shot speed, the ship cannot decelerate fast enough to get hit by its own shot. Any enemy holding pace with or overtaking the ship from behind will still get hit by the shot. Like throwing a tennis ball from the front seat of the car to the back, it still hits the back seat even though it is moving forward almost as fast as the car.
|
|
|
|
|
21
|
Game Development / Game Mechanics / Re: Physics of shooting
|
on: 2010-03-09 18:29:17
|
|
OK, I found a solution.
I needed to add the ship's movement vector with the shot's vector and then set that as the length of the shot's new vector while forcing the angle to be the desired firing angle.
Previously, I was starting with the shot moving the same as the ship and trying to apply a force to it in order to move it in the correct direction.
Just updating this post as this solution didn't work. I needed to add the ship vector and the shot vector and make the resulting vector the shot's new vector.
|
|
|
|
|
23
|
Game Development / Game Mechanics / Re: Physics of shooting
|
on: 2010-03-09 03:16:20
|
If you look at the following image, the green line represents the direction the ship is actually moving. The blue line is direction the ship is facing, and the direction I would like the shot to travel. The red line, is the actual shot trajectory. 
|
|
|
|
|
24
|
Game Development / Game Mechanics / Re: Physics of shooting
|
on: 2010-03-08 22:44:33
|
|
Yes, everything uses the same world coordinate space, and the view remains centered on the ship at render time.
I have been bug hunting as I thought that method should "just work" as well.
If you match speed/direction with an asteroid and attempt to shoot it from the side, you will always miss as the shot appears to leave from a different angle than the one you are aiming. That part is hard to describe. There are 32 angles you could turn the ship to and fire from. The sideways shots, when moving fast enough, appear to come from one angle past the current ship angle and always leading the target. The closer the angle of the ship matches line of travel, the less this error is. So, it has to be something I am doing incorrectly with initial velocity of the shot that is getting magnified by the increased initial velocity imparted by the ship.
|
|
|
|
|
25
|
Game Development / Game Mechanics / Re: Physics of shooting
|
on: 2010-03-08 21:34:17
|
|
Unfortunately, it isn't an asteroids clone, I just said Asteroids-ish. In all of the asteroids games I have seen, the ship moves around the screen while the background stays stationary, and the field of play is the screen size. In mine, the ship stays centered and viewport moves around the much larger playing field. I said Asteroids-ish in that the controls are similar, you ship can turn, apply thrust, and fire.
|
|
|
|
|
26
|
Game Development / Game Mechanics / Re: Physics of shooting
|
on: 2010-03-08 21:07:47
|
|
@Gudradain - yes, I read your post. I am really trying to avoid special handling of the shots after they have been fired. With the short time to live on the shot and the inability to quickly reduce speed, it should be very, very hard to shoot yourself.
Maybe I need to subtract the movement vector from the shot vector and use the magnitude of that result as the magnitude of the shot vector.
@Karmington - yes, a completely separate layer would get me to where I want to be in terms of appearance, but I want to get there without special handling the shots/collision
@dishmoth - that is the case when the ship isn't moving, when the ship is moving, say (5,5) then you have (15,5) (-5,5) and (5,15)
|
|
|
|
|
27
|
Game Development / Game Mechanics / Re: Physics of shooting
|
on: 2010-03-08 20:13:04
|
|
I am trying to replicate a very old game. I suspect that game had special handling for shots in that they moved only in the viewport and not in the world. The shots always moved at a constant speed and always straight in the direction of fire.
Currently, I am simply adding a fixed amount of thrust to the shot in the direction of fire. Since the shot started out with the same velocity as the ship, this works OK in a line with the direction of the ships movement. Shooting backwards results in slower shots than shooting forward and shooting at an angle to the line of movement results in the shot leaving the ship noticeably off from the desired shot direction.
I don't want it to matter how fast the ship is moving; I would like the shot travel to always look the same. At this point, though, I would settle for the shot going in the correct direction.
|
|
|
|
|
29
|
Game Development / Game Mechanics / Re: Physics of shooting
|
on: 2010-03-08 17:59:32
|
|
Sort of, I don't want to have to do special bullet calculations every movement update separate from my existing object system. I should be able to do a single calculation at time of fire to get the correct magnitude for the shot vector.
Let's say the center of the screen is 50 pixels away from any given corner. I want my bullets to move at 10 pixels per second, so a shot at any corner should take 5 seconds to arrive. Let's say the ship is moving towards the lower left corner at 20 pixels per second. A shot towards the lower left corner would need to have 10 pixels per second added to it. While a shot towards the upper right corner would need to have 30 pixels per second added to it. And forcing the magnitude of the shot vector to always be the sum of the desired speed and the ship speed, doesn't really work either, though it is close.
I guess my problem stems from the fact that the desired vector is always changing based on the vector of the ship and the direction of fire.
|
|
|
|
|
30
|
Game Development / Game Mechanics / Re: Physics of shooting
|
on: 2010-03-08 16:50:17
|
|
It is a perceived stationary point, I want a fixed speed relative to the ship, which is moving. I am achieving the movement effect by keeping the viewport centered on the ship. Not setting the bullet's initial velocity to match the ship results in greater perceived inaccuracy. To get the effect I am gong for, shots fired in the opposite direction of the vector of the ship's movement will need to have greater speed then shots fired in same direction as the vector of the ship's movement.
Does that make more sense?
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|