Skip to content

Commit

Permalink
animation
Browse files Browse the repository at this point in the history
  • Loading branch information
ylin0603 committed Dec 20, 2016
2 parents 26d6881 + f521d71 commit 1bf9932
Show file tree
Hide file tree
Showing 20 changed files with 426 additions and 332 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.

1 change: 1 addition & 0 deletions What-does-the-box-say.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/src/CDC/test" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
43 changes: 22 additions & 21 deletions src/CDC/Attack.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void attackShortRange(int ClientNO,
ArrayList<ClientItemFeature> clientItemFeature) {
ClientPlayerFeature player = clientPlayerFeature.get(ClientNO);
player.setAttackFlag(true);
boolean[] isAttacked = new boolean[clientPlayerFeature.size()];

double faceAngle = player.getFaceAngle();
double radianAngle = Math.toRadians(faceAngle);
Expand All @@ -53,7 +54,7 @@ public void attackShortRange(int ClientNO,
// attack area 1
ClientItemFeature attackArea1 = new ClientItemFeature(0, 4,
(int) Math.round(fakeX), (int) Math.round(fakeY));
attackI2P(ClientNO, attackArea1, clientPlayerFeature);
attackI2P(ClientNO, attackArea1, clientPlayerFeature, isAttacked);
attackI2B(attackArea1, clientPlayerFeature, clientItemFeature);

// 先往前走一步,轉另一方向的90度
Expand All @@ -64,22 +65,25 @@ public void attackShortRange(int ClientNO,
// attack area 2
ClientItemFeature attackArea2 = new ClientItemFeature(0, 4,
(int) Math.round(fakeX), (int) Math.round(fakeY));
attackI2P(ClientNO, attackArea2, clientPlayerFeature);
attackI2P(ClientNO, attackArea2, clientPlayerFeature, isAttacked);
attackI2B(attackArea2, clientPlayerFeature, clientItemFeature);
}

private boolean attackI2P(int ClientNO, ClientItemFeature item1,
ArrayList<ClientPlayerFeature> clientPlayerFeature) {
public boolean attackI2P(int ClientNO, ClientItemFeature item1,
ArrayList<ClientPlayerFeature> clientPlayerFeature,
boolean[] isAttacked) {
boolean isThisAttack = false;
ClientPlayerFeature player1 = clientPlayerFeature.get(ClientNO);
for (ClientPlayerFeature player2 : clientPlayerFeature) {
if (player2.getClientNo() == ClientNO) {
if (player2.getClientNo() == ClientNO
|| isAttacked[clientPlayerFeature.indexOf(player2)]) {
continue;// for prevent synchronize problem
} else {
if (Collision.isCollison(item1, player2)) {
player1.setAttackFlag(true);
player2.setAttackedFlag(true);
isThisAttack = true;
isAttacked[clientPlayerFeature.indexOf(player2)] = true;
if (subBlood(player2, item1.getItemType() - 3)) {
player1.setKillCount(player1.getKillCount() + 1);

Expand All @@ -94,18 +98,22 @@ private boolean attackI2P(int ClientNO, ClientItemFeature item1,

private boolean subBlood(ClientPlayerFeature player2, int attackType) {
int HP = player2.getHP();
boolean isDead = false;
System.out.println("HP" + HP);
int minusBlood = (attackType) * +10 + 40;// 0:子彈:40, 1:刀:50 2:假箱爆:60
HP -= minusBlood;
player2.setHP(HP);
if (HP <= 0) {
return true;
HP = 0;
isDead = true;
} else {
isDead = false;
}
player2.setHP(HP);
System.out.println("HP after" + HP);
return false;
return isDead;
}

private boolean attackI2B(ClientItemFeature item1,
public boolean attackI2B(ClientItemFeature item1,
ArrayList<ClientPlayerFeature> clientPlayerFeature,
ArrayList<ClientItemFeature> clientItemFeature) {
boolean isAttack = false;
Expand All @@ -123,18 +131,9 @@ private boolean attackI2B(ClientItemFeature item1,

private void boxRevenge(ClientItemFeature item2,
ArrayList<ClientPlayerFeature> clientPlayerFeature) {
double faceAngle = item2.getFaceAngle();
double radianAngle = Math.toRadians(faceAngle);
double sin = Math.sin(radianAngle);
double cos = Math.cos(radianAngle);

double fakeX =
item2.getLocX() + sin * Cdc.BOX_SIZE - cos * Cdc.BOX_SIZE * 0.5;
double fakeY =
item2.getLocY() - cos * Cdc.BOX_SIZE + sin * Cdc.BOX_SIZE * 0.5;

double fakeX = item2.getLocX() - 16;
double fakeY = item2.getLocY() - 16;
for (ClientPlayerFeature player2 : clientPlayerFeature) {

if (Collision.isCollison((int) Math.round(fakeX),
(int) Math.round(fakeY), 8 * 3, player2)) {
player2.setAttackedFlag(true);
Expand Down Expand Up @@ -171,6 +170,7 @@ public void attackLongRangeUpdate(
for (ClientItemFeature bullet : clientItemFeature) {
if (bullet.getItemType() != 3)
continue;
boolean[] isAttacked = new boolean[clientPlayerFeature.size()];
double faceAngle = bullet.getFaceAngle();
double radianAngle = Math.toRadians(faceAngle);
int locX, loxY, oriLocX, oriLocY;
Expand All @@ -194,7 +194,8 @@ public void attackLongRangeUpdate(

bullet.setLocX(locX);
bullet.setLocY(loxY);
if (attackI2P(bullet.getItemOwner(), bullet, clientPlayerFeature)
if (attackI2P(bullet.getItemOwner(), bullet, clientPlayerFeature,
isAttacked)
|| attackI2B(bullet, clientPlayerFeature,
clientItemFeature))
clientItemFeature.remove(bullet);
Expand Down
Loading

0 comments on commit 1bf9932

Please sign in to comment.