Skip to content

Commit

Permalink
change entity structure, add death sprite
Browse files Browse the repository at this point in the history
  • Loading branch information
ylin0603 committed Dec 24, 2016
1 parent ba2d267 commit 7e508e6
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 44 deletions.
File renamed without changes
Binary file modified res/textures/character.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/CDC/Cdc.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Cdc {
private final static int CHANGEWEAPON = 5;
private final static int BLOODPACKGEINDEX = 30;
private final static int BULLETPACKGEINDEX = 31;
private final static int VEL = 2;
private final static int VEL = 4;
private final static double ANGLEVEL = 7;// degree
private static Cdc instance;
private static RealTcpServer realTcpServer;
Expand Down
3 changes: 0 additions & 3 deletions src/renderer/data/DynamicObjectManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.awt.Point;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class DynamicObjectManager {
private List<Character> characterList = new CopyOnWriteArrayList<>();
private List<Item> itemList = new CopyOnWriteArrayList<>();
Expand Down Expand Up @@ -71,12 +70,10 @@ public List<Entity> getAllDynamicObjects() {
}

public List<Character> getCharacterList() {
assert characterList.size() > 0;
return characterList;
}

public List<Item> getItemList() {
assert itemList.size() > 0;
return itemList;
}

Expand Down
3 changes: 1 addition & 2 deletions src/renderer/data/entity/AmmoPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
public class AmmoPackage extends Item{
public AmmoPackage(int type, int index, boolean isDead, int x, int y) {
super(type, index, isDead, x, y);
this.sprite = Sprite.AMMO_PACKAGE;
super(type, index, isDead, x, y, Sprite.AMMO_PACKAGE);
}
}
3 changes: 1 addition & 2 deletions src/renderer/data/entity/BloodPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
public class BloodPackage extends Item {
public BloodPackage(int type, int index, boolean isDead, int x, int y) {
super(type, index, isDead, x, y);
this.sprite = Sprite.BLOOD_PACKAGE;
super(type, index, isDead, x, y, Sprite.BLOOD_PACKAGE );
}
}
6 changes: 5 additions & 1 deletion src/renderer/data/entity/Character.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Character extends Entity {
private Sword sword = new Sword();

public Character(int clientno, String nickName) {
super(Sprite.PLAYER);
this.clientno = clientno;
this.nickName = nickName;
Initialize();
Expand All @@ -34,8 +35,8 @@ public void Initialize() {
this.dir = 0;
this.HP = 100;

sprite = Sprite.PLAYER;
sword.sprite = Sprite.EMPTY;
setDeadSprite(Sprite.DEAD_PLAYER);
}

public void set(int weaponType, String nickName, int x, int y,
Expand All @@ -60,7 +61,9 @@ public void set(int weaponType, String nickName, int x, int y,
//this.sprite = Sprite.rotate(Sprite.PLAYER,angle);
}

@Override
public void update() {
super.update();
timer++;
if (timer % 6 == 0) {
count++;
Expand Down Expand Up @@ -95,6 +98,7 @@ public void update() {

}

@Override
public void render(int[] pixels) {
//TODO: If attack flag == true, draw addition animation
//TODO: bullet should have additional class and draw additionally.
Expand Down
27 changes: 24 additions & 3 deletions src/renderer/data/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,45 @@ public abstract class Entity {
protected double dir;
protected boolean isDead;
protected Sprite sprite;
private Sprite deadSprite = Sprite.EMPTY;
private Sprite currentSprite;

public void update() {
public Entity(Sprite s){
sprite = s;
currentSprite = s;
}
public Entity(){
this.sprite=Sprite.EMPTY;
this.currentSprite=Sprite.EMPTY;
}

public void update() {
if (isDead) currentSprite = deadSprite;
else currentSprite = sprite;
}

public void render(int pixels[]) {
EntityRenderEngine.renderEntity(this,pixels);
EntityRenderEngine.renderEntity(this, pixels);
}


protected void setDeadSprite(Sprite deadSprite) {
this.deadSprite = deadSprite;
}

public void remove() {
isDead = true;
}

public double getDirection() {
return dir;
}
public Sprite getSprite() {return sprite;}

public Sprite getSprite() {
assert currentSprite != null;
return currentSprite;
}

public boolean isDead() {
return isDead;
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/data/entity/ExplosionParticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ExplosionParticle extends Entity {
final static int FAKEBOX_SIZE = Sprite.PLAYER.SIZE;

public ExplosionParticle() {
this.sprite = Sprite.EMPTY;
super(Sprite.EMPTY);
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/data/entity/FakeBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class FakeBox extends Item {
private int deadPosX = 0;
private int deadPosY = 0;
public FakeBox(int type, int index, boolean isDead, int x, int y) {
super(type, index, isDead, x, y);
this.sprite = Sprite.PLAYER;
super(type, index, isDead, x, y, Sprite.PLAYER);
//this.sprite = Sprite.PLAYER;
}

@Override
Expand Down Expand Up @@ -50,4 +50,5 @@ public void render(int[] pixels) {
super.render(pixels);
ep.render(pixels);
}

}
4 changes: 3 additions & 1 deletion src/renderer/data/entity/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class Item extends Entity {
private int index;
private int owner;

public Item(int type, int index, boolean isDead, int x, int y) {
public Item(int type, int index, boolean isDead, int x, int y, Sprite s) {
super(s);
this.itemType = type;
this.index = index;
this.isDead = isDead;
Expand All @@ -18,6 +19,7 @@ public Item(int type, int index, boolean isDead, int x, int y) {


public void update(boolean isDead, int owner, int x, int y) {
super.update();
this.isDead = isDead;
this.owner = owner;
this.x = x;
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/data/entity/Sword.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package renderer.data.entity;

import renderer.engine.EntityRenderEngine;

/**
* Created by TsunglinYang on 2016/12/20.
*/
Expand All @@ -11,6 +13,6 @@ public void update() {

@Override
public void render(int[] pixels) {
super.render(pixels);
EntityRenderEngine.renderEntity(x,y,pixels,sprite);
}
}
22 changes: 15 additions & 7 deletions src/renderer/engine/EntityRenderEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import pseudomain.Game;
import renderer.data.DynamicObjectManager;
import renderer.data.entity.Character;
import renderer.data.entity.Entity;
import renderer.data.entity.ExplosionParticle;
import renderer.data.entity.Item;
import renderer.graphics.Sprite;

import java.util.List;
Expand All @@ -21,17 +22,24 @@ public EntityRenderEngine(){

public void render(int pixels[]) {
this.pixels = pixels;
List<Entity> allCharacter = dom.getAllDynamicObjects();
allCharacter.stream().filter(e -> !e.isDead()).forEach(e -> e.render(pixels));
List<Character> allCharacter = dom.getCharacterList();
List<Item> allItem = dom.getItemList();
for(Item i : allItem){
i.render(pixels);
}
for(Character c : allCharacter){
c.render(pixels);
}
//allCharacter.stream().filter(e -> !e.isDead()).forEach(e -> e.render(pixels));
}
public static void renderEntity(Entity character, int pixels[]){
public static void renderEntity(Entity entity, int pixels[]){
int offsetX = DynamicObjectManager.getInstance().getVirtualCharacterXY().x - Game.WIDTH / 2;
int offsetY = DynamicObjectManager.getInstance().getVirtualCharacterXY().y - Game.HEIGHT / 2;
int xp = character.x;
int yp = character.y;
int xp = entity.x;
int yp = entity.y;
xp -= offsetX;
yp -= offsetY;
Sprite s = character.getSprite();
Sprite s = entity.getSprite();
for (int y = 0; y < s.SIZE; y++) {
int ya = y + yp;
for (int x = 0; x < s.SIZE; x++) {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/engine/SceneRenderEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public SceneRenderEngine() {

public void renderScene(int[] pixels) {
this.pixels = pixels;
// real x,y position need to get from renderer.data.DynamicObjectManager

int xScroll = DynamicObjectManager.getInstance().getVirtualCharacterXY().x - Game.WIDTH / 2;
int yScroll = DynamicObjectManager.getInstance().getVirtualCharacterXY().y - Game.HEIGHT / 2;

renderLevel(xScroll, yScroll);
}

public void renderTile(int xp, int yp, int xOffset, int yOffset, Tile tile) {
xp -= xOffset; // TODO: offsets should get from renderer.data.DynamicObjectManager
xp -= xOffset;
yp -= yOffset;
for (int y = 0; y < tile.sprite.SIZE; y++) {
int ya = y + yp;
Expand Down
15 changes: 8 additions & 7 deletions src/renderer/graphics/Sprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ public class Sprite {
//for demo
public static Sprite BLOOD_PACKAGE = new Sprite(16, 4, 0, SpriteSheet.character);
public static Sprite AMMO_PACKAGE = new Sprite(16, 3, 0, SpriteSheet.character);
public static Sprite PLAYER = new Sprite(16, 0, 0, SpriteSheet.character);
public static Sprite PLAYER = new Sprite(16, 1, 0, SpriteSheet.character);
public static Sprite DEAD_PLAYER = new Sprite(16, 3, 2, SpriteSheet.character);

//Spawn Level Sprites here:
public static Sprite SPWAN_GRASS = new Sprite(16, 0, 0, SpriteSheet.SPWAN_LEVEL);
public static Sprite SPWAN_GRASS_2 = new Sprite(16, 1, 0, SpriteSheet.SPWAN_LEVEL);
public static Sprite SPWAN_HEDGE = new Sprite(16, 0, 1, SpriteSheet.SPWAN_LEVEL);
public static Sprite SPWAN_WATER = new Sprite(16, 2, 2, SpriteSheet.SPWAN_LEVEL);
public static Sprite SPWAN_WALL = new Sprite(16, 1, 1, SpriteSheet.SPWAN_LEVEL);
public static Sprite SPWAN_FLOOR = new Sprite(16, 2, 1, SpriteSheet.SPWAN_LEVEL);
public static Sprite SPAWN_GRASS = new Sprite(16, 0, 0, SpriteSheet.SPWAN_LEVEL);
public static Sprite SPAWN_GRASS_2 = new Sprite(16, 1, 0, SpriteSheet.SPWAN_LEVEL);
public static Sprite SPAWN_HEDGE = new Sprite(16, 0, 1, SpriteSheet.SPWAN_LEVEL);
public static Sprite SPAWN_WATER = new Sprite(16, 2, 2, SpriteSheet.SPWAN_LEVEL);
public static Sprite SPAWN_WALL = new Sprite(16, 1, 1, SpriteSheet.SPWAN_LEVEL);
public static Sprite SPAWN_FLOOR = new Sprite(16, 2, 1, SpriteSheet.SPWAN_LEVEL);

// below is for animation, dear StanleyLin.

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/graphics/SpriteSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SpriteSheet {

public static SpriteSheet tiles = new SpriteSheet("/textures/spritesheet.png", 256);
public static SpriteSheet character = new SpriteSheet("/textures/character.png", 256);
public static SpriteSheet SPWAN_LEVEL = new SpriteSheet("/levels/spwanLevel.png", 48);
public static SpriteSheet SPWAN_LEVEL = new SpriteSheet("/levels/spawnLevel.png", 48);


public SpriteSheet(String path, int size){
Expand Down
12 changes: 6 additions & 6 deletions src/renderer/level/tile/Tile.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public class Tile {
public Sprite sprite;

public static Tile VOID_TILE = new VoidTile(Sprite.VOID_SPRITE);
public static Tile SPAWN_GRASS = new SpawnLevelGrassTile(Sprite.SPWAN_GRASS);
public static Tile SPAWN_GRASS_2 = new SpawnLevelGrassTile(Sprite.SPWAN_GRASS_2);
public static Tile SPAWN_HEDGE = new SpawnLevelHedgeTile(Sprite.SPWAN_HEDGE);
public static Tile SPAWN_WATER = new SpawnLevelWaterTile(Sprite.SPWAN_WATER);
public static Tile SPAWN_WALL = new SpawnLevelWallTile(Sprite.SPWAN_WALL);
public static Tile SPAWN_FLOOR = new SpawnLevelFloorTile(Sprite.SPWAN_FLOOR);
public static Tile SPAWN_GRASS = new SpawnLevelGrassTile(Sprite.SPAWN_GRASS);
public static Tile SPAWN_GRASS_2 = new SpawnLevelGrassTile(Sprite.SPAWN_GRASS_2);
public static Tile SPAWN_HEDGE = new SpawnLevelHedgeTile(Sprite.SPAWN_HEDGE);
public static Tile SPAWN_WATER = new SpawnLevelWaterTile(Sprite.SPAWN_WATER);
public static Tile SPAWN_WALL = new SpawnLevelWallTile(Sprite.SPAWN_WALL);
public static Tile SPAWN_FLOOR = new SpawnLevelFloorTile(Sprite.SPAWN_FLOOR);

public final static int COLOR_SPAWN_GRASS = 0xff00ff00;
public final static int COLOR_SPAWN_GRASS_2 = 0xffffff00;
Expand Down
6 changes: 2 additions & 4 deletions src/udp/update/server/UDP_Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ private void parseData(String receiveString) {
player.isDead());
if(player.isAttackFlag())
System.out.println("ATTACK is true");

if(player.isAttackedFlag())
System.out.println("IsATTACKED is true");
break;
case "AddP":
player = gson.fromJson(eachEnData.getData(),
Expand All @@ -81,9 +82,6 @@ private void parseData(String receiveString) {
instance.updateItem(item.getItemID(), item.isDead(),
item.getItemOwner(), item.getLocX(), item.getLocY());

if(item.isDead())
System.out.println("Item dead");

break;
case "AddI":
item = gson.fromJson(eachEnData.getData(),
Expand Down

0 comments on commit 7e508e6

Please sign in to comment.