/// <summary> /// Constructors a new sprite. /// </summary> public MagicItem(string filePath,string owner, string p_ItemType, int p_Duration, Enemy enemy) { Enemy = enemy; Owner = owner; sprite = new Sprite(GV.ContentManager, filePath); Sprite.Scale = 1.0f; if (Owner != "player") { if (p_ItemType == "arrow") { this.state = new ArrowState(this); Position = new Vector2(enemy.Position.X, enemy.Position.Y -9) ; Velocity = new Vector2((GV.Player.Position.X - enemy.Position.X) / 20, (GV.Player.Position.Y - enemy.Position.Y)/20); Direction = enemy.Direction; Sprite.Rotation = 0.0f; itemType = p_ItemType; } else if (p_ItemType == "fireRow") { this.state = new FireState(this); //Position = new Vector2(enemy.Position.X, enemy.Position.Y); //Direction = enemy.Direction; light = new LightSource((int)Position.X, (int)Position.Y, (int)Position.X, (int)Position.Y, 200, 2); itemType = p_ItemType; } else if (p_ItemType == "egg") { Position = Enemy.Position; this.state = new EggState(this); light = new LightSource((int)Position.X, (int)Position.Y, (int)Position.X, (int)Position.Y, 200, 2); itemType = "light"; //Position = new Vector2(enemy.Position.X, enemy.Position.Y); //Direction = enemy.Direction; } } else { this.state = new InAirState(this); Position = GV.Player.Position; if (p_ItemType == "light") { light = new LightSource((int)Position.X, (int)Position.Y, (int)Position.X, (int)Position.Y, 200, 2); EffectRadius = light.Radius; } else if (p_ItemType == "dark") { EffectRadius = 100.0f; } else EffectRadius = 0.0f; //this.state = new InAirState(this); //Position = GV.Player.Position; itemType = p_ItemType; } Duration = p_Duration; active = true; }
/// <summary> /// Removes an object form the level /// </summary> public void RemoveObject(int x, int y) { // The area clicked to check for an intersection Rectangle remove = new Rectangle(x, y, 2, 2); // Remove a spawner for (int i = 0; i < NumSpawners; i += 1) { if (Spawners[i].BoundingBox.Intersects(remove)) { NumSpawners -= 1; SpawnPoint[] temp = new SpawnPoint[NumSpawners]; for (int j = 0; j < i; j += 1) { temp[j] = Spawners[j]; } for (int j = i; j < NumSpawners; j += 1) { temp[j] = Spawners[j + 1]; } Spawners = temp; return; } } // Remove a Warp Point for (int i = 0; i < NumWarps; i += 1) { if (Warps[i].BoundingBox.Intersects(remove)) { NumWarps -= 1; Warp[] temp = new Warp[NumWarps]; for (int j = 0; j < i; j += 1) { temp[j] = Warps[j]; } for (int j = i; j < NumWarps; j += 1) { temp[j] = Warps[j + 1]; } Warps = temp; return; } } // Remove a Light Source for (int i = 0; i < NumLights; i += 1) { if (Lights[i].BoundingBox.Intersects(remove)) { NumLights -= 1; LightSource[] temp = new LightSource[NumLights]; for (int j = 0; j < i; j += 1) { temp[j] = Lights[j]; } for (int j = i; j < NumLights; j += 1) { temp[j] = Lights[j + 1]; } Lights = temp; return; } } // Remove a trigger box for (int i = 0; i < NumTriggers; i += 1) { if (Triggers[i].BoundingBox.Intersects(remove)) { NumTriggers -= 1; TriggerBox[] temp = new TriggerBox[NumTriggers]; for (int j = 0; j < i; j += 1) { temp[j] = Triggers[j]; } for (int j = i; j < NumTriggers; j += 1) { temp[j] = Triggers[j + 1]; } Triggers = temp; return; } } }
// Save changes private void setButton_Click(object sender, EventArgs e) { game.currentObject.BoundingBox = new Microsoft.Xna.Framework.Rectangle( Convert.ToInt32(xPositionTextBox.Text), Convert.ToInt32(yPositionTextBox.Text), Convert.ToInt32(widthTextBox.Text), Convert.ToInt32(heightTextBox.Text)); game.currentObject.Position = new Vector2(Convert.ToInt32(xPositionTextBox.Text), Convert.ToInt32(yPositionTextBox.Text)); game.currentObject.Name = objectName.Text; // Add a warp object to the level's list if (game.CurrentCodeValue == "Warp") { Warp warp = new Warp((int)game.currentObject.Position.X, (int)game.currentObject.Position.Y, game.currentObject.BoundingBox.Width, game.currentObject.BoundingBox.Height, warpDestinationLevel.Text, new Vector2(Convert.ToInt32(warpDestinationX.Text), Convert.ToInt32(warpDestinationY.Text))); warp.Name = game.currentObject.Name; GV.Level.AddWarp(warp); Console.WriteLine("Added: " + warp.Name); } else if (game.CurrentCodeValue == "Spawner") { SpawnPoint spawner = new SpawnPoint(game.MonsterType, game.currentObject.Name, game.currentObject.Position); GV.Level.AddSpawnPoint(spawner); Console.WriteLine("Added: " + spawner.Name); } else if (game.CurrentCodeValue == "Light Source") { LightSource light = new LightSource((int)game.currentObject.Position.X, (int)game.currentObject.Position.Y, Convert.ToInt32(lightCentreXTextBox.Text), Convert.ToInt32(lightCentreYTextBox.Text), Convert.ToInt32(lightRadiusTextBox.Text), Convert.ToInt32(brightnessTextBox.Text)); light.Name = game.currentObject.Name; GV.Level.AddLight(light); } else if (game.CurrentCodeValue == "Trigger Box") { TriggerBox trigger = new TriggerBox(triggerBoxTarget.Text, triggerBoxTarget.Text, game.currentObject.BoundingBox); trigger.Name = game.currentObject.Name; GV.Level.AddTriggerBox(trigger); } }
/// <summary> /// Adds a light source to the level /// </summary> public void AddLight(LightSource light) { // Check to see if there is already a light source with the same // name/tag, if so, change it for the new one for (int i = 0; i < NumLights; i += 1) { if (Lights[i].Name == light.Name) { Lights[i] = light; return; } } // If it really is a new light source, then add it to the list NumLights += 1; LightSource[] temp = new LightSource[NumLights]; for (int i = 0; i < NumLights - 1; i += 1) { temp[i] = Lights[i]; } temp[NumLights - 1] = light; Lights = temp; }