more progress on shard entity

This commit is contained in:
Harrison Deng 2017-06-02 17:12:08 -05:00
parent bf9612cb3b
commit a12ec18ebb
2 changed files with 41 additions and 3 deletions

View File

@ -78,6 +78,7 @@ public class PolyJetEntity extends Actor implements Entity {
thrust.draw(batch);
batch.setColor(Color.BLACK);
batch.draw(polyjet, getX(), getY(), getWidth(), getHeight());
batch.setColor(Color.WHITE);
super.draw(batch, parentAlpha);
}

View File

@ -1,49 +1,80 @@
package zero1hd.polyjet.entity.enemies;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.Pool.Poolable;
import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.Entity;
public class Shard extends Actor implements Entity, Poolable {
public class Shard extends Actor implements Entity, Poolable, Disposable {
private Sprite sprite;
private Texture shard;
private Rectangle hitbox;
private Vector2 angle;
private Vector2 center;
private int hp;
private int maxHp;
private float rate;
public Shard(Texture shardTexture) {
this.shard = shardTexture;
hitbox = new Rectangle();
angle = new Vector2();
sprite = new Sprite(shardTexture);
center = new Vector2();
}
public void init(float x, float y, float angle, float rate, int hp) {
this.rate = rate;
this.hp = hp;
maxHp = hp;
setPosition(x, y);
this.angle.set(MathUtils.sinDeg(angle), MathUtils.cosDeg(angle));
sprite.setRotation(angle);
setSize(1f, 1f);
hitbox.setSize(getWidth(), getHeight());
center.set(getWidth()/2f, getHeight()/2f);
sprite.setOrigin(sprite.getWidth()/2f, sprite.getHeight()/2f);
}
@Override
public void reset() {
hp = 0;
setPosition(0, 0);
angle.set(0, 0);
center.set(0, 0);
setSize(0, 0);
maxHp = 0;
hitbox.set(0, 0, 0, 0);
setSize(0, 0);
sprite.setRotation(0);
}
@Override
public void act(float delta) {
moveBy(angle.x*delta*rate, angle.y*rate*delta);
sprite.setPosition(getX()+center.x, getY()+center.y);
super.act(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
sprite.draw(batch);
super.draw(batch, parentAlpha);
}
@Override
public void collided(Entity entity) {
// TODO Auto-generated method stub
}
@Override
@ -64,4 +95,10 @@ public class Shard extends Actor implements Entity, Poolable {
return false;
}
@Override
public void dispose() {
shard.dispose();
}
}