package complexion.client; import java.awt.image.BufferedImage; import java.util.ArrayList; import complexion.resource.Sprite; /** * Client-side representation of a game Atom, that is, * an object displayed on the map. * * Only provides the data required for rendering objects, * as well as interacting with them(such as using verbs). * */ public class Atom { /// Unique ID of the object, generated by the server. public int UID; /// Position on the map as a tile /// This is used for problems like visibility and lighting calculation public int tile_x,tile_y; /// Purely visual pixel offset. This is added to the calculated tile position. /// Doesn't affect visibility and lighting calculations. public int pixel_x,pixel_y; /// Sprite the object is currently associated with. public Sprite sprite; /// Determines whether the object will be rendered above or /// below other objects public int layer; /// Each sprite has multiple states, which are more or less /// sprites of their own. sprite_state determines which state /// is used. public String sprite_state; /// The current animation frame the sprite is in. public int frame; // test public ArrayList<Atom> overlays; /// A sprite can define different appearances depending on the /// direction. This variable should be one of the constants defined /// in complexion.Direction public int direction; /// This may be used to define how a click should be treated. /// Two possible values /// 0 = //Transparent to the mouse , ignored completely /// 1 = // Transparent to the mouse where the Atoms icon is transparent public int mouse_opacity = 1; /// If this is set to false, the atom will always have the same position /// on the viewport, rather than being tied to a map position. boolean onMap = true; /** * @return The image currently representing the atom, given state, frame and direction. */ public BufferedImage getCurrentImage() { return sprite.getImage(sprite_state, frame, direction); } /** * Check if the atom is transparent the pixel coordinates inside the current sprite. * @param offset_x // The x pixel coordinate inside the image * @param offset_y // The y pixel coordinate inside the image * @return : Returns true if Transparent at the coordinates false if not. */ public boolean isTransparent(int offset_x, int offset_y) { // TODO : Overlays support. BufferedImage img = sprite.getImage(sprite_state,frame,direction); int pixel = img.getRGB(offset_x,offset_y); // Get the RGBA bits if( (pixel>>24) == 0x00 ) { // Check Alpha bit if 0x00 then its transparent. return true; } return false; } }