Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 26, 2013 3:01 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sat Apr 28, 2012 6:46 pm 
Offline

Joined: Wed Mar 28, 2012 9:28 pm
Posts: 16
This is some proof of concept code for a tank game I'm writing in Java using Slick2D and lwjgl libraries.

Fraps is making this much jerkier than it actually is. I'm actually getting about 550 Frames per second and the animation is really smooth.

I'm running a two image tank over a tiled map using Kappa's Camera class (slightly modified to return camera position). The bullets are coming out of the tank turret at the proper angle. Also, I'm cleaning up memory properly so when a bullet goes beyond the edge of the screen it is released and garbage collected. The debug text at the bottom shows the number of projectiles in memory at any point.

So far, it's been pretty fun learning the Slick2D library.

http://youtu.be/2iM_dBmKYKg


Top
 Profile  
 
PostPosted: Sat Apr 28, 2012 11:18 pm 
Offline
Regular

Joined: Sun Oct 11, 2009 8:53 pm
Posts: 219
Looking like a good start!
i liked that you take care about the memory use of the game.


Top
 Profile  
 
PostPosted: Fri May 04, 2012 3:39 pm 
Offline

Joined: Wed Mar 28, 2012 9:28 pm
Posts: 16
I'm finding that a better solution to removing bullets once they're offscreen is a multi leveled approach

As an object, if I'm offscreen then set my isOffscreen to true and start a timer which goes for 2 seconds.

If, during that 2 seconds, I'm no longer offscreen then set isOffscreen to false and the timer to zero.

If 2 second end and isOffscreen is still true then set booelan shouldDelete=true.

On the update method find all objects where shouldDelete is true and put them in the "delete these things" queue. This fixes a concurrent modification error where I'm walking through a list of projectiles in my update method and trying to delete from that same list while I'm walking through it. So I walk through the list doing my update, then check the "should be deleted" queue and remove those from the projectile list. Once removed from the list there are no more references to those objects and the garbage collector should catch them the next time it runs.

The reason for the 2 seconds rule is two-fold:

I'm now adding particle effects as smoke trails to the bullets. Once the bullet goes offscreen it's deleted and the smoke trail vanishes. With a 2 second delay the smoke will flow off of the screen as well.

If a mine is just outside the screen and it fires, every projectile is offscreen so the immediately get deleted. The 2 second rule will allow me to fire from offscreen.


Top
 Profile  
 
PostPosted: Sat May 05, 2012 3:00 am 
Offline

Joined: Wed Mar 28, 2012 9:28 pm
Posts: 16
I have a new video here

I have mines which spew bullets. Tank projectiles which have particle emitter smoke trails behind them, and a block of 5 mines at the top of the page which spew about 1000 bullets from off screen. Oh, and check out the explosions! I'm using an explosion generator I found here which was written by Cliff Harris, the guy who wrote Gratuitous Space Battles.

As a proof of concept project I think it's starting to come together.

And I have to say, after all the stress of building REST based stateless interfaces for legal matter management systems all day at work, this is vastly more fun.


Top
 Profile  
 
PostPosted: Sun May 06, 2012 5:11 am 
Offline

Joined: Sun Jan 02, 2011 8:39 pm
Posts: 64
Instead of deleting bullets you could use a Object Pool and just recycle them and reset the properties when they go offscreen.


Top
 Profile  
 
PostPosted: Sun May 06, 2012 5:24 pm 
Offline

Joined: Wed Mar 28, 2012 9:28 pm
Posts: 16
Squizzle wrote:
Instead of deleting bullets you could use a Object Pool and just recycle them and reset the properties when they go offscreen.


That's a cool idea. It would remove the overhead of creating the objects and lesson the chance of the garbage collector being called during play time.

Good call.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group