Skip to content

Commit

Permalink
dom
Browse files Browse the repository at this point in the history
  • Loading branch information
ylin0603 committed Dec 14, 2016
1 parent 2e99ee2 commit e3407a0
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 75 deletions.
22 changes: 22 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions src/Input/AttackAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package Input;

import renderer.data.DynamicObjectManager;
import tcp.tcpClient.RealTcpClient;

import javax.swing.*;
import java.awt.event.ActionEvent;

/**
* Created by TsunglinYang on 2016/12/7.
*/
public class AttackAction extends AbstractAction{
private int code;
public AttackAction(int code){
this.code = code;
}
@Override
public void actionPerformed(ActionEvent e) {
try {
RealTcpClient.getInstance().inputMoves(code);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
16 changes: 0 additions & 16 deletions src/Input/FetchAction.java

This file was deleted.

3 changes: 1 addition & 2 deletions src/Input/RotateAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
*/
public class RotateAction extends AbstractAction {
private int direction;
static double degree = 0;
public RotateAction(int dir) {
this.direction = dir;
}

@Override
public void actionPerformed(ActionEvent e) {
try {
//RealTcpClient.getInstance().inputMoves(angle);
RealTcpClient.getInstance().inputMoves(direction);
} catch (Exception e1) {
e1.printStackTrace();
}
Expand Down
25 changes: 25 additions & 0 deletions src/Input/StopAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package Input;

import tcp.tcpClient.RealTcpClient;

import javax.swing.*;
import java.awt.event.ActionEvent;

/**
* Created by Tsunglin on 2016/12/13.
*/
public class StopAction extends AbstractAction{
private int code;
public StopAction(int code){
this.code = code;
}
@Override
public void actionPerformed(ActionEvent e) {
try {
System.out.println("released");
RealTcpClient.getInstance().inputMoves(code);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
52 changes: 26 additions & 26 deletions src/pseudomain/Game.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package pseudomain;

import java.awt.*;
import java.awt.event.KeyEvent;

import javax.swing.*;

import Input.FetchAction;
import Input.AttackAction;
import Input.RotateAction;
import Input.MoveAction;
import Input.StopAction;

import Input.RotateAction;
import renderer.engine.RenderEngine;
import tcp.tcpClient.RealTcpClient;
import udp.update.server.UDP_Server;
Expand All @@ -26,14 +26,12 @@ public class Game extends Canvas implements Runnable {

private static final int IFW = JComponent.WHEN_IN_FOCUSED_WINDOW;

private final static int TURNEAST = 0;
private final static int TURNSOUTH = 1;
private final static int TURNNORTH = 2;
private final static int TURNWEST = 3;
private final static int ROTATE_CLOCKWISE = 4;
private final static int ROTATE_COUNTER_CLOCKWISE = 5;
private final static String GET = "get";

private final static int FORWARD = 0;
private final static int BACKWARD = 1;
private final static int ROTATE_CLOCKWISE = 2;
private final static int ROTATE_COUNTER_CLOCKWISE = 3;
private final static int ATTACK = 4;
private final static int RELEASE = -1;

public Game() {
Dimension size = new Dimension(WIDTH * scale, HEIGHT * scale);
Expand All @@ -43,22 +41,23 @@ public Game() {
}

private void initialKeyBinding() {
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke("UP"), TURNNORTH);
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke("DOWN"), TURNSOUTH);
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke("LEFT"), TURNWEST);
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke("RIGHT"), TURNEAST);
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke("GET"), GET);
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke("A"),ROTATE_CLOCKWISE);
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke("D"),ROTATE_COUNTER_CLOCKWISE);

frame.getRootPane().getActionMap().put(TURNNORTH, new MoveAction(TURNNORTH));
frame.getRootPane().getActionMap().put(TURNSOUTH, new MoveAction(TURNSOUTH));
frame.getRootPane().getActionMap().put(TURNWEST, new MoveAction(TURNWEST));
frame.getRootPane().getActionMap().put(TURNEAST, new MoveAction(TURNEAST));
frame.getRootPane().getActionMap().put(GET, new FetchAction());

frame.getRootPane().getActionMap().put(ROTATE_CLOCKWISE,new RotateAction(ROTATE_CLOCKWISE));
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke('w'), FORWARD);
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke('w',true), RELEASE);
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke('s'), BACKWARD);
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke('s',true), RELEASE);
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke('a'),ROTATE_CLOCKWISE);
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke('a',true),RELEASE);
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke('d'),ROTATE_COUNTER_CLOCKWISE);
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke('d',true),RELEASE);
frame.getRootPane().getInputMap(IFW).put(KeyStroke.getKeyStroke(' '),ATTACK);


frame.getRootPane().getActionMap().put(FORWARD, new MoveAction(FORWARD));
frame.getRootPane().getActionMap().put(BACKWARD, new MoveAction(BACKWARD));
frame.getRootPane().getActionMap().put(ROTATE_CLOCKWISE, new RotateAction(ROTATE_CLOCKWISE));
frame.getRootPane().getActionMap().put(ROTATE_COUNTER_CLOCKWISE, new RotateAction(ROTATE_COUNTER_CLOCKWISE));
frame.getRootPane().getActionMap().put(ATTACK,new AttackAction(ATTACK));
frame.getRootPane().getActionMap().put(RELEASE, new StopAction(RELEASE));
}

public synchronized void start() {
Expand Down Expand Up @@ -106,6 +105,7 @@ public void run() {
updates = 0;
}
}
stop();
}

public void update() {
Expand Down
28 changes: 17 additions & 11 deletions src/renderer/data/DynamicObjectManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,29 @@ public static DynamicObjectManager getInstance() {
return instance;
}

public void addVirtualCharacter(int clientno) {
public void addVirtualCharacter(int clientno, String nickName) {

this.characterList.add(new Character(clientno));
this.characterList.add(new Character(clientno,nickName));
}

public void addItem(String name, int index, Boolean shared, int x, int y) {
this.itemList.add(new Item(name, index, shared, x, y));
public void addItem(int itemType, int index, boolean isDead, int x, int y) {
this.itemList.add(new Item(itemType,index,isDead,x,y));
}

public void updateVirtualCharacter(int clientno, double dir, int speed, int x, int y) {
public void updateVirtualCharacter(int clientno, int weaponType, String nickname,
int x, int y, double angle, int HP, int killCount,
int deadCount, int bulletCount, boolean isAttack,
boolean isAttacked, boolean isCollision,
boolean isDead) {
Character character = this.characterList.get(clientno);
character.update(dir, speed, x, y);
character.update(weaponType, nickname, x, y, angle, HP, killCount, deadCount,
bulletCount, isAttack, isAttacked, isCollision, isDead);
}

public void updateItem(int index, Boolean shared, int owner) {
public void updateItem(int index, boolean isDead, int owner) {

Item item = this.itemList.get(index);
item.update(shared, owner);
item.update(isDead, owner);
}

public List<Entity> getAllDynamicObjects() {
Expand All @@ -54,14 +59,15 @@ public List<Entity> getAllDynamicObjects() {
}

public Point getVirtualCharacterXY() {
if(characterList.size() == 0) return new Point(0,0);
if (characterList.size() == 0) return new Point(0, 0);
int localClientNo = 0; //TODO: localClientNo should get from TCP?
Character character = this.characterList.get(localClientNo);
return new Point(character.x, character.y);
}

public void keyGETPressed() {
int localClientNo = 0;
//TODO: unify this method with CDC
/*int localClientNo = 0;
Character character = this.characterList.get(localClientNo);
for (Item item : this.itemList) {
Expand All @@ -72,7 +78,7 @@ public void keyGETPressed() {
break;
}
}
}
}*/

}

Expand Down
40 changes: 32 additions & 8 deletions src/renderer/data/entity/Character.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,56 @@
import renderer.graphics.Sprite;

public class Character extends Entity {
private int playerId;
private int weaponType;
private String nickName;
private double faceAngle;
private int HP;
private int killCount, deadCount;
private int bulletCount;
private boolean attackFlag;
private boolean attackedFlag;
private boolean collisionFlag;
private boolean isDead;

private int speed;
private int clientno;

public Character(int clientno) {
public Character(int clientno, String nickName) {
this.clientno = clientno;
this.nickName = nickName;
Initialize();
}

public void Initialize() {
this.x = 0;
this.y = 0;
this.dir = 0;
this.speed = 0;
this.HP = 100;

sprite = Sprite.PLAYER;
}

public void update(double dir, int speed, int x, int y) {
this.dir = dir;
this.speed = speed;
public void update(int weaponType, String nickName, int x, int y,
double angle, int HP, int killCount, int deadCount,
int bulletCount, boolean attackFlag, boolean attackedFlag,
boolean collisionFlag, boolean isDead) {
this.weaponType = weaponType;
this.nickName = nickName;
this.x = x;
this.y = y;
//this.sprite = Sprite.rotate(Sprite.PLAYER,Math.toRadians(dir));
this.faceAngle = angle;
this. killCount = killCount;
this.deadCount = deadCount;
this.bulletCount = bulletCount;
this.attackFlag = attackFlag;
this.attackedFlag = attackedFlag;
this.collisionFlag = collisionFlag;
this.isDead = isDead;

//this.sprite = Sprite.rotate(Sprite.PLAYER,angle);
}

public void render(int[] pixels){
public void render(int[] pixels) {
//TODO: If attack flag == true, draw addition animation
//TODO: bullet should have additional class and draw additionally.
super.render(pixels);
Expand Down
Loading

0 comments on commit e3407a0

Please sign in to comment.