source: galcon-client/src/com/example/helloandroid/Planet.java@ 8a4e64f

Last change on this file since 8a4e64f was 8a4e64f, checked in by dportnoy <devnull@…>, 14 years ago

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

  • Property mode set to 100644
File size: 1.2 KB
Line 
1package com.example.helloandroid;
2
3import java.util.ArrayList;
4
5public class Planet {
6 int radius;
7 int regenRate; // ships per second
8 private int x;
9 private int y;
10 int faction;
11 int numShips;
12
13 public Planet(int radius, int x, int y) {
14 this.radius = radius;
15 this.x = x;
16 this.y = y;
17 faction = 0;
18 numShips = 0;
19
20 regenRate = 0; //change this to some expression / funcion call
21 }
22
23 public int getX() {
24 return x;
25 }
26
27 public int getY() {
28 return y;
29 }
30
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
43 public void update() {
44 //regen ships if not owned by faction 0
45 numShips++;
46 }
47
48 public void sendFleet(Planet p, int numShips) {
49
50 }
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 }
66}
Note: See TracBrowser for help on using the repository browser.