Rev 1296 |
Rev 1361 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.burutaru.game.entities.enemies;
import com.gebauz.bauzoid.math.Vector2;
import com.gebauz.bauzoid.math.collision.Shape;
import com.gebauz.bauzoid.parser.ParseUtil;
import com.gebauz.bauzoid.parser.ScanException;
import com.gebauz.bauzoid.parser.Tokenizer;
import com.gebauz.burutaru.GameConsts;
/* A single instance of an enemy. */
public abstract class EnemyInstance
{
// Constants========================================================================================
// Embedded Types===================================================================================
// Fields===========================================================================================
private Enemy mParent =
null;
public String name =
"";
public float spawnAt = 0.0f
;
public Vector2 spawnPosition =
new Vector2
(GameConsts.
VIRTUAL_SCREEN_WIDTH +
100, GameConsts.
VIRTUAL_SCREEN_HEIGHT/
2);
public int health =
100;
// Methods==========================================================================================
public EnemyInstance
(Enemy parent,
String instanceName,
int defaultHealth
)
{
mParent = parent
;
name = instanceName
;
health = defaultHealth
;
}
/** Called post-init. */
public abstract void init
();
/** Called when called into appearance. */
public abstract void spawn
();
public abstract void exit
();
public abstract void update
(float deltaTime
);
public abstract void render
();
public abstract void die
();
/** TODO: maybe add more parameters (source of damage, etc.). */
public abstract void projectileHit
(int damage
);
public abstract void addImpulse
(float x,
float y
);
public abstract Shape getShape
();
public void applyDamage
(int damage
)
{
health -= damage
;
if (health
<=
0)
die
();
}
public boolean readParameter
(Tokenizer t,
String id
) throws ScanException
{
if (id.
equalsIgnoreCase("spawnAt"))
{
spawnAt = t.
readNumber();
}
else if (id.
equalsIgnoreCase("spawnPosition"))
{
spawnPosition = ParseUtil.
readVector2(t
);
}
else
{
return false;
}
t.
readToken(";");
return true;
}
// Getters/Setters==================================================================================
public final Enemy getParent
() { return mParent
; }
public final boolean hasSpawned
()
{
return (mParent.
getGameLogic().
getLevelTimer() >= spawnAt
);
}
/** Subclasses can define this to narrower definitions. */
public boolean isAlive
()
{
return (hasSpawned
() && (health
> 0));
}
}