- Timestamp:
- Jun 10, 2010, 3:23:14 AM (14 years ago)
- Branches:
- master
- Children:
- 38ac100
- Parents:
- 647a312
- Location:
- src/com/example/helloandroid
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/com/example/helloandroid/Fleet.java
r647a312 r69f6f01 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); -
src/com/example/helloandroid/GameView.java
r647a312 r69f6f01 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 … … 239 245 if(Planet.collisionDetected(p, planets)) { 240 246 x--; 241 }else if(p.getX()-p.getRadius() < 0 || mCanvasWidth <=p.getX()+p.getRadius() ||242 p.getY()-p.getRadius() < 0 || mCanvasHeight <=p.getY()+p.getRadius()) {247 }else if(p.getX()-p.getRadius() < 0 || mCanvasWidth-20<=p.getX()+p.getRadius() || 248 p.getY()-p.getRadius() < 0 || mCanvasHeight-20<=p.getY()+p.getRadius()) { 243 249 x--; 244 250 }else { … … 343 349 } 344 350 } 351 352 float textSize = mTextPaint.getTextSize(); 353 mTextPaint.setTextSize(24); 354 FontMetrics metrics = mTextPaint.getFontMetrics(); 355 mTextPaint.setColor(Color.WHITE); 356 357 canvas.drawText(mFleetSize+"%", mCanvasWidth-mTextPaint.measureText(mFleetSize+"%"), mCanvasHeight-20-(metrics.ascent+metrics.descent), mTextPaint); 358 359 mTextPaint.setTextSize(textSize); 360 361 mLinePaint.setColor(Color.YELLOW); 362 canvas.drawRoundRect(new RectF(70, mCanvasHeight-15, mCanvasWidth-70, mCanvasHeight-5), 5, 5, mLinePaint); 363 364 mLinePaint.setColor(Color.GREEN); 365 canvas.drawRoundRect(new RectF(70, mCanvasHeight-15, 70+(mCanvasWidth-140)*mFleetSize/100, mCanvasHeight-5), 5, 5, mLinePaint); 345 366 } 346 367 … … 371 392 while(i.hasNext()){ 372 393 f = i.next(); 373 if(f.getNumShips() == 0) 394 if(f.getNumShips() == 0) { 374 395 i.remove(); 375 else396 }else 376 397 f.update(planets); 377 398 } … … 413 434 Log.i("Gencon", "Detected touch event"); 414 435 415 if(event.getAction() != MotionEvent.ACTION_DOWN) 416 return true; 417 418 synchronized(thread.planetsLock) { 419 if(thread.planetSelected != null) { 420 Planet target = null; 421 422 for(Planet p : thread.planets) { 423 if(p.contains((int)event.getX(), (int)event.getY())) { 424 target = p; 425 break; 426 } 427 } 428 429 if(target != null && thread.planetSelected.getFaction() != 0) { 430 synchronized(thread.fleetsLock) { 431 Fleet f = new Fleet(thread.planetSelected, target, 1, 1); 432 f.setFaction(thread.planetSelected.getFaction()); 433 thread.fleets.add(f); 434 } 435 } 436 437 thread.planetSelected.unselect(); 438 thread.planetSelected = null; 439 }else { 440 for(Planet p : thread.planets) { 441 if(p.contains((int)event.getX(), (int)event.getY())) { 442 p.select(); 443 thread.planetSelected = p; 444 break; 445 } 446 } 436 if(event.getAction() == MotionEvent.ACTION_UP) { 437 if(70 <= event.getX() && event.getX() <= thread.mCanvasWidth-70 && 438 thread.mCanvasHeight-15 <= event.getY() && event.getY() <= thread.mCanvasHeight-5) { 439 thread.mFleetSize = ((int)event.getX()-70)*100/(thread.mCanvasWidth-140); 447 440 } 441 }else if(event.getAction() == MotionEvent.ACTION_DOWN) { 442 synchronized(thread.planetsLock) { 443 if(thread.planetSelected != null) { 444 Planet target = null; 445 446 for(Planet p : thread.planets) { 447 if(p.contains((int)event.getX(), (int)event.getY())) { 448 target = p; 449 break; 450 } 451 } 452 453 if(target != null && target != thread.planetSelected && thread.planetSelected.getFaction() != 0) { 454 synchronized(thread.fleetsLock) { 455 Fleet f = new Fleet(thread.planetSelected, target, thread.planetSelected.getNumShips()*thread.mFleetSize/100, thread.planetSelected.getFaction()); 456 f.setFaction(thread.planetSelected.getFaction()); 457 thread.fleets.add(f); 458 } 459 } 460 461 thread.planetSelected.unselect(); 462 thread.planetSelected = null; 463 }else { 464 for(Planet p : thread.planets) { 465 if(p.contains((int)event.getX(), (int)event.getY())) { 466 p.select(); 467 thread.planetSelected = p; 468 break; 469 } 470 } 471 } 472 } 448 473 } 449 474 -
src/com/example/helloandroid/Planet.java
r647a312 r69f6f01 132 132 133 133 public void update() { 134 //if(faction != 0)135 //numShips++;134 if(faction != 0) 135 numShips += radius/10; 136 136 137 137 }
Note:
See TracChangeset
for help on using the changeset viewer.