Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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] 2 3 4
1  Java Game APIs & Engines / OpenGL Development / Re: LWJGL Nearest Neighbor filter has artifacts without scaling? on: 2013-04-19 06:42:00
I am the dumb stupid...  I set Display's window size to 600x400, but I left glOrtho as...
1  
GL11.glOrtho(0, 640, 480, 0, 1, -1);


Ouch...  That's what I get for copying code snippets, I guess...
2  Java Game APIs & Engines / OpenGL Development / Re: LWJGL Nearest Neighbor filter has artifacts without scaling? on: 2013-04-19 06:28:03
It's kinda hard to tell when the image is not moving.



Well, it's easier to tell with the text.  The textures are just so jagged, and I KNOW I haven't done any scaling...  The font class is my own as well, just fyi.  I am using SlickUtil to load textures.  Is there a particular way I need to be loading textures?  Perhaps I specify a filter upon creating the texture?
3  Java Game APIs & Engines / OpenGL Development / LWJGL Nearest Neighbor filter has artifacts without scaling? on: 2013-04-19 02:13:05
So, I'm trying to build my own gaming library, and I am writing my own TiledMap class.  Problem is, whenever I load in any sprite and apply a nearest neighbor filter like...

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  
   public void render()
   {
      texture.bind();
     
      // Filter code
     GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
     
      // Mins and maxes for which parts of the image to select
     float minX = srcX / (float)texture.getTextureWidth();
      float minY = srcY / (float)texture.getTextureHeight();
      float maxX = srcX2 / (float)texture.getTextureWidth();
      float maxY = srcY2 / (float)texture.getTextureHeight();
           
      // Begins drawing a quad
     GL11.glBegin(GL11.GL_QUADS);
         GL11.glTexCoord2f(minX, minY);
         GL11.glVertex2f(0, 0);
         GL11.glTexCoord2f(maxX, minY);
         GL11.glVertex2f(srcX2 - srcX, 0);
         GL11.glTexCoord2f(maxX, maxY);      //
        GL11.glVertex2f(srcX2 - srcX, srcY2 - srcY);
         GL11.glTexCoord2f(minX, maxY);      //
        GL11.glVertex2f(0, srcY2 - srcY);
      GL11.glEnd();
   }


the edges of the texture look kinda wavy, almost like some pixels are slightly ahead of each other sometimes.  I have not scaled anything, and the camera's coordinates are changing, but rounded.  I really don't know why there would be visual artifacts like this.

The code
1  
2  
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);


should have handled the nearest neighbor filtering for me, and it DOES prevent LWJGL from rendering a particular texture in a smooth manner when scaling, but it shouldn't be jagged when the coordinates are rounded!  Any clues?
4  Game Development / Performance Tuning / Re: ZipInputStream/GZIPInputStream faster than FileInputStream on: 2013-04-08 02:28:36
 Grin  Wait, wait, I have a theory suddenly!  I think it is because reading in bytes is slow, and ZipInputStream/GZIPInputStream read in fewer bytes while generating a bunch of them through decompression.  Because it is much faster to generate bytes than read them in from a file, parsing it would be faster.
5  Game Development / Performance Tuning / ZipInputStream/GZIPInputStream faster than FileInputStream on: 2013-04-08 02:24:48
So I'm writing a .json parser, and I'm giving my parser support for .json, .zip, and .gz.  Both zip and gz would be compressed versions of the json file.  When specifying input streams, it looks like this...

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  
public JsonParser(String jsonFile)
{
      builder = new StringBuilder();
      try
      {
         // Determines file type
        String fileType = jsonFile.substring(jsonFile.lastIndexOf('.')+1);
         fileType = fileType.toLowerCase();
         
         // If it is a .json file...
        if(fileType.equals("json"))
            in = new DataInputStream(new FileInputStream(jsonFile));
         
         // Otherwise, if it is a .zip file...
        else if(fileType.equals("zip"))
         {
            ZipInputStream zis = new ZipInputStream(new FileInputStream(jsonFile));
            zis.getNextEntry();
            in = new DataInputStream(zis);
         }
         
         // Otherwise, if it is a .gz file...
        else if(fileType.equals("gz"))
         {
            in = new DataInputStream(new GZIPInputStream(new FileInputStream(jsonFile)));
         }
         
         // Otherwise...
        else
            throw new RuntimeException("Extension " + fileType + " not accepted by JsonParser");
      }
      catch(IOException e)
      {
         e.printStackTrace();
      }
}


For SOME reason, when parsing the file when looking for a particular token, it is significantly faster to find it when using a GZIPInputStream or a ZipInputStream.  In case you are interested, I am parsing a .json file generated by Tiled which is half of a megabyte in size uncompressed.  Many nearly empty layers.  Anyway, the file is always read byte by byte with a DataInputStream on the outside.  Why would this happen?
6  Java Game APIs & Engines / OpenGL Development / Re: OpenGL tinting textures on: 2013-04-04 23:27:09
If you wanted it to get brighter you would have to do glcolor4f(2,2,2,1), but unfortunately input is clamped to the 0-1 range.

That's depressing...  Is that just an lwjgl thing?
7  Java Game APIs & Engines / OpenGL Development / Re: OpenGL tinting textures on: 2013-04-04 23:19:24
...when you give your color for your vertex you can use glColor4f(r,g,b,a) and use same rgba for each coord and it will tint for you over what ever texture you are using. A is alpha which is intensity. So actually opengl does have that.

Hmm, maybe I wasn't explicit.  Let's say I wanted to apply a white light to a texture.  How would I go about doing that?  By writing glColor4f(1, 1, 1, 1), I just get the original texture.  I can't really make it brighter.  That's my problem.  Maybe I should have written that in my first post.  Sorry.

I would like something like...

glColor4f(1, 1, 1, 0.5f)

to make the texture half way closer to a white silhouette.
8  Java Game APIs & Engines / OpenGL Development / OpenGL tinting textures on: 2013-04-04 23:13:34
Okay, so I'm learning OpenGL through LWJGL, and I am starting to learn to program in a more procedural manner because of it.  (I consider this to be a step back, but what can you do?)  I have some experience with Slick2D, and know a few concepts from LibGDX, but now I'm trying to make my own library that functions like these two.  I feel that by making my own library, I'll be able to know exactly what is going on under the hood and won't rely on these wrappers to talk to OpenGL for me.

BUT I DIGRESS!  Right now, I am trying to program Quad class that will allow shading to occur.  More specifically, I want to apply a tint to textures that I have binded.  Currently, my rendering code looks like this...

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  
   // Renders quad
  public void render()
   {
      texture.bind();
     
      // Mins and maxes for which parts of the image to select
     float minX = srcX / (float)texture.getImageWidth();
      float minY = srcY / (float)texture.getImageHeight();
      float maxX = srcX2 / (float)texture.getImageWidth();
      float maxY = srcY2 / (float)texture.getImageHeight();
           
      // Begins drawing a quad
     GL11.glBegin(GL11.GL_QUADS);
         GL11.glColor3f(v2Shade, v2Shade, v2Shade);
         GL11.glTexCoord2f(maxX, minY);
         GL11.glVertex2f(srcX2 - srcX, 0);
         GL11.glColor3f(1, 1, 1);
         //
        GL11.glColor3f(v3Shade, v3Shade, v3Shade);
         GL11.glTexCoord2f(maxX, maxY);      //
        GL11.glVertex2f(srcX2 - srcX, srcY2 - srcY);
         //
        GL11.glColor3f(v4Shade, v4Shade, v4Shade);
         GL11.glTexCoord2f(minX, maxY);      //
        GL11.glVertex2f(0, srcY2 - srcY);
         //
        GL11.glColor3f(v1Shade, v1Shade, v1Shade);
         GL11.glTexCoord2f(minX, minY);
         GL11.glVertex2f(0, 0);
      GL11.glEnd();
   }


This is all fine and dandy, but glColor3f only really darkens the colors.  That's good enough for me in most cases, but what if I want to apply a tint?  The tint, of course, could be for lighting.  Maybe the light is particularly yellow, and the texture would be more yellow than usual.  It would be useful if there was a method like...

1  
glTint4f(float red, float green, float blue, float intensity);


As far as I know, though, OpenGL has no such function.  Is their a painless way to do this?  Shading is already painless.
9  Game Development / Game Play & Game Design / Re: Not-so-delicious spaghetti code on: 2013-01-30 04:46:13
Alright, I think I have somewhere to go from here.  Gonna be a while before I can mass produce anything because I must refactor my code.  May need to alter how a bunch of classes to get this working again.  At least they're on the outskirts of my code and not the core.  I honestly appreciate the advice I've been given!
10  Game Development / Game Play & Game Design / Re: Not-so-delicious spaghetti code on: 2013-01-29 22:57:19
Does this mean that I need a new data structure for every new type of Entity I create?  You're suggesting that the map contain all of the Entities in some sort of partitioned way which sounds nice.  I'm a little unclear as to how you know what type of Entity is nearby, though.  For all the map data structure knows, every entity is just an entity and nothing more.  In order to choose entities of a particular type, I would either have to make separate data structures for each type of entity, or use the ugly instanceof solution.
11  Game Development / Game Play & Game Design / Re: Not-so-delicious spaghetti code on: 2013-01-29 17:58:15
I'm not sure I see the purpose of having interactive objects advertise their capabilities all the time.  Why not just have the player poll for climbable objects in the vicinity when initiating a climbing action?  No permission is needed, since the player initiated it.  If one action blocks the possibility of another, you simply don't let the player initiate the action.

Hmm, okay.  Yeah, that makes more sense.  Since the Player is the one doing the climbing, it should be making the first move.  Climbables could simply ignore the Player's request to climb if it is in a bad state.  I kind of wanted to avoid having the Player contain a reference of a collection of other Entities, though.  There may be multiple collections that are used for a selective purpose.  The purpose may vary from room to room.  I am using an external data structure that acts as a bridge between two different types of entities.  The way that two types communicate is by having their methods invoked by the data structure.  Problem is, the Entities may not be ready to consider the data entered.  It may be optimal for the entities to consider other entities in their update method.  I'm kind of stuck trying to decide if I want collections of other entities to be stored by the entities themselves, or by external data structures that link entities together through method invocation.
12  Game Development / Game Play & Game Design / Re: Not-so-delicious spaghetti code on: 2013-01-29 17:03:00
I've run into another problem, although this one is slightly smaller.  It still involves the Player, so I've decided to post my problem to the same thread.

I'll give an example of a section of my code that already does work.  I have a data structure that holds both objects that enforce collisions (Colliders), and objects that have collisions enforced on them (Collidables).  The data structure loops through both lists and compares each element in both lists.  The Collider's method enforceCollision(Collidable collidable) is invoked by the data structure which allows it to communicate with the Collidables that are contained.  When a collision happens, a Collider positions a Collidable depending on the rules of collisions for the particular Collider enforcing the collision.  Then, the Collider it is supposed to invoke one of these methods of the Collidable:  hitLeft(), hitRight(), hitTop(), hitBottom().  Each method takes in a CollisionEvent object that describes the collision itself.

This works because the Collider is the one enforcing the hit.  It is in control of the collision, and the Collidable (often the Player) merely needs to be alerted about what side was hit, and a few pieces of information about the collision itself so that it may decide what animation needs to play, how it should move based on the surface of the Collider, etc.

Now, I'll give an example of a part of my code that I consider a little broken.  Let's say I have a data structure that takes these two types: Climbable, and Climber.  Climbable can be a ladder, a vine, etc, and Climbable can be an Enemy, the Player, or some freaky spider, or WHATEVER!  The Climbable might have a method called alertPresence(Climber climber) which alerts a Climber of its presence when it is in a good state for climbing.  You can't climb a fence when it's fallen sideways on the ground, but it's still a fence that has the potential to be climbed later.  When it is in a good state, it alerts the Climber (usually the Player) by invoking its considerClimbing() method while passing itself as an argument.  In this case, though, even though the Climbable says it's ready to be climbed, we still need permission from the Player.  If a fence is all set up and the Player is within range, from the Ladder's perspective, it is ready to be climbed.  The Player may decide, however, that it cannot climb while it is running or swimming.  What I do currently is have the Player decide if it can be climbed RIGHT at the time that the considerClimbing() method is invoked by the Climbable.  I decide if it can climb with a boolean flag which is determined to be either true or false depending of the action that is currently running.  Problem is, this means that for all actions that may happen, they need to decide if they are in a state that allows the Player to climb or not.  They have to be aware of this flag.  Yeah, that's not gonna work in the long run.

Then main difference between the physics interface and the climbing interface is who gets to decide how something happens.  With collision, Colliders (walls) are the entities that decide how the collisions play out.  In the case of climbing, however, Climbables simply alert the Climbers when climbing is possible, and the Climbables (the Player, usually) get the last word in.  The Climber is doing the climbing, not the Climbable.

Mostly, I want to avoid making a bagillion and a half boolean flag variables in the Player that determine if it is ready to enter a certain action.  I was thinking that I could add a data structure in the Player like a queue, or something.  Every time the Climber's considerClimbing() method is invoked, it will add the Climbable passed to the queue.  Then, the it will determine if it can do anything with the Climbable(s) in its current state.  If the Player has an Action object running that doesn't even consider climbing, then the climbing queue will simply be ignored and cleared for the next update.  If the Action that is running DOES say something about climbing and the Player has at least 1 climbable stored, then the Player will try to climb the Climbable(s).  Of course, I don't have to have a queue, or even a list for that matter.  I could simply say "last come first serve" and only pay attention to the last Climbable that made its presence known and store it in a local variable.

By this logic, the considerClimbing() method would simply alert the Climber(Player) of Climbables (Ladder, maybe?) that could potentially be climbed in an update.  The Climber would get the last word in.

What say someone else?
13  Game Development / Game Play & Game Design / Re: Not-so-delicious spaghetti code on: 2013-01-25 21:18:18
Muahahaha!  Okay, you had me worried there!  Kinda similar to the event paradigm.  I did something like that with collision code.  Each collision object had the four methods hitLeft(), hitRight(), hitTop(), and hitBottom().  Each took a CollisionEvent argument.  It this case, though, the object just acts as a carrier for local variables.
14  Game Development / Game Play & Game Design / Re: Not-so-delicious spaghetti code on: 2013-01-25 20:54:34
I see, I see.  When I made the actions, I wanted them to be an easy way to break up instructions that were already going to exsist in the player from the start.  Now I want to take a more flexible approach, though.

Also, in response to your previous post...

Did you just write that JUST now?  If so, then I have to applaud you for your helpfulness!  Um, but are you suggesting that I get the player's local variables from a string???  I kind of have a problem with that...  Sound a little, uh, dynamic...  And not very performant.  I might have to disagree with your specific style.  After all...



I definitely like the overall idea that you've put forth.  I will not have my Action objects be expected to be located anywhere in particular.  I'll also probably have my actions be defined outside of the Player for a more flexible result.
15  Game Development / Game Play & Game Design / Re: Not-so-delicious spaghetti code on: 2013-01-25 20:38:43
Hrrm... Okay, then.  Aside from a poor naming decision, I pretty much had the idea down.  One last question, though...  Currently, the Player has a couple of Actions that expect other actions to exist.  The Player's standing action expects the Running action to exist at a particular index.  To refer to it, I say something like...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
class RunningAction implements Action
{
    // Housekeeping
   public void enter()
    {
    }

    // Runs the action
   public void run()
    {
        // Player loops animation :D

        // Player tries to go to standing action if player is in a particular state
       if(Math.abs(velovityX) > 0 && bottomTouched)
            setAction(ACTION_RUNNING);
    }

    // Usually unnecessary housekeeping
   public void exit()
    {
    }
}


In this case, ACTION_RUNNING is a public static final integer.  The Running action object is expected to be at a particular index.  If I'm adding on actions on the fly, how exactly will I be able to anticipate another action's position when the position may vary depending on the time it was added?  I would rather not search for it using an instanceof check, because, you know, EVIL!!!!!

Maybe the Action could require another Action object in it's constructor so it can always point to it?  Then the setAction method could be more like...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public void setAction(Action action)
{
    for(int i=0; i<actions.length; i++)
    {
        if(action == actions[i])
        {
            actions[actionPointer].exit();
            actionPointer = i;
            actions[actionPointer].enter();
        }
    }
}



I could always keep the old setAction() method and just overload the name.
16  Game Development / Game Play & Game Design / Re: Not-so-delicious spaghetti code on: 2013-01-25 20:18:04
Yes, but in order for the Action to be aware of the Player's local variables, they would have to be either package-private or public which sproingie described as "hacky".  I consider it to be a little hacky as well, but it could be done.  At least the hacky behavior would be isolated to the player package if the player's variables were package-private.
17  Game Development / Game Play & Game Design / Re: Not-so-delicious spaghetti code on: 2013-01-25 20:11:34
Sounds like a plan.  So, lemme see if this describes what you're suggesting.  I could write something like this in the player...

1  
2  
3  
4  
5  
6  
7  
8  
9  
public void addAction(Action action)
{
    // Adds the action
   actions[size] = action;
    size ++;

    // Gives object that references local variables that are important to the player
   action.setReferences(References ref);
}


Sounds awesome, but how exactly would the adapter object ref be able to point to the local variables in Player?  Would it itself have variables that point to those variables?
18  Game Development / Game Play & Game Design / Not-so-delicious spaghetti code on: 2013-01-25 19:31:07
Hey, so I'm making a game and have already completed the majority of the engine.  It is developed in an object-oriented fashion.  The game works well, but I have one issue that I'm afraid will begin to clutter up my code before too long.

My Player class is 1,499 lines long!

I'll admit that there are a few reasons for the lines being this long.  The Player inherits a lot of different interfaces.  I tend to skip a lot of lines for readability purposes.  For every action the player does, he refers to an Action object within an array which forces me to make many different classes implementing the Action interface who's definition is encapsulated within the Player.

Yeah, so the last item I mentioned is probably responsible for 700 of the 1,499 lines in the Player.java file.  Basically, every action the Player does is delegated by one action in an array of actions.  When I want to start another action, I call upon the method setAction(int action).  Something like this happens...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
/**
* Action gets assigned
*/

public void setAction(int action)
{
    // Leaves our current action by calling the exit method.  Potentially cleans up some leftovers.  I might get rid of this method
   //since it has proven to be pretty useless so far.
   actions[actionPointer].exit();

    // Assigns the action pointer and calls on its enter method for housekeeping purposes.  Action gets ready to be run.
   actionPointer = action;
    actions[actionPointer].enter();
}


/**
* Action gets run
*/

public void update()
{
    actions[actionPointer].run();
}



This paradigm is really nice because the Player's behavior is isolated to one Action object, and the Action object can determine when the player needs to switch to another action.  If you are in the Standing action and are on the ground and pressing up, then the player will go to the Jumping action.  If the player is Jumping, then the check to see if the user is pressing the Up key will never happen.  That check is only in the Standing action.  Many local variables can be stored within each Action object because they only ever related to that action.

This paradigm is also bad because each action takes up many lines of code since each new Action must have a definition that is written in the Player class.

Well, I don't have TOO much of a problem with this since each Action is easy to maintain, but there are also a lot of variables that simply belong to the Player class that determine if the Player is allowed to do something or not.  If the Player is close to a ladder, the ladder will invoke the method consider(Climbable climbable) from the player which alerts the player that a Climbable is nearby.  The player will proceed to climb the ladder if the local boolean canClimb is true.  canClimb is only true if the current Action that is running says it's true.  This code is starting to become tangled...

If anyone has experience preventing this pattern from becoming a disaster, I would appreciate it if you could give me some advice.  As things currently stand, I am perfectly capable of proceeding.  I am just afraid that 1,499 lines of code is unreasonable for a single class.  Like I said before, most of the fluff comes from having to write out new class definitions for new Action object.  I would also like to mention that it is too late for me to adopt the functional paradigm with entities/components because my game engine is rather OO.  I would have to scrap my entire project, excluding some resources, in order to adopt that paradigm.
19  Game Development / Newbie & Debugging Questions / Re: Game gets slower on: 2013-01-25 18:52:18
One thing I've done in the past to locate a memory leak is to implement the finalize method of particularly large objects and have them print out their last words before they get gc'd.  This worked for me because every time I transitioned from room to room in my game, I expected the last room to be gc'd.  When one wasn't, I checked to see what could be hanging on to the room that was also connected to the root of the program.  Just kept deleting elements from the room until that finalize method was called.  I also forced the gc to run to get more immediate results.  I dunno if this will help you, but I just thought I might give you my two cents.
20  Game Development / Game Play & Game Design / Re: Communicating between entities colliding on: 2012-12-24 21:56:01
I would rather start off with something like this:
1  
2  
3  
public void onCollision(CollisionEvent ce) {
   ...
}

You have events and event handlers. One handler could look up an appropriate sound according to the collision participants and play it.
Clearly assign responsibilities and do not mix them.
It could make sense to create different kind of collision events, like player-opponent or player-platform.


I think I get what you're saying.  Forgive me, as I have never written an event driven environment of my own.  Let me paraphrase, if you'll let me.

Would this make my interface, Moveable (the entity that moves and can have collisions enforced on it) the handler, and my interface Collider (the entity that enforces collisions on Moveables) the entity that sends an event object representing the characteristics of the collision?  The Moveable getting hit would handle the event based on the data within it, and the Collider would be the sender.

Instead of having four methods (hitLeft, hitRight, hitUp, hitDown), I could have one called hit(CollisionEvent e)
and e might contain data about which side was hit, what type Collider was responsible for the collision, the time it occurred, the type of surface the Collider has (eg: Gravelly, icy), the relative velocities that should be adopted by the Moveable, etc).
21  Game Development / Game Play & Game Design / Re: Communicating between entities colliding on: 2012-12-24 00:17:04
I do use recycled collision objects as well.
The event/listener concept is very simple but powerful for organizing code.
You could attach multiple listeners responsible for different tasks like:
- low level physics handling
- maintaining the environment, like spawning enemies, opening doors
- effects, animation, sounds
- trigger the game ai
- attach the network module in a multiplayer game

Good to see that I'm not insane.  So, does this imply that I could shamelessly write something like this?

public void hitLeft(CollisionEvent ce, SoundEvent se)
{
    // Insert competent programmer's code here!
}

This WOULD solve my problem in the specific scenario that I've put forth, but I don't want it to hurt me later on.

A collision object should only describe what has happened but not how to handle it, so it should not store concrete sound names, e.g.

The hit methods are there primarily to represent a course of action that should take place in a Moveable object that has been hit.  In reality, it merely alerts it and sends a bit of information regarding the hit.  The Collider is still responsible for positioning the Moveable in the event of a collision.  Sending an event object would simply let the object getting hit handle the rest of the collision in a polymorphic way (usually, this this triggers an Animation in the Entity).  Anywho, I'm worried that passing sound in a method that is supposed to represent collision will end up being a tad arbitrary.  I've had bad experiences in writing god classes, so that's why I'm mentioning this.

What say you?
22  Game Development / Game Play & Game Design / Communicating between entities colliding on: 2012-12-23 02:40:26
Heya!  I'm making a 2D platformer and I already have the collision working well.  Sadly, there isn't enough communication between objects that are colliding with each other that will allow anything specific to happen when a collision occurs.  Lemme describe what currently happens.

I have two interfaces.  The Collider interface enforces collisions on game entitites implementing the Moveable interface.  Entities implementing the Moveable interface store information regarding its velocities and previous positions so that a Collider may do it's job.

When a Collider enforces a collision on a Moveable, the Collider does whatever it needs to do to enforce its collision (positioning the Moveable and setting its velocities to whatever), then it invokes one of the following methods that the Moveable interface specifies:  hitLeft(), hitRight(), hitTop(), hitBottom().  So far, this merely alerts a Moveable that a particular side has been hit.  It's useful when I want an animation to play when a side has been hit, but it doesn't provide enough information.

Currently, when my Player entity (which implements Moveable) is touching the ground, if |velocityX| > 0, then the running animation starts.  What if the platform that the Player is on is moving, though?  The Player's vx will be greater than 0, so the animation for running will play even though the Player SHOULD be standing still on the moving platform.  I want to go about fixing this by allowing there to be a bit more communication between the Collider and the Player when a collision occurs, but I don't want to bloat the Moveable and the Collider interfaces too much.

My first thought was to have the methods hitLeft(), hitRight(), etc...  Require a multitude of parameters such as...

public void hitLeft(float relativeVx)
{
    // Codeity code...
}

The parameter 'relativeVx' would be a velocity x that the Player's run animation would be centered around (instead of having the animation depend on Player's vx being greater than 0).

BUT WAIT!  THERE'S MORE!

What if after I've finally refactored my code, I decide that I also want sound to be attached to collisions?  Now I need to add more parameters to the enforceCollision method, then refactor my code once more!

Then I though of something...  What if I sent in an object representing the collision that happens?  It would allow me to add a multitude of arguments and store it in one object like so:

public void hitLeft(CollisionEvent e)
{
    // Montage of code...
}

Huh, reminds me of swing...

Each time that I invoke this method, of course, I will be reusing the CollisionEvent object instead of creating a new one.  This will work because the CollisionEvent object will be muteable.  The Moveable taking in the CollisionEvent from the Collider will be able to pick and choose which elements of the event to consider, and which to ignore.  The Event could have variables pointing to sounds, the Collider enforcing the collision, visual effects that may be generated because of the collision (sparks, dust particles), info about the Collider's trajectory, etc...  Since I'm not instantiating a new CollisionEvent object each time this happens, I don't have to feel bad about making the garbage collector discard a bunch of short-lived objects, because I'm not.

My only regret is that, one way or another, there is a little bit of bloat that comes about from this process.  The CollisionEvent object may not need a sound attached to it, or the relativeVx variable could be useless because the Collider never moves.

I'm not quite sure if this is the best way to handle this situation, so I'd like to hear what other people have to say!
23  Game Development / Newbie & Debugging Questions / Re: EofException when instantiating ObjectInputStream? on: 2012-12-16 17:45:25
I should have commented that I had solved my problem earlier, but better late than never, I suppose.  I didn't realize that OIS read the file header before actually its actual use.  I was instantiating an OIS with a FileInputStream pointing to an empty file.

So, in conclusion, I should have created an OIS if, and only if, the file existed and had been written to.   Yawn
24  Game Development / Newbie & Debugging Questions / EofException when instantiating ObjectInputStream? on: 2012-12-14 01:26:41
Can anyone explain to me why this would throw an EofException?  It really doesn't make sense to me.

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 void setSaveFile(File saveFile)
   {
      // Assigns the save file
     this.saveFile = saveFile;
      try
      {
         // May create the save file if it does not yet exist
        saveFile.createNewFile();
         
         // Potentially closes streams
        if(!isClosed && in != null)
         {
            in.close();
            out.close();
         }
         
         // Creates new in and out streams
        in = new ObjectInputStream(new FileInputStream(saveFile));    // Decides to get thrown here...
        out = new ObjectOutputStream(new FileOutputStream(saveFile));
      }
      catch(IOException e)
      {
         e.printStackTrace();
      }
   }


Basically, I'm trying to load a save file from the directory "data".  When the file does not exist in this folder, I create a new one.  When I do this, however, this exception gets thrown.

1  
2  
3  
4  
5  
java.io.EOFException
   at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
   at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
   at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
   at java.io.ObjectInputStream.<init>(Unknown Source)


This exception does not get thrown when the file already exists.  Any suggestions?
25  Game Development / Newbie & Debugging Questions / Re: Slick2D Latest distribution on: 2012-11-12 19:00:51
AH!  Thanks so much!  I was looking forever for this!   Grin
26  Game Development / Newbie & Debugging Questions / Slick2D Latest distribution on: 2012-11-12 17:58:40
I am having the hardest time in finding the latest version of Slick2D.  Ever since I discovered the nifty little library, the location of the latest distribution has eluded me.  When downloading from http://slick.cokeandcode.com/, the distribution number is 274.  There is a readme file that states that it is an outdated version.  I also know that it is outdated because the method Image.createOffscreenImage(int width, int height) does not exist in the version I have currently installed.

So, I find the bitbucket page https://bitbucket.org/kevglass/slick/src/3e9cbd75207f569cd951e4e8b0b3d99adf9caaa1/?at=development that should have the latest distribution as specified by http://slick.cokeandcode.com/wiki/doku.php?id=keeping_up_with_the_development_branch.  I click on the development button on the drop window.  Problem is, there is not a "get source" button that is shown in the instructions.  I try downloading the other files given, but none of the downloads have the latest distribution.

I hate to ask this seeing as some people might look down on me for not having the basic google skills to find to find it, but I might need someone to point me in the right direction here.   Undecided
27  Game Development / Newbie & Debugging Questions / Re: (Slick2D) setFilter Resource not found? on: 2012-11-09 22:42:57
Creating a Slick image with no texture should not be possible; it will likely throw a null pointer since Texture is expected to be non-null.

For offscreen buffers where you plan to use getGraphics, you should use the new Image.createOffscreenImage utility and specify a filter there.

I don't understand why you don't just use non-power-of-two tiles, e.g. 45x45. Huh

P.S. In future, always post the exception.




Non power of two tiles don't fit quite as well on my sprite sheets...  Well, that WOULD solve my problem, but let me play the devil's advocate for a moment.  What would be the best course of action if I wanted my game's camera to zoom in and out occasionally?

Edit:  Before I forget, I would like to point out that I've never been able to download a copy of slick that has the method createOffscreenImage() located in the Image class.  Am I perhaps downloading the incorrect distribution?  I always try to find the latest, but I can't seem to find one with that method.  I only every see it in examples.
28  Game Development / Newbie & Debugging Questions / Re: (Slick2D) setFilter Resource not found? on: 2012-11-09 22:34:07
I'm trying to avoid visual artifacts.  I either have to settle for making my tiles 32x32, or 64x64.  32x32 is too small, and 64x64 is too big, so I want to scale the entire screen down by about 30%.  Well, TiledMaps generally don't scale well, so I decided to buffer all the content to an offscreen buffer, then scale the buffer.
29  Game Development / Newbie & Debugging Questions / (Slick2D) setFilter Resource not found? on: 2012-11-09 20:22:05
Seems that whenever you create a new image in slick that has no texture, setting its filter throws an exception that complains about the resource not being found.  I am trying to double buffer something.  Any thoughts as to how to apply a filter to a buffer image?
30  Game Development / Newbie & Debugging Questions / Re: (Slick2D) TiledMap scaling quality on: 2012-11-02 20:15:40
Quote
I've considered rendering all that there is to a second buffer, then scaling said buffer.  I would do this by drawing my objects to an Image, then drawing the scaled image to the graphics context in the render method.
This is an easy solution and should give you pretty good results. Benchmark & stress test it to see if the performance is acceptable, as it will lead to extra texture binds and high fill rate.

Read the following links to get a better understanding of sprite rendering in Slick/OpenGL:
http://www.slick2d.org/wiki/index.php/Performance
http://slick.javaunlimited.net/viewtopic.php?p=31225#p31225
http://slick.javaunlimited.net/viewtopic.php?p=31187#p31187

Thanks for the rendering tips!  Eventually, I AM going to have to learn how to use openGL.  I just post that the method I suggested seems to work fine.  I don't know how it will perform on a larger scale, though.
Pages: [1] 2 3 4
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (70 views)
2013-05-17 21:29:12

alaslipknot (80 views)
2013-05-16 21:24:48

gouessej (111 views)
2013-05-16 00:53:38

gouessej (106 views)
2013-05-16 00:17:58

theagentd (117 views)
2013-05-15 15:01:13

theagentd (106 views)
2013-05-15 15:00:54

StreetDoggy (150 views)
2013-05-14 15:56:26

kutucuk (174 views)
2013-05-12 17:10:36

kutucuk (171 views)
2013-05-12 15:36:09

UnluckyDevil (180 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.408 seconds with 20 queries.