- Timestamp:
- May 28, 2010, 4:02:05 AM (14 years ago)
- Branches:
- master
- Children:
- 5053d90
- Parents:
- 5a03a06
- Location:
- src/com/example/helloandroid
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/com/example/helloandroid/Game.java
r5a03a06 rb6a9b5f 112 112 if (savedInstanceState == null) { 113 113 // we were just launched: set up a new game 114 mThread.setState(DrawingThread.STATE_R EADY);114 mThread.setState(DrawingThread.STATE_RUNNING); 115 115 Log.w(this.getClass().getName(), "SIS is null"); 116 116 } else { -
src/com/example/helloandroid/GameView.java
r5a03a06 rb6a9b5f 202 202 mTextPaint = new Paint(); 203 203 mTextPaint.setAntiAlias(true); 204 mTextPaint.setARGB(255, 255, 0, 0);204 mTextPaint.setARGB(255, 255, 255, 255); 205 205 206 206 mWinsInARow = 0; … … 310 310 public void run() { 311 311 while (mRun) { 312 //Log.i("Gencon", "run called"); 313 312 314 Canvas c = null; 313 315 try { 314 316 c = mSurfaceHolder.lockCanvas(null); 315 317 synchronized (mSurfaceHolder) { 318 //Log.i("Gencon", "about to call stuff: mode is "+mMode); 319 316 320 if (mMode == STATE_RUNNING) updatePhysics(); 317 321 doDraw(c); … … 418 422 * thread, which updates the user-text View. 419 423 */ 420 boolean test = true;421 if(test)422 return;423 424 synchronized (mSurfaceHolder) { 424 425 mMode = mode; … … 470 471 mCanvasHeight = height; 471 472 472 Log.i( this.getClass().getName(), "width: "+mCanvasWidth+", height: "+mCanvasHeight);473 Log.i("Gencon", "width: "+mCanvasWidth+", height: "+mCanvasHeight); 473 474 474 475 Random rand = new Random(); 475 476 476 for(int x=0; x<1 0; x++) {477 for(int x=0; x<15; x++) { 477 478 Planet p = new Planet(rand.nextInt(45)+5, rand.nextInt(mCanvasWidth), rand.nextInt(mCanvasHeight)); 478 p.setNumShips(rand.nextInt(150));479 479 480 480 if(Planet.collisionDetected(p, planets)) { … … 484 484 x--; 485 485 }else { 486 p.setNumShips(rand.nextInt(150)); 487 p.setFaction(rand.nextInt(5)); 486 488 planets.add(p); 487 489 } … … 569 571 // Draw the background image. Operations on the Canvas accumulate 570 572 // so this is like clearing the screen. 571 canvas.drawBitmap(mBackgroundImage, 0, 0, null);572 573 574 //Log.i("Gencon", "doDraw called"); 575 576 canvas.drawBitmap(mBackgroundImage, 0, 0, null); 573 577 for(Planet p : planets) { 574 canvas.drawCircle(p.getX(), p.getY(), p.getRadius(), mLinePaint); 575 canvas.drawText(Integer.toString(p.getNumShips()), p.getX(), p.getY(), mTextPaint); 578 p.draw(canvas, mLinePaint, mTextPaint); 576 579 } 577 580 … … 601 604 */ 602 605 private void updatePhysics() { 606 //Log.i("Gencon", "updatePhysics called"); 607 603 608 long now = System.currentTimeMillis(); 604 609 … … 702 707 } 703 708 704 setState(result, message);709 //setState(result, message); 705 710 } 706 711 } -
src/com/example/helloandroid/Planet.java
r5a03a06 rb6a9b5f 2 2 3 3 import java.util.ArrayList; 4 5 import android.graphics.Canvas; 6 import android.graphics.Color; 7 import android.graphics.Paint; 8 import android.graphics.Paint.FontMetrics; 9 import android.util.Log; 4 10 5 11 public class Planet { … … 40 46 numShips = num; 41 47 } 42 48 43 49 public void setFaction(int faction) { 44 50 this.faction = faction; 45 51 } 46 52 53 public void draw(Canvas canvas, Paint linePaint, Paint textPaint) { 54 FontMetrics metrics = textPaint.getFontMetrics(); 55 56 int c, prevC = linePaint.getColor(); 57 58 switch(faction) { 59 case 0: 60 c = Color.argb(255, 100, 100, 100); 61 break; 62 case 1: 63 c = Color.argb(255, 255, 0, 0); 64 break; 65 case 2: 66 c = Color.argb(255, 0, 255, 0); 67 break; 68 case 3: 69 c = Color.argb(255, 0, 0, 255); 70 break; 71 case 4: 72 c = Color.argb(255, 255, 255, 0); 73 break; 74 default: 75 c = prevC; 76 } 77 78 linePaint.setColor(c); 79 80 canvas.drawCircle(x, y, getRadius(), linePaint); 81 canvas.drawText(Integer.toString(numShips), x-textPaint.measureText(Integer.toString(numShips))/2, y-(metrics.ascent+metrics.descent)/2, textPaint); 82 83 linePaint.setColor(prevC); 84 } 85 47 86 public void update() { 48 //regen ships if not owned by faction 0 49 numShips++; 87 if(faction != 0) 88 numShips++; 89 50 90 } 51 91
Note:
See TracChangeset
for help on using the changeset viewer.