private static Unit _BuildScoutUnit(string Name) { Unit unit = new Unit(); unit.Name = Name; unit.Model = ToylandSiege.GetInstance().Content.Load <Model>("Units/Soldier"); unit.Type = "Unit"; unit.IsEnabled = false; unit.Health = 50; unit.MaxHealth = 50; unit.Damage = 10; unit.ShotDistance = 3; unit.TimeBetweeenShoots = 1; unit.Speed = 8; unit.UnitType = "Scout"; var skinningData = ToylandSiege.GetInstance().Content.Load <Model>("Units/Soldier").Tag as SkinningData; unit.AnimationPlayer = new AnimationPlayer(skinningData); unit.Clips = new Dictionary <string, AnimationClip>(); unit.Clips.Add("walking", skinningData.AnimationClips["walking"]); unit.Clips.Add("standing", new AnimationClip(skinningData.AnimationClips["walking"], skinningData.AnimationClips["standing"])); unit.Clips.Add("crouch", new AnimationClip(skinningData.AnimationClips["standing"], skinningData.AnimationClips["crouch"])); unit.Clips.Add("crouching", new AnimationClip(skinningData.AnimationClips["crouch"], skinningData.AnimationClips["crouching"])); unit.Clips.Add("standup", new AnimationClip(skinningData.AnimationClips["crouching"], skinningData.AnimationClips["standup"])); unit.AnimationPlayer.StartClip(unit.Clips.Values.ElementAt(1)); unit.Position = Vector3.Zero; unit.Scale = new Vector3(0.05f, 0.05f, 0.05f); unit.Rotation = new Vector3(3.14f, 0, 0); Logger.Log.Debug("Scout unit created"); return(unit); }
public static void DrawGlobalLightning(Effect effect) { LightView = Matrix.CreateLookAt(Vector3.Zero, Vector3.Zero + GlobalLightning.Direction, Vector3.Up); LightProjection = Matrix.CreateOrthographic(ToylandSiege.GetInstance().configurationManager.WidthResolution, ToylandSiege.GetInstance().configurationManager.HeightResolution, 1, 1000); LightViewProjection = LightView * LightProjection; if (!ToylandSiege.GetInstance().configurationManager.LigthningEnabled) { return; } if (effect is BasicEffect) { (effect as BasicEffect).DirectionalLight0.DiffuseColor = DiffuseColor; (effect as BasicEffect).DirectionalLight0.Direction = Direction; (effect as BasicEffect).DirectionalLight0.SpecularColor = SpecularColor; } else if (effect is SkinnedEffect) { (effect as SkinnedEffect).DirectionalLight0.DiffuseColor = DiffuseColor; (effect as SkinnedEffect).DirectionalLight0.Direction = Direction; (effect as SkinnedEffect).DirectionalLight0.SpecularColor = SpecularColor; } else { Logger.Log.Debug("Unsupported effect: " + effect); } }
public void Update(GameTime gameTime) { try { this.gameTime = gameTime; if (CurrentWave != null && RoundRunning) { if (!ToylandSiege.GetInstance().gameStateManager.IsPaused()) { CurrentWave.TimeLeft -= gameTime.ElapsedGameTime.TotalSeconds; } CurrentWave.RefreshLists(); if (CurrentWave.TimeLeft <= 0.0 || CurrentWave.UnitsInWave.Count == 0 || CurrentWave.UnitsInWave.All(unit => unit.Field.FinishingTile)) { FinishRound(); } } } catch (Exception e) { Logger.Log.Error(e); } }
public void StartRound() { RoundNumber++; RoundRunning = true; CurrentWave.WaveStartedTime = gameTime.TotalGameTime; Camera.SetCurrentCamera(Camera.AvailableCameras["FirstPersonCamera"]); ToylandSiege.GetInstance().gameStateManager.SetNewGameState(ToylandSiege.GetInstance().gameStateManager.AvailableGameStates["FirstPerson"]); }
public void FinishRound() { RoundRunning = false; Camera.SetCurrentCamera(Camera.AvailableCameras["StrategicCamera"]); CurrentWave.RefreshLists(); //Should add units which are alive to next wave? List <Unit> AliveUnits = new List <Unit>(); CurrentWave.UnitsInWave.ForEach(unit => AliveUnits.Add(unit)); CurrentWave.AvailableUnits.ForEach(unit => AliveUnits.Add(unit)); //Remove Units in Wave foreach (Unit unit in CurrentWave.UnitsInWave) { unit.Field.unit = null; unit.Field = null; unit.TargetFields.Clear(); unit.FieldsInWay.Clear(); Level.GetCurrentLevel().RootGameObject.Childs["Units"].RemoveChild(unit); } //Remove Wave Waves.Remove(CurrentWave); CurrentWave = Waves.FirstOrDefault(); //TODO: Finish game here //Maybe throw exception to toyland siege Update method level?? if (CurrentWave == null && Waves.Count == 0) { ToylandSiege.GetInstance().gameStateManager.SetNewGameState(ToylandSiege.GetInstance().gameStateManager.AvailableGameStates["Menu"]); return; } foreach (Unit unit in AliveUnits) { CurrentWave.AvailableUnits.Add(unit); } //Set IsPartOfWay to false for each field in board foreach (var rows in Level.GetCurrentLevel().RootGameObject.Childs["Board"].Childs.Values) { foreach (var field in rows.Childs.Values) { if (field is Field) { (field as Field).IsPartOfWay = false; } } } ToylandSiege.GetInstance().gameStateManager.SetNewGameState(ToylandSiege.GetInstance().gameStateManager.AvailableGameStates["Strategic"]); }
public static void drawCurve3D(Object[] curveData) { ToylandSiege.GetInstance().GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, (VertexPositionTexture[])curveData[0], 0, ((VertexPositionTexture[])curveData[0]).Length, (int[])curveData[1], 0, ((int[])curveData[1]).Length / 3); }
private Camera ParseCameraObject(JObject currentGameObject, GameObject parent = null) { var name = JSONHelper.GetValue("Name", currentGameObject); var camera = new Camera(name); camera.Type = JSONHelper.GetValue("Type", currentGameObject); camera.Model = null; if (JSONHelper.ToBool(JSONHelper.GetValue("CurrentCamera", currentGameObject))) { Camera.SetCurrentCamera(camera); } camera.IsEnabled = JSONHelper.ToBool(JSONHelper.GetValue("isEnabled", currentGameObject)); camera.IsCollidable = false; //Camera position if (JSONHelper.ValueExist("Position", currentGameObject)) { camera.Position = JSONHelper.ParseVector3(currentGameObject.GetValue("Position")); } //Camera Direction if (JSONHelper.ValueExist("Direction", currentGameObject)) { camera.Direction = JSONHelper.ParseVector3(currentGameObject.GetValue("Direction")); } //Camera Up Vector if (JSONHelper.ValueExist("UpVector", currentGameObject)) { camera.Up = JSONHelper.ParseVector3(currentGameObject.GetValue("UpVector")); } //Camera Speed if (JSONHelper.ValueExist("Speed", currentGameObject)) { camera.Speed = float.Parse(JSONHelper.GetValue("Speed", currentGameObject)); } //Projection Matrix float NearDistance = float.Parse(JSONHelper.GetValue("NearPlaneDistance", currentGameObject)); float FarDistance = float.Parse(JSONHelper.GetValue("FarPlaneDistance", currentGameObject)); float Angle = float.Parse(JSONHelper.GetValue("Angle", currentGameObject)); camera.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(Angle), ToylandSiege.GetInstance().GraphicsDevice.Viewport.AspectRatio, NearDistance, FarDistance); camera.NearDistance = NearDistance; camera.FarDistance = FarDistance; camera.Angle = Angle; return(camera); }
public Menubutton(Texture2D textur, int X, int Y, int width, int heihgt, string text) { this.texture = textur; this.coords.X = X; this.coords.Y = Y; this.text = text; this.heigth = heihgt; this.width = width; rectangle = new Rectangle(X, Y, width, heihgt); font = ToylandSiege.GetInstance().Content.Load <SpriteFont>("Fonts/MenuFont"); }
public void Initialize() { LoadedSounds.Add("SniperShootSound", ToylandSiege.GetInstance().Content.Load <SoundEffect>("Sounds/SniperShootSound")); LoadedSounds.Add("DefenderShootSound", ToylandSiege.GetInstance().Content.Load <SoundEffect>("Sounds/DefenderShootSound")); LoadedSounds.Add("StandartShootSound", ToylandSiege.GetInstance().Content.Load <SoundEffect>("Sounds/StandartShootSound")); LoadedSounds.Add("SoldierShootSound", ToylandSiege.GetInstance().Content.Load <SoundEffect>("Sounds/SoldierShootSound")); LoadedSounds.Add("TankShootSound", ToylandSiege.GetInstance().Content.Load <SoundEffect>("Sounds/TankShootSound")); LoadedSounds.Add("ScoutShootSound", ToylandSiege.GetInstance().Content.Load <SoundEffect>("Sounds/ScoutShootSound")); LoadedSounds.Add("EnemyDeathSound", ToylandSiege.GetInstance().Content.Load <SoundEffect>("Sounds/EnemyDeathSound")); LoadedSounds.Add("UnitDeathSound", ToylandSiege.GetInstance().Content.Load <SoundEffect>("Sounds/UnitDeathSound")); }
public void Update(GameTime gameTime) { // disable everything during pause if (!ToylandSiege.GetInstance().gameStateManager.IsPaused()) { Camera.GetCurrentCamera().Update(gameTime); WaveController.Update(gameTime); foreach (var child in RootGameObject.Childs.Values) { child.Update(gameTime); } } }
public void Draw() { _sky.Draw(); ToylandSiege.GetInstance().GraphicsDevice.BlendState = BlendState.Opaque; ToylandSiege.GetInstance().GraphicsDevice.DepthStencilState = DepthStencilState.Default; ToylandSiege.GetInstance().GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; Camera.GetCurrentCamera().Draw(); foreach (var child in RootGameObject.Childs.Values) { child.Draw(); } }
public void InitGameStates() { var gameStateManager = ToylandSiege.GetInstance().gameStateManager; for (int i = 0; i < Configuration.GetValue("GameStates").Count(); i++) { var state = Configuration.GetValue("GameStates")[i].Value <string>(); switch (state.ToLower()) { case "godmode": if (!GodModeEnabled) { throw new ArgumentException("GodMode is not Enabled in configuration file!"); } gameStateManager.AddGameState("GodMode", new GodMode()); Logger.Log.Debug("GameState added: GodMode"); break; case "firstperson": gameStateManager.AddGameState("FirstPerson", new FirstPerson()); Logger.Log.Debug("GameState added: FirstPerson"); break; case "strategic": gameStateManager.AddGameState("Strategic", new Strategic()); Logger.Log.Debug("GameState added: Strategic"); break; case "menu": gameStateManager.AddGameState("Menu", new Menu()); Logger.Log.Debug("GameState added: Menu"); break; case "paused": gameStateManager.AddGameState("Paused", new Paused()); Logger.Log.Debug("GameState added: Paused"); break; default: throw new ArgumentException("Not supported game state " + state); } } //Set starting game state if (JSONHelper.ValueExist("StartingGameState", Configuration)) { gameStateManager.SetNewGameState(gameStateManager.AvailableGameStates[JSONHelper.GetValue("StartingGameState", Configuration)]); } }
private TerrainObject ParseTerrainObject(JObject currentGameObject, GameObject parent = null) { var name = JSONHelper.GetValue("Name", currentGameObject); var model = JSONHelper.GetValue("Model", currentGameObject); var IsEnabled = JSONHelper.ToBool(JSONHelper.GetValue("isEnabled", currentGameObject)); var mod = ToylandSiege.GetInstance().Content.Load <Model>(model); var terrainObj = new TerrainObject(name, mod); terrainObj.IsEnabled = IsEnabled; terrainObj.IsStatic = true; terrainObj.IsCollidable = true; terrainObj.Type = JSONHelper.GetValue("Type", currentGameObject); terrainObj.Parent = parent; if (JSONHelper.ValueExist("Position", currentGameObject)) { terrainObj.Position = JSONHelper.ParseVector3(currentGameObject.GetValue("Position")); } if (JSONHelper.ValueExist("Rotation", currentGameObject)) { terrainObj.Rotation = JSONHelper.ParseVector3(currentGameObject.GetValue("Rotation")); } if (JSONHelper.ValueExist("Scale", currentGameObject)) { terrainObj.Scale = JSONHelper.ParseVector3(currentGameObject.GetValue("Scale")); } terrainObj.CreateTransformationMatrix(); if (JSONHelper.ValueExist("Child", currentGameObject)) { for (int i = 0; i < currentGameObject.GetValue("Child").Count(); i++) { terrainObj.AddChild(ParseGameObject(currentGameObject.GetValue("Child")[i].ToObject <JObject>(), terrainObj)); } } // TODO: Load from a config file? terrainObj.Collider.BType = Collider.BoundingType.Box; terrainObj.Collider.RecreateBounding(); return(terrainObj); }
private static Enemy _BuildStandart(string Name) { Enemy unit = new Enemy(); unit.Name = Name; unit.Model = ToylandSiege.GetInstance().Content.Load <Model>("EnemyUnits/BlockmanDefender"); unit.Type = "Enemy"; unit.IsEnabled = false; unit.Health = 75; unit.MaxHealth = 75; unit.Damage = 25; unit.ShotDistance = 3; unit.TimeBetweeenShoots = 3; unit.UnitType = "Standart"; var skinningData = ToylandSiege.GetInstance().Content.Load <Model>("EnemyUnits/BlockmanDefender").Tag as SkinningData; unit.AnimationPlayer = new AnimationPlayer(skinningData); unit.Clips = new Dictionary <string, AnimationClip>() { { "shoot", skinningData.AnimationClips["Take 001"] } }; /* * unit.Clips.Add("walking", skinningData.AnimationClips["walking"]); * unit.Clips.Add("standing", new AnimationClip(skinningData.AnimationClips["walking"], skinningData.AnimationClips["standing"])); * unit.Clips.Add("crouch", new AnimationClip(skinningData.AnimationClips["standing"], skinningData.AnimationClips["crouch"])); * unit.Clips.Add("crouching", new AnimationClip(skinningData.AnimationClips["crouch"], skinningData.AnimationClips["crouching"])); * unit.Clips.Add("standup", new AnimationClip(skinningData.AnimationClips["crouching"], skinningData.AnimationClips["standup"])); */ unit.AnimationPlayer.StartClip(unit.Clips.Values.ElementAt(0)); unit.Position = Vector3.Zero; unit.Scale = new Vector3(0.05f, 0.05f, 0.05f); unit.Rotation = new Vector3(0f, 0, 0); Logger.Log.Debug("Standart enemy created"); return(unit); }
public Sky() { Model = ToylandSiege.GetInstance().Content.Load <Model>("Sphere"); Texture = ToylandSiege.GetInstance().Content.Load <Texture2D>("SkyTexture"); Initialize(); }
public static void DrawColliderWireframes() { RasterizerState rasterizerStateOriginal = ToylandSiege.GetInstance().GraphicsDevice.RasterizerState; RasterizerState rasterizerStateWireframe = new RasterizerState(); rasterizerStateWireframe.FillMode = FillMode.WireFrame; rasterizerStateWireframe.CullMode = CullMode.CullCounterClockwiseFace; ToylandSiege.GetInstance().GraphicsDevice.RasterizerState = rasterizerStateWireframe; ToylandSiege.GetInstance().GraphicsDevice.BlendState = BlendState.Opaque; ToylandSiege.GetInstance().GraphicsDevice.DepthStencilState = DepthStencilState.Default; foreach (var child in Level.GetCurrentLevel().RootGameObject.GetAllChilds(Level.GetCurrentLevel().RootGameObject)) { if (child.IsEnabled && child.IsCollidable) { switch (child.Collider.BType) { case Collider.BoundingType.Sphere: { Model colliderModel = GetSphereModel(child.Collider.SphereCollider.Radius, child.Collider.SphereCollider.Center); foreach (ModelMesh mesh in colliderModel.Meshes) { mesh.Draw(); } break; } // TODO: Add Box debug drawing case Collider.BoundingType.Box: { Model colliderModel = GetBoxModel(child.Collider.BoxCollider.Min, child.Collider.BoxCollider.Max); foreach (ModelMesh mesh in colliderModel.Meshes) { mesh.Draw(); } break; } // TODO: Add Complex debug drawing case Collider.BoundingType.Complex: { foreach (BoundingSphere sphere in child.Collider.SphereColliders) { Model colliderModel = GetSphereModel(sphere.Radius, sphere.Center); foreach (ModelMesh mesh in colliderModel.Meshes) { mesh.Draw(); } } break; } } } } ToylandSiege.GetInstance().GraphicsDevice.RasterizerState = rasterizerStateOriginal; }
public void Initialize() { LoadedShaders.Add("ReflectionShader", ToylandSiege.GetInstance().Content.Load <Effect>("Shaders/ReflectionShader")); }
private UnitBase ParseUnitObject(JObject currentGameObject, GameObject parent = null) { var name = JSONHelper.GetValue("Name", currentGameObject); var model = JSONHelper.GetValue("Model", currentGameObject); var type = JSONHelper.GetValue("Type", currentGameObject); var IsEnabled = JSONHelper.ToBool(JSONHelper.GetValue("isEnabled", currentGameObject)); var health = float.Parse(JSONHelper.GetValue("Health", currentGameObject)); var unitType = JSONHelper.GetValue("UnitType", currentGameObject); var mod = ToylandSiege.GetInstance().Content.Load <Model>(model); UnitBase unitObj; if (type == "Unit") { unitObj = new Unit(); } else if (type == "Enemy") { unitObj = new Enemy(); } else { throw new ArgumentException("Unknown unit type " + type); } unitObj.Model = mod; //Parse animation ParseAnimationPlayer(unitObj, currentGameObject.GetValue("Animation")); unitObj.Name = name; unitObj.Type = type; unitObj.IsEnabled = IsEnabled; unitObj.Health = health; unitObj.UnitType = unitType; unitObj.IsStatic = false; unitObj.IsAnimated = true; unitObj.Parent = parent; if (JSONHelper.ValueExist("Position", currentGameObject)) { unitObj.Position = JSONHelper.ParseVector3(currentGameObject.GetValue("Position")); } if (JSONHelper.ValueExist("Rotation", currentGameObject)) { unitObj.Rotation = JSONHelper.ParseVector3(currentGameObject.GetValue("Rotation")); } if (JSONHelper.ValueExist("Scale", currentGameObject)) { unitObj.Scale = JSONHelper.ParseVector3(currentGameObject.GetValue("Scale")); } unitObj.CreateTransformationMatrix(); if (JSONHelper.ValueExist("Child", currentGameObject)) { for (int i = 0; i < currentGameObject.GetValue("Child").Count(); i++) { unitObj.AddChild(ParseGameObject(currentGameObject.GetValue("Child")[i].ToObject <JObject>(), unitObj)); } } // TODO: Load from a config file? unitObj.Collider.BType = Collider.BoundingType.Sphere; unitObj.Collider.RecreateBounding(); return(unitObj); }
static DebugUtilities() { PrimitiveBox = ToylandSiege.GetInstance().Content.Load <Model>("PrimitiveShapes/Cube"); PrimitiveSphere = ToylandSiege.GetInstance().Content.Load <Model>("PrimitiveShapes/Sphere"); }