Skip to content

Commit

Permalink
try merge, still have gson bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ylin0603 committed Dec 9, 2016
2 parents f4c5796 + 1d6c562 commit e916a9b
Show file tree
Hide file tree
Showing 14 changed files with 235 additions and 79 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ local.properties

# Package Files #
*.jar

#lib
!lib/*.jar

Expand Down
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.

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.

9 changes: 9 additions & 0 deletions What-does-the-box-say.iml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$USER_HOME$/Desktop/gson-2.8.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="gson-2.8.0" level="project" />
</component>
</module>
1 change: 0 additions & 1 deletion src/Input/MoveAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/
public class MoveAction extends AbstractAction {
private int direction;

public MoveAction(int dir) {
direction = dir;
}
Expand Down
27 changes: 27 additions & 0 deletions src/Input/RotateAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package Input;

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

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

/**
* Created by TsunglinYang on 2016/12/9.
*/
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);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
10 changes: 10 additions & 0 deletions src/pseudomain/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import Input.FetchAction;
import Input.MoveAction;

import Input.RotateAction;
import renderer.engine.RenderEngine;
import tcp.tcpClient.RealTcpClient;
import udp.update.server.UDP_Server;
Expand All @@ -28,6 +30,8 @@ public class Game extends Canvas implements Runnable {
private final static int TURNSOUTH = 1;
private final static int TURNNORTH = 2;
private final static int TURNWEST = 3;
private final static int ROTATE_CLOCKWISE = 0;
private final static int ROTATE_COUNTER_CLOCKWISE = 1;
private final static String GET = "get";


Expand All @@ -45,11 +49,17 @@ private void initialKeyBinding() {
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().getActionMap().put(ROTATE_COUNTER_CLOCKWISE, new RotateAction(ROTATE_COUNTER_CLOCKWISE));
}

public synchronized void start() {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/data/DynamicObjectManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ 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 updateVirtualCharacter(int clientno, int dir, int speed, int x, int y) {
public void updateVirtualCharacter(int clientno, double dir, int speed, int x, int y) {
Character character = this.characterList.get(clientno);
character.update(dir, speed, x, y);
}
Expand Down
11 changes: 9 additions & 2 deletions src/renderer/data/entity/Character.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import pseudomain.Game;
import renderer.data.DynamicObjectManager;
import renderer.engine.EntityRenderEngine;
import renderer.graphics.Sprite;

public class Character extends Entity {

private int dir;
private int speed;
private int clientno;

Expand All @@ -23,11 +23,18 @@ public void Initialize() {
sprite = Sprite.PLAYER;
}

public void update(int dir, int speed, int x, int y) {
public void update(double dir, int speed, int x, int y) {
this.dir = dir;
this.speed = speed;
this.x = x;
this.y = y;
//this.sprite = Sprite.rotate(Sprite.PLAYER,Math.toRadians(dir));
}

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
25 changes: 9 additions & 16 deletions src/renderer/data/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,27 @@

import pseudomain.Game;
import renderer.data.DynamicObjectManager;
import renderer.engine.EntityRenderEngine;
import renderer.graphics.Sprite;

import java.util.Map;
import java.util.Random;

/**
* Created by tsunglin on 2016/12/2.
*/
public abstract class Entity {
public int x, y;
protected double dir;
private boolean removed = false;
protected Sprite sprite;

public void update() {

}

public void render(int pixels[]) {
int offsetX = DynamicObjectManager.getInstance().getVirtualCharacterXY().x - Game.WIDTH/2;
int offsetY = DynamicObjectManager.getInstance().getVirtualCharacterXY().y - Game.HEIGHT/2;
int xp = this.x;
int yp = this.y;
xp -= offsetX;
yp -= offsetY;
for (int y = 0; y < sprite.SIZE; y++) {
int ya = y + yp;
for (int x = 0; x < sprite.SIZE; x++) {
int xa = x + xp;
if (xa < -sprite.SIZE || xa >= Game.WIDTH || ya < 0 || ya >= Game.HEIGHT) break;
if (xa < 0) xa = 0;
int color = sprite.pixels[x + y * sprite.SIZE];
if (color != 0xffffffff) pixels[xa + ya * Game.WIDTH] = color;
}
}
EntityRenderEngine.renderEntity(this,pixels);
}


Expand All @@ -42,6 +31,10 @@ public void remove() {
removed = true;
}

public double getDirection() {
return dir;
}
public Sprite getSprite() {return sprite;}
public boolean isRemoved() {
return removed;
}
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/data/entity/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pseudomain.Game;
import renderer.data.DynamicObjectManager;
import renderer.engine.EntityRenderEngine;
import renderer.graphics.Sprite;

public class Item extends Entity {
Expand All @@ -25,6 +26,10 @@ public void update(boolean shared, int owner){
this.owner = owner;
}

public void render(int[] pixels){
super.render(pixels);
}

public String getName() {
return name;
}
Expand Down
21 changes: 21 additions & 0 deletions src/renderer/engine/EntityRenderEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

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

import java.util.List;
Expand All @@ -25,5 +27,24 @@ public void render(int pixels[]) {
e.render(pixels);
}
}
public static void renderEntity(Entity character, 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;
xp -= offsetX;
yp -= offsetY;
Sprite s = character.getSprite();
for (int y = 0; y < s.SIZE; y++) {
int ya = y + yp;
for (int x = 0; x < s.SIZE; x++) {
int xa = x + xp;
if (xa < -s.SIZE || xa >= Game.WIDTH || ya < 0 || ya >= Game.HEIGHT) break;
if (xa < 0) xa = 0;
int color = s.pixels[x + y * s.SIZE];
if (color != 0xffffffff) pixels[xa + ya * Game.WIDTH] = color;
}
}
}

}
Loading

0 comments on commit e916a9b

Please sign in to comment.