Changeset 9d030cb in galcon-client for src/com/example


Ignore:
Timestamp:
Jun 14, 2010, 1:19:14 AM (14 years ago)
Author:
dportnoy <devnull@…>
Branches:
master
Children:
3a0d468
Parents:
04a9a00 (diff), 38ac100 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with 422c8ef5772e988da2065d1c4b95e6d6ab6192e7

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

Legend:

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

    r04a9a00 r9d030cb  
    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);
     
    236236                       
    237237                        double dist = Math.abs(destination.getY() - (Math.tan(direction)*destination.getX()) - xIntercept)/(double)Math.sqrt(Math.pow(direction,2)+1);
    238                         if(dist < 2){
     238                        int allowedError = 2;
     239                        if(nearPlanet.radius <= 10)
     240                                allowedError = 10;
     241                        else if(nearPlanet.radius <= 30)
     242                                allowedError = 5;
     243                        if(dist < allowedError){
    239244                                dblY += (Math.sin(direction)*speed);
    240245                                dblX += (Math.cos(direction)*speed);
     
    246251                                        isNextToAPlanet = false;
    247252                                        nearPlanet = null;
     253                                       
     254                                        slope = getSlope(x,y,destination.getX(),destination.getY());
     255                                       
     256                                        xIntercept = destination.getY() - (slope*destination.getX());
     257
     258                                        //direction
     259                                        direction = Math.atan(slope);
     260
     261                                        //coordinates for all 4 coordinates
     262                                        if((destination.getX() - x) < 0 )
     263                                                direction += Math.PI;
    248264                                }
    249265                        } else {
  • src/com/example/helloandroid/GameView.java

    r04a9a00 r9d030cb  
    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
     
    236242                                if(Planet.collisionDetected(p, planets)) {
    237243                                        x--;
    238                                 }else if(p.getX()-p.getRadius() < 0 || mCanvasWidth<=p.getX()+p.getRadius() ||
    239                                                  p.getY()-p.getRadius() < 0 || mCanvasHeight<=p.getY()+p.getRadius()) {
     244                                }else if(p.getX()-p.getRadius() < 0 || mCanvasWidth-20<=p.getX()+p.getRadius() ||
     245                                                 p.getY()-p.getRadius() < 0 || mCanvasHeight-20<=p.getY()+p.getRadius()) {
    240246                                        x--;
    241247                                }else {
     
    340346                }
    341347                }
     348               
     349                float textSize = mTextPaint.getTextSize();
     350                mTextPaint.setTextSize(24);
     351                FontMetrics metrics = mTextPaint.getFontMetrics();
     352                mTextPaint.setColor(Color.WHITE);
     353               
     354                canvas.drawText(mFleetSize+"%", mCanvasWidth-mTextPaint.measureText(mFleetSize+"%"), mCanvasHeight-20-(metrics.ascent+metrics.descent), mTextPaint);
     355               
     356                mTextPaint.setTextSize(textSize);
     357               
     358                mLinePaint.setColor(Color.YELLOW);
     359                canvas.drawRoundRect(new RectF(70, mCanvasHeight-15, mCanvasWidth-70, mCanvasHeight-5), 5, 5, mLinePaint);
     360               
     361                mLinePaint.setColor(Color.GREEN);
     362                canvas.drawRoundRect(new RectF(70, mCanvasHeight-15, 70+(mCanvasWidth-140)*mFleetSize/100, mCanvasHeight-5), 5, 5, mLinePaint);
    342363        }
    343364
     
    366387                while(i.hasNext()){
    367388                        f = i.next();
    368                         if(f.getNumShips() == 0)
     389                        if(f.getNumShips() == 0) {
    369390                                i.remove();
    370                         else
     391                        }else
    371392                                f.update(planets);
    372393                }
     
    408429        Log.i("Gencon", "Detected touch event");
    409430       
    410         if(event.getAction() != MotionEvent.ACTION_DOWN)
    411                 return true;
    412        
    413         synchronized(thread.planetsLock) {
    414                 if(thread.planetSelected != null) {
    415                         Planet target = null;
    416                        
    417                         for(Planet p : thread.planets) {
    418                                 if(p.contains((int)event.getX(), (int)event.getY())) {
    419                                         target = p;
    420                                         break;
    421                                 }
    422                         }
    423                        
    424                         if(target != null && thread.planetSelected.getFaction() != 0) {
    425                                 synchronized(thread.fleetsLock) {
    426                                 Fleet f = new Fleet(thread.planetSelected, target, 1, 1);
    427                                 f.setFaction(thread.planetSelected.getFaction());
    428                                 thread.fleets.add(f);
    429                     }
    430                         }
    431                                
    432                         thread.planetSelected.unselect();
    433                         thread.planetSelected = null;
    434                 }else {
    435                         for(Planet p : thread.planets) {
    436                                 if(p.contains((int)event.getX(), (int)event.getY())) {
    437                                         p.select();
    438                                         thread.planetSelected = p;
    439                                         break;
    440                                 }
    441                         }
     431        if(event.getAction() == MotionEvent.ACTION_UP) {
     432                if(70 <= event.getX() && event.getX() <= thread.mCanvasWidth-70 &&
     433                   thread.mCanvasHeight-15 <= event.getY() && event.getY() <= thread.mCanvasHeight-5) {
     434                        thread.mFleetSize = ((int)event.getX()-70)*100/(thread.mCanvasWidth-140);
    442435                }
     436        }else if(event.getAction() == MotionEvent.ACTION_DOWN) {
     437                synchronized(thread.planetsLock) {
     438                        if(thread.planetSelected != null) {
     439                                Planet target = null;
     440                               
     441                                for(Planet p : thread.planets) {
     442                                        if(p.contains((int)event.getX(), (int)event.getY())) {
     443                                                target = p;
     444                                                break;
     445                                        }
     446                                }
     447                               
     448                                if(target != null && target != thread.planetSelected && thread.planetSelected.getFaction() != 0) {
     449                                        synchronized(thread.fleetsLock) {
     450                                        Fleet f = new Fleet(thread.planetSelected, target, thread.planetSelected.getNumShips()*thread.mFleetSize/100, thread.planetSelected.getFaction());
     451                                        f.setFaction(thread.planetSelected.getFaction());
     452                                        thread.fleets.add(f);
     453                            }
     454                                }
     455                                       
     456                                thread.planetSelected.unselect();
     457                                thread.planetSelected = null;
     458                        }else {
     459                                for(Planet p : thread.planets) {
     460                                        if(p.contains((int)event.getX(), (int)event.getY())) {
     461                                                p.select();
     462                                                thread.planetSelected = p;
     463                                                break;
     464                                        }
     465                                }
     466                        }
     467                }
    443468        }
    444469       
Note: See TracChangeset for help on using the changeset viewer.