Changeset 96857ee in galcon-client for src/com/example


Ignore:
Timestamp:
May 26, 2010, 3:46:05 AM (14 years ago)
Author:
Zero Cool <devnull@…>
Branches:
master
Children:
1a91f0d
Parents:
159eef8
Message:

Fleet.java

File:
1 edited

Legend:

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

    r159eef8 r96857ee  
    11package com.example.helloandroid;
    22
     3import java.math.*;
     4
    35public class Fleet {
    4         int x;
    5         int y;
    6         double direction;
    7         Planet destination;
    8         int numShips;
    9         int faction;
     6        private int x;
     7        private int y;
     8        private double slope, xIntercept;
     9        private double direction;
     10        private Planet destination;
     11        private int numShips;
     12        private int faction;
    1013       
     14        /* Optimising: pre-calculate paths */
    1115        public Fleet(Planet source, Planet destination, int numShips, int faction) {
    12                 x = source.getX();
    13                 y = source.getY();
     16                //Calculate initial coordinates and direction
    1417               
     18                //line formula
     19                slope = ((source.y - destination.y)/(source.x - destination.x));
     20                xIntercept = destination.y - (slope*destination.x);
     21               
     22                //direction
     23                direction = 1/Math.tan(slope);
     24               
     25                //coordinates for all 4 coordinates
     26                if ((direction >= 0) && (direction < Math.PI/2)){
     27                        x = (int)(Math.cos(direction)*(source.radius + 10) + source.x );
     28                        y = (int)(Math.sin(direction)*(source.radius + 10) + source.y );
     29                } else if((direction >= Math.PI/2) && (direction < Math.PI)){
     30                       
     31                } else if((direction >= Math.PI) && (direction < 3*Math.PI/2)){
     32               
     33                } else {
     34               
     35                }
    1536                this.numShips = numShips;
    1637                this.faction = faction;
     
    1839        }
    1940       
     41               
     42        public int getX() {
     43                return x;
     44        }
     45
     46
     47
     48        public void setX(int x) {
     49                this.x = x;
     50        }
     51
     52
     53
     54        public int getY() {
     55                return y;
     56        }
     57
     58
     59
     60        public void setY(int y) {
     61                this.y = y;
     62        }
     63
     64
     65
     66        public double getDirection() {
     67                return direction;
     68        }
     69
     70
     71
     72        public void setDirection(double direction) {
     73                this.direction = direction;
     74        }
     75
     76
     77
     78        public Planet getDestination() {
     79                return destination;
     80        }
     81
     82
     83
     84        public void setDestination(Planet destination) {
     85                this.destination = destination;
     86        }
     87
     88
     89
     90        public int getNumShips() {
     91                return numShips;
     92        }
     93
     94
     95
     96        public void setNumShips(int numShips) {
     97                this.numShips = numShips;
     98        }
     99
     100
     101
     102        public int getFaction() {
     103                return faction;
     104        }
     105
     106
     107
     108        public void setFaction(int faction) {
     109                this.faction = faction;
     110        }
     111
     112
     113
    20114        public void update() {
    21                
     115                //update coordinates
     116       
    22117        }
    23118       
    24119        // attack the destination planet
    25120        public void attack() {
    26                
     121                //planet attack
    27122        }
    28123}
Note: See TracChangeset for help on using the changeset viewer.