public MainHero(Texture2D Texture, Vector2 StartPos) { keyboardState = keyboardStatePast = new KeyboardState(); width = 57; height = 57; position = StartPos; texture = Texture; speed = 10f; health = 5000; //rectangle = new Rectangle((int)StartPos.X, (int)StartPos.Y, Width, Height); rectangle = new RectangleV3(StartPos, width, height); guns = new Weapon[4]; guns[0] = new Pistol(); //guns[0].isEnemy = false; guns[1] = new Blaster(); // guns[1].isEnemy = false; guns[2] = new Lightsaber(); // guns[2].isEnemy = false; guns[3] = new Rocket(); // guns[3].isEnemy = false; //guns[1] = new Blaster(); //guns[2] = new Lightsaber(); abilities = new List <Ability>(); //abilities.Add(new Standart(this)); }
/* ~Monster() * { * if(gun is Lightsaber) * { * * } * }*/ public static void RandomSpawn(World world, GameTime gameTime) { elapsedSpawnTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds; if (elapsedSpawnTime > reloadSpawn) { elapsedSpawnTime = 0f; int min = 400; int max = 1200; Random rand = new Random(); int x; int y; x = rand.Next(-max, max); y = rand.Next(-max, max); RectangleV3 rec = new RectangleV3(new Vector2(x, y) + world.Hero.position, 50, 50); //Rectangle rec = new Rectangle(x, y, width, height); while (IntersectsWithCharAndWalls(rec, world.entities) || Math.Abs(y) * Math.Abs(y) + Math.Abs(x) * Math.Abs(x) < min * min) { x = rand.Next(-max, max); y = rand.Next(-max, max); rec = new RectangleV3(new Vector2(x, y) + world.Hero.position, 50, 50); } Monster mon = new Monster(new Vector2(x, y) + world.Hero.position); mon.gun = crGun(world); mon.gun.isEnemy = true; world.entities.Add(mon); } }
public override void BeforeCheck(World world, GameTime gameTime) { flx = false; fly = false; recX = new RectangleV3(new Vector2((int)(Hero.position.X + Hero.move.X), (int)(Hero.position.Y)), Hero.width, Hero.height); recY = new RectangleV3(new Vector2((int)(Hero.position.X), (int)(Hero.position.Y + Hero.move.Y)), Hero.width, Hero.height); }
public bool Intersect(RectangleV3 rectangle) { int Xmin = (int)-centre.X; int Xmax = r.Width - (int)centre.X; int Ymin = (int)-centre.Y; int Ymax = r.Height - (int)centre.Y; Vector2 V = new Vector2(rectangle.r.X - r.X, rectangle.r.Y - r.Y); int x = (int)(cos * (rectangle.x1 + V.X) + sin * (rectangle.y1 + V.Y)); int y = (int)(-sin * (rectangle.x1 + V.X) + cos * (rectangle.y1 + V.Y)); if (Xmin <= x && Xmax >= x && Ymin <= y && Ymax >= y) { return(true); } x = (int)(cos * (rectangle.x2 + V.X) + sin * (rectangle.y2 + V.Y)); y = (int)(-sin * (rectangle.x2 + V.X) + cos * (rectangle.y2 + V.Y)); if (Xmin <= x && Xmax >= x && Ymin <= y && Ymax >= y) { return(true); } x = (int)(cos * (rectangle.x3 + V.X) + sin * (rectangle.y3 + V.Y)); y = (int)(-sin * (rectangle.x3 + V.X) + cos * (rectangle.y3 + V.Y)); if (Xmin <= x && Xmax >= x && Ymin <= y && Ymax >= y) { return(true); } x = (int)(cos * (rectangle.x4 + V.X) + sin * (rectangle.y4 + V.Y)); y = (int)(-sin * (rectangle.x4 + V.X) + cos * (rectangle.y4 + V.Y)); if (Xmin <= x && Xmax >= x && Ymin <= y && Ymax >= y) { return(true); } //x = (int)(cos * (rectangle.centre.X + V.X) + sin * (rectangle.centre.Y + V.Y)); y = (int)(-sin * (rectangle.centre.X + V.X) + cos * (rectangle.centre.Y + V.Y)); //if (Xmin <= x && Xmax >= x && Ymin <= y && Ymax >= y) return true; Xmin = (int)-rectangle.centre.X; Xmax = rectangle.r.Width - (int)rectangle.centre.X; Ymin = (int)-rectangle.centre.Y; Ymax = rectangle.r.Height - (int)rectangle.centre.Y; V = new Vector2(r.X - rectangle.r.X, r.Y - rectangle.r.Y); x = (int)(rectangle.cos * (x1 + V.X) + rectangle.sin * (y1 + V.Y)); y = (int)(-rectangle.sin * (x1 + V.X) + rectangle.cos * (y1 + V.Y)); if (Xmin <= x && Xmax >= x && Ymin <= y && Ymax >= y) { return(true); } x = (int)(rectangle.cos * (x2 + V.X) + rectangle.sin * (y2 + V.Y)); y = (int)(-rectangle.sin * (x2 + V.X) + rectangle.cos * (y2 + V.Y)); if (Xmin <= x && Xmax >= x && Ymin <= y && Ymax >= y) { return(true); } x = (int)(rectangle.cos * (x3 + V.X) + rectangle.sin * (y3 + V.Y)); y = (int)(-rectangle.sin * (x3 + V.X) + rectangle.cos * (y3 + V.Y)); if (Xmin <= x && Xmax >= x && Ymin <= y && Ymax >= y) { return(true); } x = (int)(rectangle.cos * (x4 + V.X) + rectangle.sin * (y4 + V.Y)); y = (int)(-rectangle.sin * (x4 + V.X) + rectangle.cos * (y4 + V.Y)); if (Xmin <= x && Xmax >= x && Ymin <= y && Ymax >= y) { return(true); } // x = (int)(rectangle.cos * (centre.X + V.X) + rectangle.sin * (centre.Y + V.Y)); y = (int)(-rectangle.sin * (centre.X + V.X) + rectangle.cos * (centre.Y + V.Y)); // if (Xmin <= x && Xmax >= x && Ymin <= y && Ymax >= y) return true; return(false); }
public Wall(int x, int y) { //name = "wall"; texture = iron; this.y = y; this.x = x; // rectangle = new Rectangle(x * CellWIDTH, y * CellHEIGHT, CellWIDTH, CellHEIGHT); rectangle = new RectangleV3(new Vector2(x * CellWIDTH, y * CellHEIGHT), CellWIDTH, CellHEIGHT); }
public Monster(Vector2 StartPos) { position = StartPos; speed = 7f; health = 1; rectangle = new RectangleV3(new Vector2((int)position.X, (int)position.Y), width, height); gun = new Lightsaber(); gun.isEnemy = true; }
public float existingTime = 8000; //положенное время существования public RocketFire(Vector2 startPosition, Vector2 direction, bool isEnemy) { this.damage = 3; this.position = startPosition; this.direction = direction; this.direction.Normalize(); this.currentExistingTime = 0; rec = new RectangleV3(startPosition, 0.5f, 0.5f, direction, width, height); this.isEnemy = isEnemy; }
public void Check(World world) { bool flx = false; bool fly = false; RectangleV3 recX = new RectangleV3(new Vector2((int)(position.X + move.X), (int)(position.Y)), width, height); RectangleV3 recY = new RectangleV3(new Vector2((int)(position.X), (int)(position.Y + move.Y)), width, height); foreach (Entity e in world.entities) { if (!e.Equals(this)) { if (e is Wall) { Wall w = (Wall)e; //if (Intersects(recX, w.rectangle)) if (w.rectangle.Intersect(recX)) { flx = true; } if (w.rectangle.Intersect(recY)) { fly = true; } } else if (e is Character) { Character ch = (Character)e; if (ch.rectangle.Intersect(recX)) { flx = true; } if (ch.rectangle.Intersect(recY)) { fly = true; } } } } if (!flx) { //rectangle.Move(new Vector2(move.X, 0)); position.X += move.X; } if (!fly) { //rectangle.Move(new Vector2(0, move.Y)); position.Y += move.Y; } rectangle.r.X = (int)position.X; rectangle.r.Y = (int)position.Y; }
public LightsaberFire(Vector2 startPosition, Vector2 direction, bool isEnemy, Lightsaber lightsaber) { this.lightsaber = lightsaber; this.damage = 1; this.position = startPosition; this.direction = direction; // rec2 = new RectangleV2(direction, width, height, startPosition); // rectangle = new Rectangle((int)startPosition.X, (int)startPosition.Y, width, height); rec = new RectangleV3(startPosition, 0.5f, 0.5f, direction, width, height); this.isEnemy = isEnemy; /* this.width = width; * this.height = height; * this.startpos = startpos; * Pos = startpos; * rectangle = new Rectangle((int)startpos.X, (int)startpos.Y, width, height); * Velocity = new Vector2(endpos.X-startpos.X , endpos.Y-startpos.Y); * rec2 = new RectangleV2(Velocity, width, height, startpos); * damage = 1;*/ }
static bool IntersectsWithCharAndWalls(RectangleV3 r, List <Entity> list) { foreach (Entity e in list) { if (e is Wall) { Wall wall = (Wall)e; if (r.Intersect(wall.rectangle)) { return(true); } } else if (e is Character) { Character ch = (Character)e; if (r.Intersect(ch.rectangle)) { return(true); } } } return(false); }