Changeset b6a9b5f in galcon-client for src/com/example/helloandroid/Planet.java


Ignore:
Timestamp:
May 28, 2010, 4:02:05 AM (14 years ago)
Author:
dportnoy <devnull@…>
Branches:
master
Children:
5053d90
Parents:
5a03a06
Message:

Each planet is colored based on the faction that controls it and the ship count is centered on the planet and increases over time.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/com/example/helloandroid/Planet.java

    r5a03a06 rb6a9b5f  
    22
    33import java.util.ArrayList;
     4
     5import android.graphics.Canvas;
     6import android.graphics.Color;
     7import android.graphics.Paint;
     8import android.graphics.Paint.FontMetrics;
     9import android.util.Log;
    410
    511public class Planet {
     
    4046                numShips = num;
    4147        }
    42        
     48
    4349        public void setFaction(int faction) {
    4450                this.faction = faction;
    4551        }
    4652       
     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       
    4786        public void update() {
    48                 //regen ships if not owned by faction 0
    49                 numShips++;
     87                if(faction != 0)
     88                        numShips++;
     89               
    5090        }
    5191       
Note: See TracChangeset for help on using the changeset viewer.