source: galcon-client/src/com/example/helloandroid/Fleet.java@ b6a9b5f

Last change on this file since b6a9b5f was 5a03a06, checked in by Zero Cool <devnull@…>, 14 years ago

Some more updates to fleet update method

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[159eef8]1package com.example.helloandroid;
2
3public class Fleet {
[96857ee]4 private int x;
5 private int y;
[5a03a06]6 private double dblX;
7 private double dblY;
[96857ee]8 private double slope, xIntercept;
9 private double direction;
10 private Planet destination;
11 private int numShips;
12 private int faction;
[159eef8]13
[96857ee]14 /* Optimising: pre-calculate paths */
[159eef8]15 public Fleet(Planet source, Planet destination, int numShips, int faction) {
[96857ee]16 //Calculate initial coordinates and direction
[5a03a06]17 if((destination.getX() - source.getX()) != 0){
[96857ee]18 //line formula
[1291908]19 slope = ((source.getY() - destination.getY())/(source.getX() - destination.getX()));
20 xIntercept = destination.getY() - (slope*destination.getX());
[96857ee]21
22 //direction
23 direction = 1/Math.tan(slope);
24
25 //coordinates for all 4 coordinates
[5a03a06]26 if((destination.getX() - source.getX()) < 0 )
[1a91f0d]27 direction += Math.PI;
[159eef8]28
[5a03a06]29 dblX = ((Math.cos(direction)*(source.radius + 10) + source.getX()));
30 dblY = ((Math.sin(direction)*(source.radius + 10) + source.getY()));
31
[96857ee]32 } else {
[1291908]33 if((destination.getY() - source.getY()) > 0 ){
[1a91f0d]34 direction = Math.PI/2;
[5a03a06]35 dblX = destination.getX();
36 dblY = source.getY() + source.radius + 10;
[1a91f0d]37 } else {
38 direction = 3*Math.PI/2;
[5a03a06]39 dblX = destination.getX();
40 dblY = source.getY() - source.radius - 10;
[1a91f0d]41 }
[96857ee]42 }
[1a91f0d]43
[5a03a06]44 x = (int)dblX;
45 y = (int)dblY;
46
[159eef8]47 this.numShips = numShips;
48 this.faction = faction;
49 this.destination = destination;
50 }
51
52
[96857ee]53 public int getX() {
54 return x;
55 }
56
57
58
59 public void setX(int x) {
60 this.x = x;
61 }
62
63
64
65 public int getY() {
66 return y;
67 }
68
69
70
71 public void setY(int y) {
72 this.y = y;
73 }
74
75
76
77 public double getDirection() {
78 return direction;
79 }
80
81
82
83 public void setDirection(double direction) {
84 this.direction = direction;
85 }
86
87
88
89 public Planet getDestination() {
90 return destination;
91 }
92
93
94
95 public void setDestination(Planet destination) {
96 this.destination = destination;
97 }
98
99
100
101 public int getNumShips() {
102 return numShips;
103 }
104
105
106
107 public void setNumShips(int numShips) {
108 this.numShips = numShips;
109 }
110
111
112
113 public int getFaction() {
114 return faction;
115 }
116
117
118
119 public void setFaction(int faction) {
120 this.faction = faction;
121 }
122
123
124
125 public void update() {
[5a03a06]126 int speed = 1; //pixels per move
[159eef8]127 }
128
129 // attack the destination planet
[5a03a06]130 //after the method is called the fleet needs to removed
[159eef8]131 public void attack() {
[1291908]132 if(numShips <= destination.getNumShips()){
133 destination.setNumShips(destination.getNumShips() - numShips);
134 } else {
135 destination.setNumShips(numShips - destination.getNumShips());
136 destination.setFaction(this.faction);
[1a91f0d]137 }
[159eef8]138 }
139}
Note: See TracBrowser for help on using the repository browser.