Changeset 1291908 in galcon-client for src/com


Ignore:
Timestamp:
May 28, 2010, 12:55:50 AM (14 years ago)
Author:
Zero Cool <devnull@…>
Branches:
master
Children:
5a03a06
Parents:
3e9f39e
Message:

Fleet attack function works now

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

Legend:

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

    r3e9f39e r1291908  
    1515        public Fleet(Planet source, Planet destination, int numShips, int faction) {
    1616                //Calculate initial coordinates and direction
    17                 if(destination.x - source.x != 0){
     17                if(destination.getX() - source.getX() != 0){
    1818                //line formula
    19                 slope = ((source.y - destination.y)/(source.x - destination.x));
    20                 xIntercept = destination.y - (slope*destination.x);
     19                slope = ((source.getY() - destination.getY())/(source.getX() - destination.getX()));
     20                xIntercept = destination.getY() - (slope*destination.getX());
    2121               
    2222                //direction
     
    2424               
    2525                //coordinates for all 4 coordinates
    26                 if(destination.x - source.x < 0 )
     26                if(destination.getX() - source.getX() < 0 )
    2727                        direction += Math.PI;
    2828               
    29                 x = (int)((Math.cos(direction)*(source.radius + 10) + source.x));
    30                 y = (int)((Math.sin(direction)*(source.radius + 10) + source.y));
     29                x = (int)((Math.cos(direction)*(source.radius + 10) + source.getX()));
     30                y = (int)((Math.sin(direction)*(source.radius + 10) + source.getY()));
    3131                } else {
    32                         if((destination.y - source.y) > 0 ){
     32                        if((destination.getY() - source.getY()) > 0 ){
    3333                                direction = Math.PI/2;
    34                                 x = destination.x;
    35                                 y = source.y + source.radius + 10;
     34                                x = destination.getX();
     35                                y = source.getY() + source.radius + 10;
    3636                        } else {
    3737                                direction = 3*Math.PI/2;
    38                                 x = destination.x;
    39                                 y = source.y - source.radius - 10;
     38                                x = destination.getX();
     39                                y = source.getY() - source.radius - 10;
    4040                        }
    4141                }
     
    125125        // attack the destination planet
    126126        public void attack() {
    127                 if(numShips <= destination.numShips ){
    128                
     127                if(numShips <= destination.getNumShips()){
     128                        destination.setNumShips(destination.getNumShips() - numShips);
     129                } else {
     130                        destination.setNumShips(numShips - destination.getNumShips());
     131                        destination.setFaction(this.faction);
    129132                }
    130133        }
  • src/com/example/helloandroid/Planet.java

    r3e9f39e r1291908  
    4141        }
    4242       
     43        public void setFaction(int faction) {
     44                this.faction = faction;
     45        }
     46       
    4347        public void update() {
    4448                //regen ships if not owned by faction 0
Note: See TracChangeset for help on using the changeset viewer.