Ignore:
File:
1 edited

Legend:

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

    r8a4e64f r159eef8  
    11package com.example.helloandroid;
    2 
    3 import java.util.ArrayList;
    42
    53public class Planet {
    64        int radius;
    75        int regenRate;  // ships per second
    8         private int x;
    9         private int y;
     6        int x;
     7        int y;
    108        int faction;
    119        int numShips;
     
    2927        }
    3028       
    31         public int getRadius() {
    32                 return radius;
    33         }
    34        
    35         public int getNumShips() {
    36                 return numShips;
    37         }
    38        
    39         public void setNumShips(int num) {
    40                 numShips = num;
    41         }
    42        
    4329        public void update() {
    4430                //regen ships if not owned by faction 0
    45                 numShips++;
    4631        }
    4732       
     
    4934               
    5035        }
    51        
    52         public boolean collides(Planet p) {
    53                 double dist = Math.sqrt(Math.pow(this.x-p.x, 2) + Math.pow(this.y-p.y, 2));
    54                
    55                 return dist <= this.radius + p.radius;
    56         }
    57        
    58         public static boolean collisionDetected(Planet p, ArrayList<Planet> curPlanets) {
    59                 for(Planet p2 : curPlanets) {
    60                         if(p.collides(p2))
    61                                 return true;
    62                 }
    63                
    64                 return false;
    65         }
    6636}
Note: See TracChangeset for help on using the changeset viewer.