Changeset 6ebf60f in galcon-client
- Timestamp:
- Jun 5, 2010, 9:55:49 PM (15 years ago)
- Branches:
- master
- Children:
- b15ff93
- Parents:
- 17dfb52
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
res/values/strings.xml
r17dfb52 r6ebf60f 2 2 3 3 <resources> 4 <string name="app_name"> Lunar Lander</string>4 <string name="app_name">Uber Galaxy War</string> 5 5 6 6 <string name="menu_start">Start</string> -
src/com/example/helloandroid/Fleet.java
r17dfb52 r6ebf60f 16 16 private double slope, xIntercept; 17 17 private double direction; 18 private Planet destination ;18 private Planet destination, nearPlanet; 19 19 private int numShips; 20 20 private int faction; 21 21 private boolean isNextToAPlanet; 22 private boolean dirChanged, isClockwise; 22 private boolean isClockwise; 23 23 24 24 25 /* Optimising: pre-calculate paths */ … … 63 64 this.destination = destination; 64 65 this.isNextToAPlanet = false; 65 dirChanged = false;66 66 } 67 67 … … 175 175 176 176 public void update(ArrayList<Planet> planets) { 177 int speed = 1; //pixels per move177 int speed = 3; //pixels per move 178 178 double distance, tangentDirection, angle; 179 Planet temp = null;179 180 180 //is the ship going around a planet already 181 181 if(!isNextToAPlanet){ … … 186 186 distance = getDistanceBetween(dblX,dblY,p.getX(),p.getY()); 187 187 if(distance <= p.radius){ 188 temp= p;188 nearPlanet = p; 189 189 break; 190 190 } 191 191 } 192 192 //if temp planet is not picked move along the direction by #speed 193 if( temp == null || dirChanged) {193 if(nearPlanet == null) { 194 194 dblY += (Math.sin(direction)*speed); 195 195 dblX += (Math.cos(direction)*speed); … … 198 198 y = (int)dblY; 199 199 }else { 200 double radAngle = Math.atan(getSlope(temp.getX(), temp.getY(), dblX, dblY)); 200 if(nearPlanet == destination){ 201 attack(); 202 return; 203 } 204 205 double radAngle = Math.atan(getSlope(nearPlanet.getX(), nearPlanet.getY(), dblX, dblY)); 201 206 //figure out which way to go clockwise or counter clockwise 202 tangentDirection = (Math.atan(getSlope( temp.getX(),temp.getY(),dblX,dblY))) + (Math.PI/2);207 tangentDirection = (Math.atan(getSlope(nearPlanet.getX(),nearPlanet.getY(),dblX,dblY))) + (Math.PI/2); 203 208 angle = Math.atan((Math.tan(tangentDirection) - Math.tan(direction))/(1 + Math.tan(tangentDirection)*Math.tan(direction))); 209 204 210 if (angle <= Math.PI/2) 205 211 angle = Math.PI - angle; 206 212 207 if(dblX < temp.getX())213 if(dblX < nearPlanet.getX()) 208 214 radAngle += Math.PI; 209 215 … … 216 222 else 217 223 isClockwise = true; 224 218 225 if(Math.abs(diff)>Math.PI/2) 219 226 direction = angle-Math.PI; 220 227 else 221 228 direction = angle; 222 223 dirChanged = true; 224 229 230 xIntercept = dblY - (dblX*Math.tan(direction)); 231 232 isNextToAPlanet = true; 225 233 //figure out which way to go clockwise or counter clockwise 226 234 /*tangentDirection = (Math.atan(getSlope(temp.getX(),temp.getY(),dblX,dblY))) + (Math.PI/2); … … 235 243 //otherwise continue moving along the circumferenceds4 236 244 237 238 if(true){ 239 245 double dist = Math.abs(destination.getY() - (direction*destination.getY()) - xIntercept)/(double)Math.sqrt(Math.pow(direction,2)+1); 246 Log.i("Gencon", dist + " units"); 247 if(dist < 5){ 248 dblY += (Math.sin(direction)*speed); 249 dblX += (Math.cos(direction)*speed); 250 251 x = (int)dblX; 252 y = (int)dblY; 253 254 if (getDistanceBetween(dblX,dblY,nearPlanet.getX(),nearPlanet.getY()) > nearPlanet.radius){ 255 isNextToAPlanet = false; 256 nearPlanet = null; 257 } 240 258 } else { 241 angle = speed/temp.radius; 259 angle = speed/(double)nearPlanet.radius; 260 Log.i("Gencon", angle + "%"); 242 261 if(isClockwise){ 243 dblX = ((Math.cos(direction + (Math.PI/2) - angle)*( temp.radius) + temp.getX()));244 dblY = ((Math.sin(direction + (Math.PI/2) - angle)*( temp.radius) + temp.getY()));245 direction = direction - ( Math.PI/2);262 dblX = ((Math.cos(direction + (Math.PI/2) - angle)*(nearPlanet.radius) + nearPlanet.getX())); 263 dblY = ((Math.sin(direction + (Math.PI/2) - angle)*(nearPlanet.radius) + nearPlanet.getY())); 264 direction = direction - (angle*.4); 246 265 } else { 247 dblX = ((Math.cos(direction - (Math.PI/2) + angle)*( temp.radius) + temp.getX()));248 dblY = ((Math.sin(direction - (Math.PI/2) + angle)*( temp.radius) + temp.getY()));249 direction = direction + ( Math.PI/2);266 dblX = ((Math.cos(direction - (Math.PI/2) + angle)*(nearPlanet.radius) + nearPlanet.getX())); 267 dblY = ((Math.sin(direction - (Math.PI/2) + angle)*(nearPlanet.radius) + nearPlanet.getY())); 268 direction = direction + (angle*.4); 250 269 } 270 x = (int)dblX; 271 y = (int)dblY; 272 xIntercept = dblY - (dblX*Math.tan(direction)); 251 273 } 252 274 } … … 256 278 //after the method is called the fleet needs to removed 257 279 public void attack() { 258 if(numShips <= destination.getNumShips()){ 280 if(this.faction == destination.getFaction()) 281 destination.setNumShips(destination.getNumShips() + numShips); 282 else if(numShips <= destination.getNumShips()){ 259 283 destination.setNumShips(destination.getNumShips() - numShips); 260 284 } else { … … 262 286 destination.setFaction(this.faction); 263 287 } 288 this.numShips = 0; 264 289 } 265 290 -
src/com/example/helloandroid/GameView.java
r17dfb52 r6ebf60f 2 2 3 3 import java.util.ArrayList; 4 import java.util.Iterator; 4 5 import java.util.Random; 5 6 … … 366 367 367 368 synchronized(fleetsLock) { 368 for(Fleet f : fleets) { 369 f.update(planets); 369 Iterator<Fleet> i = fleets.iterator(); 370 Fleet f = null; 371 while(i.hasNext()){ 372 f = i.next(); 373 if(f.getNumShips() == 0) 374 i.remove(); 375 else 376 f.update(planets); 370 377 } 371 378 }
Note:
See TracChangeset
for help on using the changeset viewer.