public Skilltree(Player playerInfo, Game1 game) { activeSkills = new ActiveSkills(); this.fireRate = 0; this.projectileSpeed = 0.039f; this.damage = 0; this.playerInfo = playerInfo; this.playerLevel = playerInfo.playerLevel; this.maxHp = 100; //Set Hp and Athyl on player this.maxAthyl = 500; //this.playerMaxAthyl = this.maxAthyl; //this.playerMaxHP = this.maxHp; firebreathPoint = AtkSpdPoint = AtkDmgPoint = DodgePoint = 0; //Close talentpoints FireBurstPoint = FastShotPoint = AthylPoint = PassthroughPoint = 0; //Mid talentpoints ShieldPoint = KevlarPoint = AimPoint = ShieldCDPoint = 0; //Long talentpoints DodgePoint = PassthroughPoint = KevlarPoint = AimPoint = ShieldCDPoint = 5; //Skills that are still under construction! //Set default values for melee meleeFireRate = 0.3f; meleeMoveSpd = 1.4f; meleeDmg = 75; meleeJmpHeight = new Vector2(0, -28.0f); meleeEthanolConsumption = 0; meleePlayerDmg = 0.5f; meleeMaxAthyl = maxAthyl; //Set default values for melee midFireRate = 0.13f; midMoveSpd = 1.4f; midDmg = 50; midJmpHeight = new Vector2(0, -26.6f); midEthanolConsumption = 2; midPlayerDmg = 0.75f; midMaxAthyl = maxAthyl; //Set default values for melee longFireRate = 0.7f; longMoveSpd = 0.8f; longDmg = 200; longJmpHeight = new Vector2(0, -23.1f); longEthanolConsumption = 10; longPlayerDmg = 1.0f; longMaxAthyl = maxAthyl; }
/// <summary> /// Handle all input /// </summary> private void Input() { keyboardState = Keyboard.GetState(); MouseState mouse = Mouse.GetState(); //leave /Timmo //flying debug! /*if(keyboardState.IsKeyDown(Keys.Up)) player.torso.body.ApplyForce(new Vector2(0, -21.0f)); if (keyboardState.IsKeyDown(Keys.Down)) player.torso.body.ApplyForce(new Vector2(0, 21)); if(keyboardState.IsKeyDown(Keys.Right)) player.torso.body.ApplyForce(new Vector2(21, 0)); if (keyboardState.IsKeyDown(Keys.Left)) player.torso.body.ApplyForce(new Vector2(-21, 0));*/ //Debug /*if (keyboardState.IsKeyDown(Keys.M) && !prevKeyboardState.IsKeyDown(Keys.M)) { endOfMapSpawn = endOfMapSpawn ? false : true; }*/ //Jump (jumpKey) if (keyboardState.IsKeyDown(InputClass.jumpKey) && !prevKeyboardState.IsKeyDown(InputClass.jumpKey)) { player.Jump(); } //Shoot (shootKey) if (keyboardState.IsKeyDown(InputClass.shootKey)) { player.useWeapon(world); } //Use stuff ex.lifting stuff (useKey) if (keyboardState.IsKeyDown(InputClass.useKey)) { if (player.Stance == Player.Stances.LongRange && prevKeyboardState.IsKeyUp(InputClass.useKey) && player.playerAthyl > 150 && player.skillTree.ShieldPoint > 0) { if (activeSkills != null) { world.RemoveBody(activeSkills.shieldGfx.body); } activeSkills = new ActiveSkills(world, this, player, player.direction); activeSkills.UseShield(player); activeSkills.shieldActivate = true; activeSkills.shieldGfx.body.OnCollision += activeSkills.makeShieldStatic; player.playerAthyl -= 150; } else if (player.Stance == Player.Stances.CloseRange && player.skillTree.firebreathPoint > 0) { player.UseFirebreath(world); } else if (player.Stance == Player.Stances.MidRange && player.skillTree.FireBurstPoint > 0) { player.UseFireburst(world); } } if (keyboardState.IsKeyUp(InputClass.useKey)) //change stances (closeKey, middleKey, longKey) if (keyboardState.IsKeyDown(InputClass.closeKey)) { player.Stance = Player.Stances.CloseRange; if (activeSkills != null) { world.RemoveBody(activeSkills.shieldGfx.body); activeSkills = null; } } else if (keyboardState.IsKeyDown(InputClass.middleKey)) { player.Stance = Player.Stances.MidRange; if (activeSkills != null) { world.RemoveBody(activeSkills.shieldGfx.body); activeSkills = null; } } else if (keyboardState.IsKeyDown(InputClass.longKey)) { player.Stance = Player.Stances.LongRange; } //Movement keys (leftKey, UuKey, downKey, rightKey, crouchKey) //Left if (keyboardState.IsKeyDown(InputClass.leftKey)) { player.Move(Player.Movement.Left); if (keyboardState.IsKeyDown(InputClass.upKey)) { player.direction = Player.Direction.Upleft; } else if (keyboardState.IsKeyDown(InputClass.downKey) && !player.Crouching) { player.direction = Player.Direction.Downleft; } } //Right else if (keyboardState.IsKeyDown(InputClass.rightKey)) { player.Move(Player.Movement.Right); if (keyboardState.IsKeyDown(InputClass.upKey)) { player.direction = Player.Direction.Upright; } else if (keyboardState.IsKeyDown(InputClass.downKey) && !player.Crouching) { player.direction = Player.Direction.Downright; } } //Up else if (keyboardState.IsKeyDown(InputClass.upKey)) { player.direction = Player.Direction.Up; player.Move(Player.Movement.Stop); } //crouch else if (keyboardState.IsKeyUp(InputClass.crouchKey) && prevKeyboardState.IsKeyDown(InputClass.crouchKey)) { player.Crouching = false; } else if (keyboardState.IsKeyDown(InputClass.crouchKey)) { player.Crouching = true; } else if (!player.OnGround) { player.Move(Player.Movement.Stop); } else { player.Move(Player.Movement.Stop); player.Crouching = false; //Vänder riktningen åt rätt håll ifall man har skjutit diagonalt, upp eller ner if (player.lastDirection) player.direction = Player.Direction.Left; else player.direction = Player.Direction.Right; } //Använder M som snabbknapp för att kunna spawna fiender. /*if (keyboardState.IsKeyDown(Keys.M) && prevKeyboardState.IsKeyDown(Keys.M)) { theAI.Add(new AI(world, enemyTexture, new Vector2(42, 90), new Vector2(50, 1300), 100, 20, this, AI.Behavior.Patrol, "enemy")); for (int i = 0; i < theAI.Count; i++) { for (int j = 0; j < theAI.Count; j++) { theAI[i].torso.body.IgnoreCollisionWith(theAI[j].torso.body); theAI[i].wheel.body.IgnoreCollisionWith(theAI[j].wheel.body); theAI[i].torso.body.IgnoreCollisionWith(theAI[j].wheel.body); theAI[i].wheel.body.IgnoreCollisionWith(theAI[j].torso.body); } } }*/ prevKeyboardState = keyboardState; }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { menu.UpdateMenu(gameTime, this, player); keyboardState = Keyboard.GetState(); /*if (keyboardState.IsKeyDown(Keys.R)) { map.currentLevel = 1; Restart(); }*/ if (player != null && player.Dead) { player.UpdatePlayer(); } else if (player != null) { if (menu.gameState == Menu.GameState.Paused) { timer.Stop(); // menu.StartMenu(this); } else if (menu.gameState == Menu.GameState.Skilltree) { timer.Stop(); } else if (menu.gameState == Menu.GameState.Playing) { if (!timer.Enabled) { timer.Start(); } Input(); if (SpawnEnemies() == 1) { for (int i = 0; i < theAI.Count; i++) { for (int j = 0; j < theAI.Count; j++) { theAI[i].torso.body.IgnoreCollisionWith(theAI[j].torso.body); theAI[i].wheel.body.IgnoreCollisionWith(theAI[j].wheel.body); theAI[i].torso.body.IgnoreCollisionWith(theAI[j].wheel.body); theAI[i].wheel.body.IgnoreCollisionWith(theAI[j].torso.body); } } } foreach (AI ai in theAI) { ai.UpdateEnemy(player, world, drops); } player.UpdatePlayer(); Damage(); camera.UpdateCamera(player); removedDropsList.Clear(); foreach (var d in drops) { if (d.ethanolDrop) { removedDropsList.Add(d); } else if (d.hpDrop) { removedDropsList.Add(d); } } try { for (int i = 0; i < removedDropsList.Count; i++) { world.RemoveBody(removedDropsList[i].hpBox.body); world.RemoveBody(removedDropsList[i].ethanolBox.body); drops.Remove(removedDropsList[i]); } } catch (Exception ex) { logger.Fatal(ex.Message + " " + ex.TargetSite + " " + ex.StackTrace); } Fixture fixture = world.TestPoint(ConvertUnits.ToSimUnits(new Vector2(player.torso.Position.X + player.torso.Size.X, player.torso.Position.Y))); if (fixture != null && fixture.Body.FixtureList[0].UserData.ToString() == "goal") { map.currentLevel++; if (map.currentLevel > 3) map.currentLevel = 1; //Restart(); RestartMapWon(); } world.Step(0.033333f); } } if (activeSkills != null) { activeSkills.Update(world, gameTime); if (activeSkills.removeShield) { activeSkills = null; } } base.Update(gameTime); }
public void RestartMapWon() { try { if (activeSkills != null) { world.RemoveBody(activeSkills.shieldGfx.body); activeSkills = null; } foreach (AI ai in theAI) { ai.projectile.Clear(world); world.RemoveBody(ai.wheel.body); world.RemoveBody(ai.torso.body); } theAI.Clear(); if (drops.Count > 0) { foreach (Drops d in drops) { world.RemoveBody(d.hpBox.body); world.RemoveBody(d.ethanolBox.body); } } if (player != null) player.projectile.Clear(world); //player.torso.Position = new Vector2(60, 1300); player.MovePlayer(new Vector2(60, 1300)); if (map != null) { map.InializeMap(); } //reset spawnpoints foreach (Spawn sp in spawnpoints) { if (sp.Visited) sp.Visited = false; } drops.Clear(); menu.totalTime = 0f; runTime = 0; player.torso.Position = new Vector2(60, 1300); player.wheel.Position = new Vector2(60, 1300); camera = new Camera(graphics.GraphicsDevice.Viewport); camera.UpdateCamera(player); /* if (quest != null) { world.RemoveBody(quest.boulder.body); } quest = new Quests(world, this); if (map != null) map.button.body.OnCollision += quest.InteractWithQuestItems; * */ } catch (Exception ex) { logger.Fatal("Restart: " + ex.Message + " " + ex.TargetSite + " " + ex.StackTrace); } }
/// <summary> /// Restart the game /// </summary> public void Restart() { try { if (activeSkills != null) { world.RemoveBody(activeSkills.shieldGfx.body); activeSkills = null; } foreach (AI ai in theAI) { ai.projectile.Clear(world); world.RemoveBody(ai.wheel.body); world.RemoveBody(ai.torso.body); } theAI.Clear(); if (player != null) { world.RemoveBody(player.torso.body); world.RemoveBody(player.wheel.body); } if (drops.Count > 0) { foreach (Drops d in drops) { world.RemoveBody(d.hpBox.body); world.RemoveBody(d.ethanolBox.body); } } if (player != null) player.projectile.Clear(world); player = null; //starta i slutet av banan (låt va kvar /Timmo) if (endOfMapSpawn) player = new Player(world, playerTexture, new Vector2(42, 90), 10.0f, new Vector2(8385, 1000), this, "player"); else player = new Player(world, playerTexture, new Vector2(60, 88), 10.0f, new Vector2(60, 1300), this, "player"); if (map != null) { map.InializeMap(); } //reset spawnpoints foreach (Spawn sp in spawnpoints) { if (sp.Visited) sp.Visited = false; } drops.Clear(); menu.totalTime = 0f; runTime = 0; camera = new Camera(graphics.GraphicsDevice.Viewport); camera.UpdateCamera(player); /* if (quest != null) { world.RemoveBody(quest.boulder.body); } quest = new Quests(world, this); if (map != null) map.button.body.OnCollision += quest.InteractWithQuestItems; * */ skilltree = new Skilltree(player, this); } catch (Exception ex) { logger.Fatal("Restart: " + ex.Message + " " + ex.TargetSite + " " + ex.StackTrace); } }