Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 / Re: Realistic missile speed relative to ship velocity on: 2010-03-18 12:54:30
Hi, thanks for replying Smiley

My lookup tables are populated as follows: -

1  
2  
3  
4  
5  
6  
for (int s = 0; s < sinLookupTable.length; s++) {
    sinLookupTable[s] = Math.sin(Math.toRadians(s));
}
for (int c = 0; c < cosLookupTable.length; c++) {
    cosLookupTable[c] = Math.cos(Math.toRadians(c));
}


I'll have a look at your code tonight - I'm clearly doing something wrong Cheesy
2  Game Development / Game Mechanics / Re: Realistic missile speed relative to ship velocity on: 2010-03-17 16:08:42
Is it some kind of homework and all the class will pop here?

Anyway there is already a solution in the other thread.

Nope, although I surely understand the stress of having to look at two similar threads. How dreadful for you.

Anyway...

I'm writing a small vector game using no external assets, is all. Unlike the other guy, I'm using a "wrap-around" world. What confuses me is that the solution in the other thread produces strange results. I initially have this: -

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public Missile(Mechanics theMech, Ship theShip, int GFX_X, int GFX_Y, Color c) {
      angle = (-theShip.getAngle() + 180) % 360.0;
      if (angle < 0.0) { angle = angle + 360.0; }
      theMechanics = theMech;
      screen_X = GFX_X;
      screen_Y = GFX_Y;
      theColour = c;

      velocity = new Vector2D(MISSILE_SPEED, MISSILE_SPEED);

      startPosition = new Vector2D((theShip.getHeight() / 2) * theMechanics.sinLookupTable[(int)angle - 1] + theShip.getPosX(), (theShip.getHeight() / 2) * theMechanics.cosLookupTable[(int)angle - 1] + theShip.getPosY());
      endPosition = new Vector2D(10 * theMechanics.sinLookupTable[(int)angle - 1] + startPosition.x, 10 * theMechanics.cosLookupTable[(int) angle - 1] + startPosition.y);
}


...which works well enough. But obviously, the missile speed is constant. The solution from the other thread appears to be: -

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public Missile(Mechanics theMech, Ship theShip, int GFX_X, int GFX_Y, Color c) {
      angle = (-theShip.getAngle() + 180) % 360.0;
      if (angle < 0.0) { angle = angle + 360.0; }
      theMechanics = theMech;
      screen_X = GFX_X;
      screen_Y = GFX_Y;
      theColour = c;

      velocity = new Vector2D(theShip.getVX() + theMech.cosLookupTable[(int) angle - l] * MISSILE_SPEED, theShip.getVY() + theMech.sinLookupTable[(int) angle - l] * MISSILE_SPEED);

      startPosition = new Vector2D((theShip.getHeight() / 2) * theMechanics.sinLookupTable[(int)angle - 1] + theShip.getPosX(), (theShip.getHeight() / 2) * theMechanics.cosLookupTable[(int)angle - 1] + theShip.getPosY());
      endPosition = new Vector2D(10 * theMechanics.sinLookupTable[(int)angle - 1] + startPosition.x, 10 * theMechanics.cosLookupTable[(int) angle - 1] + startPosition.y);
}


...produces odd results as well. If the ship is stationary with an angle of 0.0, the missiles travel *very* slowly at an angle of about 320 degrees (11 0'clock-ish). If the ship has a forward velocity at this angle, the missiles appear at 180 degrees (aft of the ship). Rotating and firing produces even stranger results.

Have I got my math mixed up above?
3  Game Development / Game Mechanics / Re: Realistic missile speed relative to ship velocity on: 2010-03-17 14:11:46
Nope, that doesn't seem to work - can someone explain it in layman's terms?
4  Game Development / Game Mechanics / Re: Realistic missile speed relative to ship velocity on: 2010-03-17 13:51:13
Hmm....nevermind, I've just seen the post below mine. Fortuitous! Cheesy
5  Game Development / Game Mechanics / Realistic missile speed relative to ship velocity on: 2010-03-17 13:48:56
I have a very basic Asteroids-ish demo. At the moment, no matter how fast the velocity of the ship is, the missiles travel at a constant velocity: -

missile_velocity = new Vector2D(MISSILE_SPEED, MISSILE_SPEED);

Now, if the ship was always facing in the direction of motion when firing, it would be simple enough with: -

missile_velocity = new Vector2D(MISSILE_SPEED + theShip.getVX(), MISSILE_SPEED + theShip.getVY());

But...since this is Asteroids-alike, the ship could be travelling in one direction and facing in another direction, which leads to very odd results - such as if the ship was facing 180 degrees of the direction of travel, the missile speed is still MISSILE_SPEED + Ship Speed when I assume it should be either a steady rate or halved.

So, what to do? My math isn't great. The ship's motion is worked out with: -

if (isThrusting) {
   acceleration.x = THRUST_POWER * theMechanics.cosLookupTable[(int)angle - 1];
   acceleration.y = THRUST_POWER * theMechanics.sinLookupTable[(int)angle - 1];
} else {
   acceleration.x = 0.0;
   acceleration.y = 0.0;
}
velocity.x += acceleration.x;
velocity.y += acceleration.y;
position.x += velocity.x;
position.y += velocity.y;

Any help would be great Smiley
6  Java Game APIs & Engines / Java 2D / 2D vectors and rotation. on: 2010-03-04 09:55:51
I'm building a simple little vector game in 2D. I have a vector class which simply holds X and Y co-ordinates and have used three of these to create a little triangle spaceship. The co-ordinates are based about the arbitary origin posX and posY - which just happens to be the centre of the screen.

How do I go about rotating the points around this arbitary origin? Should I temporarily reset the posX and posY to (0,0) rotate and then move back to the arbitary origin or can I rotate the points where they are?
7  Game Development / Newbie & Debugging Questions / Re: Why does this simple Java program work correctly under Windows but not Fedora 10? on: 2009-08-08 08:28:11
Okay, so I have read and understand the principle, but still don't see how this applies to my program as in the examples I've seen create JFrames and such in the main() method. So would I have to change my Universe object to include the SwingUtilties.invokeLater() method and move my initUniverse() method to there or can I include the SwingUtilities.invokeLater() method in my Game object and create my Universe instance there and if so, how will main() know to call the invokeLater() method and thus start the game?

Thanks for your patience.
8  Game Development / Newbie & Debugging Questions / Re: Why does this simple Java program work correctly under Windows but not Fedora 10? on: 2009-08-07 23:36:29
Can you explain that in a little more detail, please? Sorry!
9  Game Development / Newbie & Debugging Questions / Why does this simple Java program work correctly under Windows but not Fedora 10? on: 2009-07-29 18:55:42
I have written the following little framework for a game I was hoping to write for Linux. This works fine with the same version of the JDK on Windows - a black screened window with a frames-per-second readout on the top left, but this fails to work under Fedora 10. I have installed Sun's official JDK and all I get is the Swing window which is the default grey and nothing else.

Little help?

Game.java
1  
2  
3  
4  
5  
6  
7  
public class Game {
        private static Universe theGame = null;

        public static void main(String[] args) {
                theGame = new Universe();
        }
}


Universe.java
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  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.Random;
import javax.swing.JFrame;

public class Universe extends Canvas {
   private JFrame theFrame;
   private BufferStrategy bufferStrategy;
   private BufferedImage bufferedImage;
   private GraphicsEnvironment graphicsEnvironment;
   private GraphicsDevice graphicsDevice;
   private GraphicsConfiguration graphicsConfiguration;
   private Graphics graphics;
   private Graphics2D graphics2D;
   private Color colorBackground;
   private Random random;
        private static final int SCREEN_WIDTH = 640;
        private static final int SCREEN_HEIGHT = 480;
   private static final int SCREEN_DEPTH = 32;
   private static int fps;
   private static int frames;
   private static long totalTime;
   private static long currentTime;
   private static long lastTime;
   private boolean isRunning = false;
   private Font theFont = new Font("Courier New", Font.PLAIN, 12);
   private static boolean isFullScreen = false;

   public Universe() {
      initUniverse();
   }

   private void initUniverse() {
      theFrame = new JFrame();
      theFrame.setIgnoreRepaint(true);
      //theFrame.setCursor(getToolkit().createCustomCursor(new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB),new Point(0,0),null));
     graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
      graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
      graphicsConfiguration = graphicsDevice.getDefaultConfiguration();
      bufferedImage = graphicsConfiguration.createCompatibleImage(Universe.SCREEN_WIDTH, Universe.SCREEN_HEIGHT);
      if (!isFullScreen) {
                   theFrame.add(this);
                   theFrame.pack();
                   theFrame.setVisible(true);                 theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   theFrame.add(this);
                   theFrame.pack();
                   theFrame.setVisible(true);
         theFrame.setSize(Universe.SCREEN_WIDTH, Universe.SCREEN_HEIGHT);
      } else {
         theFrame.setUndecorated(true);
         theFrame.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent ke) {
                                if(ke.getKeyCode() == KeyEvent.VK_ESCAPE )
                                        isRunning = false;
                                }
                        });
         graphicsDevice.setFullScreenWindow(theFrame);
         if(graphicsDevice.isDisplayChangeSupported()) {
              graphicsDevice.setDisplayMode(new DisplayMode(Universe.SCREEN_WIDTH, Universe.SCREEN_HEIGHT, Universe.SCREEN_DEPTH, DisplayMode.REFRESH_RATE_UNKNOWN));

         }
      }
      theFrame.createBufferStrategy(2);
                bufferStrategy = theFrame.getBufferStrategy();
      colorBackground = Color.BLACK;
      random = new Random();
      setupFPS();
      gameLoop();
   }

   private void setupFPS() {
      Universe.fps = 0;
      Universe.frames = 0;
      Universe.totalTime = 0;
      Universe.currentTime = 0;
      Universe.lastTime = 0;
   }

   private void gameLoop() {
      isRunning = true;
      Universe.currentTime = System.currentTimeMillis();
      while(isRunning) {
         try {
            Universe.lastTime = Universe.currentTime;
            Universe.currentTime = System.currentTimeMillis();
            Universe.totalTime += Universe.currentTime - Universe.lastTime;
            if (Universe.totalTime > 1000) {
               Universe.totalTime -= 1000;
               Universe.fps = Universe.frames;
               Universe.frames = 0;
            }
            ++Universe.frames;
            clear();
            updateInput();
            updateLogic();
            updateRender();
            displayFPS();
            flip();
         } catch (Exception e) {
            System.out.println("ERROR:" + e.getMessage());
         } finally {
            cleanUp();
         }
      }
      isRunning = false;
      shutdownGame();
      shutDownProgram();
   }

   private void shutDownProgram() {
      cleanUp();
      if (isFullScreen) {
         graphicsDevice.setFullScreenWindow(null);
      }
      System.exit(0);
   }

   private void shutdownGame() {
   }

   private void updateInput() {
   }

   private void updateLogic() {
   }

   private void updateRender() {
   }

       private void displayFPS() {
      graphics2D.setColor(Color.WHITE);
      graphics2D.setFont(theFont);
                graphics2D.drawString(String.format("FPS: %s", Universe.fps), 20, 20);
   }

   private void clear() {
      graphics2D = bufferedImage.createGraphics();
             graphics2D.setColor(colorBackground);
           graphics2D.fillRect(0, 0, Universe.SCREEN_WIDTH, Universe.SCREEN_HEIGHT);
   }

   private void flip() {
      graphics = bufferStrategy.getDrawGraphics();
                graphics.drawImage(bufferedImage, 0, 0, null);
                if (!bufferStrategy.contentsLost()) {
                   bufferStrategy.show();
           }
      Thread.yield();
   }

   private void cleanUp() {
      if (graphics != null) {
         graphics.dispose();
         graphics = null;
      }

      if (graphics2D != null) {
         graphics2D.dispose();
         graphics2D = null;
      }
   }

   public boolean isRunning() {
      return isRunning;
   }
}


The official Sun JDK is in the system path (/etc/profile) and I have compiled it using that and also uninstalled the OpenJDK stuff but to no avail. What the hell is going on? Any ideas? As I said, this code works perfectly under Windows with the same version of the JDK. I even ran "javac -version" and "java -version" to make sure no other Fedora-specific JDK was overriding the official one. But nothing helps. Sad
10  Java Game APIs & Engines / J2ME / Re: Spread the knowledge... in a fun way! on: 2006-10-05 12:05:59

displayable.setFullScreenMode(true);

Device: Motorola V525 (May affect other Motorola handsets).
Problem: Only paints in area not used by softbuttons, even if no softbuttons are used, so you get a white non-repainted area along the bottom of the screen.
Solution: Override displayable.getHeight() and +10 to the result of the normal method. This should then give you proper fullscreen.

Sorry, I can't think of anything else to choose offhand. Someone else can choose another method.
11  Java Game APIs & Engines / J2ME / Re: Transparency issues on: 2005-05-18 01:22:32
Why are you doing this?

gf.setColor(0xff0000);   // seems to fille the image with a red background Huh?
gf.fillRect(0,0,getWidth(),getHeight());

This does exactly what you're complaining about....fills the image with a red background.

Anyway....

First off, what MIDP version are you using? If you're using MIDP1.0, you can't use transparencies with memory-created images (Image.createImage()). Since you've not provided much information, I'll assume this is the problem.
12  Discussions / Miscellaneous Topics / Re: Puppy Invaders on: 2005-03-25 12:17:39
Quote
With the "Outer Glow" effect in Photoshop Wink

Cas Smiley


Okay, thanks. Looks awesome. Smiley
13  Discussions / Miscellaneous Topics / Re: Puppy Invaders on: 2005-03-24 09:46:22
How the hell do you do those "glowy" effects on the sprites?
14  Java Game APIs & Engines / J2ME / Re: Design woes: Inheritance or Interfaces? on: 2005-03-13 19:09:44
Okey-dokey. Guess I'll have to have a mess around and see whats works best. So no hard and fast rules then?

...no real need to answer that, I guess. Wink
15  Java Game APIs & Engines / J2ME / Re: Design woes: Inheritance or Interfaces? on: 2005-03-13 16:45:30
Interesting idea with the state machine. Wouldn't some of sort if/switch construct slow things down the more "types" of entities you have or is it negligable?
Anyhow, I'll be sure to try it.
16  Java Game APIs & Engines / J2ME / Design woes: Inheritance or Interfaces? on: 2005-03-11 09:40:14
Okay, I'm now at the stage where I need to keep track of my game entities for each level. In terms of space-saving and efficiency, whats the best method: -

1. First off, I need to pool some object instances and create them all at the beginning to keep the speed up. How fast is the J2ME implementation of the Vector class? Worth using this, or creating my own doubly-linked list?

2. Should I use seperate data structures for each type of entity or lump everything all together? If the latter, I need a common way of accessing all my entities. Inheritance or Interfaces?

I need things like: -

projectiles
enemies
collectables
player
platforms

So, should all these have say the same base class or implement several interfaces? This wouldn't really be something I'd ask if I was using J2SE, but since this is mobile development, I think design needs to be really well-thought out.

Advice?
17  Java Game APIs & Engines / J2ME / Re: Thrust and Gravity... on: 2005-03-01 19:10:09
Thanks Smiley
18  Java Game APIs & Engines / J2ME / Re: Thrust and Gravity... on: 2005-03-01 18:05:17
>sustained, fixed rate, smooth animation is preferable.

Sorry....you've lost me slightly. What are you saying is the best way to handle this?
19  Java Game APIs & Engines / J2ME / Re: Thrust and Gravity... on: 2005-03-01 12:53:37
Okay. Could you please explain how I can get my little spaceman to move more slowly around the screen whilst using a speed that is less than 1 pixel per cycle?

If I can avoid FP, I certainly will.
20  Java Game APIs & Engines / J2ME / Re: Thrust and Gravity... on: 2005-03-01 06:17:21
Thanks. At the moment, I'm trying to get MathFP to work with EclipseME, but had no luck. Is this FP lib easier to work with?
21  Java Game APIs & Engines / J2ME / Re: Thrust and Gravity... on: 2005-02-26 11:56:54
Thanks Smiley
22  Java Game APIs & Engines / J2ME / Thrust and Gravity... on: 2005-02-25 07:41:51
Hello there,

First post at these 'ere forums, so hi everyone.  Cheesy

I'm trying to implement the following and have no real idea on how to do this, especially because of the lack of floating point under J2ME and also because my math sucks.

What I want to do is have a sprite at the bottom of the screen that when you press UP thrusts into the air up the Y axis up to a maximum acceleration. When letting go of the UP button, I'd like him to fall back down again until he either hits a platform or the "ground" which is (getHeight()).

Any pointers, hints, advice on how to achieve this? This is actually (from my point of view) the hardest part of my game.....after this, its plain sailing. Smiley

Thanks.
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.

BurntPizza (17 views)
2014-09-21 02:42:18

BurntPizza (13 views)
2014-09-21 01:30:30

moogie (13 views)
2014-09-21 00:26:15

UprightPath (24 views)
2014-09-20 20:14:06

BurntPizza (27 views)
2014-09-19 03:14:18

Dwinin (40 views)
2014-09-12 09:08:26

Norakomi (71 views)
2014-09-10 13:57:51

TehJavaDev (96 views)
2014-09-10 06:39:09

Tekkerue (49 views)
2014-09-09 02:24:56

mitcheeb (70 views)
2014-09-08 06:06:29
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!