Changeset 8a4e64f in galcon-client for src/com/example/helloandroid/Planet.java


Ignore:
Timestamp:
May 25, 2010, 2:46:37 PM (14 years ago)
Author:
dportnoy <devnull@…>
Branches:
master
Children:
3e9f39e
Parents:
9b87c8d
Message:

Generated planets are guaranteed not to collide or or be off the screen. Number of ships on each planet is also displayed.

File:
1 edited

Legend:

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

    r9b87c8d r8a4e64f  
    11package com.example.helloandroid;
     2
     3import java.util.ArrayList;
    24
    35public class Planet {
     
    3133        }
    3234       
     35        public int getNumShips() {
     36                return numShips;
     37        }
     38       
     39        public void setNumShips(int num) {
     40                numShips = num;
     41        }
     42       
    3343        public void update() {
    3444                //regen ships if not owned by faction 0
     45                numShips++;
    3546        }
    3647       
     
    3849               
    3950        }
     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        }
    4066}
Note: See TracChangeset for help on using the changeset viewer.