/// <summary> /// Update shot "bullets" /// </summary> /// <param name="players">players list used for damage</param> /// <param name="walls">walls list used for damage</param> /// <returns>returns true if the shot should be removed</returns> public bool Update(PlayerCollection players, WallCollection walls) { if (decay < 0) { return(true); } Rectangle hit = new Rectangle(rectangle.Center.X, rectangle.Y, Math.Abs(speed.X), Math.Abs(speed.Y)); // test players if (players.TestHit(hit, damage, owner)) { return(true); } // test walls if (walls.TestDamage(hit, damage)) { return(true); } rectangle.X += speed.X; rectangle.Y += speed.Y; return(false); }
public void Update(WallCollection walls, PlayerCollection players) { foreach (var weapon in this) { weapon.Update(null, walls, players); } }
public void Update(int gravity, WallCollection walls, PlayerCollection players, WeaponCollection weapons, int jump_force, int speed) { if (Live) { TestInput(jump_force, speed); if (hero.weapon == null) { foreach (var weapon in weapons) { int dis = Tool.distance(hero.GetPoint(), weapon.GetPoint()); if (dis < 100) { hero.pickup(weapon); weapons.Remove(weapon); break; } } } } else { hero.stop(); hero.drop(weapons); } Live = hero.Update(gravity, walls, players); }
public Screen Update(int gravity, WallCollection walls, PlayerCollection players, WeaponCollection weapons, MouseState mouse) { if (menu.IsPressed(mouse)) { return(Screen.Menu); } foreach (var player in this) { player.Update(gravity, walls, players, weapons, jump, speed); } return(Screen.Play); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); fill = loadColorTexture(Color.White); sans = Content.Load <SpriteFont>("sans"); // load in the textures for heros List <Texture2D> heroTextures = new List <Texture2D>(); // load textures into the list Texture2D heroTex = Content.Load <Texture2D>("newBasic"); heroTextures.Add(heroTex); Texture2D chungTex = Content.Load <Texture2D>("chungus"); heroTextures.Add(chungTex); Texture2D dogeTex = Content.Load <Texture2D>("doge"); heroTextures.Add(dogeTex); Texture2D blockTex = Content.Load <Texture2D>("blocks"); Texture2D weaponsTex = Content.Load <Texture2D>("weapons"); players = new PlayerCollection(heroTextures, UNIT_SIZE / 3 * 2, UNIT_SIZE, sans, fill); Texture2D wallTexture = loadColorTexture(Color.DarkGreen); walls = new WallCollection(wallTexture, TILE_SIZE); //walls.createBlock(0, 200, screenWidth, screenHeight); builder = new Builder(walls, sans, fill, heroTex, UNIT_SIZE / 3 * 2, UNIT_SIZE, weaponsTex, UNIT_SIZE, UNIT_SIZE / 2); builder.loadMap("last.gmd"); // delete this sometime players.AddPlayer(new Point(100, 100), Heros.Chungus, "player 1", Color.Red, Keys.Left, Keys.Right, Keys.Up, Keys.Space); players.AddPlayer(new Point(200, 100), Heros.Doge, "Player 2", Color.Blue, Keys.A, Keys.D, Keys.W, Keys.LeftShift); weapons = new WeaponCollection(); Gun gun = new Gun(new Rectangle(0, 0, UNIT_SIZE, UNIT_SIZE / 2), weaponsTex, fill, 2); weapons.Add(gun); mainMenu = new Menus(sans, fill); // TODO: use this.Content to load your game content here }
public override void Update(Hero owner, WallCollection walls, PlayerCollection players) { if (owner == null) { return; } // set the gun rectangle and start point if (owner.IsRight) { rectangle.X = owner.HitBox.Right - rectangle.Width / 2; rectangle.Y = owner.HitBox.Y + rectangle.Height / 2; shotLocation = new Point(owner.HitBox.Center.X, rectangle.Center.Y); loadShotSpeed = shotSpeed; // TODO change source rectangle to point right } else { rectangle.X = owner.HitBox.Left - rectangle.Width; rectangle.Y = owner.HitBox.Y + rectangle.Height / 2; shotLocation = new Point(owner.HitBox.Center.X - shotSpeed, rectangle.Center.Y); loadShotSpeed = -shotSpeed; // TODO change source rectangle to point left } for (int i = 0; i < shot.Count; i++) { if (shot[i].Update(players, walls)) { shot.RemoveAt(i); i--; } } // update shot varialbes if (lastShot > 0) { lastShot--; } // throw new NotImplementedException(); }
public Map(WallCollection collection, List <Point> startLocations, List <Point> gunLocations) { // save wall data walls = new List <WallData>(); foreach (var wall in collection) { walls.Add(wall.GetWallData()); } // save start locations this.startLocations = new List <PointData>(); foreach (var loc in startLocations) { this.startLocations.Add(new PointData(loc.X, loc.Y)); } // save gun locations this.gunLocations = new List <PointData>(); foreach (var loc in gunLocations) { this.gunLocations.Add(new PointData(loc.X, loc.Y)); } }
public Builder(WallCollection walls, SpriteFont buttonFont, Texture2D buttonTexture, Texture2D playerTexture, int playerWidth, int playerHeight, Texture2D gunTexture, int gunWidth, int gunHeight) { startLocation = new List <Point>(); gunLocations = new List <Point>(); this.playerHeight = playerHeight; this.playerWidth = playerWidth; this.gunHeight = gunHeight; this.gunWidth = gunWidth; this.playerTexture = playerTexture; this.gunTexture = gunTexture; this.walls = walls; radius = 64; state = BuildState.Pan; last_pressed = new Point(0, 0); // Create buttons menu = new Button(100, 100, 100, 40, "Menu", buttonFont, buttonTexture); panButton = new Button(100, 150, 100, 40, "Pan", buttonFont, buttonTexture); buildButton = new Button(100, 200, 100, 40, "Build", buttonFont, buttonTexture); }
public bool Update(int gravity, WallCollection walls, PlayerCollection players) { if (HitBox.Y > KILL_LEVEL) { return(false); } AccelY = gravity; // Save Velocity and Rec values to be manipulated Rectangle rectangle = HitBox; Point velocity = Velocity; // update velocity based on acceeleration velocity.X += AccelX; velocity.Y += AccelY; if (velocity.X > MAX_SPEED) { velocity.X = MAX_SPEED; } else if (velocity.X < -MAX_SPEED) { velocity.X = -MAX_SPEED; } if (OnGround) { velocity.Y = 0; if (AccelX == 0) { if (velocity.X > DAMPEN) { velocity.X -= DAMPEN; } else if (velocity.X < -DAMPEN) { velocity.X += DAMPEN; } else { velocity.X = 0; } } } // test to see if on the ground OnGround = false; if (walls.Intersects(new Rectangle(HitBox.X, HitBox.Bottom, HitBox.Width, 1)) != new Rectangle()) { OnGround = true; } // test to see if on the ground Rectangle test; Rectangle wall = new Rectangle(); Point offset = new Point(0); // Test Y if (velocity.Y > 0) // fall on v { test = new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height + velocity.Y); wall = walls.Intersects(test); if (wall != new Rectangle()) { velocity.Y = wall.Top - rectangle.Bottom; } } else if (velocity.Y < 0) // hit from top ^ { test = new Rectangle(rectangle.X, rectangle.Y + velocity.Y, rectangle.Width, rectangle.Height - velocity.Y); wall = walls.Intersects(test); if (wall != new Rectangle()) { velocity.Y = 0; } } rectangle.Y += velocity.Y; // Test X if (velocity.X > 0) // hit from right side ->| { test = new Rectangle(rectangle.X, rectangle.Y, rectangle.Width + velocity.X, rectangle.Height / 2); wall = walls.Intersects(test); if (wall != new Rectangle()) { velocity.X = -rectangle.Right + wall.Left; AccelX = 0; } else { // test for moveing over an incline test = new Rectangle(rectangle.X, rectangle.Y, rectangle.Width + velocity.X, rectangle.Height); wall = walls.Intersects(test); if (wall != new Rectangle()) { test = new Rectangle(rectangle.X, rectangle.Y - wall.Height, rectangle.Width + velocity.X, rectangle.Height); test = walls.Intersects(test); if (test == new Rectangle()) { offset.Y -= wall.Height; } else { velocity.X = -rectangle.Right + wall.Left; AccelX = 0; } } } } else if (velocity.X < 0) // hit from right side |<- { test = new Rectangle(rectangle.X + velocity.X, rectangle.Y, rectangle.Width - velocity.X, rectangle.Height / 2); wall = walls.Intersects(test); if (wall != new Rectangle()) { velocity.X = wall.Right - rectangle.Left; AccelX = 0; } else { // test for moveing over an incline test = new Rectangle(rectangle.X + velocity.X, rectangle.Y, rectangle.Width - velocity.X, rectangle.Height); wall = walls.Intersects(test); if (wall != new Rectangle()) { test = new Rectangle(rectangle.X + velocity.X, rectangle.Y - wall.Height, rectangle.Width - velocity.X, rectangle.Height); test = walls.Intersects(test); if (test == new Rectangle()) { offset.Y -= wall.Height; } else { velocity.X = wall.Right - rectangle.Left; AccelX = 0; } } } } // update weapon if exists if (weapon != null) { weapon.Update(this, walls, players); } // uppdate the rectangle based on velocity rectangle.Y += offset.Y; rectangle.X += velocity.X + offset.X; // reset Velocity and Rec values Velocity = velocity; HitBox = rectangle; return(Health > 0); }
/// <summary> /// This method is used to update anything needed with the weapon like location. /// </summary> /// <param name="owner"></param> /// <param name="walls"></param> /// <param name="players"></param> public abstract void Update(Hero owner, WallCollection walls, PlayerCollection players);