/// <summary> /// Updates the tween. /// </summary> public override void Update() { base.Update(); var r = Convert.ToUInt32(FP.Clamp(_startR + _rangeR * _t, 0, 255)); var g = Convert.ToUInt32(FP.Clamp(_startG + _rangeG * _t, 0, 255)); var b = Convert.ToUInt32(FP.Clamp(_startB + _rangeB * _t, 0, 255)); var color = r << 16 | g << 8 | b; Color = FP.Color(color); }
public static void Init(float musicVolume) { MusicVolume = FP.Clamp(musicVolume, 0, 1); foreach (string file in Utility.RetrieveFilePathForFilesInDirectory(@"./content/music", @"*.ogg|*.wav")) { var sound = new Sound(Library.GetSoundStream(file)); sound.OnComplete += LoopMusic; musics.Add(Path.GetFileNameWithoutExtension(file), sound); } foreach (string file in Utility.RetrieveFilePathForFilesInDirectory(@"./content/sounds", @"*.ogg|*.wav")) { sounds.Add(Path.GetFileNameWithoutExtension(file), new Sound(Library.GetSoundBuffer(file))); } }
/// <summary> /// Renders the particles. /// </summary> /// <param name="x">X position of the owning entity.</param> /// <param name="y">Y position of the owning entity.</param> public override void Render(float x, float y, Camera camera) { _vertexArray.Clear(); // quit if there are no particles if (_particle == null) { return; } // get rendering position // _point.x = point.x + x - camera.x * ScrollX; // _point.y = point.y + y - camera.y * ScrollY; // particle info float t, td; Particle p = _particle; ParticleType type = null; Vector2f _p = new Vector2f(); Vector2f _point = new Vector2f(X + x - (camera.X - FP.HalfWidth) * ScrollX, Y + y - (camera.Y - FP.HalfHeight) * ScrollY); var color = new Color(); var states = new RenderStates(_source); // loop through the particles while (p != null) { // get time scale t = p._time / p._duration; // get particle type type = p._type; // get position td = (type._ease == null) ? t : type._ease(t); _p.X = _point.X + p._x + p._moveX * td; _p.Y = _point.Y + p._y + p._moveY * td; // stops particles from moving when gravity is enabled // and if emitter.Active = false (for game pausing for example) if (Active) { p._moveY += p._gravity * td; } // get frame float frameX = _frameWidth * type._frames[(int)FP.Clamp(td * type._frameCount, 0, type._frames.Length - 1)]; float frameY = (int)(frameX / type._width) * _frameHeight; frameX %= (int)type._width; // get alpha float alphaT = (type._alphaEase == null) ? t : type._alphaEase(t); float a = type._alpha + type._alphaRange * alphaT; // get color td = (type._colorEase == null) ? t : type._colorEase(t); float r = type._red + type._redRange * td; float g = type._green + type._greenRange * td; float b = type._blue + type._blueRange * td; unchecked // screw you C# { color.R = (byte)(255 * r); color.G = (byte)(255 * g); color.B = (byte)(255 * b); color.A = (byte)(255 * a); } uint _x = _frameWidth; uint _y = _frameHeight; _vertexArray.Append(new Vertex(new Vector2f(_p.X, _p.Y), color, new Vector2f(frameX, frameY))); _vertexArray.Append(new Vertex(new Vector2f(_p.X + _x, _p.Y), color, new Vector2f(_x + frameX, frameY))); _vertexArray.Append(new Vertex(new Vector2f(_p.X + _x, _p.Y + _y), color, new Vector2f(_x + frameX, _y + frameY))); _vertexArray.Append(new Vertex(new Vector2f(_p.X, _p.Y + _y), color, new Vector2f(frameX, _y + frameY))); // get next particle p = p._next; } FP.Screen.Draw(_vertexArray, states); }
public override void Update() { base.Update(); if (health <= 0) { if (myShip != null) { if (myShip as Ship == null) { List <PartBase> temp = myShip.shipParts; World.Remove(myShip); for (int i = 0; i < temp.Count; i++) { if (temp[i].MyType != 0) { Part replacementPart = new Part(temp[i].MyType); replacementPart.X = temp[i].X; replacementPart.Y = temp[i].Y; World.Add(replacementPart); } World.Remove(temp[i]); } World.Remove(myShip); } else { World.Add(new EmptyPart(myShip, curCol, curRow, curCol, curRow)); World.Remove(this); if (myShip.shipParts.Count <= 0) { var Title = new Text("Game Over! Press R to Restart The Game.", 100, FP.HalfHeight - 200, 0, 0); Title.Size = 100; AddGraphic(Title); } } } else { World.Remove(this); } } if (Attached) { SetHitboxTo(aPart); aPart.CenterOO(); CenterOrigin(); FP.AnchorTo(ref X, ref Y, myShip.X, myShip.Y, Distance, Distance); FP.RotateAround(ref X, ref Y, myShip.X, myShip.Y, myShip.ShipCenter.Angle + angle, false); aPart.Angle = myShip.ShipCenter.Angle; if (PartNum == 3) { //FP.Log(FP.Angle(X, Y, World.MouseX, World.MouseY)); if (myShip.ShipCenter.Angle + 2 > 360) { myShip.ShipCenter.Angle = (myShip.ShipCenter.Angle + 2) - 360; } if (myShip.ShipCenter.Angle - 2 <= 0) { myShip.ShipCenter.Angle = (myShip.ShipCenter.Angle - 2) + 360; } if ((myShip.ShipCenter.Angle + 45 > FP.Angle(X, Y, World.MouseX, World.MouseY)) && (myShip.ShipCenter.Angle - 45 < FP.Angle(X, Y, World.MouseX, World.MouseY))) { aPart.Angle = FP.Angle(X, Y, World.MouseX, World.MouseY); if (Mouse.IsButtonPressed(Mouse.Button.Right)) { TurretSfx.Volume = FP.Random * 20 + 20; TurretSfx.Pitch = FP.Random * .3f + .2f; TurretSfx.Play(); World.Add(new Bullet(X, Y, new Vector2f((float)Math.Cos(aPart.Angle * FP.RAD) * 5, (float)Math.Sin(aPart.Angle * FP.RAD) * 5), myShip)); } else { //TurretSfx.Pitch = .01f; //+ 0.5f; } } else { //TurretSfx.Pitch = .01f; //+ 0.5f; aPart.Angle = myShip.ShipCenter.Angle; } } else { aPart.Angle = myShip.ShipCenter.Angle + rotationOffSet; } } else { SetHitboxTo(aPart); aPart.CenterOO(); CenterOrigin(); EmptyPart temp = World.CollideRect("EmptyPart", X, Y, Width, Height) as EmptyPart; if (temp != null) { float t = (float)Math.Atan2(temp.curRow - temp.parentRow, temp.curCol - temp.parentCol); Part add = new Part(temp.myShip, MyType, temp.curCol, temp.curRow); add.rotationOffSet = (t * FP.DEG) - 90; add.rotationOffSet = (float)Math.Round(add.rotationOffSet); if (add.rotationOffSet < 0.0002 && add.rotationOffSet > -0.0002) { add.rotationOffSet = 0; } World.Add(add); World.Remove(temp); World.Remove(this); } if (Input.Pressed(Mouse.Button.Left)) { if (World.CollidePoint("Part", World.MouseX, World.MouseY) == this) { Dragging = true; } } else if (Input.Released(Mouse.Button.Left)) { Dragging = false; } if (Dragging) { X = World.MouseX; Y = World.MouseY; Flying = false; } if (Flying) { X += FP.Rand(2); Y += FP.Rand(2); } } //aPart.Color = FP.Color(0x000000); aPart.Color = new SFML.Graphics.Color((byte)(byte)(FP.Clamp <int>((int)((health / totalHealth) * 255), 0, 255)), (byte)(byte)(FP.Clamp <int>((int)((health / totalHealth) * 255), 0, 255)), (byte)(byte)(FP.Clamp <int>((int)((health / totalHealth) * 255), 0, 255))); }