public void Notice(GameMap gameMap, List <Fighter> fighters, List <Enemy> enemies) { foreach (var f in fighters) { if (!f.IsAlive) { continue; } List <Vector2> points = new List <Vector2>(); points.Add(Vector2.Zero); Vector2 v = new Vector2(f.position.X - position.X, f.position.Y - position.Y); if (v != Vector2.Zero) { v.Normalize(); } points.Add(new Vector2(20 * v.X, 20 * v.Y)); boundaries = Boundaries.CreateFromPoints(points); Vector2 current = new Vector2(position.X, position.Y); bool intersects = false; int i = 0, j = 0; while (!current.Similar(f.position, 5) && i >= 0 && j >= 0) { i = (int)current.GetMapPosition(gameMap).X; j = (int)current.GetMapPosition(gameMap).Y; foreach (var mo in gameMap[i, j].mapObjects) { if (mo.boundaries.Intersects(boundaries + current)) { intersects = true; } } if (intersects) { break; } current += v * 5; } if (!intersects) { aware = true; this.moveStrategy = new PathFind(gameMap, fighters, enemies, this, f); target = f; break; } } }
public Fighter(bool playerControlled, Vector2 position, Camera2d camera) : base(camera) { this.playerControlled = playerControlled; this.position = position; // Definicja animacji postaci this.animation = new Animation(2, 5, Direction.Left); AnimationFrame mini1 = new AnimationFrame(@"Game\mini1", new Rectangle(0, 0, 200, 200), new Rectangle(0, 0, 40, 40)); mini1.origin = new Vector2(100, 180); AnimationFrame mini2 = new AnimationFrame(@"Game\mini2", new Rectangle(0, 0, 200, 200), new Rectangle(0, 0, 40, 40)); mini2.origin = new Vector2(100, 180); this.animation.framesLeft.Add(mini1); this.animation.framesLeft.Add(mini2); this.animation.framesRight.Add(mini1); this.animation.framesRight.Add(mini2); this.animation.framesUp.Add(mini1); this.animation.framesUp.Add(mini2); this.animation.framesDown.Add(mini1); this.animation.framesDown.Add(mini2); this.animationDeath = new Animation(20, 15, Direction.Left); AnimationFrame frame; for (int i = 1; i <= 10; i++) { frame = new AnimationFrame(@"Game\AnimationDeath\mini1_klatka" + i.ToString(), new Rectangle(0, 0, 200, 200), new Rectangle(0, 0, 40, 40)); frame.origin = new Vector2(100, 180); if (i == 10) { for (int j = 0; j < 11; j++) { this.animationDeath.framesLeft.Add(frame); this.animationDeath.framesRight.Add(frame); this.animationDeath.framesUp.Add(frame); this.animationDeath.framesDown.Add(frame); } } else { this.animationDeath.framesLeft.Add(frame); this.animationDeath.framesRight.Add(frame); this.animationDeath.framesUp.Add(frame); this.animationDeath.framesDown.Add(frame); } } List <Vector2> points = new List <Vector2>(); points.Add(new Vector2(-BoundariesSize, 0)); points.Add(new Vector2(0, -BoundariesSize)); points.Add(new Vector2(BoundariesSize, 0)); points.Add(new Vector2(0, BoundariesSize)); this.boundaries = Boundaries.CreateFromPoints(points); this.health = 8; this.isActive = true; this.speed = 0.75f; this.timeLastShot = new TimeSpan(); this.destination = new Vector2(position.X, position.Y); }
public Enemy(Vector2 position, Camera2d camera) : base(camera) { this.position = position; // Definicja animacji postaci this.animation = new Animation(2, 5, Direction.Left); AnimationFrame eiti1 = new AnimationFrame(@"Game\eiti1", new Rectangle(0, 0, 200, 200), new Rectangle(0, 0, 40, 40)); eiti1.origin = new Vector2(100, 180); AnimationFrame eiti2 = new AnimationFrame(@"Game\eiti2", new Rectangle(0, 0, 200, 200), new Rectangle(0, 0, 40, 40)); eiti2.origin = new Vector2(100, 180); this.animation.framesLeft.Add(eiti1); this.animation.framesLeft.Add(eiti2); this.animation.framesRight.Add(eiti1); this.animation.framesRight.Add(eiti2); this.animation.framesUp.Add(eiti1); this.animation.framesUp.Add(eiti2); this.animation.framesDown.Add(eiti1); this.animation.framesDown.Add(eiti2); this.animationDeath = new Animation(20, 15, Direction.Left); AnimationFrame frame; for (int i = 1; i <= 10; i++) { frame = new AnimationFrame(@"Game\AnimationDeath\eiti1_klatka" + i.ToString(), new Rectangle(0, 0, 200, 200), new Rectangle(0, 0, 40, 40)); frame.origin = new Vector2(100, 180); if (i == 10) { for (int j = 0; j < 11; j++) { this.animationDeath.framesLeft.Add(frame); this.animationDeath.framesRight.Add(frame); this.animationDeath.framesUp.Add(frame); this.animationDeath.framesDown.Add(frame); } } else { this.animationDeath.framesLeft.Add(frame); this.animationDeath.framesRight.Add(frame); this.animationDeath.framesUp.Add(frame); this.animationDeath.framesDown.Add(frame); } } List <Vector2> points = new List <Vector2>(); points.Add(new Vector2(-BoundariesSize, 0)); points.Add(new Vector2(0, -BoundariesSize)); points.Add(new Vector2(BoundariesSize, 0)); points.Add(new Vector2(0, BoundariesSize)); this.boundaries = Boundaries.CreateFromPoints(points); this.health = 6; this.speed = 0.55f; this.timeLastShot = new TimeSpan(); }
private void Level1() { GameMap = new GameMap(150, 150); MapTile t1 = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>()); MapTile t2 = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 291, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>()); MapTile t3 = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 317, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>()); MapObject mo = new MapObject(); List <Vector2> punkty = new List <Vector2>(); punkty.Add(new Vector2(-0.5f, 7)); punkty.Add(new Vector2(24, 23)); punkty.Add(new Vector2(48.5f, 7)); punkty.Add(new Vector2(24, -2)); mo.boundaries = Boundaries.CreateFromPoints(punkty); mo.collectible = false; mo.Source = new Source(539, 0, 48, 47); mo.textureName = @"Game\newtile"; mo.throwableOver = true; mo.type = new Bonus(); mo.viewBlocking = true; mo.origin = new Vector2(0, 24); for (int i = 0; i < 20; i++) { for (int j = 0; j < 40; j++) { GameMap[i + j / 2, 40 - 2 * i + j] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>()); GameMap[i + j / 2 + 1, 40 - 2 * i + j] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 291, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>()); } } for (int i = 0; i < 42; i++) { GameMap[i / 2, 42 - i].mapObjects.Add(mo.Clone()); GameMap[i / 2 + 20, 82 - i].mapObjects.Add(mo.Clone()); } GameMap[20, 43].mapObjects.Add(mo.Clone()); GameMap[21, 44].mapObjects.Add(mo.Clone()); GameMap[20, 30].mapObjects.Add(mo.Clone()); GameMap[1, 11].mapObjects.Add(mo.Clone()); GameMap[4, 60] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>()); GameMap[4, 60].mapObjects.Add(mo.Clone()); for (int i = 0; i < 70; i++) { GameMap[7, i *5] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>()); } GameMap[0, 0] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>()); GameMap[1, 1] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>()); GameMap[10, 2] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>()); GameMap[10, 3] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>()); GameMap[13, 2] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>()); GameMap[13, 3] = new MapTile(new BackgroundSprite(@"Game\fire1", new Rectangle(6, 267, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List <MapObject>()); GameMap.Load(content); /* * GameMap = new GameMap(50, 100); * * for (int i = 0; i < 50; i++) * for (int j = 0; j < 100; j++) * GameMap.mapTiles[i][j] = new MapTile(new BackgroundSprite(@"Game\texture", new Rectangle(152, 379, (int)GameMap.TileShift.X, (int)GameMap.TileShift.Y)), new List<MapObject>()); * * GameMap.Load(content); * * MapObject mo = new MapObject(); * List<Vector2> punkty = new List<Vector2>(); * punkty.Add(new Vector2(1, 6)); * punkty.Add(new Vector2(4, 13)); * punkty.Add(new Vector2(8, 13)); * punkty.Add(new Vector2(25, 0)); * mo.boundaries = Boundaries.CreateFromPoints(punkty); * mo.collectible = false; * mo.Source = new Source(372, 429, 30, 38); * mo.textureName = @"Game\texture"; * mo.throwableOver = true; * mo.type = new Bonus(); * mo.viewBlocking = true; * mo.origin = new Vector2(0, 24); * mo.Load(content); * * for (int i = 0; i < 50; i++) * GameMap.mapTiles[i][10].mapObjects.Add(mo); * * mo = new MapObject(); * punkty.Clear(); * punkty.Add(new Vector2(40, 13)); * punkty.Add(new Vector2(43, 13)); * punkty.Add(new Vector2(46, 6)); * punkty.Add(new Vector2(25, 0)); * //punkty.Add(new Vector2(18, 2)); * mo.boundaries = Boundaries.CreateFromPoints(punkty); * mo.collectible = false; * mo.Source = new Source(403, 429, 30, 38); * mo.textureName = @"Game\texture"; * mo.throwableOver = true; * mo.type = new Bonus(); * mo.viewBlocking = true; * mo.origin = new Vector2(-18, 24); * mo.Load(content); * * * for (int i = 0; i < 50; i++) * GameMap.mapTiles[i][10].mapObjects.Add(mo); */ }