Changeset 9d030cb in galcon-client for src/com/example/helloandroid
- Timestamp:
- Jun 14, 2010, 1:19:14 AM (14 years ago)
- Branches:
- master
- Children:
- 3a0d468
- Parents:
- 04a9a00 (diff), 38ac100 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/com/example/helloandroid
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/com/example/helloandroid/Fleet.java
r04a9a00 r9d030cb 22 22 private boolean isClockwise; 23 23 24 /* Optimi sing: pre-calculate paths */24 /* Optimizing: 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 if(dist < 2){ 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){ 239 244 dblY += (Math.sin(direction)*speed); 240 245 dblX += (Math.cos(direction)*speed); … … 246 251 isNextToAPlanet = false; 247 252 nearPlanet = null; 253 254 slope = getSlope(x,y,destination.getX(),destination.getY()); 255 256 xIntercept = destination.getY() - (slope*destination.getX()); 257 258 //direction 259 direction = Math.atan(slope); 260 261 //coordinates for all 4 coordinates 262 if((destination.getX() - x) < 0 ) 263 direction += Math.PI; 248 264 } 249 265 } else { -
src/com/example/helloandroid/GameView.java
r04a9a00 r9d030cb 10 10 import android.graphics.Color; 11 11 import android.graphics.Paint; 12 import android.graphics.RectF; 13 import android.graphics.Paint.FontMetrics; 12 14 import android.os.Bundle; 13 15 import android.os.Handler; … … 77 79 public ArrayList<Fleet> fleets; 78 80 public Planet planetSelected; 81 82 int mFleetSize; 79 83 80 84 public DrawingThread(SurfaceHolder surfaceHolder, Context context, … … 101 105 102 106 fleets = new ArrayList<Fleet>(); 107 108 mFleetSize = 50; 103 109 } 104 110 … … 236 242 if(Planet.collisionDetected(p, planets)) { 237 243 x--; 238 }else if(p.getX()-p.getRadius() < 0 || mCanvasWidth <=p.getX()+p.getRadius() ||239 p.getY()-p.getRadius() < 0 || mCanvasHeight <=p.getY()+p.getRadius()) {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()) { 240 246 x--; 241 247 }else { … … 340 346 } 341 347 } 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); 342 363 } 343 364 … … 366 387 while(i.hasNext()){ 367 388 f = i.next(); 368 if(f.getNumShips() == 0) 389 if(f.getNumShips() == 0) { 369 390 i.remove(); 370 else391 }else 371 392 f.update(planets); 372 393 } … … 408 429 Log.i("Gencon", "Detected touch event"); 409 430 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 } 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); 442 435 } 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 } 443 468 } 444 469
Note:
See TracChangeset
for help on using the changeset viewer.