Changeset 5053d90 in galcon-client for src/com/example/helloandroid/Planet.java
- Timestamp:
- May 30, 2010, 9:32:02 PM (15 years ago)
- Branches:
- master
- Children:
- c27abf4
- Parents:
- b6a9b5f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/com/example/helloandroid/Planet.java
rb6a9b5f r5053d90 3 3 import java.util.ArrayList; 4 4 5 import android.graphics.Bitmap; 5 6 import android.graphics.Canvas; 6 7 import android.graphics.Color; 7 8 import android.graphics.Paint; 8 9 import android.graphics.Paint.FontMetrics; 9 import android.util.Log;10 10 11 11 public class Planet { … … 16 16 int faction; 17 17 int numShips; 18 18 boolean selected; 19 private Bitmap selection; 20 19 21 public Planet(int radius, int x, int y) { 20 22 this.radius = radius; … … 23 25 faction = 0; 24 26 numShips = 0; 27 selected = false; 25 28 26 29 regenRate = 0; //change this to some expression / funcion call 30 31 int size = getRadius()+15; 32 33 selection = Bitmap.createBitmap(size*2, size*2, Bitmap.Config.ARGB_8888); 34 Canvas c = new Canvas(selection); 35 c.drawColor(Color.argb(0, 0, 0, 0)); 36 37 Paint p = new Paint(); 38 p.setAntiAlias(true); 39 40 p.setColor(Color.argb(255, 255, 255, 255)); 41 c.drawCircle(size, size, getRadius()+11, p); 42 43 p.setColor(Color.argb(255, 100, 100, 100)); 44 c.drawCircle(size, size, getRadius()+5, p); 45 46 for(int i=0; i<size*2; i++) { 47 for(int j=0; j<size*2; j++) { 48 if(selection.getPixel(i,j) == Color.argb(255, 100, 100, 100)) 49 selection.setPixel(i, j, Color.argb(0, 0, 0, 0)); 50 } 51 } 27 52 } 28 53 … … 43 68 } 44 69 70 public boolean isSelected() { 71 return selected; 72 } 73 45 74 public void setNumShips(int num) { 46 75 numShips = num; … … 51 80 } 52 81 82 public void select() { 83 selected = true; 84 } 85 86 public void unselect() { 87 selected = false; 88 } 89 53 90 public void draw(Canvas canvas, Paint linePaint, Paint textPaint) { 54 91 FontMetrics metrics = textPaint.getFontMetrics(); 55 92 56 93 int c, prevC = linePaint.getColor(); 94 95 if(selected) { 96 //drawSelectionCircle(canvas); 97 } 57 98 58 99 switch(faction) { … … 84 125 } 85 126 127 public void drawSelectionCircle(Canvas canvas) { 128 int size = getRadius()+15; 129 130 canvas.drawBitmap(selection, x-size, y-size, null); 131 } 132 86 133 public void update() { 87 134 if(faction != 0) … … 92 139 public void sendFleet(Planet p, int numShips) { 93 140 141 } 142 143 public boolean contains(int x, int y) { 144 double dist = Math.sqrt(Math.pow(this.x-x, 2) + Math.pow(this.y-y, 2)); 145 146 return dist <= this.radius; 94 147 } 95 148
Note:
See TracChangeset
for help on using the changeset viewer.