Initial upload
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package io.anuke.moment.entities;
|
||||
|
||||
import io.anuke.ucore.entities.BulletEntity;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.entities.SolidEntity;
|
||||
|
||||
public class Bullet extends BulletEntity{
|
||||
BulletType type;
|
||||
|
||||
public Bullet(BulletType type, Entity owner, float x, float y, float angle){
|
||||
super(owner, type.speed, angle);
|
||||
set(x, y);
|
||||
this.lifetime = type.lifetime;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
type.draw(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collision(SolidEntity other){
|
||||
super.collision(other);
|
||||
type.collide(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamage(){
|
||||
return type.damage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package io.anuke.moment.entities;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.entities.Effects;
|
||||
|
||||
public enum BulletType{
|
||||
stone(1.5f, 2){
|
||||
public void draw(Bullet b){
|
||||
Draw.color("gray");
|
||||
Draw.square(b.x, b.y, 1f);
|
||||
Draw.clear();
|
||||
}
|
||||
},
|
||||
iron(1.7f, 2){
|
||||
public void draw(Bullet b){
|
||||
Draw.color("gray");
|
||||
Draw.rect("bullet", b.x, b.y, b.angle());
|
||||
Draw.clear();
|
||||
}
|
||||
},
|
||||
small(1.5f, 1){
|
||||
public void draw(Bullet b){
|
||||
Draw.color("orange");
|
||||
Draw.rect("bullet", b.x, b.y, b.angle());
|
||||
Draw.clear();
|
||||
}
|
||||
},
|
||||
shot(2.4f, 2){
|
||||
{lifetime=40;}
|
||||
public void draw(Bullet b){
|
||||
Draw.color(Color.GOLD);
|
||||
Draw.rect("bullet", b.x, b.y, b.angle());
|
||||
Draw.clear();
|
||||
}
|
||||
};;
|
||||
public float speed;
|
||||
public int damage;
|
||||
public float lifetime = 60;
|
||||
|
||||
private BulletType(float speed, int damage){
|
||||
this.speed = speed;
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
public void collide(Bullet b){
|
||||
Effects.effect("hit", b);
|
||||
}
|
||||
public void draw(Bullet b){}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package io.anuke.moment.entities;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import io.anuke.moment.Control;
|
||||
import io.anuke.moment.Moment;
|
||||
import io.anuke.moment.ai.Pathfind;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.entities.*;
|
||||
import io.anuke.ucore.util.Timers;
|
||||
|
||||
public class Enemy extends DestructibleEntity{
|
||||
public static int amount = 0;
|
||||
|
||||
public Vector2 direction = new Vector2();
|
||||
public float xvelocity, yvelocity;
|
||||
public float speed = 0.3f;
|
||||
public int node = -1;
|
||||
public Entity target;
|
||||
public int spawn;
|
||||
public float reload = 40;
|
||||
|
||||
public Enemy(int spawn){
|
||||
this.spawn = spawn;
|
||||
|
||||
hitsize = 5;
|
||||
|
||||
maxhealth = 30;
|
||||
heal();
|
||||
|
||||
amount ++;
|
||||
}
|
||||
|
||||
void move(){
|
||||
Vector2 vec = Pathfind.find(this);
|
||||
vec.sub(x, y).setLength(speed);
|
||||
|
||||
Moment.module(Control.class).tryMove(this, vec.x*delta, vec.y*delta);
|
||||
|
||||
target = Entities.getClosest(x, y, 60, e->{
|
||||
return (e instanceof TileEntity || e instanceof Player);
|
||||
});
|
||||
|
||||
if(target != null){
|
||||
if(Timers.get(this, reload))
|
||||
new Bullet(BulletType.small, this, x, y, direction.angle()).add();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean collides(SolidEntity other){
|
||||
return (other instanceof Bullet) && !(((Bullet)other).owner instanceof Enemy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeath(){
|
||||
Effects.effect("explosion", this);
|
||||
Effects.shake(3f, 4f);
|
||||
remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed(){
|
||||
amount --;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
float lastx = x, lasty = y;
|
||||
|
||||
move();
|
||||
|
||||
xvelocity = x - lastx;
|
||||
yvelocity = y-lasty;
|
||||
|
||||
if(target == null){
|
||||
direction.add(xvelocity, yvelocity);
|
||||
direction.limit(speed*8);
|
||||
}else{
|
||||
float angle = angleTo(target);
|
||||
direction.lerp(vector.set(0, 1).setAngle(angle), 0.25f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
Draw.rect("mech1", x, y, direction.angle()-90);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package io.anuke.moment.entities;
|
||||
|
||||
import com.badlogic.gdx.Input.Buttons;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import io.anuke.moment.Control;
|
||||
import io.anuke.moment.Moment;
|
||||
import io.anuke.moment.UI;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.core.UInput;
|
||||
import io.anuke.ucore.entities.DestructibleEntity;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
|
||||
public class Player extends DestructibleEntity{
|
||||
Vector2 direction = new Vector2();
|
||||
float speed = 2f;
|
||||
float rotation;
|
||||
float reload;
|
||||
Weapon weapon = Weapon.blaster;
|
||||
|
||||
public Player(){
|
||||
hitsize = 5;
|
||||
|
||||
maxhealth = 100;
|
||||
heal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
Draw.rect("player", x, y, direction.angle()-90);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
vector.set(0, 0);
|
||||
|
||||
if(UInput.keyDown("up"))
|
||||
vector.y += speed;
|
||||
if(UInput.keyDown("down"))
|
||||
vector.y -= speed;
|
||||
if(UInput.keyDown("left"))
|
||||
vector.x -= speed;
|
||||
if(UInput.keyDown("right"))
|
||||
vector.x += speed;
|
||||
|
||||
reload -= delta;
|
||||
|
||||
boolean shooting = UInput.buttonDown(Buttons.LEFT) && Moment.i.recipe == null && !Moment.module(UI.class).hasMouse();
|
||||
|
||||
if(shooting && reload <= 0){
|
||||
weapon.shoot(this);
|
||||
reload = weapon.reload;
|
||||
}
|
||||
|
||||
vector.limit(speed);
|
||||
|
||||
//x += vector.x*delta;
|
||||
//y += vector.y*delta;
|
||||
|
||||
Moment.module(Control.class).tryMove(this, vector.x*delta, vector.y*delta);
|
||||
|
||||
if(!shooting){
|
||||
direction.add(vector.scl(delta));
|
||||
direction.limit(speed*6);
|
||||
}else{
|
||||
float angle = Angles.mouseAngle(x, y);
|
||||
direction.lerp(vector.set(0, 1).setAngle(angle), 0.26f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package io.anuke.moment.entities;
|
||||
|
||||
import com.badlogic.gdx.utils.DelayedRemovalArray;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
|
||||
import io.anuke.moment.Moment;
|
||||
import io.anuke.moment.ai.Pathfind;
|
||||
import io.anuke.moment.resource.Item;
|
||||
import io.anuke.moment.world.Tile;
|
||||
import io.anuke.moment.world.TileType;
|
||||
import io.anuke.ucore.entities.DestructibleEntity;
|
||||
import io.anuke.ucore.entities.Effects;
|
||||
import io.anuke.ucore.entities.SolidEntity;
|
||||
|
||||
public class TileEntity extends DestructibleEntity{
|
||||
public final Tile tile;
|
||||
public DelayedRemovalArray<ItemPos> convey = new DelayedRemovalArray<>();
|
||||
public ObjectMap<Item, Integer> items = new ObjectMap<>();
|
||||
public int shots;
|
||||
public TileEntity link;
|
||||
public float rotation;
|
||||
|
||||
public TileEntity(Tile tile){
|
||||
this.tile = tile;
|
||||
x = tile.worldx();
|
||||
y = tile.worldy();
|
||||
hitsize = TileType.tilesize;
|
||||
|
||||
maxhealth = tile.block().health;
|
||||
heal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean collides(SolidEntity other){
|
||||
return (other instanceof Bullet) && ((Bullet)other).owner instanceof Enemy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeath(){
|
||||
if(tile.block() == TileType.core){
|
||||
Moment.i.coreDestroyed();
|
||||
}
|
||||
tile.setBlock(TileType.air);
|
||||
Pathfind.updatePath();
|
||||
Effects.shake(4f, 4f);
|
||||
Effects.effect("explosion", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
tile.block().update(tile);
|
||||
}
|
||||
|
||||
public int totalItems(){
|
||||
int sum = 0;
|
||||
for(Item item : Item.values()){
|
||||
sum += items.get(item, 0);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public boolean hasItem(Item item){
|
||||
return items.get(item, 0) > 0;
|
||||
}
|
||||
|
||||
public void addItem(Item item, int amount){
|
||||
items.put(item, items.get(item, 0) + amount);
|
||||
}
|
||||
|
||||
public void removeItem(Item item, int amount){
|
||||
items.put(item, items.get(item, 0) - amount);
|
||||
}
|
||||
|
||||
public void addConvey(Item item){
|
||||
addConvey(item, 0);
|
||||
}
|
||||
|
||||
public void addConvey(Item item, float pos){
|
||||
ItemPos posa = new ItemPos(item);
|
||||
posa.pos = pos;
|
||||
convey.add(posa);
|
||||
}
|
||||
|
||||
public void removeConvey(ItemPos pos){
|
||||
convey.removeValue(pos, true);
|
||||
}
|
||||
|
||||
static public class ItemPos{
|
||||
public Item item;
|
||||
public float pos;
|
||||
|
||||
public ItemPos(Item item){
|
||||
this.item = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.anuke.moment.entities;
|
||||
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
|
||||
public enum Weapon{
|
||||
blaster(15, BulletType.shot){
|
||||
{
|
||||
unlocked = true;
|
||||
}
|
||||
};
|
||||
public float reload;
|
||||
public BulletType type;
|
||||
public boolean unlocked;
|
||||
|
||||
private Weapon(float reload, BulletType type){
|
||||
this.reload = reload;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void shoot(Player p){
|
||||
bullet(p, p.x, p.y);
|
||||
}
|
||||
|
||||
void bullet(Entity owner, float x, float y){
|
||||
new Bullet(type, owner, x, y, Angles.mouseAngle(owner.x, owner.y)).add();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user