Rev 993 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 929 | chris | 1 | package com.gebauz.burutaru.game.entities; |
| 2 | |||
| 3 | import com.gebauz.bauzoid.math.Matrix4; |
||
| 950 | chris | 4 | import com.gebauz.bauzoid.math.collision.AABoundingBox; |
| 929 | chris | 5 | import com.gebauz.bauzoid.math.collision.Shape; |
| 6 | |||
| 7 | /** Abstract base class for enemies that provides access to position, hit-check, and utility functionality. */ |
||
| 993 | chris | 8 | public abstract class Enemy implements ICollidable |
| 929 | chris | 9 | { |
| 10 | // Constants======================================================================================== |
||
| 11 | |||
| 965 | chris | 12 | public static final float DAMAGE_COOLDOWN_TIME = 0.25f; |
| 929 | chris | 13 | |
| 14 | // Embedded Types=================================================================================== |
||
| 15 | |||
| 16 | // Fields=========================================================================================== |
||
| 17 | |||
| 18 | private int mHealth = 10; |
||
| 19 | |||
| 20 | /** Timer to prevent that an object is instantly killed. */ |
||
| 21 | private float mDamageCoolDown = -1.0f; |
||
| 22 | |||
| 23 | // Methods========================================================================================== |
||
| 24 | |||
| 934 | chris | 25 | public Enemy(int health) |
| 929 | chris | 26 | { |
| 934 | chris | 27 | mHealth = health; |
| 929 | chris | 28 | } |
| 29 | |||
| 30 | public void update(float deltaTime) |
||
| 31 | { |
||
| 32 | if (mDamageCoolDown > 0.0f) |
||
| 33 | mDamageCoolDown -= deltaTime; |
||
| 34 | } |
||
| 35 | |||
| 940 | chris | 36 | public abstract void render(); |
| 37 | |||
| 993 | chris | 38 | @Override |
| 929 | chris | 39 | public void hit(int damage) |
| 40 | { |
||
| 964 | chris | 41 | if (mDamageCoolDown > 0.0f) |
| 929 | chris | 42 | return; |
| 43 | |||
| 44 | mHealth -= damage; |
||
| 45 | |||
| 46 | if (mHealth <= 0) |
||
| 47 | { |
||
| 48 | die(); |
||
| 49 | return; |
||
| 50 | } |
||
| 51 | |||
| 52 | mDamageCoolDown = DAMAGE_COOLDOWN_TIME; |
||
| 53 | } |
||
| 54 | |||
| 997 | chris | 55 | /** Do the same as checkHit as default. */ |
| 56 | @Override |
||
| 57 | public boolean checkShipHit(Ship ship) |
||
| 58 | { |
||
| 59 | return checkHit(ship.getShape(), ship.getShapeTransform()); |
||
| 60 | } |
||
| 61 | |||
| 936 | chris | 62 | public abstract void die(); |
| 929 | chris | 63 | |
| 941 | chris | 64 | /** Similar to die, but simply vanishes. */ |
| 65 | public void vanish() { mHealth = -1; } |
||
| 66 | |||
| 929 | chris | 67 | // Getters/Setters================================================================================== |
| 68 | |||
| 937 | chris | 69 | public final void setHealth(int health) { mHealth = health; } |
| 70 | public final void addHealth(int health) { mHealth += health; } |
||
| 929 | chris | 71 | public final int getHealth() { return mHealth; } |
| 72 | public final boolean isAlive() { return (mHealth > 0); } |
||
| 73 | |||
| 993 | chris | 74 | |
| 929 | chris | 75 | |
| 76 | } |
||
| 77 | |||
| 78 | |||
| 79 |