Changeset 3e9f39e in galcon-client for src/com/example/helloandroid/Planet.java


Ignore:
Timestamp:
May 28, 2010, 12:47:31 AM (14 years ago)
Author:
Zero Cool <devnull@…>
Branches:
master
Children:
1291908
Parents:
1a91f0d (diff), 8a4e64f (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 a30e7e8b565e27d0defe9bba05b1e60e10906df6

File:
1 edited

Legend:

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

    r1a91f0d r3e9f39e  
    11package com.example.helloandroid;
     2
     3import java.util.ArrayList;
    24
    35public class Planet {
    46        int radius;
    57        int regenRate;  // ships per second
    6         int x;
    7         int y;
     8        private int x;
     9        private int y;
    810        int faction;
    911        int numShips;
     
    2729        }
    2830       
     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       
    2943        public void update() {
    3044                //regen ships if not owned by faction 0
     45                numShips++;
    3146        }
    3247       
     
    3449               
    3550        }
     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        }
    3666}
Note: See TracChangeset for help on using the changeset viewer.