Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (753) Games in Android Showcase (228) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Show Posts Pages: [1]
 1 Game Development / Newbie & Debugging Questions / Re: Linear Motion on: 2008-11-23 18:05:28 Thanks.  I just thought it was some error in my code, due to the fact that an increase in fps somehow made the results more accurate, and because of the fact that it was constantly off by approximately the same ammount.This hasn't caused me any trouble, but I just wanted to make sure that the method itself wasn't flawed.  The longer the program runs, the more the number goes off, so for implementation it might be better to just update the displacement to the correct value every second.
2  Game Development / Newbie & Debugging Questions / Linear Motion on: 2008-11-23 15:46:26
In order to program something interesting with 2-d motion, I figured that I should start with the absolute basics... linear motion.  I typed up this program today to try it out, and it doesn't completely work.  All the calculations it performs at run time turn out slightly differently from what it should be.  I noticed that this error margin decreases when I up the fps, but it only does that, decreases it.  Does anyone know what I should change to make the game displacement equal to the one it gets from the equation: x=x0 + v0*t + (1/2)a*t^2?
my source code:
 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 `  import java.awt.*;   import java.awt.event.*;   import javax.swing.*;   import javax.swing.event.*;   import java.util.*;   import java.applet.*;    public class LinearMotion extends Applet implements MouseMotionListener    {       Graphics g;       Image offscreen;       Dimension dim;       int mouseX, mouseY;       int mouseDX, mouseDY;            double initialVelocity=45;// m/s      double velocity=initialVelocity;      double acceleration=-6;// m/s^2      double startingPosition=20.0;      double position =startingPosition;// m      int meterLength=5;// m/10*pixel            boolean backwards=true;//can velocity become negative? false if friction, etc      boolean finished=false;//if backwards = true, and velocity becomes negative            int fps=100;      int frames = 0;//incremented every screen      ArrayList oldPositions = new ArrayList();            Thread t = new Thread();       public void init()        {          dim = getSize();          addMouseMotionListener(this);          setBackground(Color.black);          offscreen = createImage(dim.width,dim.height);          g = offscreen.getGraphics();          t.start();      }           public void paint(Graphics z)        {          try{ t.sleep(1000/fps); }              catch(Exception e){};         g.clearRect(0,0,dim.width,dim.width);                   /*Physics Calculations*/         position+=(velocity/(double)fps);         velocity+=(acceleration/(double)fps);         System.out.println(acceleration/fps);         System.out.println(position);         System.out.println(velocity);         if(backwards==false && velocity<0){            velocity=0;            finished=true;         }                  frames++;         /*Mark previous displacement positions*/         if(frames%fps==0 && !finished)            oldPositions.add(new Double(position));                                    /*Draw Grid*/         g.setColor(Color.white);         g.drawLine(0,70,dim.width,70);         for(int x=0;x
3  Game Development / Newbie & Debugging Questions / Re: Need some help with a project I'm working on on: 2008-11-20 19:20:16
Thanks for the tips guys, but dang is that a lot of reading  .  I know what I'll be doing this weekend.  Rewriting the entire applet seems like the best option at this point, but it just seems like such a waste of code.  That entity idea is great though, so I'll implement it the next time I work on a game.  Would it look something like:
 1  2  3  4  5  6 `public class Entity{public Entity(){}public void draw(Graphics g){//g.draw stuff here;}}`

and
 1  2  3  4  5  6  7  8  9  10  11 `public class GameMap extends Entity{int [][] map;public GameMap(int x, int y){map=new int[x][y];}public void draw(Graphics g){for(int x=0;x

As for loading resources, would you guys just make some kind of resource class, that just loads every sound and image when its instantiated, and then pass that on to every other entity method, along with the Graphics?  The reason my original main applet class was so long was because of resource management.  One last thing, theres a class for every single unit, so that all their actions can be made unique from unit to unit.  Every unit also has a unique shooting sound, so I'm not sure what to do about that either.  Should I just do:
 1  2  3  4  5  6  7  8  9 `if (unit instanceof CombatTank){combatTankFire.stop();combatTankFire.play();}else if (unit instanceof Medic){medicHeal.stop();medicHeal.play();}//... And so on, for all 20 units?`
 4 Game Development / Newbie & Debugging Questions / Need some help with a project I'm working on on: 2008-11-19 17:49:47 Hey guys, I've only recently started learning java (self teaching for around half a year) so that I could create this game I thought up.  It was basically thrown together, but is still the only java program I've made so far, so I would like to finish it up.  Currently, the code is approximately 5000 lines, but the more I look at it, the more it looks as if I could have written it better from the beginning.  (I looped through all my arrays at least 50 times every frame).So my question is, "How would I go about optimizing my code"?  Right now, it is only one main applet class, with a class for every single unit, and a building class.  I would like to break up the huge paint method into different classes, but am unsure of how the best way to do this would be, as well as how to pass variables efficiently from one class to the next.Also, I wanted to know if it is possible to make a png image a different color or rotate it, as there are multiple factions, and I wanted to make all their units and buildings their color.Lastly, I was wondering how I could make effective unit movement.  As of now, all movement is calculated using distance, which requires me to loop through the whole map, except this does not work well.  There are some units which should not be able to cross water, or go across a pit, but using my method they just disappear and reappear somewhere else.I have tried to solve all these problems independantly, but was unable to come up with a solution.  Here are some pics of the current build:and the picture of the map editor:
 Pages: [1]
 ivj94 (583 views) 2018-03-24 14:47:39 ivj94 (47 views) 2018-03-24 14:46:31 ivj94 (374 views) 2018-03-24 14:43:53 Solater (61 views) 2018-03-17 05:04:08 nelsongames (108 views) 2018-03-05 17:56:34 Gornova (150 views) 2018-03-02 22:15:33 buddyBro (693 views) 2018-02-28 16:59:18 buddyBro (91 views) 2018-02-28 16:45:17 xxMrPHDxx (493 views) 2017-12-31 17:17:51 xxMrPHDxx (731 views) 2017-12-31 17:15:51
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 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