/// <summary> /// Constructor for damageSprite /// </summary> /// <param name="position">Coordinates of centre of sprite</param> /// <param name="dimensions">X and Y scale</param> /// <param name="hitbox">Hitbox to target</param> public DamageSprite(Vector2 position, Vector2 dimensions, HitBox hitbox) { target = hitbox; GM.engineM.AddSprite(this); Frame.Define(Tex.SingleWhitePixel); Position2D = position; SX = dimensions.X; SY = dimensions.Y; Wash = new Color(0, 255, 0); Layer += 2; TimerInitialise(); UpdateCallBack += Tick; }
/// <summary> /// Code to run each second /// </summary> internal void OneSecond() { //Repairing if (IsRepairing) { float repairAmount = crewNum; //Spread repair amount amongst each part HitBox[] repairArray = new HitBox[7]; int repairNum = 0; for (int i = 0; i <= 6; i++) { if (hitBoxArray[i].Health < 100 && ((hitBoxArray[i].DamageType == 0 && hullRepMats > 0) || (hitBoxArray[i].DamageType == 1 && sailRepMats > 0)) || hitBoxArray[i].IsBurning) { repairArray[repairNum] = hitBoxArray[i]; repairNum++; } } if (repairNum == 0) { if (!rightLoaded) { tiReloadRight.Paused = false; } if (!leftLoaded) { tiReloadLeft.Paused = false; } IsRepairing = false; } else { float repairPerPart = (repairAmount * 0.025f) / repairNum; for (int i = 0; i < repairNum; i++) { repairArray[i].Health += repairPerPart; if (repairArray[i].Health > 100) { repairArray[i].Health = 100; } if (repairArray[i].IsBurning && GM.r.FloatBetween(0, 1) > 0.9 * (0.9 - GameSetup.WeatherController.RainAmount)) { repairArray[i].IsBurning = false; } if (repairArray[i].DamageType == 0) { hullRepMats -= (repairPerPart * 0.5f); } else { sailRepMats -= (repairPerPart * (3 / 2)); } } } } //Calculations for sinking float hullHealthMissing = 0; for (int i = 0; i <= 3; i++) { hullHealthMissing += (100 - hitBoxArray[i].Health); } sinkAmount += (int)(hullHealthMissing * 0.15); if (GameSetup.WeatherController.RainAmount > 0.75f) { sinkAmount -= 4; } else { sinkAmount -= 6; } if (sinkAmount >= 1000) { //Splash for (int i = 0; i <= GM.r.FloatBetween(200, 400); i++) { float spawnRot = GM.r.FloatBetween(0, 360); Vector3 spawnVel = RotationHelper.Direction3DFromAngle(spawnRot, 0) * 200; FadingParticle splash = new FadingParticle(Position2D, spawnVel, spawnRot, 0.25f); splash.Wash = Color.Aqua; splash.SX = 1f; splash.SY = 5f; } Kill(); } //Calculations for sail damage speed multiplier sailDamageSpeedMul = 0; for (int i = 4; i <= 6; i++) { sailDamageSpeedMul += hitBoxArray[i].Health; } sailDamageSpeedMul *= 0.003f; //Boarding checks if (isBoarded && isCuttingRopes) { if (GM.r.FloatBetween(0, 1) > 0.75f) { isCuttingRopes = false; isBoarded = false; GameSetup.BoardingInProgress = false; if (isPlayer) { GameSetup.Opponent.isBoarding = false; } else { GameSetup.Player.isBoarding = false; } } } }
/// <summary> /// Ship contains all the functions used by both the player and the AI /// </summary> public Ship() { //Init values sailAmount = 0; shotTypeLeft = 0; shotTypeRight = 0; crewNum = 100; IsRepairing = false; hitBoxArray = new HitBox[7]; leftLoaded = false; rightLoaded = false; isBoarding = false; isBoarded = false; isCuttingRopes = false; GM.engineM.AddSprite(this); UpdateCallBack += Tick; GM.eventM.AddTimer(tiReloadRight = new Event(10, "Reload Cooldown Left")); GM.eventM.AddTimer(tiReloadLeft = new Event(10, "Reload Cooldown Right")); GM.eventM.AddTimer(tiOneSecond = new Event(1, "Repair Tick")); moveLocSprite = new Sprite(); GM.engineM.AddSprite(moveLocSprite); moveLocSprite.Frame.Define(Tex.Circle8by8); moveLocSprite.Visible = false; CollisionActive = true; Friction = 0.25f; Visible = true; Frame.Define(Tex.SingleWhitePixel); SY = 100; SX = 40; RotationAngle = 0; //Hitboxes hitBoxHullLeft = new HitBox(this, new Vector2(-10, 0), new Vector2(25, 70), 1, 0); hitBoxHullLeft.Wash = Color.Red; hitBoxArray[0] = hitBoxHullLeft; hitBoxHullRight = new HitBox(this, new Vector2(10, 0), new Vector2(25, 70), 1, 0); hitBoxHullRight.Wash = Color.Blue; hitBoxArray[1] = hitBoxHullRight; hitBoxHullFront = new HitBox(this, new Vector2(0, 40), new Vector2(45, 25), 0.5f, 0); hitBoxHullFront.Wash = Color.Green; hitBoxArray[2] = hitBoxHullFront; hitBoxHullBack = new HitBox(this, new Vector2(0, -40), new Vector2(45, 25), 0.5f, 0); hitBoxHullBack.Wash = Color.Yellow; hitBoxArray[3] = hitBoxHullBack; hitBoxSailFront = new HitBox(this, new Vector2(0, 25), new Vector2(60, 5), 1, 1); hitBoxSailFront.Wash = Color.Violet; hitBoxArray[4] = hitBoxSailFront; hitBoxSailMiddle = new HitBox(this, new Vector2(0, 1), new Vector2(70, 5), 1, 1); hitBoxSailMiddle.Wash = Color.Violet; hitBoxArray[5] = hitBoxSailMiddle; hitBoxSailBack = new HitBox(this, new Vector2(0, -30), new Vector2(65, 5), 1, 1); hitBoxSailBack.Wash = Color.Violet; hitBoxArray[6] = hitBoxSailBack; //DEBUG hitBoxHullBack.Health = 100; hitBoxHullFront.Health = 100; hitBoxHullLeft.Health = 100; hitBoxHullRight.Health = 100; hitBoxSailFront.Health = 100; hitBoxSailMiddle.Health = 100; hitBoxSailBack.Health = 100; crewNum = 100; }