Changeset 69f6f01 in galcon-client for src


Ignore:
Timestamp:
Jun 10, 2010, 3:23:14 AM (14 years ago)
Author:
dportnoy <devnull@…>
Branches:
master
Children:
38ac100
Parents:
647a312
Message:

Added a display of the fleet size, a percentage of the population of the fleet's source planet. Prevented dispatching fleets with the same source and destination planets. The rate at which ships spawn on a planet is now based on the planet radius.

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

Legend:

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

    r647a312 r69f6f01  
    2222        private boolean isClockwise;
    2323
    24         /* Optimising: pre-calculate paths */
     24        /* Optimizing: pre-calculate paths */
    2525        public Fleet(Planet source, Planet destination, int numShips, int faction) {
    2626                source.setNumShips(source.getNumShips()-numShips);
  • src/com/example/helloandroid/GameView.java

    r647a312 r69f6f01  
    1010import android.graphics.Color;
    1111import android.graphics.Paint;
     12import android.graphics.RectF;
     13import android.graphics.Paint.FontMetrics;
    1214import android.os.Bundle;
    1315import android.os.Handler;
     
    7779        public ArrayList<Fleet> fleets;
    7880        public Planet planetSelected;
     81       
     82        int mFleetSize;
    7983
    8084        public DrawingThread(SurfaceHolder surfaceHolder, Context context,
     
    101105           
    102106            fleets = new ArrayList<Fleet>();
     107           
     108            mFleetSize = 50;
    103109        }
    104110
     
    239245                                if(Planet.collisionDetected(p, planets)) {
    240246                                        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()) {
    243249                                        x--;
    244250                                }else {
     
    343349                }
    344350                }
     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);
    345366        }
    346367
     
    371392                while(i.hasNext()){
    372393                        f = i.next();
    373                         if(f.getNumShips() == 0)
     394                        if(f.getNumShips() == 0) {
    374395                                i.remove();
    375                         else
     396                        }else
    376397                                f.update(planets);
    377398                }
     
    413434        Log.i("Gencon", "Detected touch event");
    414435       
    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);
    447440                }
     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                }
    448473        }
    449474       
  • src/com/example/helloandroid/Planet.java

    r647a312 r69f6f01  
    132132       
    133133        public void update() {
    134                 //if(faction != 0)
    135                         //numShips++;
     134                if(faction != 0)
     135                        numShips += radius/10;
    136136               
    137137        }
Note: See TracChangeset for help on using the changeset viewer.