public Drops(Game1 game, World world, Player player) { ethanolTexture = game.Content.Load<Texture2D>("Flask"); hpTexture = game.Content.Load<Texture2D>("MedKit"); ethanolBox = new DrawableGameObject(world, ethanolTexture, new Vector2(32, 32), 1, "athyl", 0); hpBox = new DrawableGameObject(world, hpTexture, new Vector2(32, 32), 1, "hpBox", 0); //ethanolBox.body.OnCollision += PickupsForPlayer; //hpBox.body.OnCollision += PickupsForPlayer; ethanolBox.body.OnCollision += new OnCollisionEventHandler(PickupsForPlayer); hpBox.body.OnCollision += new OnCollisionEventHandler(PickupsForPlayer); hpBox.body.FixedRotation = true; ethanolBox.body.FixedRotation = true; this.playerz = player; this.gamez = game; this.world = world; ethanolBox.body.BodyType = BodyType.Dynamic; hpBox.body.BodyType = BodyType.Dynamic; ethanolDrop = false; hpDrop = false; //ethanolBox.body.IgnoreCollisionWith(player.torso.body); //hpBox.body.IgnoreCollisionWith(player.torso.body); //hpBox.body.IgnoreCollisionWith(player.wheel.body); //ethanolBox.body.IgnoreCollisionWith(player.wheel.body); hpBox.body.SleepingAllowed = false; ethanolBox.body.SleepingAllowed = false; hpBox.body.Friction = 100f; ethanolBox.body.Friction = 100f; }
public Bullet(DrawableGameObject Obj, float Damage, Game1 game, World world, float LifeTime) { this.Obj = Obj; this.Damage = Damage; this.game = game; this.world = world; this.WasFired = Game1.runTime; this.LifeTime = LifeTime; }
public ActiveSkills() { this.shieldGfx = null; this.shieldOnGround = false; this.player = null; this.rowFrame = 0; this.world = null; this.shieldTexture = null; this.shieldHP = 0; this.removeShield = false; this.shieldCooldown = 0; this.shieldActivate = false; this.direction = Player.Direction.Right; this.shieldDuration = 0; }
public ActiveSkills(World world, Game1 game, Player player, Player.Direction direction) { this.shieldTexture = game.Content.Load<Texture2D>("Projectiles/Shield"); this.direction = direction; this.player = player; this.world = world; this.shieldHP = (int)((player.skillTree.playerInfo.playerHP / 10) * player.skillTree.ShieldPoint); this.shieldDuration += 2 * player.skillTree.ShieldPoint; this.shieldCooldown -= 4 * player.skillTree.ShieldCDPoint; shieldGfx = new DrawableGameObject(world, shieldTexture, new Vector2(shieldTexture.Width, shieldTexture.Height), 90, "shield"); if (direction == Player.Direction.Right) { shieldGfx.Position = new Vector2(player.torso.Position.X + shieldGfx.texture.Width * 1.5f, player.torso.Position.Y); } else { shieldGfx.Position = new Vector2(player.torso.Position.X - shieldGfx.texture.Width * 1.5f, player.torso.Position.Y); } shieldGfx.body.FixedRotation = true; shieldGfx.body.BodyType = BodyType.Dynamic; }
private void SetCollisionCategories(DrawableGameObject b, int tileNumber) { if (tileNumber == 0) b.body.CollisionCategories = Category.Cat5; //LeftUpperCorner else if (tileNumber == 1) b.body.CollisionCategories = Category.Cat5; //Ground else if (tileNumber == 2) b.body.CollisionCategories = Category.Cat5; //RightUpperCorner else if (tileNumber == 3) b.body.CollisionCategories = Category.Cat6; //LeftWall else if (tileNumber == 4) b.body.CollisionCategories = Category.Cat6; //Middle else if (tileNumber == 5) b.body.CollisionCategories = Category.Cat6; //RightWall else if (tileNumber == 6) b.body.CollisionCategories = Category.Cat7; //LeftDownCorner else if (tileNumber == 7) b.body.CollisionCategories = Category.Cat7; //Ceiling else if (tileNumber == 8) b.body.CollisionCategories = Category.Cat7; //RightDownCorner }
private void DrawTilesOnPlace() { Vector2 bodySize = new Vector2(33f, 33f); for (int y = 0; y < 70; y++) { middleTileNr++; if (middleTileNr > 9) middleTileNr = 1; for (int x = 0; x < 322; x++) { if (colors2D[x, y] == new Color(255, 0, 0)) //Red LeftUpperCorner { CreateDrawableGameObject(x, y, 0, bodySize, true); } else if (colors2D[x, y] == new Color(255, 255, 0)) //Yellow Ground { CreateDrawableGameObject(x, y, 1, bodySize, true); } else if (colors2D[x, y] == new Color(0, 255, 0)) //Green RightUpperCorner { CreateDrawableGameObject(x, y, 2, bodySize, true); } else if (colors2D[x, y] == new Color(0, 0, 255)) //DarkBlue LeftWall { CreateDrawableGameObject(x, y, 3, bodySize, true); } else if (colors2D[x, y] == new Color(0, 0, 0)) //Black Middle { CreateDrawableGameObject(x, y, 4, bodySize, false); } else if (colors2D[x, y] == new Color(0, 246, 255)) //LightBlue RightWall { CreateDrawableGameObject(x, y, 5, bodySize, true); } else if (colors2D[x, y] == new Color(96, 57, 19)) //Brown LeftDownCorner { CreateDrawableGameObject(x, y, 6, bodySize, true); } else if (colors2D[x, y] == new Color(83, 71, 65)) //Gray Ceiling { CreateDrawableGameObject(x, y, 7, bodySize, true); } else if (colors2D[x, y] == new Color(77, 0, 68)) //Purple RightDownCorner { CreateDrawableGameObject(x, y, 8, bodySize, true); } else if (colors2D[x, y] == new Color(121, 0, 0)) //Goal Tiles; { b = new DrawableGameObject(world, lvl3[0], bodySize, 0, "goal"); b.Position = new Vector2((x - 1) * 32 + 16, (y - 1) * 32 + 16); b.body.BodyType = BodyType.Static; b.body.Awake = false; b.body.CollisionCategories = Category.Cat13; } else if (colors2D[x, y] == new Color(150, 150, 150)) //Quest Button { button = new DrawableGameObject(world, buttonTexture, 0, "button"); button.Position = new Vector2((x - 1) * 32 + 16, (y - 1) * 32 + 16); button.body.BodyType = BodyType.Static; b.body.Awake = false; body.Add(button); } else if (colors2D[x, y] == new Color(255, 102, 0)) //Invicible walls { b = new DrawableGameObject(world, lvl3[0], bodySize, 0, "ground"); b.Position = new Vector2((x - 1) * 32 + 16, (y - 1) * 32 + 16); b.body.BodyType = BodyType.Static; b.body.Awake = false; b.body.CollisionCategories = Category.Cat12; } progress++; } progress++; } RandomizeList(); }
private void CreateDrawableGameObject(int x, int y, int tileNumber, Vector2 BodySize, bool Collidable) { if (currentLevel == 1) //Sets the borders between the different levels in our game. b = new DrawableGameObject(world, lvl1[tileNumber], BodySize, 0, "ground"); else if (currentLevel == 2) b = new DrawableGameObject(world, lvl2[tileNumber], BodySize, 0, "ground"); else if (currentLevel == 3) b = new DrawableGameObject(world, lvl3[tileNumber], BodySize, 0, "ground"); b.Position = new Vector2((x - 1) * 32 + 16, (y-1) * 32 + 16); b.body.BodyType = BodyType.Static; b.body.Awake = false; if (!Collidable) { for (int i = 0; i < b.body.FixtureList.Count; i++) { b.body.DestroyFixture(b.body.FixtureList[i]); } } SetCollisionCategories(b, tileNumber); body.Add(b); randomizeMiddleTexture(x, y, BodySize); }
/// <summary> /// Adds a melee bullet /// </summary> /// <param name="position"></param> /// <param name="direction"></param> /// <param name="world"></param> /// <param name="speed"></param> /// <param name="wheel"></param> /// <param name="damage"></param> public void NewMeleeBullet(Vector2 position, Player.Direction direction, World world, float speed, Body wheel, float damage) { DrawableGameObject Obj = new DrawableGameObject(world, game.Content.Load<Texture2D>("Projectiles/Fist"), new Vector2(22, 14), 10, "melee"); Obj.body.IsBullet = true; Obj.body.Position = position; Obj.body.IgnoreGravity = true; Obj.body.IsSensor = true; Obj.body.IgnoreCollisionWith(wheel); switch (direction) { case Player.Direction.Right: Obj.texture = game.Content.Load<Texture2D>("Projectiles/FistFlip"); Obj.body.FixedRotation = true; Obj.body.ApplyLinearImpulse(new Vector2(speed, 0)); break; case Player.Direction.Left: Obj.body.FixedRotation = true; Obj.body.ApplyLinearImpulse(new Vector2(speed * -1, 0)); break; default: break; } newbullets.Add(new Bullet(Obj, damage, game, world, meleeBulletLifeTime)); newbullets[newbullets.Count - 1].Obj.body.OnCollision += new OnCollisionEventHandler(body_OnCollision); }
/// <summary> /// prototyp, kulor som fienden skjuter /// </summary> /// <param name="position"></param> /// <param name="direction"></param> /// <param name="world"></param> /// <param name="speed"></param> public void NewEnemyBullet(Vector2 position, Player.Direction direction, World world, float speed, Body wheel, float damage) { //Allows the linear bullets to have some spread! float spread = random.Next(-2, 2); //Allows diagonal bullets to have some spread! float spreaddiagonal = random.Next(1, 5); spread /= 133; spread = 0; spreaddiagonal = 3; DrawableGameObject Obj = new DrawableGameObject(world, game.Content.Load<Texture2D>("Projectiles/Bullet"), new Vector2(10, 4), 10, "hostile"); Obj.body.IsBullet = true; Obj.body.Position = position; Obj.body.IgnoreGravity = true; Obj.body.IsSensor = true; Obj.body.IgnoreCollisionWith(wheel); switch (direction) { case Player.Direction.Right: Obj.body.Rotation = MathHelper.ToRadians(180); Obj.body.FixedRotation = true; Obj.body.ApplyLinearImpulse(new Vector2(speed, spread * 0.2f)); break; case Player.Direction.Left: Obj.body.FixedRotation = true; Obj.body.ApplyLinearImpulse(new Vector2(speed * -1, spread * 0.2f)); break; } newbullets.Add(new Bullet(Obj, damage, game, world, bulletLifeTime)); newbullets[newbullets.Count - 1].Obj.body.OnCollision += new OnCollisionEventHandler(body_OnCollision); }
/// <summary> /// Create a sniper bullet in the direction of the crosshair /// </summary> /// <param name="position">Position to shoot from</param> /// <param name="direction">Direction of bullet</param> /// <param name="world"></param> /// <param name="wheel"></param> /// <param name="damage">Bullet damage</param> public void NewBullet(Vector2 position, Vector2 direction, World world, Body wheel, Body torso, float damage, bool player) { DrawableGameObject Obj; if(player) Obj = new DrawableGameObject(world, game.Content.Load<Texture2D>("Projectiles/Bullet"), new Vector2(11, 8), 10, "shot"); else Obj = new DrawableGameObject(world, game.Content.Load<Texture2D>("Projectiles/Bullet"), new Vector2(11, 8), 10, "hostile"); Obj.body.IsBullet = true; Obj.body.Position = position; Obj.body.IgnoreGravity = true; Obj.body.IsSensor = true; Obj.body.IgnoreCollisionWith(wheel); Obj.body.IgnoreCollisionWith(torso); //calculate direction and rotation float dotProd = Vector2.Dot(Vector2.UnitY, direction); float rotation = (direction.X > 0) ? -(float)Math.Acos(dotProd) + MathHelper.ToRadians(-90) : (float)Math.Acos(dotProd) + MathHelper.ToRadians(-90); Obj.body.Rotation = rotation; Obj.body.FixedRotation = true; Obj.body.ApplyLinearImpulse(direction / 20); newbullets.Add(new Bullet(Obj, damage, game, world, bulletLifeTime)); newbullets[newbullets.Count - 1].Obj.body.OnCollision += new OnCollisionEventHandler(body_OnCollision); }
/// <summary> /// Adds a new bullet to the list /// </summary> /// <param name="position"></param> /// <param name="direction"></param> /// <param name="world"></param> public void NewBullet(Vector2 position, Player.Direction direction, World world, float speed, Body wheel, Body torso, float damage, bool sniper) { float spread = 0; float spreadDiagonal = 1; if (!sniper) { //Allows the linear bullets to have some spread! //spread = random.Next(-2, 2); //Allows diagonal bullets to have some spread! //spreadDiagonal = random.Next(1, 5); //spread /= 133; } DrawableGameObject Obj = new DrawableGameObject(world, game.Content.Load<Texture2D>("Projectiles/Bullet"), new Vector2(11, 8), 10, "shot"); Obj.body.IsBullet = true; Obj.body.Position = position; Obj.body.IgnoreGravity = true; Obj.body.IsSensor = true; Obj.body.IgnoreCollisionWith(wheel); Obj.body.IgnoreCollisionWith(torso); switch (direction) { case Player.Direction.Right: Obj.body.Rotation = MathHelper.ToRadians(180); Obj.body.FixedRotation = true; Obj.body.ApplyLinearImpulse(new Vector2(speed, spread * 0.2f)); break; case Player.Direction.Left: Obj.body.FixedRotation = true; Obj.body.ApplyLinearImpulse(new Vector2(speed * -1, spread * 0.2f)); break; case Player.Direction.Down: Obj.body.Rotation = MathHelper.ToRadians(270); Obj.body.FixedRotation = true; Obj.body.ApplyLinearImpulse(new Vector2(spread * 0.2f, speed)); break; case Player.Direction.Up: Obj.body.Rotation = MathHelper.ToRadians(90); Obj.body.FixedRotation = true; Obj.body.ApplyLinearImpulse(new Vector2(spread * 0.2f, speed * -1.0f)); break; case Player.Direction.Upright: Obj.body.Rotation = MathHelper.ToRadians(135); Obj.body.FixedRotation = true; Obj.body.ApplyLinearImpulse(new Vector2(speed / 2, speed / 2 * -1.0f) * spreadDiagonal); break; case Player.Direction.Upleft: Obj.body.Rotation = MathHelper.ToRadians(45); Obj.body.FixedRotation = true; Obj.body.ApplyLinearImpulse(new Vector2(speed / 2 * -1.0f, speed / 2 * -1.0f) * spreadDiagonal); break; case Player.Direction.Downright: Obj.body.Rotation = MathHelper.ToRadians(-135); Obj.body.FixedRotation = true; Obj.body.ApplyLinearImpulse(new Vector2(speed / 2, speed / 2) * spreadDiagonal); break; case Player.Direction.Downleft: Obj.body.Rotation = MathHelper.ToRadians(-45); Obj.body.FixedRotation = true; Obj.body.ApplyLinearImpulse(new Vector2(speed / 2 * -1.0f, speed / 2) * spreadDiagonal); break; default: break; } newbullets.Add(new Bullet(Obj, damage, game, world, bulletLifeTime)); newbullets[newbullets.Count - 1].Obj.body.OnCollision += new OnCollisionEventHandler(body_OnCollision); }
public void FireBreath(Vector2 position, Player.Direction direction, World world, float speed, float damage) { for (int i = 0; i < 5; i++) { DrawableGameObject Obj = new DrawableGameObject(world, game.Content.Load<Texture2D>("Projectiles/Bullet"), new Vector2(22, 14), 10, "fire"); Obj.body.IsBullet = true; Obj.body.Position = position; Obj.body.IgnoreGravity = true; Obj.body.IsSensor = true; switch (direction) { case Player.Direction.Right: Obj.body.Rotation = MathHelper.ToRadians(180); Obj.body.FixedRotation = true; Obj.body.ApplyLinearImpulse(new Vector2(speed, 0.1f - (float)i/20)); break; case Player.Direction.Left: Obj.body.FixedRotation = true; Obj.body.ApplyLinearImpulse(new Vector2(speed * -1, -0.1f + (float)i/20)); break; } newbullets.Add(new Bullet(Obj, damage, game, world, FireLifeTime)); newbullets[newbullets.Count - 1].Obj.body.OnCollision += new OnCollisionEventHandler(body_OnCollision); } }