Changeset 17dfb52 in galcon-client


Ignore:
Timestamp:
Jun 5, 2010, 8:02:26 PM (14 years ago)
Author:
dportnoy <devnull@…>
Branches:
master
Children:
1bc5794, 6ebf60f
Parents:
c65ef39 (diff), 0986844 (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:

handeld merge

File:
1 edited

Legend:

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

    rc65ef39 r17dfb52  
    2020        private int faction;
    2121        private boolean isNextToAPlanet;
    22         private boolean dirChanged;
    23        
     22        private boolean dirChanged, isClockwise;
     23
    2424        /* Optimising: pre-calculate paths */
    2525        public Fleet(Planet source, Planet destination, int numShips, int faction) {
     
    2828                //Calculate initial coordinates and direction
    2929                if((destination.getX() - source.getX()) != 0){
    30                 //line formula
    31                 slope = getSlope(source.getX(),source.getY(),destination.getX(),destination.getY());
    32                
    33                 xIntercept = destination.getY() - (slope*destination.getX());
    34                
    35                 //direction
    36                 direction = Math.atan(slope);
    37                
    38                 //coordinates for all 4 coordinates
    39                 if((destination.getX() - source.getX()) < 0 )
    40                         direction += Math.PI;
    41                
    42                 dblX = ((Math.cos(direction)*(source.radius + 10) + source.getX()));
    43                 dblY = ((Math.sin(direction)*(source.radius + 10) + source.getY()));
    44                
     30                        //line formula
     31                        slope = getSlope(source.getX(),source.getY(),destination.getX(),destination.getY());
     32               
     33                        xIntercept = destination.getY() - (slope*destination.getX());
     34
     35                        //direction
     36                        direction = Math.atan(slope);
     37
     38                        //coordinates for all 4 coordinates
     39                        if((destination.getX() - source.getX()) < 0 )
     40                                direction += Math.PI;
     41
     42                        dblX = ((Math.cos(direction)*(source.radius + 10) + source.getX()));
     43                        dblY = ((Math.sin(direction)*(source.radius + 10) + source.getY()));
     44
    4545                } else {
    4646                        if((destination.getY() - source.getY()) > 0 ){
     
    5353                                dblY = source.getY() - source.radius - 10;
    5454                        }
    55                 }
    56                
     55                        xIntercept = destination.getX();
     56                }
     57
    5758                x = (int)dblX;
    5859                y = (int)dblY;
    59                
     60
    6061                this.numShips = numShips;
    6162                this.faction = faction;
     
    6465                dirChanged = false;
    6566        }
    66        
    67                
     67
     68
    6869        public int getX() {
    6970                return x;
     
    175176        public void update(ArrayList<Planet> planets) {
    176177                int speed = 1; //pixels per move
    177                 double distance, tangentDirection;
     178                double distance, tangentDirection, angle;
    178179                Planet temp = null;
    179180                //is the ship going around a planet already
     
    193194                                dblY += (Math.sin(direction)*speed);
    194195                                dblX += (Math.cos(direction)*speed);
    195                                
     196
    196197                                x = (int)dblX;
    197198                                y = (int)dblY;
    198199                        }else {                         
    199200                                double radAngle = Math.atan(getSlope(temp.getX(), temp.getY(), dblX, dblY));
     201                                //figure out which way to go clockwise or counter clockwise
     202                                tangentDirection = (Math.atan(getSlope(temp.getX(),temp.getY(),dblX,dblY))) + (Math.PI/2);
     203                                angle = Math.atan((Math.tan(tangentDirection) - Math.tan(direction))/(1 + Math.tan(tangentDirection)*Math.tan(direction)));
     204                                if (angle <= Math.PI/2)
     205                                        angle = Math.PI - angle;
    200206                               
    201207                                if(dblX < temp.getX())
    202208                                        radAngle += Math.PI;
    203209                               
    204                                 double angle = radAngle + Math.PI/2;
     210                                angle = radAngle + Math.PI/2;
    205211                               
    206212                                double diff = direction-angle;
    207213                               
     214                                if(diff > 0)
     215                                        isClockwise = false;
     216                                else
     217                                        isClockwise = true;
    208218                                if(Math.abs(diff)>Math.PI/2)
    209219                                        direction = angle-Math.PI;
    210220                                else
    211221                                        direction = angle;
    212                                
     222                                       
    213223                                dirChanged = true;
    214224                               
     
    224234                        //if so set isNextToAPlanet to false and move
    225235                        //otherwise continue moving along the circumferenceds4
    226                
    227                 }
    228                
    229                
    230         }
    231        
     236                       
     237                       
     238                        if(true){
     239                               
     240                        } else {
     241                                angle = speed/temp.radius;
     242                                if(isClockwise){
     243                                        dblX = ((Math.cos(direction + (Math.PI/2) - angle)*(temp.radius) + temp.getX()));
     244                                        dblY = ((Math.sin(direction + (Math.PI/2) - angle)*(temp.radius) + temp.getY()));
     245                                        direction = direction - (Math.PI/2);
     246                                } else {
     247                                        dblX = ((Math.cos(direction - (Math.PI/2) + angle)*(temp.radius) + temp.getX()));
     248                                        dblY = ((Math.sin(direction - (Math.PI/2) + angle)*(temp.radius) + temp.getY()));
     249                                        direction = direction + (Math.PI/2);
     250                                }
     251                        }
     252                }
     253        }
     254
    232255        // attack the destination planet
    233256        //after the method is called the fleet needs to removed
     
    240263                }
    241264        }
    242        
     265
    243266        //helper functions
    244267        private double getDistanceBetween(double x1, double y1, double x2, double y2) {
    245268                return Math.sqrt(Math.pow((x2 - x1),2) + Math.pow((y2 - y1),2));
    246269        }
    247        
     270
    248271        private double getSlope(double x1, double y1, double x2, double y2) {
    249272                return ((y2 - y1)/(double)(x2 - x1));
Note: See TracChangeset for help on using the changeset viewer.