/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.maps.entities;
import transientlibs.maps.units.GenericUnit;
import transientlibs.maps.units.Unit;
import transientlibs.maps.tiles.Tile;
import transientlibs.maps.implementation.TilelessMap;
import transientlibs.bindedobjects.gamecontent.Missiles;
import transientlibs.bindedobjects.gamecontent.Terrain;
import java.util.Random;
import transientlibs.maps.implementation.TilelessMap;
/**
*
* @author kibertoad
*/
public class Bullet extends MapObject {
public float tileX = 0.0f;
public float tileY = 0.0f;
public float bornX = 0.0f;
public Missiles missile;
public static Bullet lastBullet;
public int damage;
public float vectorX;
public float vectorY;
public void processTurn() {
}
@Override
public void becomeDestroyed() {
//isDestroyed = true;
super.becomeDestroyed();
onMap.missiles.remove(this);
currentTile().missiles.remove(this);
}
public void initRemoval (){
isDestroyed = true;
MapObject.killList.add(this);
}
@Override
public void performMove(float xDelta, float yDelta) {
if (terrainCollision(xDelta, yDelta)){
//if (onMap.tile[mapCoords.getIntX()][mapCoords.getIntY()].terrain.moveCost == -1) {
initRemoval();
} else{
//if (onMap.tile[mapCoords.getIntX() + xDelta][mapCoords.getIntY() + yDelta].terrain.moveCost!=-1){
performTeleport(mapCoords.x + xDelta, mapCoords.y + yDelta);
}
/*
* } else
*
* {
* isDestroyed = true; MapObject.killList.add(this); }
*
*/
}
public void bindToMap() {
onMap.missiles.add(this);
}
public void bindToTile() {
onMap.getTile(mapCoords.getIntX(), mapCoords.getIntY()).missiles.add(this);
calcImagePosition();
}
@Override
public void performTeleport(float toX, float toY) {
//Log.info("Pre-move coords are: "+mapCoords.toString());
Tile oldTile = onMap.getTile(mapCoords.getIntX(), mapCoords.getIntY());
Tile newTile = onMap.getTile(mapCoords.getIntX(), mapCoords.getIntY());
mapCoords.x = toX;
mapCoords.y = toY;
if (oldTile != newTile){
oldTile.missiles.remove(this);
newTile.missiles.add(this);
}
calcImagePosition();
processEncounteredUnits();
//Log.info("after move coords are: "+mapCoords.toString());
}
public void processEncounteredUnits() {
/*
* if (!(currentTile().units.isEmpty())) {
*
* currentTile().units.get(0).getDamage(damage);
*
* MapObject.killList.add(this);
*
*
* }
*
*
*/
for (GenericUnit u : onMap.units) {
if ((u.getSide().value != side.value) && (isVisiblyCollided((Unit)u))) {
u.getDamage(damage);
MapObject.killList.add(this);
}
}
}
public Bullet(int onX, int onY, int setType, TilelessMap setMap) {
super(setMap, Missiles.missiles.get(setType).image);
missile = Missiles.missiles.get(setType);
ofType = setType;
mapCoords.x = onX;
mapCoords.y = onY;
isDrawn = true;
Random r = new Random();
bornX = r.nextFloat();
//pathfinder = new PathFinder(mapCoords);
//pathfinder.movementReach = creature.movementSpeed;
//maxActionPoints.value = creature.movementSpeed;
//actionPoints.value = maxActionPoints.value;
}
public static void setupNew(Bullet newBullet, int onSide, int ofID, int setX, int setY, TilelessMap setMap) {
lastBullet = newBullet;
lastBullet.side.value = onSide;
lastBullet.ID = ofID;
lastBullet.bindToMap();
lastBullet.bindToTile();
}
@Override
public void draw(int onX, int onY) {
int x, y;
if (currentTile().onScreen) {
x = onX + (int) ((tileX + bornX) * 32.0);
y = onY + (int) (tileY * 32.0);
//Log.info("onX "+onX);
if (currentAnimation != null) {
//Log.info("draw animation");
currentAnimation.draw(x, y);
} else {
super.draw(x, y);
}
}
}
@Override
public void calcImagePosition() {
screenCoords.x = mapCoords.x - onMap.eye.eyePosition.x;
screenCoords.y = mapCoords.y - onMap.eye.eyePosition.y;
//screenCoords.x = (Terrain.tileWidth) + (Terrain.tileWidth * screenCoords.x) + 13;
//screenCoords.getIntY() = (Terrain.tileHeight) + (Terrain.tileHeight * screenCoords.getIntY()) + 16;
//screenCoords.x = (Terrain.tileWidth * screenCoords.x) + 13;
screenCoords.x = (Terrain.tileWidth * screenCoords.x);
//screenCoords.y = (Terrain.tileHeight) + (Terrain.tileHeight * screenCoords.y) + 16;
//screenCoords.y = (Terrain.tileHeight) + (Terrain.tileHeight * screenCoords.y);
screenCoords.y = (Terrain.tileHeight) + (Terrain.tileHeight * screenCoords.y)-14;
//screenCoords.x = (imageLink.getWidth()) + (imageLink.getWidth() * screenCoords.x);
//screenCoords.y = (imageLink.getHeight()) + (imageLink.getHeight() * screenCoords.y);
}
public void drawLegacy() {
//Log.info(screenCoords.x+"/"+screenCoords.getIntY());
//Log.info(mapCoords.x+"/"+mapCoords.y);
//calcImagePosition();
if (currentTile().onScreen) {
int x, y;
x = (int) ((tileX + bornX) * 32.0);
y = (int) (tileY * 32.0);
if (currentAnimation != null) {
//Log.info("draw animation");
currentAnimation.draw(screenCoords.getIntX() + x, (int) screenCoords.getIntY() + y);
} else {
super.draw(screenCoords.getIntX() + x, (int) screenCoords.getIntY() + y);
}
}
}
@Override
public void draw() {
//Log.info(screenCoords.x+"/"+screenCoords.getIntY());
//Log.info(mapCoords.x+"/"+mapCoords.y);
//calcImagePosition();
if (currentTile().onScreen) {
if (currentAnimation != null) {
//Log.info("draw animation");
currentAnimation.draw(screenCoords.getIntX(), (int) screenCoords.getIntY());
} else {
super.draw(screenCoords.getIntX(), (int) screenCoords.getIntY());
}
}
}
}