Java-Gaming.org
 Featured games (79) games approved by the League of Dukes Games in Showcase (498) games submitted by our members Games in WIP (422) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Show Posts Pages: [1] 2 3 ... 8
 1 Discussions / General Discussions / Re: Bad Habits on: 2013-12-02 19:59:45 I don't document my code at a high enough level. I document the nuts and bolts of classes and methods well enough, but I find myself coming back to code later thinking....why did I do it this way? Why is this an interface? What was I planning on using this class for?I find myself much more productive when I document my intentions. Something like: "My Action class is part of a GOAP framework. The idea is that all other Actions will inherit from this class and then only need to implement the update, onSuccess, and onFailure methods. These actions should really only be used when a GameEntity needs to do something that takes more than one time step."This kind of document doesn't really fit into javadoc and needs its own file.
 2 Game Development / Game Play & Game Design / Re: Card Battling System on: 2013-10-23 11:06:34 A "crap ton" of conditional statements is usually a bad idea. If you are looking to implement the game in OOP, then more typical style would be for the card to do its own calculations and carry out its own actions, rather than a separate system.Some questions that might help clarify things:Even though there are a wide variety of actions, can they be categorized (Damage causing, healing, stat improvement, etc)? Will a given card have actions of more than one type? Do all of the actions come into play all of the time or does the player choose among a set of available actions for a given card?Without knowing more, I would create a class that represents an Action. A Card can own one or more Actions and would iterate through them to calculate the overall effect.
 3 Games Center / Showcase / Re: Generic Zombie Shooter on: 2013-10-16 04:56:20 Your download URL isn't formatted correctly. this is what you are looking for.
4  Game Development / Shared Code / Re: Easy LibGDX sprite creator on: 2013-10-15 21:15:55
If you want to go with an enum type approach another option is to attach the methods directly to the enum itself. Something like:
 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18 public enum Sprites {   Rock("res/tiles/","rock.png"),   Paper("res/tiles/","paper.png"),   VoidTile("res/tiles/","void.png");         private String imageFilePath;      SpriteType(String path, String fileName) {      imageFilePath = path + fileName;   }         public Sprite getSprite() {      return new Sprite(new Texture(imageFilePath));   }}

Then you could call it by saying Sprite myRock = Sprites.Rock.getSprite();. This doesn't negate some of the other criticisms people have with the approach (caching, using pre-built solutions) but it is easier to use and doesn't involve multiple expanding switch statements.

 5 Discussions / Miscellaneous Topics / Re: What would you like to see in Java? on: 2013-10-08 03:29:25 One thing I would like is the ability to better fine tune the visibility of classes and methods. Often times I will want a class to be accessible by another class in a different package (maybe a sub package) but not publicly accessible.
 6 Game Development / Newbie & Debugging Questions / Re: Interfaces and game design ? on: 2013-10-07 15:04:04 Starting out with interfaces is an example of the advice program to an interface not an implementation. This Stack Overflow question has some good answers as to why it is desirable.
 7 Game Development / Newbie & Debugging Questions / Re: is it possible to manipulate with BufferedReader and BufferedWriter on: 2013-09-30 14:48:55 Is the file large? If not, then simply read the file into a data structure, make your changes to that data structure, and then write the data structure back out to the file. It seems like the simplest approach to get you what you want.
 8 Game Development / Newbie & Debugging Questions / Re: Does it make sense to load actor images of moving right and left? on: 2013-09-26 20:56:27 You can flip texture regions by setting negative bounds on the constructor, see the api docs. I would say do it....especially if it makes development easier.
 9 Games Center / WIP games, tools & toy projects / Re: Stryker Game Engine and Development Suite on: 2013-09-26 16:42:52 Quote from: dus998 on 2013-09-26 13:33:42we are planning to have unity - unreal engine quality with a lot easier usage and more features.Can you go into a little detail as to what features currently in unreal/unity that you are looking to simplify/make easier for the user and what features you are planning on that unity/unreal does not have?
 10 Discussions / General Discussions / Re: Do you customize your IDE (Eclipse?) on: 2013-09-16 01:29:44 While I don't like white on black, I do find light text on a darker background to be easier on the eyes especially when I am coding at night. Most of the websites, docs, etc. that I am consulting while programming are dark on light so maybe it's just the variety that helps?
11  Game Development / Newbie & Debugging Questions / Re: Enum and texture on: 2013-09-04 16:43:00
If you really want to go the enum route and do not want to load unnecessary textures, try pushing the texture loading out of the constructor.

 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 public enum Clan {      HUMAN("human.png"), ORC("orc.png");   private String imageFile;   private int textIdCards;   private Clan(String file) {      imageFile = file;   }   public void loadTexture() {        try{         texture = TextureLoader.getTexture("PNG" , ResourceLoader.getResourceAsStream(imageFile));         texIdCards = texture.getTextureID();      } catch (Exception e){         System.out.println("Can't load Textures : " + texture);      }   }   public int getTexIdCards(){      return texIdCards;   }}

 12 Discussions / General Discussions / Re: Any suggestions on how to create a basic AI? on: 2013-08-28 21:52:43 AI is a huge topic and there are lots of possible approaches (decision trees, state machines, GOAP). For a simple game, some if-then statements can actually take you pretty far. Pulling lots of historical data to do statistics on is a possible solution but I don't think there is a particular need to do that here. For one, your Entities do not need to take the absolute best action at every step, only that they take actions that make sense.If you have a reasonably short list of possible actions, one approach might be to loop through all of the possible actions the Entity could take and calculate a desirability score. The Entity would then execute the one with the highest score. The calculations could be very simple such as the desirability of the CastHealthSpellAction could be monster.getHealth() / monster.getMaxHealth();. For a little variety you could:1. Have the Entity could randomly select between the 2-3 highest scoring Actions.2. Add a small bit of randomness to each calculated value so that the Entity does not always take the same Action in a given situation.3. Use "personality traits" of the Entity to help calculate values. For instance, give the Entity an AggressionScore. The desirability of a MeleAttack Action could then include the Aggression Score as part of the calculation. This way you could have Entities with a high aggression score that would be more likely to attack or those with a lower score who would be less likely.Going further down this road can take you to full on GOAP (Goal Oriented Action Planning) but there is no reason for it to. Simply calculating the most desirable action based on the Entity's personality and the current situation should be enough to give you a pretty decent AI.
13  Game Development / Newbie & Debugging Questions / Re: Require aid refining a "Game Of Life"-esque project (Dead entities on the edges) on: 2013-08-23 20:48:03
I think you would want to loop from 1-99 otherwise you will still have nulls along on edge.

The easiest to ensure you are working with values from the same board would be to simply have a "newID" field in your Entity class. Your update could be something like:

 1  2  3  4  5  6  7  8  9  10  11 public void tick() {   if (entitiesOfOppositeID(this, surEnt) >= thresholdForConversion) {      if (ID == 0) {         newID = 1;      } else if (ID == 1) {         newID = 0;      }   }   else {      newID = ID;}

Then after you have run through the board you would then loop through and set ID to newID. There are probably more efficient ways to do this, but this should work fine.

Re: Hysteresis:

I wasn't sure if the problem you were having was that entities would flip, and then the threshold would be met, they would flip back, causing it to flip back as well, on and on... (your comment about IDs just switching back and forth). I wasn't sure if the the threshold changed depending on whether the ID is 1 or 0 would help. Something like:

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19 public void tick() {  // For this entity to flip from 0 to 1, there must be at least 5 entities that are 1.  int threshold0To1 = 5;    // For this entity to flip from 1 to 0 there must be at least 3 entities that are a 0.  int threshold1To0 = 3;   int oppositeIdCount = entitiesOfOppositeID(this,surEnt);   if (ID == 0 && oppositeIdCount >= threshold0To1) {         newID = 1;      } else if (ID == 1 && oppositeIdCount >= threshold1To0) {         newID = 0;      }   }   else {      newID = ID;}

I'm not sure if it will do anything, it is just a thought I had while reading your problem and code.

On an unrelated note, do you anticipate having more than 0 or 1 as IDs? If not. what if you switched your Id type to a boolean? It might make some of your code easier to write.

 14 Game Development / Newbie & Debugging Questions / Re: Require aid refining a "Game Of Life"-esque project (Dead entities on the edges) on: 2013-08-23 19:31:52 To stop having to check for null all the time what if you made the board with a strip of extra tiles. So if you want a 100-100 board, your tile array would be new Tile[102][102]. Then when you are checking entities for being surrounded you loop from 1 to 101. A possible thought. It looks like you are modifying the board as you go. So when you are calculating the value of the current cell, you are using the current frame's value for half of the cells but the already updated values for the other half. This leaves the board in an in-between and inconsistent state. Ideally as you calculate the new states of the entities, you would ensure that you are only using the state of the current state to calculate the new values, and then update all of the values at the end.EDIT: Another thought is that your entities may be getting into a pattern where entities are flipping back and forth because there is only a single set point (the same way a thermostat would constantly switch on and off around its set point). Hysteresis may be your friend here.
 15 Game Development / Newbie & Debugging Questions / Re: Sequential and multiple method calls? (function pointer alternatives-ish) on: 2013-08-22 21:04:24 Quote from: BurntPizza on 2013-08-22 20:51:54Quote from: Mac70 on 2013-08-22 20:48:40Java 8 will have built-in support for passing methods as arguments. Really?Yup. They are calling them Lambda Expressions.Java Dzone articleOracle tutorial.
 16 Game Development / Artificial Intelligence / Re: Is This Book Good To Learn AI ? on: 2013-08-20 17:14:32 If you don't know much about AI and are primarily looking to use it in a game, I think there are other options that might be more suitable. The book you linked to looks like it talks about AI in general and not necessarily focused on implementing AI in games.Mat Buckland's Programming Game AI By Example is a good introduction. The code examples are in C++ but there are easy enough to convert. Indeed someone has already gone ahead and converted the examples.Another good book is Artificial Intelligence for Games by Ian Millington. It gives a nice overview of lots of different AI techniques from path finding to implementing sensory systems. It is well written and the code is easy to follow pseudo-code.
 17 Game Development / Newbie & Debugging Questions / Re: Libs ? on: 2013-08-19 13:58:07 This gets discussed fairly often here is a google search of JGO that turns up some relevant prior threads.
 18 Discussions / General Discussions / Re: Another IDE born - Nightcode on: 2013-08-07 18:15:12 Has a built in libGDX template too. My only question is to what extent they will focus on Java vs. Clojure (it seems more Clojure centric). I know they are both JVM languages, but given that one is statically typed and the other dynamically typed (not to mention the completely different syntactical structures) I would guess that they would have different priorities from a features point of view.
 19 Game Development / Newbie & Debugging Questions / Re: Change a variable in another class based on a variable string. on: 2013-08-06 19:13:49 Another possibility is to use the Properties Pattern. A long but interesting article explaining the Properties pattern as implemented in an RPG. This article talks about a Java implementation.This approach would allow you to stick with plain Java code while skipping the overhead of reflection and gaining the additional flexibility.  You will still lose the nice features of static typing and compiler checking, however.
 20 Game Development / Shared Code / Re: TrieHard - A Trie implementation! on: 2013-07-30 13:11:26 So that's you on reddit .Why are you using Boolean.TRUE and Boolean.FALSE rather than just true amd false?  I don't think I've ever seen a Boolean object used in production code before
 21 Game Development / Performance Tuning / Re: Why is static not used? on: 2013-07-18 21:53:59 Stack Overflow has some questions that ask when it's appropriate to use statics.Where statics have gotten me into trouble is that it is so convenient to make things static that I was creating dependencies where none needed to exist. This made it harder for me to keep things understandable.
 22 Discussions / General Discussions / Re: Eclipse Kepler 4.3 on: 2013-07-18 12:30:07
 23 Java Game APIs & Engines / Engines, Libraries and Tools / Re: libGDX utils package - general quality and impressions on: 2013-07-15 21:03:03 Thanks, I am using it for my game rather than a third party library so i will give them a look. i think i have finally gotten past the 'i will implement everything form scratch as a learning experience" and actually focus on making a stinkin' game.
 24 Java Game APIs & Engines / Engines, Libraries and Tools / libGDX utils package - general quality and impressions on: 2013-07-15 15:29:43 Not sure why I did not see it before, but I finally noticed all of the utility classes packed into com.badlogic.gdx.utils as well as the math and physics packages. I was curious if people have used these classes and what their impressions were, specifically around the collection classes.I could see myself switching over to the libgdx collections, specifically for maps and sets. I know it's good to avoid premature optimization, but if there are ready-made classes in a library I am already using, then why not use them?I know the answer to my question is (1) if what you're doing works well enough stick with that and (2) try it for yourself and see; but I was curious what other people's experience has been.
 25 Discussions / General Discussions / Re: Eclipse Kepler 4.3 on: 2013-07-01 06:25:48 I've got it and like it. At this point, the main difference I see is that the editor no longer hangs when doing autocomplete like it did with Juno. I typically upgrade soon after releases are available and I have not had any problems. I don't use a whole lot of plugins though.
 26 Game Development / Newbie & Debugging Questions / Re: Eclipse not exporting on: 2013-06-27 22:42:22 Ok, it wasn't clear to me. Are you using version control? If so, you could pull a snapshot of your project that was the last time you remember it working and re-run it. If not, just do what BurntPizza recommended which will give you a better clue as to what the error is.
 27 Game Development / Newbie & Debugging Questions / Re: Eclipse not exporting on: 2013-06-27 21:25:38 Quote I have exported this project numerous times before but one day after not changing anything, it just stopped. (this is especially ironic because it was such a large update ).Both of these things can't be true. Did you keep your jar settings the same but make a lot of code changes? If so, did you add any jars to your library or do you have a new entry point for the game?
 28 Game Development / Game Play & Game Design / Re: Emotional motivation in gaming, and Firefly on: 2013-06-24 14:34:31 I like Firefly a lot as well and connected well with the "sullen" theme of the show.Firefly creates a lot of sympathy and empathy from the audience due to their circumstances. The main characters are the "good guys" even though they are criminals. They are both likeable and underdogs. You root for them and want them to succeed. At the same time, the show sets up an environment where you get the feeling that they won't ever really succeed. They may score enough jobs to survive, but they won't ever get the "big score" that will allow them to retire fat, happy, and rich. They will continue to fly that outdated transport ship, staying (barely) one step ahead of the law and the other criminals they deal with.I think it would be a challenge to implement this dynamic in a game as it works against common aspects of games such as:Winning: In a game like this, there is no winning, only not losing. Progression: If you are stomping around in your +50 Enchanted Dragon Armor, wielding your +30 Legendary Vorpal Sword of Destruction, you aren't really an underdog any more.To design a game like this, the game world and/or game play would have to be so engrossing so as not to seem repetitive. You'd have to give them something else to play for rather than beating the game or maxing out on stats/levels.I think Flotilla by Blendo Games comes close to this. There is no win condition, you play until you reach a set number of turns or until you die. You never really get a chance to build a massive or overly powerful fleet. One reason it works pretty well is that each game is so short. I don't think the game necessarily generates empathy, or sympathy, but it is a place to start.
29  Game Development / Articles & tutorials / Working with YAML: Configuration Files on: 2013-06-23 01:16:27
In game programming it's generally considered good practice to specify game information in external configuration files.
1. It gathers parameters that may be scattered across the code base into a couple of small files.
2. The external files can be easier to read, understand, and modify.
3. Modifications can be made without changing (and having to rebuild) the source.

In the Java world XML is the typical choice although JSON, properties, INI, and other formats are also used. Another, less well known format, is YAML(YAML Ain't Markup Language). YAML is a structured text format which provides a viable alternative to XML and JSON as means of specifying configuration data, particularly when the files are being edited by hand.

This article gives a brief overview of YAML, with a focus on using it as a means for writing configuration files.

There are two main libraries for working with YAML in Java; snakeYAML and YamlBeans. Both have fairly equivalent functionality, and at the bottom of this article is a simple class that uses snakeYAML to read in a yaml file, convert the YAML result tree into a simple set of nested maps, and write the output to the console. Both snakeYAML and YamlBeans provide additional functionality such as loading YAML data directly into POJOs and walking the YAML parse result tree.

Here is a simple YAML file:

# Properties and values are separated by a colon.
# There has to be at least one space between the colon and the value.

menuFontColor: blue       # Blue is my favorite color

Reading this in via the code at the end of the post gives us the following following simple map:

So for cases where all you need is a simple set of key/value pairs, a YAML file is not any more verbose than a properties file. Imagine what the equivalent XML might look like.

Maps

YAML uses indentation to specify hierarchical data. If we change the file to:

font:
family: Arial
color: blue
size: 14pt

# Font and BackgroundImage need to be indented the same amount.
backgroundImage:
tile:  true

...and run the code again we get a series of nested maps:

It does not matter how many spaces you indent, as long as it is consistent within a map. Try adding a space in front of "color: blue" and see what happens. You cannot use tabs for indentation.

YAML also allows you to define multiple keys on the same line. The previous example could also be written as:

font: { family: Arial, color: blue, size: 14pt }

backgroundImage:
{ image: menu.png, tile: true }

Lists

Let's say we want to add to our configuration a list of sound files to load at start up. All of the files are in the same directory, and for each sound we want to specify both the name of the file and the name to be used to get the sound from the library (something like soundLibrary.getSound("PlayerDied")).

font: { family: Arial, color: blue, size: 14pt }

backgroundImage:
{ image: menu.png, tile: true }

audio:
# Path is relative to the main game directory
base-path: .\sounds\raw\

# Each entry in the list starts with a "-" and must be at the same level of indentation.
sounds:
- name: Hit
file: hit_1.ogg

- name: PlayerDied
file: player_death.ogg

- { name: Miss, file: miss_target.ogg }  # We can also define a sound on one line.

This results in the following output:

{menu={font={family=Arial, color=blue, size=14pt}, backgroundImage={image=menu.png, tile=true}}, audio={base-path=.\sounds\raw\, sounds=[{name=Hit, file=hit_1.ogg}, {name=PlayerDied, file=player_death.ogg}, {name=Miss, file=miss_target.ogg}]}}

Like maps, lists can be defined on one line with list items separated with a comma and space.

sounds: [ {name: Hit, file: hit_1.ogg}, { name: playerDied, file: player_death.ogg}, { name:Miss, file:miss_target.ogg}]

There is more to YAML than what I have shown such as:
1. Support for multi-line strings
2. Anchors and References which allow nodes to reference previous nodes in the document
3. Specifying the type of values
4. Automated mapping of YAML data to POJOs.
5. Serialization of objects to YAML.

Some scattered, closing thoughts

Personally I like YAML. It keeps the simple things simple. When all I need is a flat list of properties, a YAML file has no more overhead than a .properties file. I can then add a bit of hierarchy for convenience without having to switch to a new format.

I find YAML to be easier to read and modify than either XML or JSON.

YAML's use of whitespace may welcome or annoying depending on your preference.

XML and JSON have much larger communities with much richer toolset available.

Like JSON, YAML is not as self describing as XML and more care may be required to ensure that your format is understandable from a semantic standpoint.

Unlike XML, YAML has no standard way of defining a schema and validating a document against it, although projects such as Kwalify have been developed to meet that need.

References
Official YAML site

snakeYAML
YamlBeans

Simple class to run example files

 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 import java.io.*;import java.util.Map;// Download the snakeYaml jar at: http://code.google.com/p/snakeyaml/downloads/listimport org.yaml.snakeyaml.Yaml;public class SimpleYAMLMain {         public static void main(String[] args) {            // The path of your YAML file.      final String fileName = "path\\to\\yaml\\file\\test.yaml";            Yaml yaml = new Yaml();         try {         InputStream ios = new FileInputStream(new File(fileName));                  // Parse the YAML file and return the output as a series of Maps and Lists         Map result = (Map)yaml.load(ios);         System.out.println(result.toString());               } catch (Exception e) {         e.printStackTrace();      }   }}

30  Game Development / Newbie & Debugging Questions / Re: Class that creates another new superclass at runtime on: 2013-06-19 19:56:16
One way to get rid of the if/then/else checks is to use the Class object.

Some items:
 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16 public abstract class Item {   public abstract String getName();}public class DoorItem extends Item {   public String getName() {      return "Door";   }}public class  WallItem extends Item {   public String getName() {      return "Wall";   }}

Now create a BuildableItem that takes the class object you want it to create:

 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 class BuildableItem {        // We use generics to make sure we only have classes that extend Item.   private Class itemClass;      BuildableItem(Class itemClass) {      this.itemClass = itemClass;   }          // Here we are instantiating a class based on its Class Object.      // NOTE: We are assuming these are all 0 argument constructors.   public Item buildItem() {            Item item = null;      try {         item =  itemClass.newInstance();      } catch (Exception e) {         e.printStackTrace();         }         return item;   }}

Now you can use the code like this:

 1  2  3  4  5    BuildableItem buildableDoor = new BuildableItem(DoorItem.class);  Item item = buildableDoor.build();  System.out.println(item.getName());  // <-- Will print out Door

EDIT: I read Danny's post more carefully and I like his approach. It's a bit more wordy on the usage end but you aren't messing around with class objects.

Looking at your BuildableItem class, it would look like this:

 1  2  3  4  5  6  7  8  9  10  11  12 // We don't create BuildableItems directly any more.public abstract class BuildableItem {    public String name;    public ArrayList matsRequired;    public BuildableItem() {        matsRequired = new ArrayList();        name = null;    }    public abstract Item buildItem();}

Now, when you want a BuildableItem of a specific type, you create an anonymous class and override the buildItem method.

 1  2  3  4  5  6  7  8 BuildableItem buildableDoor = new BuildableItem() {      public Item buildItem() {          return new ItemDoor();      }}Item item = buildableDoor.buildItem();  //  <-- This will return an ItemDoor.

 Pages: [1] 2 3 ... 8
 Add your game by posting it in the WIP section, or publish it in Showcase. The first screenshot will be displayed as a thumbnail.
 Phased (20 views) 2013-12-07 10:06:59 wessles (50 views) 2013-11-28 23:37:31 wreed12345 (59 views) 2013-11-23 17:42:34 Damocles (107 views) 2013-11-15 12:23:59 StumpyStrust (83 views) 2013-11-14 14:42:32 StumpyStrust (79 views) 2013-11-14 14:41:43 EliwoodL (91 views) 2013-11-11 10:52:42 EliwoodL (85 views) 2013-11-11 10:52:33 EliwoodL (85 views) 2013-11-11 10:51:49 Samdy (106 views) 2013-11-07 10:06:49
 opiop65 24x Spasi 15x wessles 15x Groboclown 12x theagentd 12x CodeHead 12x HeroesGraveDev 11x SHC 10x Roquen 10x ctomni231 9x saucymeatman 8x Riven 8x doppler 7x Luffaren 7x Nate 7x Danny02 6x
 HotSpot Intrinsicsby Roquen2013-11-25 17:44:34How do I start Java Game Development?by Nate2013-11-18 18:35:15Concurrencyby Roquen2013-11-08 22:39:59Concurrencyby Roquen2013-11-08 20:43:31Concurrencyby Roquen2013-11-08 15:31:17Concurrencyby Roquen2013-11-08 15:20:42Concurrencyby Roquen2013-11-08 15:00:50Resources for learning software design.2013-10-17 16:25:24