public virtual void Start() { shipID = GetInstanceID(); rb = gameObject.GetComponent <Rigidbody2D>(); attributes = GetComponent <ShipAttributes>(); engineSound = GetComponent <AudioSource>(); if (!attributes.HasKillCallback()) { attributes.OnKill(RemoveWhenKilled); } if (trails.Length > 0) { foreach (ParticleSystem trail in trails) { trail.Stop(); } } if (module && module.GetDefaultState()) { module.isActive = true; module.OnActivate(this); } ships.Add(this); }
void OnCollisionEnter(Collision collision) { ShipAttributes s = collision.gameObject.GetComponent <ShipAttributes>(); if (s != null) { s.TakeDamage(damage); } // Instantiate(contact, transform.position, transform.rotation); GameObject.Destroy(gameObject); }
public void Display(Ship ship) { ShipAttributes attributes = ship.GetComponent <ShipAttributes>(); Set(health, attributes.maxHealth); Set(shields, attributes.maxShields); Set(repairRate, attributes.shieldRepairRate + "p"); Set(repairCD, attributes.shieldRepairCooldown + "s"); Set(weapons, (ship is Fighter) ? (ship as Fighter).weapons.Length : 0); Set(DPS, CalculateDPS(ship)); Set(module, ship.module ? ship.module.GetModuleName() : "None"); Set(speed, attributes.speed * 10f); Set(acceleration, attributes.acceleration * 10f); Set(handling, attributes.handling); Set(mass, (ship.GetComponent <Rigidbody2D>() ? ship.GetComponent <Rigidbody2D>().mass : -1f) * 10 + "kg"); }
//Load a ship public Ship(int[] attributes) { if (attributes.Length < 12) { //if input array is wrong, create a new one NewShip(); return; } for (int i = 0; i < 12; i++) { //Check if the level is out of range, if yes create a new one if (attributes[i] < 0 || attributes[i] > 4) { NewShip(); return; } } ShipAttributes = new ShipAttributes(attributes); }
public void DrawShip(ShipAttributes ship, IMapView map) { var tmp = CellToScreen(ship.Pos); DrawTexture(Textures[ship.TexName], rotate(-ship.Direction, ship.TexSize, tmp.X + Consts.CELL_SIDE, tmp.Y + (float)Math.Sqrt(3) / 2 * Consts.CELL_SIDE)); DrawTexture(Textures[ship.TexName + ship.Color], rotate(-ship.Direction, ship.TexSize, tmp.X + Consts.CELL_SIDE, tmp.Y + (float)Math.Sqrt(3) / 2 * Consts.CELL_SIDE)); DrawShipStatus(map); DrawHealthBar(ship.HealthBar); //TODO: добавить в атрибуты размер модельки, наладить поворот и прочую хуиту }
private void NewShip() { ShipAttributes = new ShipAttributes(new int[12]); }
void Start() { //currentMat = GetComponent<Material>(); myAttributes = GetComponentInParent<ShipAttributes>(); }