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

Last change on this file since 5053d90 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
Line 
1package com.example.helloandroid;
2
3public class Fleet {
4 private int x;
5 private int y;
6 private double dblX;
7 private double dblY;
8 private double slope, xIntercept;
9 private double direction;
10 private Planet destination;
11 private int numShips;
12 private int faction;
13
14 /* Optimising: pre-calculate paths */
15 public Fleet(Planet source, Planet destination, int numShips, int faction) {
16 //Calculate initial coordinates and direction
17 if((destination.getX() - source.getX()) != 0){
18 //line formula
19 slope = ((source.getY() - destination.getY())/(source.getX() - destination.getX()));
20 xIntercept = destination.getY() - (slope*destination.getX());
21
22 //direction
23 direction = 1/Math.tan(slope);
24
25 //coordinates for all 4 coordinates
26 if((destination.getX() - source.getX()) < 0 )
27 direction += Math.PI;
28
29 dblX = ((Math.cos(direction)*(source.radius + 10) + source.getX()));
30 dblY = ((Math.sin(direction)*(source.radius + 10) + source.getY()));
31
32 } else {
33 if((destination.getY() - source.getY()) > 0 ){
34 direction = Math.PI/2;
35 dblX = destination.getX();
36 dblY = source.getY() + source.radius + 10;
37 } else {
38 direction = 3*Math.PI/2;
39 dblX = destination.getX();
40 dblY = source.getY() - source.radius - 10;
41 }
42 }
43
44 x = (int)dblX;
45 y = (int)dblY;
46
47 this.numShips = numShips;
48 this.faction = faction;
49 this.destination = destination;
50 }
51
52
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() {
126 int speed = 1; //pixels per move
127 }
128
129 // attack the destination planet
130 //after the method is called the fleet needs to removed
131 public void attack() {
132 if(numShips <= destination.getNumShips()){
133 destination.setNumShips(destination.getNumShips() - numShips);
134 } else {
135 destination.setNumShips(numShips - destination.getNumShips());
136 destination.setFaction(this.faction);
137 }
138 }
139}
Note: See TracBrowser for help on using the repository browser.