Changes in / [9d030cb:04a9a00] in galcon-client
- Location:
- src/com/example/helloandroid
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/com/example/helloandroid/Fleet.java
r9d030cb r04a9a00 22 22 private boolean isClockwise; 23 23 24 /* Optimi zing: pre-calculate paths */24 /* Optimising: pre-calculate paths */ 25 25 public Fleet(Planet source, Planet destination, int numShips, int faction) { 26 26 source.setNumShips(source.getNumShips()-numShips); … … 236 236 237 237 double dist = Math.abs(destination.getY() - (Math.tan(direction)*destination.getX()) - xIntercept)/(double)Math.sqrt(Math.pow(direction,2)+1); 238 int allowedError = 2; 239 if(nearPlanet.radius <= 10) 240 allowedError = 10; 241 else if(nearPlanet.radius <= 30) 242 allowedError = 5; 243 if(dist < allowedError){ 238 if(dist < 2){ 244 239 dblY += (Math.sin(direction)*speed); 245 240 dblX += (Math.cos(direction)*speed); … … 251 246 isNextToAPlanet = false; 252 247 nearPlanet = null; 253 254 slope = getSlope(x,y,destination.getX(),destination.getY());255 256 xIntercept = destination.getY() - (slope*destination.getX());257 258 //direction259 direction = Math.atan(slope);260 261 //coordinates for all 4 coordinates262 if((destination.getX() - x) < 0 )263 direction += Math.PI;264 248 } 265 249 } else { -
src/com/example/helloandroid/GameView.java
r9d030cb r04a9a00 10 10 import android.graphics.Color; 11 11 import android.graphics.Paint; 12 import android.graphics.RectF;13 import android.graphics.Paint.FontMetrics;14 12 import android.os.Bundle; 15 13 import android.os.Handler; … … 79 77 public ArrayList<Fleet> fleets; 80 78 public Planet planetSelected; 81 82 int mFleetSize;83 79 84 80 public DrawingThread(SurfaceHolder surfaceHolder, Context context, … … 105 101 106 102 fleets = new ArrayList<Fleet>(); 107 108 mFleetSize = 50;109 103 } 110 104 … … 242 236 if(Planet.collisionDetected(p, planets)) { 243 237 x--; 244 }else if(p.getX()-p.getRadius() < 0 || mCanvasWidth -20<=p.getX()+p.getRadius() ||245 p.getY()-p.getRadius() < 0 || mCanvasHeight -20<=p.getY()+p.getRadius()) {238 }else if(p.getX()-p.getRadius() < 0 || mCanvasWidth<=p.getX()+p.getRadius() || 239 p.getY()-p.getRadius() < 0 || mCanvasHeight<=p.getY()+p.getRadius()) { 246 240 x--; 247 241 }else { … … 346 340 } 347 341 } 348 349 float textSize = mTextPaint.getTextSize();350 mTextPaint.setTextSize(24);351 FontMetrics metrics = mTextPaint.getFontMetrics();352 mTextPaint.setColor(Color.WHITE);353 354 canvas.drawText(mFleetSize+"%", mCanvasWidth-mTextPaint.measureText(mFleetSize+"%"), mCanvasHeight-20-(metrics.ascent+metrics.descent), mTextPaint);355 356 mTextPaint.setTextSize(textSize);357 358 mLinePaint.setColor(Color.YELLOW);359 canvas.drawRoundRect(new RectF(70, mCanvasHeight-15, mCanvasWidth-70, mCanvasHeight-5), 5, 5, mLinePaint);360 361 mLinePaint.setColor(Color.GREEN);362 canvas.drawRoundRect(new RectF(70, mCanvasHeight-15, 70+(mCanvasWidth-140)*mFleetSize/100, mCanvasHeight-5), 5, 5, mLinePaint);363 342 } 364 343 … … 387 366 while(i.hasNext()){ 388 367 f = i.next(); 389 if(f.getNumShips() == 0) {368 if(f.getNumShips() == 0) 390 369 i.remove(); 391 }else370 else 392 371 f.update(planets); 393 372 } … … 429 408 Log.i("Gencon", "Detected touch event"); 430 409 431 if(event.getAction() == MotionEvent.ACTION_UP) { 432 if(70 <= event.getX() && event.getX() <= thread.mCanvasWidth-70 && 433 thread.mCanvasHeight-15 <= event.getY() && event.getY() <= thread.mCanvasHeight-5) { 434 thread.mFleetSize = ((int)event.getX()-70)*100/(thread.mCanvasWidth-140); 410 if(event.getAction() != MotionEvent.ACTION_DOWN) 411 return true; 412 413 synchronized(thread.planetsLock) { 414 if(thread.planetSelected != null) { 415 Planet target = null; 416 417 for(Planet p : thread.planets) { 418 if(p.contains((int)event.getX(), (int)event.getY())) { 419 target = p; 420 break; 421 } 422 } 423 424 if(target != null && thread.planetSelected.getFaction() != 0) { 425 synchronized(thread.fleetsLock) { 426 Fleet f = new Fleet(thread.planetSelected, target, 1, 1); 427 f.setFaction(thread.planetSelected.getFaction()); 428 thread.fleets.add(f); 429 } 430 } 431 432 thread.planetSelected.unselect(); 433 thread.planetSelected = null; 434 }else { 435 for(Planet p : thread.planets) { 436 if(p.contains((int)event.getX(), (int)event.getY())) { 437 p.select(); 438 thread.planetSelected = p; 439 break; 440 } 441 } 435 442 } 436 }else if(event.getAction() == MotionEvent.ACTION_DOWN) {437 synchronized(thread.planetsLock) {438 if(thread.planetSelected != null) {439 Planet target = null;440 441 for(Planet p : thread.planets) {442 if(p.contains((int)event.getX(), (int)event.getY())) {443 target = p;444 break;445 }446 }447 448 if(target != null && target != thread.planetSelected && thread.planetSelected.getFaction() != 0) {449 synchronized(thread.fleetsLock) {450 Fleet f = new Fleet(thread.planetSelected, target, thread.planetSelected.getNumShips()*thread.mFleetSize/100, thread.planetSelected.getFaction());451 f.setFaction(thread.planetSelected.getFaction());452 thread.fleets.add(f);453 }454 }455 456 thread.planetSelected.unselect();457 thread.planetSelected = null;458 }else {459 for(Planet p : thread.planets) {460 if(p.contains((int)event.getX(), (int)event.getY())) {461 p.select();462 thread.planetSelected = p;463 break;464 }465 }466 }467 }468 443 } 469 444
Note:
See TracChangeset
for help on using the changeset viewer.