public override void OnUpdate(float deltaTime) { RotateBody(deltaTime); MoveBody(deltaTime); RotateTurret(deltaTime); Game.CurCenter = Position; // Fire bullets if (IsKeyPressed(KeyboardKey.KEY_SPACE) & attackDelay.Check(false) && !ammoCount.IsComplete(false)) { float rotation = MathF.Atan2(turretObject.GlobalTransform.m2, turretObject.GlobalTransform.m1); rotation = (rotation < 0) ? rotation + (2 * MathF.PI) : rotation; Vector2 bulletPos = Position + (new Vector2(turretObject.GlobalTransform.m1, turretObject.GlobalTransform.m2).Normalised() * turretSprite.Height); bullets.Add(new Bullet(ref PreLoadedTextures.EnemyBulletTexture, 800, bulletPos, rotation, 3, this)); ammoCount.CountByValue(1); attackDelay.Reset(); } // Update bullets and check for bullet collision for (int x = 0; x < bullets.Count; x++) { bullets[x].Update(deltaTime); if (x >= bullets.Count) { continue; } // Collision deection for bullets against enemies AI tmpEnemy = null; float dist = float.MaxValue; for (int y = 0; y < EnemyManager.curEnemies.Count; y++) { float tmpDist = bullets[x].Position.Distance(EnemyManager.curEnemies[y].Position); if (tmpDist < dist) { dist = tmpDist; tmpEnemy = EnemyManager.curEnemies[y]; } } if (tmpEnemy != null) { bullets[x].CheckCollision(tmpEnemy); } } // Push player back if they run into enemies for (int x = 0; x < EnemyManager.curEnemies.Count; x++) { EnemyManager.curEnemies[x].Push(this); } // Alter color when player gets hit tankColor = Color.WHITE; if (!hurtTime.Check(false)) { if (hurtTime.Time / (hurtTime.delay / 2) < 1) // Become more red until halfway through timer { tankColor = ColorRGB.Lerp(Color.WHITE, hurtColor, hurtTime.Time / (hurtTime.delay / 2)); } else // Become less red from halfway through timer to completion { tankColor = ColorRGB.Lerp(hurtColor, Color.WHITE, (hurtTime.Time - (hurtTime.delay / 2)) / ((hurtTime.delay / 2))); } } tankSprite.spriteColor = tankColor; turretSprite.spriteColor = tankColor; // Shift object back to simulate camera movement base.OnUpdate(deltaTime); }