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
 
    Home     Help   Search   Login   Register   
Pages: 1 [2] 3 4 ... 10
 11 
 on: 2017-10-18 09:23:14 
Started by JaredBGreat - Last post by JaredBGreat
write some music? You should use some stuff from: https://freesound.org/

What's the fun in that!  Wink  Writing music was something I used to be into and would like to get back into it -- but not for this.

I've decided its loud enough already; sounds already get dropped once it gets fast (I'm not sure whether to blame Java or
Linux, or if this happens on all OS's, but I've seen in at least one other game).  Instead I added widgets (well, buttons, at
least, and an info page.  May still add moving stars...?  But basically its done (I may revisit the idea of an Android port
later, or make a few tweaks, at least I think it is.

 12 
 on: 2017-10-18 07:39:49 
Started by dime26 - Last post by MarthaWilson710
I don't use Twitter much but you can find me @MaryMiller710  Kiss

 13 
 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();
   }
}

 14 
 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:Vector3

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

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

 16 
 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();

 17 
 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?

 18 
 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 <MapButton>  mapChangeButtons = new ArrayList<MapButton>();
   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<Things> thingsToDraw= new ArrayList<Things>();
      thingsToDraw.addAll(tile.getThings());
      int numberOfThings=thingsToDraw.size();
      if (numberOfThings>0){
      for (int counter=0; counter<numberOfThings; counter++){
          imageSource=thingsToDraw.get(counter).getImageSource();
         drawOnMap( paneMap[xLocation][yLocation], imageSource,  xLocation,  yLocation);
      }
      }
      mapPane.add(paneMap[xLocation][yLocation], xLocation, yLocation );
      reDrawMap();
   }
   public void reDrawTile( ArrayList<LandSquareTile> tiles){
      int size=tiles.size();
      for (int count=0; count<size; count++){
      int xLocation=tiles.get(count).getLocationx();
      int yLocation=tiles.get(count).getLocationy();
      paneMap[xLocation][yLocation]= new StackPane();
      paneMap[xLocation][yLocation].getChildren().add(buttonMap[xLocation][yLocation]);
      String imageSource=tiles.get(count).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<Things> thingsToDraw= new ArrayList<Things>();
      thingsToDraw.addAll(tiles.get(count).getThings());
      int numberOfThings=thingsToDraw.size();
      if (numberOfThings>0){
      for (int counter=0; counter<numberOfThings; counter++){
          imageSource=thingsToDraw.get(counter).getImageSource();
System.out.println("xlocation" + xLocation);
System.out.println("ylocation" + yLocation);
         drawOnMap( paneMap[xLocation][yLocation], imageSource,  xLocation,  yLocation);
      }
      }
      mapPane.add(paneMap[xLocation][yLocation], xLocation, yLocation );
      }
      reDrawMap();
   }
private   void drawOnMap( StackPane pane, String imageSource, int xLocation, int yLocation){
      Image  image = new Image(imageSource);
      ImageView imageView= new ImageView(image);
      imageView.setMouseTransparent(true);
      double height=imageView.getFitHeight();
      double width=imageView.getFitWidth();
      double newHeight=height;
      double newWidth=width;
      if (height>width){
       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<xSize; countx++){
         for (int county=0; county<ySize; county++){
            imageSource=map[countx][county].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);
            buttonMap[countx][county].setMinSize(25,25);
            buttonMap[countx][county].setMaxSize(25,25);
            buttonMap[countx][county].setStyle("  -fx-border-style: none; -fx-border-width: 0; -fx-border-insets: 0; -fx-fout-size: 4px");  
            StackPane stackPane= new StackPane();
            stackPane.getChildren().add(buttonMap[countx][county]);
            stackPane.getChildren().add(imageView);
            stackPane.setMaxSize(25,25);
            stackPane.setMinSize(25,25);
            paneMap[countx][county]=stackPane;
         }
      }
      imageSource="";
      this.buttonMap=buttonMap;
      for (int countx=0; countx<xSize; countx++){
         for (int county=0; county<ySize; county++){
            ArrayList<Things> thingsToDraw= new ArrayList<Things>();
            thingsToDraw.addAll(map[countx][county].getThings());
            int numberOfThings=thingsToDraw.size();
            if (numberOfThings>0){
            for (int count=0; count<numberOfThings; count++){
                imageSource=thingsToDraw.get(count).getImageSource();
               drawOnMap( paneMap[countx][county], imageSource,  count,  county);
            }
         }
            mapPane.add(paneMap[countx][county],countx,county);
         }
      }
      displayMap();
   }
private void displayMap(){
      bottomConsole=console.getConsole();
      ScrollPane pane = new ScrollPane(mapPane);
      pane.setPrefSize(1200,1000);
      String mapName=maps[currentMap].getMapName();
      this.title.setText(mapName);
      mainPane.getChildren().add(headerPane);
      mainPane.getChildren().add(pane);
      mainPane.getChildren().add(bottomConsole);
      scene= new Scene (mainPane);
      stage.setScene(scene);
      stage.show();
      System.out.println("here");
      }
private void reDrawMap(){
 pane = new ScrollPane(mapPane);
   pane.setPrefSize(1200,1000);
   stage.setScene(scene);
   stage.show();
   System.out.println("here");
   }
   public  void newMap(Map map, Stage stage){ // makes a new map button and adds it to the header
      maps[mapCounter]=map;
      currentMap=mapCounter;
      int xSize=map.getXSize();
      int ySize=map.getYSize();
      paneMap= new StackPane[xSize][ySize];
      MapButton button= new MapButton(0, mapCounter, null, map);// y location is mapnumber
      String mapName=map.getMapName();
      button.setText(mapName);
      button.setOnAction(new EventHandler <ActionEvent>(){
         @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<size; count++){
          action=fightersOnMap.get(count).getAction();
          if  (action.equals("move")){
          fightersOnMap.get(count).run();
          }
          if  (action.equals("rest")){
             fightersOnMap.get(count).rest();
             }
          if  (action.equals("attack")){
             fightersOnMap.get(count).attack();
             }
          if  (action.equals("distanceattack")){
             fightersOnMap.get(count).distanceAttack();
             }
          if  (action.equals("tent")){
             fightersOnMap.get(count).pitchTent();
             }
          if  (action.equals("eat")){
             fightersOnMap.get(count).eat();
             }
          if  (action.equals("drink")){
             fightersOnMap.get(count).drink();
             }
          if  (action.equals("pick up")){
             fightersOnMap.get(count).pickUpItem();
             }
          if  (action.equals("throw")){
             fightersOnMap.get(count).throwItem();
             }
         
          if  (action.equals("launchcanoe")){
             ((Soliders) fightersOnMap.get(count)).launchCanoe();
             }
       
       
       times++;
       
       
    }

    }
       
   }
   
   
   
   
      public void addFighter(Enemies  fighter){ // add a new enemy to the game loop
         
         fightersOnMap.add(fighter);
         numberOfEnemies++;
         
      }
public void addFighter(Soliders fighter){ // adds a new solider to the game loop
         
         fightersOnMap.add(fighter);
         numberOfSoliders++;
         System.out.println("ewghwefy");
               
         
      }

public void removeFighter(Enemies fighter){ // removes an an enemy from the game loop
   
   fightersOnMap.remove(fighter);
   numberOfEnemies--;
   
}
public void removeFighter(Soliders fighter){ //removes  a solider from the game loop
   
   fightersOnMap.remove(fighter);
   numberOfSoliders--;
   
   
}
           
     
     
     
   }
   
   


 19 
 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.  Cranky

 20 
 on: 2017-10-16 19:56:31 
Started by RyanAlbano - Last post by RyanAlbano
New Version Released Today

RECENT CHANGES:

'Driver Seat' control
Sync improvements in Remote Game mode
On Pyramid Paradise--fixed issue where checkpoints were inside pyramids and unreachable
Fixed some artifacts in track textures, and improvements in the scenery

Tracks Added: The Golden Desert
Tracks Removed: Hard Forest

-----------------------------------------------------------------

FUTURE CHANGES?

Fixing the remaining track textures

Pages: 1 [2] 3 4 ... 10
 
Ecumene (50 views)
2017-09-30 02:57:34

theagentd (75 views)
2017-09-26 18:23:31

cybrmynd (183 views)
2017-08-02 12:28:51

cybrmynd (181 views)
2017-08-02 12:19:43

cybrmynd (188 views)
2017-08-02 12:18:09

Sralse (195 views)
2017-07-25 17:13:48

Archive (745 views)
2017-04-27 17:45:51

buddyBro (879 views)
2017-04-05 03:38:00

CopyableCougar4 (1428 views)
2017-03-24 15:39:42

theagentd (1318 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-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
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!