Changeset b6a9b5f in galcon-client for src/com/example


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.

Location:
src/com/example/helloandroid
Files:
3 edited

Legend:

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

    r5a03a06 rb6a9b5f  
    112112        if (savedInstanceState == null) {
    113113            // we were just launched: set up a new game
    114                 mThread.setState(DrawingThread.STATE_READY);
     114                mThread.setState(DrawingThread.STATE_RUNNING);
    115115            Log.w(this.getClass().getName(), "SIS is null");
    116116        } else {
  • src/com/example/helloandroid/GameView.java

    r5a03a06 rb6a9b5f  
    202202            mTextPaint = new Paint();
    203203            mTextPaint.setAntiAlias(true);
    204             mTextPaint.setARGB(255, 255, 0, 0);
     204            mTextPaint.setARGB(255, 255, 255, 255);
    205205
    206206            mWinsInARow = 0;
     
    310310        public void run() {
    311311            while (mRun) {
     312                //Log.i("Gencon", "run called");
     313               
    312314                Canvas c = null;
    313315                try {
    314316                    c = mSurfaceHolder.lockCanvas(null);
    315317                    synchronized (mSurfaceHolder) {
     318                        //Log.i("Gencon", "about to call stuff: mode is "+mMode);
     319                       
    316320                        if (mMode == STATE_RUNNING) updatePhysics();
    317321                        doDraw(c);
     
    418422             * thread, which updates the user-text View.
    419423             */
    420                 boolean test = true;
    421                 if(test)
    422                         return;
    423424            synchronized (mSurfaceHolder) {
    424425                mMode = mode;
     
    470471                mCanvasHeight = height;
    471472               
    472                 Log.i(this.getClass().getName(), "width: "+mCanvasWidth+", height: "+mCanvasHeight);
     473                Log.i("Gencon", "width: "+mCanvasWidth+", height: "+mCanvasHeight);
    473474               
    474475                Random rand = new Random();
    475476
    476                 for(int x=0; x<10; x++) {
     477                for(int x=0; x<15; x++) {
    477478                        Planet p = new Planet(rand.nextInt(45)+5, rand.nextInt(mCanvasWidth), rand.nextInt(mCanvasHeight));
    478                         p.setNumShips(rand.nextInt(150));
    479479                       
    480480                        if(Planet.collisionDetected(p, planets)) {
     
    484484                                x--;
    485485                        }else {
     486                                p.setNumShips(rand.nextInt(150));
     487                                p.setFaction(rand.nextInt(5));
    486488                                planets.add(p);
    487489                        }
     
    569571            // Draw the background image. Operations on the Canvas accumulate
    570572            // so this is like clearing the screen.
    571             canvas.drawBitmap(mBackgroundImage, 0, 0, null);
    572573           
     574                //Log.i("Gencon", "doDraw called");
     575               
     576                canvas.drawBitmap(mBackgroundImage, 0, 0, null);
    573577            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);
    576579            }
    577580           
     
    601604         */
    602605        private void updatePhysics() {
     606                //Log.i("Gencon", "updatePhysics called");
     607               
    603608            long now = System.currentTimeMillis();
    604609
     
    702707                }
    703708
    704                 setState(result, message);
     709                //setState(result, message);
    705710            }
    706711        }
  • 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.