Results 1 to 13 of 13
- 05-10-2012, 07:50 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 27
- Rep Power
- 0
Wasn't my code was genetics while adding the harsh map
package model;
import controller.MyLogger;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
/**
* A resource manager for sprites in the game. Its often quite important how and
* where you get your game resources from. In most cases it makes sense to have
* a central resource loader that goes away, gets your resources and caches them
* for future use. <p> [singleton] <p>
*
* @author Kevin Glass
*/
public class SpriteStore {
protected static String SPRITE_FOLDER = "sprites/";
/**
* The single instance of this class
*/
private static SpriteStore single = new SpriteStore();
/**
* The cached sprite map, from reference to sprite instance
*/
private HashMap<String, Sprite> sprites = new HashMap<String, Sprite>();
/**
* Get the single instance of this class
*
* @return The single instance of this class
*/
public static SpriteStore get() {
return single;
}
/**
* Retrieve a sprite from the store
*
* @param ref The reference to the image to use for the sprite
* @return A sprite instance containing an accelerate image of the request
* reference
*/
public Sprite getSprite(String ref) {
// if we've already got the sprite in the cache
// then just return the existing version
if (sprites.get(ref) != null) {
return sprites.get(ref);
}
// otherwise, go away and grab the sprite from the resource
// loader
BufferedImage sourceImage = null;
try {
// The ClassLoader.getResource() ensures we get the sprite
// from the appropriate place, this helps with deploying the game
// with things like webstart. You could equally do a file look
// up here.
URL url = getClass().getClassLoader().getResource(SPRITE_FOL DER + ref);
if (url == null) {
fail("Can't find ref: " + SPRITE_FOLDER + ref);
}
// use ImageIO to read the image in
sourceImage = ImageIO.read(url);
} catch (IOException e) {
e.printStackTrace();
fail("Failed to load: " + ref);
}
// create an accelerated image of the right size to store our sprite in
//GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration() ;
//Image image = gc.createCompatibleImage(sourceImage.getWidth(), sourceImage.getHeight(), Transparency.BITMASK);
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration() ;
Image image = gc.createCompatibleImage(sourceImage.getWidth(), sourceImage.getHeight(), 2);
// draw our source image into the accelerated image
image.getGraphics().drawImage(sourceImage, 0, 0, null);
// create a sprite, add it the cache then return it
Sprite sprite = new Sprite(ref, image);
sprites.put(ref, sprite);
return sprite;
}
/**
* Utility method to handle resource loading failure
*
* @param message The message to display on failure
*/
private void fail(String message) {
// we're pretty dramatic here, if a resource isn't available
// we dump the message and exit the game
Logger.getLogger("SpaceInvadersLog").log(Level.SEV ERE, message);
System.exit(0);
}
}
wasn't sure my code is genetics while adding the harshmap including the method
- 05-10-2012, 08:56 AM #2
Re: Wasn't my code was genetics while adding the harsh map
Your code? You're Kevin Glass?
http://www.cs.unc.edu/~hedlund/comp1...priteStore.txt
I can guess why a StackOverflow moderator removed your cross post.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-10-2012, 09:23 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
Re: Wasn't my code was genetics while adding the harsh map
If I had to handle a harsh map I'd violently push those keys and associated values through its throat; that should teach it ;-)
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-10-2012, 10:02 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
Re: Wasn't my code was genetics while adding the harsh map
The trouble with the Corrections Framework is that these young maps get influenced by the older ones. Someone introduces them to unmodifiableMap() and, basically, they'll never be any good.If I had to handle a harsh map...
- 05-10-2012, 10:04 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: Wasn't my code was genetics while adding the harsh map
I blame their genetics.
Please do not ask for code as refusal often offends.
- 05-10-2012, 10:05 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
- 05-10-2012, 11:54 AM #7
- 05-10-2012, 01:12 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
Re: Wasn't my code was genetics while adding the harsh map
Don't ever do that; rumours go that harsh maps eat all the gloves in the compartment and when they're bored they break their way to the engine compartment (they have huge fangs you know) and create a total mess out of your engine so don't say I didn't warn you when your car makes it to a shrieking halt on the middle of the highway; they're nasty rascals those harsh maps ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-10-2012, 05:35 PM #9
Member
- Join Date
- May 2012
- Posts
- 18
- Rep Power
- 0
Re: Wasn't my code was genetics while adding the harsh map
I must strongly disagree with this, and I recent the accusation. My father – and his father before him – were both harsh maps, and they never hurt any gloves unless they are in immediately danger. If anything it is the gloves who are the bad guys here. You have no idea what they try to smuggle in their thumbs; everything from sawn-off fingers to memory sticks containing God knows what.
You can read more about the poor maps on www.harshmapsarealsopeople.com
- 05-10-2012, 05:49 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
Re: Wasn't my code was genetics while adding the harsh map
The SPIGARHM (Society Protecting Innocent Gloves Against Rude Harsh Maps) protests against the previous message in the strongest possible way and have taken the mentioned web site off the air because it contains all just damned lies. Gloves are cute, harshmaps are evil.
kind regards,
Jos (founding father of the SPIGARHM)When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-10-2012, 07:07 PM #11
Member
- Join Date
- May 2012
- Posts
- 18
- Rep Power
- 0
- 05-10-2012, 07:19 PM #12
- 05-10-2012, 08:11 PM #13
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
Re: Wasn't my code was genetics while adding the harsh map
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Class Wasn't Found in Project
By BrooksyFC in forum NetBeansReplies: 14Last Post: 05-03-2012, 10:35 AM -
Code review on adding sentences to String array
By nn12 in forum New To JavaReplies: 6Last Post: 03-21-2011, 02:27 PM -
Adding line numbers to code in output file
By misterwebb in forum New To JavaReplies: 2Last Post: 02-14-2011, 12:37 AM -
adding code to constructor
By twillders in forum New To JavaReplies: 5Last Post: 12-13-2010, 08:29 PM -
Code for adding search function in an application
By Avdhut in forum Threads and SynchronizationReplies: 5Last Post: 03-03-2009, 10:15 AM


4Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks