Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (739) Games in Android Showcase (224) games submitted by our members Games in WIP (820) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: 1 2 [3] 4 5 ... 10
21
on: 2017-10-18 04:14:06
Started by orange451 - Last post by orange451
Here is my current implementation:
 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 `package math;import org.luaj.vm2.LuaValue;import org.luaj.vm2.lib.ThreeArgFunction;import org.luaj.vm2.lib.jse.CoerceJavaToLua;public class Vector3Lua {   public float X;   public float Y;   public float Z;      public Vector3Lua unit;      public Vector3Lua() {      // Empty   }      // Java constructor    public Vector3Lua(float X, float Y, float Z) {       this.X = X;       this.Y = Y;       this.Z = Z;              this.unit = new Vector3Lua(); // TODO Make this automatically calculate   }        // Lua constructor    static public class New extends ThreeArgFunction {      @Override      public LuaValue call(LuaValue arg0, LuaValue arg1, LuaValue arg2) {            return CoerceJavaToLua.coerce(new Vector3Lua(arg0.tofloat(), arg1.tofloat(), arg2.tofloat()));      }    }       // Lua Function - Dot Product    public float Dot(Vector3Lua other) {       if ( other == null ) {          return 0;       }               return X * other.X + Y * other.Y + Z * other.Z;    }       // Lua Function - Cross Product    public LuaValue Cross(Vector3Lua other) {       Vector3Lua result = new Vector3Lua( Y * other.Z - Z * other.Y,                                  Z * other.X - X * other.Z,                                  X * other.Y - Y * other.X );        return CoerceJavaToLua.coerce(result);    }}`

Testable example:
 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 `package math;import org.luaj.vm2.*;import org.luaj.vm2.lib.*;import org.luaj.vm2.lib.jse.*;public class luaj {   public static void main(String[] args) {      // Normal Lua defaults      Globals globals = JsePlatform.standardGlobals();            // Setup Vector class      LuaValue vectorClass = CoerceJavaToLua.coerce(Vector3Lua.class);      globals.set("Vector3", vectorClass);      // Bind .new() to constructor function      LuaTable t = new LuaTable();      t.set("new", new Vector3Lua.New());      t.set("__index", t);      vectorClass.setmetatable(t);      // Test it      LuaValue chunk = globals.load("local test1 = Vector3.new(9, 8, 7); local test2 = Vector3.new(1, 2, 3); print(test1.Z); print(test1:Dot(test2)); print(Vector3:func())");      chunk.call();   }}`

 22   on: 2017-10-18 03:27:59 Started by orange451 - Last post by orange451 Hiah. I am trying to implement luaj into my project, and I was hoping to get some help!I want to implement a Vector class similar to this structure:http://wiki.roblox.com/index.php?title=API:Vector3The problem is I can't seem to find proper documentation on a few things that are necessary. Firstly, I like the .new() convention for constructors, but I am not sure how that would translate to java, as "new" is a protected keyword.Secondly, how would I go about operator overloading? i.e. Vector3 * Vector3, ect.Thirdly, I don't know how to go about creating a property that automatically updates as other properties are changed. For example, in the Vector class I linked: X, Y, Z, Unit, and Magnitude are all fields of a Vector. If X, Y, or Z changes then the Unit and Magnitude variable automatically change. There are no setters or getters.Ideally I would have most of the functionality in java, and just expose some methods to the user via lua.

 23   on: 2017-10-17 23:05:13 Started by Slyth2727 - Last post by Slyth2727 Imagine an incompressible fluid surface in 1D - if the line is completely flat and let's say the default density at a point is 5. So essentially our surface can be defined by f(x) = 5. Now if I 'push' down on the line at x = 2 (ie add some positive and negative velocity at x = 2), the surface would rise at x < 2 and x > 2 due to advection of density using the velocities just introduced. I'm trying to model this with the ability to add force like I just described. Can anyone explain how I would implement this?I've looked into 1d heat diffusion and I'm pretty sure that's what I'm looking for - I've implemented this and it solves diffusion just fine but I'm a bit confused on how to add forces to the model. I don't know why I'm having issues wrapping my head around adding velocities and density advection w the velocities in 1d even though I've done it in 2d... I was going to reimplement navier stokes in 1d but I'm certain there's a more simple way to model what I'm describing.Doesn't necessarily have to be physically accurate, just visually pleasing and maintaining a constant sum of densities.

24
on: 2017-10-17 17:29:27
Started by macmanmatty - Last post by macmanmatty
most of my problems have been solved by properly creating  a new thread to  run my gameloop in.  implementing runnable  and calling the overridden run  method does not make new thread.

you have to do
 1  2 ` Thread thread = new Thread(this);thread.start();`

 25   on: 2017-10-17 17:14:52 Started by macmanmatty - Last post by philfrei I'd like to help, especially since JavaFX is being used. But this is a lot of material to digest (for the amount of time and brain space I have available). Is there a more specific question that can be considered?

26
on: 2017-10-17 15:45:29
Started by macmanmatty - Last post by macmanmatty
I have  an RPG I am writing  in javafx kind of like an RPG / RTS  mix. You have many units  and there are many enemies.  You click on tile to move units , pick up items, pitch tents, launch canoes, ECT.  The tiles are all are  linked to a GridPane of  sub classed buttons that have an event listener tied to each one.  Each tile has  an array list of items that are drawn and  one TileOccupant plant, enemy solider, wall, table that is also drawn. When the Gui needs to be updated  only the tiles that change are drawn.  The tiles are  on maps and each map has  150 x 150 tiles.  Each is 25 px by 25 px in size. So drawing just the tiles I need to is faster.
,
I was able to get one man moving from  tile  to tile using a while loop

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22 `while(newLocation != currentLocation){move();Enemy  enemy= enemyCheck();if (enemy!=null){attack(enemy);}if (hunger==0){eat();}if (thirst==0){drink();}hunger--;thirst--;}`

My horrible plan for  the game progressing  was to have all the moving /attacking / action  code called from  the Run() method have each instance of the fighter class (which is the  base class that enemies and soliders extend ) implement the Runnable interface  and when  a new instance of an enemy was created  pick a tile and call  the Run() method and have start moving somewhere in real time and when hit something start attacking it same for soliders only  the the user would tell them where to move through button clicks.  Since each time run was called they would be moving / attacking / eating ECt.  in new thread the units would be moving in real time like an RTS game.

Now I know my plan stinks and has many pitfalls. I know I need some kind of game loop. I think I still need two threads though as having my game  loop running on the JaxaFX applaction thread  is not a good Idea.  I'm doing this whole  game my self  and since I suck at drawing and animation there will not but much of that  just men / enemies moving from tile to tile.  My question is how do I write a proper game loop? Since I'm not animating anything or doing heavy logic what kind of timer do I need for the loop? How do I enter the loop?   I have made a loop but after I enter  the game while loop the map is never drawn on the screen and the game just stays at the start screen.

here is the drawing code liked to the map classes

 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  168  169  170  171  172  173  174  175  176  177  178  179  180  181  182  183  184  185  186  187  188  189  190  191  192  193  194  195  196  197  198  199  200  201  202  203  204  205  206  207  208  209  210  211  212  213  214  215  216  217 `public class MapDraw {   Stage stage;   HBox headerPane;   ScrollPane bottomConsole;   Label title;   Console console;   GridPane mapPane;   Button [] [] buttonMap;   StackPane [] [] paneMap;   int mapCounter;   int currentMap;   VBox mainPane;   Scene scene;   ScrollPane pane;   Map []  maps= new Map [4];   ArrayList  mapChangeButtons = new ArrayList();   MapDraw(){      console= new Console();mainPane= new VBox();       headerPane=new HBox();       title= new Label("");       title.setStyle( "-fx-border-style: none; -fx-border-width: 0; -fx-border-insets: 0; -fx-font-size:34px;");       headerPane.setStyle("-fx-background-color: #2A7226");       headerPane.setPrefSize(1200,100);       headerPane.getChildren().add(title);       mapPane= new GridPane();       mapPane.setHgap(0);       mapPane.setVgap(0);       mapCounter=0;   }   public void reDrawTile( LandSquareTile tile){      int xLocation=tile.getLocationx();      int yLocation=tile.getLocationy();      System.out.println("xlocation" + xLocation);      System.out.println("ylocation" + yLocation);      paneMap[xLocation][yLocation]= new StackPane();      paneMap[xLocation][yLocation].getChildren().add(buttonMap[xLocation][yLocation]);      String imageSource=tile.getImage();      if(imageSource==null){         imageSource="empty.png";      }      Image image= new Image(imageSource);      ImageView imageView= new ImageView(image);      imageView.setFitHeight(25);      imageView.setFitWidth(25);      imageView.setMouseTransparent(true);      paneMap[xLocation][yLocation].getChildren().add(imageView);      ArrayList thingsToDraw= new ArrayList();      thingsToDraw.addAll(tile.getThings());      int numberOfThings=thingsToDraw.size();      if (numberOfThings>0){      for (int counter=0; counter tiles){      int size=tiles.size();      for (int count=0; count thingsToDraw= new ArrayList();      thingsToDraw.addAll(tiles.get(count).getThings());      int numberOfThings=thingsToDraw.size();      if (numberOfThings>0){      for (int counter=0; counterwidth){       newHeight=20;       newWidth= (height/20)*width;      }      else if (height>width){          newWidth=20;          newHeight= (width/20)*height;         }      else {          newHeight=20;          newWidth=20;      }      imageView.setFitHeight(newHeight);      imageView.setFitWidth(newWidth);      pane.getChildren().add(imageView);   }public void addConsoleInfo(String info){   console.addDisplayInfo(info);}   public void drawMap(int xSize, int ySize,  LandSquareTile [] [] map, Button [] [] buttonMap, Stage stage){ /// draws the map of tiles      this.stage=stage;         String imageSource="";      for (int countx=0; countx thingsToDraw= new ArrayList();            thingsToDraw.addAll(map[countx][county].getThings());            int numberOfThings=thingsToDraw.size();            if (numberOfThings>0){            for (int count=0; count(){         @Override         public void handle (ActionEvent k ){            MapButton button= (MapButton) k.getSource();            int mapNumber= button.getYLocation();            LandSquareTile[] [] map=maps[mapNumber].getMap();            Button [] [] buttonMap = maps[mapNumber].getButtonMap();            int xSize=maps[mapNumber].getXSize();            int ySize=maps[mapNumber].getYSize();               currentMap=mapNumber;            drawMap( xSize, ySize, map, buttonMap, stage);         }});      mapChangeButtons.add(button);      headerPane.getChildren().add(button);      mapCounter++;console.addDisplayInfo("welcome to the " +mapName+"!");   }   private StackPane getNodeFromGridPane(GridPane gridPane, int col, int row) {       for (Node node : gridPane.getChildren()) {           if (GridPane.getColumnIndex(node) == col && GridPane.getRowIndex(node) == row) {               return (StackPane) node;           }       }       return null;   }}`

and my crappy  game loop that doesn't work the drawing code is called from each fighter function to update the map with the changed tiles.

 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 `MainLoop(){         }   public void setMap(Map map){      this.map=map;   }      public void moveLoop(){   run();         }         public void    run(){            int times=0;       while(numberOfSoliders!=0){if( times==0){   map.drawMap();   }      String action="";   int size=fightersOnMap.size();          for (int count=0; count

 27   on: 2017-10-17 03:24:51 Started by FabulousFellini - Last post by janesmith76 Pretty sure that sentence is going on my tombstone.  Tongue No worries man.

 28   on: 2017-10-16 19:56:31 Started by RyanAlbano - Last post by RyanAlbano New Version Released TodayRECENT CHANGES:'Driver Seat' controlSync improvements in Remote Game modeOn Pyramid Paradise--fixed issue where checkpoints were inside pyramids and unreachableFixed some artifacts in track textures, and improvements in the sceneryTracks Added: The Golden DesertTracks Removed: Hard Forest-----------------------------------------------------------------FUTURE CHANGES?Fixing the remaining track textures

 29   on: 2017-10-16 19:36:51 Started by gouessej - Last post by gouessej HiAt first, some friends of mine have some laptops under OS X but they are too much recent to allow me to reproduce the previously mentioned bug and to test the suggested workarounds. Feel free to let me know your findings.Secondly, I haven't started to move the whole website yet but maybe I'll move the downloadable files as a first step.Thirdly, we'll have to publish a new maintenance release of JOGL to fix a major bug affecting Mesa under GNU Linux.Fourthly, I'm a bit discouraged and frustrated when I think about supporting some other platforms. Maybe Android will remain in my todo list but other platforms won't. WebGL is neither fast enough nor stable enough for my project (it's barely "ok" on lots of machines and catastrophic on others) and using software rendering would require to sacrifice the quality by reducing the resolution or the complexity of the geometry to obtain a decent result. Maybe I'll revisit the very last option with WebAssembly. Anyway, there are tons of other things to improve.

 30   on: 2017-10-16 19:08:29 Started by BurntPizza - Last post by Slyth2727 Quote from: h.pernpeintner on 2017-10-16 14:33:11@Slyth2727  If you put this in a library and make it available as compute shader, maybe someone (I?) tests it with render to texture in his game engine Oh yeah definitely, I'm aiming to code it so it's completely library independent besides maybe LWJGL or whatever I'm going to use for OpenGL. Maybe have an OpenCL and OpenGL/shader version, though due to the nature of the algorithm shaders would be much faster I think. I'm just using LibGDX to take the data computed by my library and render it for ease of use right now. I'll make sure to let you know. 3D support is already under way. I'm not even trying to run it at decent speeds until I implement it in GLSL so I can just use 3d textures.

Pages: 1 2 [3] 4 5 ... 10
 Ecumene (55 views) 2017-09-30 02:57:34 theagentd (78 views) 2017-09-26 18:23:31 cybrmynd (186 views) 2017-08-02 12:28:51 cybrmynd (184 views) 2017-08-02 12:19:43 cybrmynd (191 views) 2017-08-02 12:18:09 Sralse (201 views) 2017-07-25 17:13:48 Archive (757 views) 2017-04-27 17:45:51 buddyBro (891 views) 2017-04-05 03:38:00 CopyableCougar4 (1440 views) 2017-03-24 15:39:42 theagentd (1323 views) 2017-03-24 15:32:08
 List 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:05SF/X Librariesby SkyAphid2017-03-02 06:38:56SF/X Librariesby SkyAphid2017-03-02 06:38:32SF/X Librariesby SkyAphid2017-03-02 06:38:05SF/X Librariesby SkyAphid2017-03-02 06:37:51
 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