|
| 1 | +package org.sfsoft.jfighter2dx.characters; |
| 2 | + |
| 3 | +import com.badlogic.gdx.graphics.g2d.Animation; |
| 4 | +import com.badlogic.gdx.graphics.g2d.SpriteBatch; |
| 5 | +import com.badlogic.gdx.graphics.g2d.TextureRegion; |
| 6 | +import com.badlogic.gdx.math.Rectangle; |
| 7 | +import com.badlogic.gdx.utils.Disposable; |
| 8 | + |
| 9 | +/** |
| 10 | + * Representa cualquier elemento animado (juegador o NPC) del juego |
| 11 | + * @author Santiago Faci |
| 12 | + * |
| 13 | + */ |
| 14 | +public abstract class Character implements Disposable { |
| 15 | + |
| 16 | + // Velocidad del personaje |
| 17 | + private float speed; |
| 18 | + // Velocidad de los proyectiles del personaje |
| 19 | + private float bulletSpeed; |
| 20 | + // Ratio de disparo |
| 21 | + private float bulletRate; |
| 22 | + // Puntos (si procede) |
| 23 | + private int points; |
| 24 | + // Vidas |
| 25 | + private int lives; |
| 26 | + |
| 27 | + // Posición y rectángulo representados por el personaje |
| 28 | + protected float x; |
| 29 | + protected float y; |
| 30 | + private Rectangle rect; |
| 31 | + |
| 32 | + // Animación del personaje |
| 33 | + protected Animation animation; |
| 34 | + protected float stateTime; |
| 35 | + protected TextureRegion currentFrame; |
| 36 | + |
| 37 | + // Dirección de salida del personaje |
| 38 | + public enum Direction { |
| 39 | + LEFT, RIGHT |
| 40 | + } |
| 41 | + |
| 42 | + public Character(float x, float y) { |
| 43 | + |
| 44 | + // Default values |
| 45 | + speed = 200f; |
| 46 | + bulletSpeed = 400f; |
| 47 | + bulletRate = 0.2f; |
| 48 | + points = 100; |
| 49 | + lives = 1; |
| 50 | + |
| 51 | + this.x = x; |
| 52 | + this.y = y; |
| 53 | + } |
| 54 | + |
| 55 | + public Character(float x, float y, float speed) { |
| 56 | + |
| 57 | + // Default values |
| 58 | + bulletSpeed = 400f; |
| 59 | + bulletRate = 0.2f; |
| 60 | + points = 100; |
| 61 | + lives = 1; |
| 62 | + |
| 63 | + this.speed = speed; |
| 64 | + this.x = x; |
| 65 | + this.y = y; |
| 66 | + } |
| 67 | + |
| 68 | + public float getSpeed() { |
| 69 | + return speed; |
| 70 | + } |
| 71 | + |
| 72 | + public void setSpeed(float speed) { |
| 73 | + this.speed = speed; |
| 74 | + } |
| 75 | + |
| 76 | + public float getBulletSpeed() { |
| 77 | + return bulletSpeed; |
| 78 | + } |
| 79 | + |
| 80 | + public void setBulletSpeed(float bulletSpeed) { |
| 81 | + this.bulletSpeed = bulletSpeed; |
| 82 | + } |
| 83 | + |
| 84 | + public float getBulletRate() { |
| 85 | + return bulletRate; |
| 86 | + } |
| 87 | + |
| 88 | + public void setBulletRate(float bulletRate) { |
| 89 | + this.bulletRate = bulletRate; |
| 90 | + } |
| 91 | + |
| 92 | + public int getPoints() { |
| 93 | + return points; |
| 94 | + } |
| 95 | + |
| 96 | + public void setPoints(int points) { |
| 97 | + this.points = points; |
| 98 | + } |
| 99 | + |
| 100 | + public int getLives() { |
| 101 | + return lives; |
| 102 | + } |
| 103 | + |
| 104 | + public void setLives(int lives) { |
| 105 | + this.lives = lives; |
| 106 | + } |
| 107 | + |
| 108 | + public float getX() { |
| 109 | + return x; |
| 110 | + } |
| 111 | + |
| 112 | + public void setX(float x) { |
| 113 | + this.x = x; |
| 114 | + } |
| 115 | + |
| 116 | + public float getY() { |
| 117 | + return y; |
| 118 | + } |
| 119 | + |
| 120 | + public void setY(float y) { |
| 121 | + this.y = y; |
| 122 | + } |
| 123 | + |
| 124 | + public Rectangle getRect() { |
| 125 | + return rect; |
| 126 | + } |
| 127 | + |
| 128 | + public void setRect(Rectangle rect) { |
| 129 | + this.rect = rect; |
| 130 | + } |
| 131 | + |
| 132 | + public float getRectX() { |
| 133 | + return rect.getX(); |
| 134 | + } |
| 135 | + |
| 136 | + public void setRectX(float x) { |
| 137 | + rect.setX(x); |
| 138 | + } |
| 139 | + |
| 140 | + public float getRectY() { |
| 141 | + return rect.getY(); |
| 142 | + } |
| 143 | + |
| 144 | + public void setRectY(float y) { |
| 145 | + rect.setY(y); |
| 146 | + } |
| 147 | + |
| 148 | + // Recibe un impacto |
| 149 | + public void hit() { |
| 150 | + lives--; |
| 151 | + } |
| 152 | + |
| 153 | + // Dibuja en pantalla el personaje |
| 154 | + public abstract void draw(SpriteBatch batch); |
| 155 | + |
| 156 | + public void die() {} |
| 157 | + |
| 158 | + @Override |
| 159 | + public void dispose() { |
| 160 | + |
| 161 | + rect = null; |
| 162 | + animation = null; |
| 163 | + } |
| 164 | +} |
0 commit comments