public override void Intersect(InteractiveModel interactive) { if(this==interactive || !interactive.GetType().IsSubclassOf(typeof(Unit))) { return ; } if (this.model.Spheres[0].Intersects(interactive.Model.BoundingSphere)) { interactive.Hp -= (int)1; ((Unit)interactive).LifeBar.LifeLength = ((Unit)interactive).LifeBar.LifeLength - ((Unit)interactive).LifeBar.LifeLength * ((float)5 / interactive.MaxHp); } }
void UpdateSmokePlumeBuilding(InteractiveModel building) { // This is trivial: we just create one new smoke particle per frame. smokePlumeParticles.AddParticle(RandomPointOnCircleBuilding(building), Vector3.Zero); }
Vector3 RandomPointOnCircleBuilding(InteractiveModel building) { double angle = random.NextDouble() * Math.PI * 2; float x = (float)Math.Sin(angle); float z = (float)Math.Cos(angle); return new Vector3(building.Model.Position.X + x * building.Model.BoundingSphere.Radius, building.Model.Position.Y, building.Model.Position.Z + z * building.Model.BoundingSphere.Radius); }
public void addObjects(InteractiveModel model) { models1.Add(model); }
public virtual void Intersect(InteractiveModel interactive) { }
public static Vector3 RandomPointOnCircleBuilding(InteractiveModel building) { Random random = new Random(); double angle = random.NextDouble() * Math.PI * 2; float x = (float)Math.Sin(angle); float z = (float)Math.Cos(angle); return new Vector3(building.Model.Position.X + x * (building.Model.BoundingSphere.Radius+50), StaticHelpers.StaticHelper.GetHeightAt(building.Model.Position.X + x * (building.Model.BoundingSphere.Radius), building.Model.Position.Z + z * (building.Model.BoundingSphere.Radius)), building.Model.Position.Z + z * (building.Model.BoundingSphere.Radius+50)); }
public void Update(GameTime gameTime) { ///interface -------------------------------------------------------------------------------- if (control.selectedObject != null) { selectedModel = control.selectedObject; description = selectedModel.ToString(); if (selectedModel.GetType() == (typeof(BuildingPlace))) { buildMenuON = true; } else if (selectedModel.GetType() != typeof(BuildingPlace) && selectedModel.GetType().IsSubclassOf(typeof(Building))) { description = selectedModel.ToString(); if (selectedModel.GetType() == typeof(HyacyntFarm)) { hyacyntFarmOn = true; dicentraFarmOn = false; mainBuildingOn = false; buildMenuON = false; unitMenuON = false; beetleBuildingOn=false; grassHopperBuildingOn=false; helidoniumFarmOn = false; } else if (selectedModel.GetType() == typeof(DicentraFarm)) { hyacyntFarmOn = false; dicentraFarmOn = true; mainBuildingOn = false; buildMenuON = false; unitMenuON = false; helidoniumFarmOn = false; } else if (selectedModel.GetType() == typeof(BeetleBuilding)) { hyacyntFarmOn = false; dicentraFarmOn = false; mainBuildingOn = false; buildMenuON = false; unitMenuON = false; beetleBuildingOn = true; grassHopperBuildingOn = false; helidoniumFarmOn = false; } else if (selectedModel.GetType() == typeof(GrassHopperBuilding)) { hyacyntFarmOn = false; dicentraFarmOn = false; mainBuildingOn = false; buildMenuON = false; unitMenuON = false; beetleBuildingOn = false; grassHopperBuildingOn = true; helidoniumFarmOn = false; } else if (selectedModel.GetType() == typeof(ChelidoniumFarm)) { hyacyntFarmOn = false; dicentraFarmOn = false; mainBuildingOn = false; buildMenuON = false; unitMenuON = false; helidoniumFarmOn = true; } else { hyacyntFarmOn = false; dicentraFarmOn = false; mainBuildingOn = false; buildMenuON = false; unitMenuON = false; helidoniumFarmOn = false; } } } else { description = ""; } if (control.SelectedModels.Count > 0) { selectedModels = control.SelectedModels; } // get elapsed frame time in seconds frame_time = gameTime.ElapsedGameTime.Milliseconds / 1000.0; // update mouse variables MouseState mouse_state = Mouse.GetState(); mx = mouse_state.X; my = mouse_state.Y; prev_mpressed = mpressed; mpressed = mouse_state.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed; update_buttons(); //--------------------------------------------------------------------------------------------------------------------------------- uncomment and fix }
private void EditObjectRotation(InteractiveModel model2) { model2.Model.Rotation =new Vector3( (float)numericUpDown4.Value,(float)numericUpDown5.Value,(float)numericUpDown6.Value); }
private void EditObjectScale(InteractiveModel model2) { model2.Model.Scale = new Vector3((float)numericUpDown1.Value, (float)numericUpDown2.Value, (float)numericUpDown3.Value); }
private void EditObjectPosition(InteractiveModel model2) { model2.Model.Position = new Vector3((float)numericUpDown9.Value, (float)numericUpDown8.Value, (float)numericUpDown7.Value); }
private void btnAdd_MouseClick(object sender, MouseEventArgs e) { selected = true; foreach (string name in checkedListBox1.CheckedItems) { switch (name) { case "AntPeasant": { AntPeasant p = new AntPeasant(10, 10, 10, 10, 10, 10, new LoadModel(CreatorController.content.Load<Model>("Models/ant"), CreatorController.MousePosition, new Vector3(0, 6, 0), new Vector3(0.5f), CreatorController.device,CreatorController.content), 10, 100); model = p; model.Model.switchAnimation("Idle"); break; } case "Log": { Log p = new Log(new LoadModel(CreatorController.content.Load<Model>("Models/apple_pack"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device), Convert.ToInt16(textBox1.Text)); model = p; break; } case "Rock": { Rock p = new Rock(new LoadModel(CreatorController.content.Load<Model>("Models/stone2"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device), Convert.ToInt16(textBox1.Text)); model = p; break; } case "BuildingPlace": { BuildingPlace p = new BuildingPlace(new LoadModel(CreatorController.content.Load<Model>("Models//buildRing"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device)); model = p; break; } case "AntGranary": { AntGranary p = new AntGranary(new LoadModel(CreatorController.content.Load<Model>("Models//buildingPlace"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device), 100, 100, 100, 23, 10000); model = p; break; } case "TownCenter": { Logic.Building.AntBuildings.TownCenter p = new Logic.Building.AntBuildings.TownCenter(new LoadModel(CreatorController.content.Load<Model>("Models//buildingPlace"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device)); model = p; break; } case "Spider": { Spider p = new Spider(new LoadModel(CreatorController.content.Load<Model>("Models//spider"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device,CreatorController.content)); model = p; model.Model.switchAnimation("Idle"); break; } case "Tree": { Tree p = new Tree(new LoadModel(CreatorController.content.Load<Model>("Models//tree1"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device)); model = p; break; } case "Tree2": { Tree2 p = new Tree2(new LoadModel(CreatorController.content.Load<Model>("Models//tree2"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device)); model = p; break; } case "Szyszka": { Cone p = new Cone(new LoadModel(CreatorController.content.Load<Model>("Models/Szyszka1"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device)); model = p; break; } case "Szyszka2": { Cone1 p = new Cone1(new LoadModel(CreatorController.content.Load<Model>("Models/Szyszka2"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device)); model = p; break; } case "Trawa": { Grass p = new Grass(new LoadModel(CreatorController.content.Load<Model>("Models/grass3d"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device)); model = p; break; } case "Zuk": { Beetle p = new Beetle(new LoadModel(CreatorController.content.Load<Model>("Models/beetle"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device,CreatorController.content)); model = p; model.Model.switchAnimation("Idle"); break; } case "Konik": { GrassHopper p = new GrassHopper(new LoadModel(CreatorController.content.Load<Model>("Models/grasshopper"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device, CreatorController.content)); model = p; model.Model.switchAnimation("Idle"); break; } case "Plujka": { AntSpitter p = new AntSpitter(new LoadModel(CreatorController.content.Load<Model>("Models/plujka"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device, CreatorController.content)); model = p; model.Model.switchAnimation("Idle"); break; } case "Królowa": { Queen p = new Queen(new LoadModel(CreatorController.content.Load<Model>("Models/queen"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device, CreatorController.content)); model = p; model.Model.switchAnimation("Idle"); break; } case "Silacz": { StrongAnt p = new StrongAnt(new LoadModel(CreatorController.content.Load<Model>("Models/strongAnt"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device, CreatorController.content)); model = p; model.Model.switchAnimation("Idle"); break; } case "DomKoników": { GrassHopperBuilding p = new GrassHopperBuilding(new LoadModel(CreatorController.content.Load<Model>("Models//h3"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device)); model = p; break; } case "DomZukow": { BeetleBuilding p = new BeetleBuilding(new LoadModel(CreatorController.content.Load<Model>("Models//h4"), CreatorController.MousePosition, Vector3.Zero, Vector3.One, CreatorController.device)); model = p; break; } } } }
public void reachTarget(GameTime gameTime, InteractiveModel ship, Vector3 target) { float pullDistance = Vector2.Distance(new Vector2(target.X,target.Z), new Vector2(ship.Model.Position.X, ship.Model.Position.Y)); //Only do something if we are not already there // if (pullDistance > 1) Vector3 pull = (target - ship.Model.Position) * (1 / pullDistance); //the target tries to 'pull us in' Vector3 totalPush = Vector3.Zero; this.moving = true; int contenders = 0; for (int i = 0; i < obstacles.Count; ++i) { //draw a vector from the obstacle to the ship, that 'pushes the ship away' Vector3 push = ship.Model.Position - obstacles[i].Model.Position; //calculate how much we are pushed away from this obstacle, the closer, the more push float distance = (Vector3.Distance(ship.Model.Position, obstacles[i].Model.Position) - obstacles[i].Model.BoundingSphere.Radius) - ship.Model.BoundingSphere.Radius; //only use push force if this object is close enough such that an effect is needed if (distance < ship.Model.BoundingSphere.Radius) { ++contenders; //note that this object is actively pushing if (distance < 0.0001f) //prevent division by zero errors and extreme pushes { distance = 0.0001f; } float weight = 1 / distance; // totalPush += push * weight; } } pull *= Math.Max(1, 4 * contenders); //4 * contenders gives the pull enough force to pull stuff trough (tweak this setting for your game!) pull += totalPush; //Normalize the vector so that we get a vector that points in a certain direction, which we van multiply by our desired speed pull.Normalize(); //Set the ships new position; // if (this.target != null && Vector3.Distance(this.target.Model.Position, this.model.Position) < this.rangeOfSight) // { // model.Rotation = new Vector3(model.Rotation.X, StaticHelpers.StaticHelper.TurnToFace(new Vector2(model.Position.X, model.Position.Z), new Vector2(this.target.Model.Position.X, this.target.Model.Position.Y), model.Rotation.Y, 1.0f), model.Rotation.Z); //} ship.Model.Position = new Vector3(ship.Model.Position.X + (pull.X * 60) * (float)gameTime.ElapsedGameTime.TotalSeconds, StaticHelpers.StaticHelper.GetHeightAt(ship.Model.Position.X, ship.Model.Position.Z) + modelHeight, ship.Model.Position.Z + (pull.Z * 60) * (float)gameTime.ElapsedGameTime.TotalSeconds); if (this.target != null && pullDistance < this.target.Model.BoundingSphere.Radius/2) { this.moving = false; } }
public override void Intersect(InteractiveModel interactive) { base.Intersect(interactive); }
public void Update(GameTime gameTime) { if(selectedObject!=null) Console.WriteLine(selectedObject); currentMouseState = Mouse.GetState(); Vector3 mouse3d2 = CalculateMouse3DPosition(); positionMouseOnlyMove = new Vector2(currentMouseState.X, currentMouseState.Y); position3DMouseOnlyMove = CalculateMouse3DPosition(positionMouseOnlyMove); selectedObjectMouseOnlyMove = SelectedObject(position3DMouseOnlyMove); /* if(currentMouseState.LeftButton==ButtonState.Pressed) { position = new Vector2(currentMouseState.X, currentMouseState.Y); position3d = CalculateMouse3DPosition(position); selectedObject = SelectedObject(mouse3d2); }*/ if (currentMouseState.RightButton == ButtonState.Pressed && !mouseDown) { SelectedModels.Clear(); position = new Vector2(currentMouseState.X, currentMouseState.Y); position3d = CalculateMouse3DPosition(position); selectCorner = position; selectRectangle = new Rectangle((int)position.X, (int)position.Y, 0, 0); //selectedObject = SelectedObject(mouse3d2); //if ((mouse3d2.X > pozycja_X_lewo && mouse3d2.X < pozycja_X_prawo) && (mouse3d2.Z > pozycja_Z_dol && mouse3d2.Z < pozycja_Z_gora)) mouseDown = true; } else if (currentMouseState.RightButton == ButtonState.Pressed) { SelectedModels.Clear(); selectCorner = new Vector2(currentMouseState.X, currentMouseState.Y); if (selectCorner.X > position.X) { selectRectangle.X = (int)position.X; } else { selectRectangle.X = (int)selectCorner.X; } if(selectCorner.Y > position.Y) { selectRectangle.Y = (int)position.Y; } else { selectRectangle.Y = (int)selectCorner.Y; } selectRectangle.Width = (int)Math.Abs(position.X - selectCorner.X); selectRectangle.Height = (int)Math.Abs(position.Y - selectCorner.Y); } else { if (mouseDown == true) { Selected(); foreach (InteractiveModel ant in models) if (ant.Model.Selected) { if (ant.GetType().BaseType == typeof(Ant)) { SelectedModels.Add(ant); } } /* else { //f = 0; //SelectedModels.Clear(); } */ } mouseDown = false; } //Console.WriteLine(f); if (currentMouseState.LeftButton == ButtonState.Pressed) { position = new Vector2(currentMouseState.X, currentMouseState.Y); position3d = CalculateMouse3DPosition(position); selectedObject = SelectedObject(mouse3d2); // This will give the player a target to go to. foreach (InteractiveModel ant in SelectedModels) { ant.Model.playerTarget.X = mouse3d2.X; ant.Model.playerTarget.Z = mouse3d2.Z; } } updateAnt(gameTime); }