/// <summary> /// Initialise une nouvelle instance de la class <see cref="GameEntity"/>. /// </summary> /// <param name="position">Position</param> /// <param name="speed">Vitesse</param> /// <param name="hp">Points de vie</param> /// <param name="sprite">Sprite</param> public GameEntity(Vecteur2D position, double speed, int hp, Bitmap sprite) { this.Position = position; this.Speed = speed; this.hp = hp; this.Sprite = new Bitmap(sprite); }
/// <summary> /// Initialise une nouvelle instance de la class <see cref="GameEntity"/>. /// </summary> /// <param name="position">The position.</param> public GameEntity(Vecteur2D position) { this.Position = new Vecteur2D(position.x, position.y); this.Speed = 50; this.hp = 1; this.Sprite = GameSprites.Ship9; }
public void Update(double time) { listNode = Engine.instance.NodeListByType[typeof(MovePlayerNode)]; Vecteur2D movementVector = new Vecteur2D(); if (Engine.instance.keyPressed.Contains(Keys.Left)) { movementVector += new Vecteur2D(-time, 0); } if (Engine.instance.keyPressed.Contains(Keys.Right)) { movementVector += new Vecteur2D(time, 0); } if (movementVector != new Vecteur2D()) { foreach (MovePlayerNode n in listNode) { Vecteur2D tempPos = n.TransformComponent.Position + movementVector * n.VelocityComponent.Velocity; if (tempPos.x > RenderForm.instance.Width - n.RenderComponent.sprite.Width - 15) //-25 pour empecher le bug de fenetre ou la sprite sort a moitié { tempPos.x = RenderForm.instance.Width - n.RenderComponent.sprite.Width - 15; //-25 pour empecher le bug de fenetre ou la sprite sort a moitié } else if (tempPos.x < 0) { tempPos.x = 0; } n.TransformComponent.Position = tempPos; } } }
public Ennemy(Vecteur2D p, Double s, int hp, Bitmap spr) : base(p, s, hp) { position = p; speed = s; this.hp = hp; this.sprite = spr; }
/// <summary> /// Constructeur /// </summary> /// <param name="e">L'entité du composant</param> /// <param name="a">L'image à afficher</param> public RenderComponent(Entity e, Image a) : base(e) { sprite = a; if (a == null) { throw new Exception("image is null"); } view = new Vecteur2D(); }
public EnnemyLine(Vecteur2D p, Bitmap b) { for (int i = 0; i < 11; i++) { EnnemyShip ennemy = new EnnemyShip(new Vecteur2D((p.x) + GameVariables.offsetX.x * i, p.y), GameVariables.ennemySpeed, 7, b, GameVariables.defaultShootSpeed); ennemyList.Add(ennemy); Game.game.GameEntities.Add(ennemy); } }
/// <summary> /// Genère les enemis du schema /// </summary> /// <param name="instance">Instance de la partie</param> /// <param name="sizeLine">Taille de la ligne</param> /// <param name="start">Le coin en haut a gauche de la ligne</param> public void generateScheme(Game instance, int sizeLine, Vecteur2D start) { int offset = (sizeLine - count * scheme.GetSprite().Draw().Width) / (count + 1); start += new Vecteur2D(offset, 0); for (int i = 0; i < count; i++) { instance.AddNewGameObject(new Enemy(scheme, start, lives)); start += new Vecteur2D(offset + scheme.GetSprite().Draw().Width, 0); } }
public void LaunchMissile(double time) { foreach (ShootPlayerNode n in listNode) { n.ShootComponent.TimeSinceLastShoot += time; //Console.WriteLine("Time since last shoot: "+ n.ShootComponent.TimeSinceLastShoot); //Console.WriteLine("Fire rate: " + n.ShootComponent.FireRate); if (!Engine.instance.EntitiesList.OfType <PlayerMissile>().Any()) { n.ShootComponent.TimeSinceLastShoot = 0; Vecteur2D posMissile = n.PlayerPosition.Position + new Vecteur2D(15, -15); PlayerMissile missile = new PlayerMissile(posMissile); Engine.instance.AddEntity(missile); } } }
/// <summary> /// Vérifie si il y a collision entre l'entité actuel et une entité définis. /// </summary> /// <param name="g">GameEntity</param> /// <param name="">Faire une vérification pixel par pixel.</param> /// <returns>True si collision avéré False si aucune collision.</returns> public virtual bool CheckCollision(GameEntity g, bool isBunker = false) { if (g.Position.x > Position.x + Sprite.Width || g.Position.y > Position.y + Sprite.Height || Position.x > g.Position.x + g.Sprite.Width || Position.y > g.Position.y + g.Sprite.Height) { return(false); } for (int j = 0; j < Sprite.Height; j++) { for (int i = 0; i < Sprite.Width; i++) { Color c = new Color(); c = Sprite.GetPixel(i, j); if (c.R == 0 && c.G == 0 && c.B == 0) { Vecteur2D pixelPos = new Vecteur2D(this.Position.x + i, this.Position.y + j); //Console.WriteLine("x: {0} y: {1}", pixelPos.x, pixelPos.y); int otherPixelX = (int)pixelPos.x - (int)g.Position.x; int otherPixelY = (int)pixelPos.y - (int)g.Position.y; //Console.WriteLine("x: {0} y: {1}", otherPixelX, otherPixelY); //Console.WriteLine("Size {0};{1}", g.Sprite.Width, g.Sprite.Height); Color targetColor = Color.Red; if ((otherPixelX >= 0 && otherPixelX < g.Sprite.Width) && otherPixelY >= 0 && otherPixelY < g.Sprite.Height) { targetColor = g.Sprite.GetPixel(otherPixelX, otherPixelY); } if (targetColor.R == 0 && targetColor.G == 0 && targetColor.B == 0 && targetColor.A == 255) { if (isBunker) { g.Sprite.SetPixel(otherPixelX, otherPixelY, Color.Transparent); hp -= 1; } return(true); } } } } return(false); }
public void Update(double time) { listNode = Engine.instance.NodeListByType[typeof(MoveEnemyNode)]; foreach (MoveEnemyNode n in listNode) { if (n.TransformComponent.Position.y >= (RenderForm.instance.Size.Height * 5.2 / 6) - 30) { Engine.instance.IsDefeat = true; } Vecteur2D movementVector = new Vecteur2D(); if (n.toLeft) { movementVector += new Vecteur2D(time, 0); } else { movementVector -= new Vecteur2D(time, 0); } Vecteur2D tempPos = n.TransformComponent.Position + movementVector * n.VelocityComponent.Velocity; if (tempPos.x > RenderForm.instance.Width - n.RenderComponent.sprite.Width - 15)//-15 pour empecher le bug de fenetre ou la sprite sort a moitié { foreach (MoveEnemyNode no in listNode) { no.TransformComponent.Position.y += 25; no.VelocityComponent.Velocity.x += 4; //augmente la velocité des ennemis a chaque descente de ligne no.toLeft = false; } } else if (tempPos.x < 0) { foreach (MoveEnemyNode no in listNode) { no.TransformComponent.Position.y += 25; no.VelocityComponent.Velocity.x += 4; //augmente la velocité des ennemis a chaque descente de ligne no.toLeft = true; } } else { n.TransformComponent.Position = tempPos; } } }
public void Update(double time) { listNode = Engine.instance.NodeListByType[typeof(MoveMissileNode)]; Vecteur2D movementVector = new Vecteur2D(0, 2); foreach (MoveMissileNode n in listNode) { if (n.IsFromPlayer) { n.TransformComponent.Position += new Vecteur2D(0, -2); } else { n.TransformComponent.Position += new Vecteur2D(0, +0.5); } } }
public void Update(double time) { listNode = Engine.instance.NodeListByType[typeof(ShootEnemyNode)]; foreach (ShootEnemyNode n in listNode) { n.ShootComponent.TimeSinceLastShoot += time; if (n.ShootComponent.TimeSinceLastShoot >= n.ShootComponent.FireRate) { int probabilty = this.random.Next(0, 200000);//Changer le maximum pour diminuer la proba de tirer if (probabilty < n.ShootComponent.NextShootProbability) { n.ShootComponent.NextShootProbability = n.ShootComponent.ShootBaseProbability; n.ShootComponent.TimeSinceLastShoot = 0; Vecteur2D posMissile = n.EnemyPosition.Position + new Vecteur2D(15, 24); EnemyMissile missile = new EnemyMissile(posMissile); Engine.instance.AddEntity(missile); } else { n.ShootComponent.NextShootProbability += 1; } } } }
/// <summary> /// Initializes a new instance of the <see cref="PlayerShip" /> class. /// </summary> /// <param name="position">Position</param> /// <param name="speed">Vitesse</param> /// <param name="hp">Points de vie</param> /// <param name="sprite">Sprite</param> /// <param name="shootSpeed">Vitesse de tir des missiles</param> public PlayerShip(Vecteur2D p, Double s, int hp, Bitmap sprite, float shotspd) : base(p, s, hp, sprite, shotspd) { }
/// <summary> ///Initialise une nouvelle instance de la class <see cref="Bonus"/>. /// </summary> /// <param name="position">Position</param> /// <param name="speed">Vitesse</param> public Bonus(Vecteur2D position, double speed, int hp, BonusType bonus) : base(position, speed, hp, GameSprites.None) { this.bonusType = bonus; Sprite = GetSpriteByTypde(bonus); Console.WriteLine(String.Format("Apparition d'un bonus en {0} Type. : {1}", position, bonus.ToString())); }
public Bunker(Vecteur2D position) : base(Image.FromFile("../../Resources/bunker.png"), CollisionTag.BUNKER) { PositionComponent BunkerPosition = GetComponent(typeof(PositionComponent)) as PositionComponent; BunkerPosition.Position = position; }
/// <summary> /// Constructeur /// </summary> /// <param name="origin"></param> /// <param name="width"></param> /// <param name="height"></param> public Box(Vecteur2D origin, double width, double height) : this(origin.x, origin.y, width, height) { }
/// <summary> /// Initializes a new instance of the <see cref="Bullet" /> class. /// </summary> /// <param name="position">The position.</param> /// <param name="speed">The speed.</param> /// <param name="hp">The hp.</param> /// <param name="direction">The direction.</param> /// <param name="sprite">The sprite.</param> public Bullet(Vecteur2D position, double speed, int hp, Direction direction, Bitmap sprite) : base(position, speed, hp, sprite) { this.direction = direction; Console.WriteLine(String.Format("Création d'un missile en {0} Dir. : {1}", position, direction)); }
/// <summary> /// Constructeur /// </summary> /// <param name="e">L'entité du composant</param> /// <param name="tag">Le tag de collision</param> /// <param name="origin">Le vecteur 2D permettant de connaitre le point d'origine de la hitbox </param> /// <param name="width">la largeur de la hitbox</param> /// <param name="height">la hauteur de la hitbox</param> public HitBoxComponent(Entity e, CollisionTag tag, Vecteur2D origin, double width, double height) : base(e) { HitBox = new Box(origin, width, height); //Console.WriteLine(HitBox.ToString()); this.tag = tag; }
public MissileAbs(Vecteur2D origin, Image img, CollisionTag tag) : base(img, tag) { NbPixelToDestroy = 14; PositionComponent startPos = GetComponent(typeof(PositionComponent)) as PositionComponent; VelocityComponent velocity = GetComponent(typeof(VelocityComponent)) as VelocityComponent; }
public SpecialEnnemyShip(Vecteur2D p, Double s, int hp, Bitmap spr, Direction d) : base(p, s, hp, spr) { direction = d; }
/// <summary> /// Initializes a new instance of the <see cref="ShipBaseEntity" /> class. /// </summary> /// <param name="position">Position</param> /// <param name="speed">Vitesse</param> /// <param name="hp">Points de vie</param> /// <param name="sprite">Sprite</param> /// <param name="shootSpeed">Vitesse de tir des missiles</param> public ShipBaseEntity(Vecteur2D p, double s, int hp, Bitmap sprite, float shootSpeed) : base(p, s, hp, sprite) { Bullets = new List <Bullet>(); ShootingSpeed = shootSpeed; }
public VelocityComponent(Entity e) : base(e) { Velocity = new Vecteur2D(); }
public EnnemyShip(Vecteur2D p, Double s, int hp, Bitmap spr, float shotspd) : base(p, s, hp, spr, shotspd) { }
public Bunker(Vecteur2D p, Double s, int hp, Bitmap sprite) : base(p, s, hp, sprite) { }
public PositionComponent(Entity e) : base(e) { position = new Vecteur2D(); LocalScale = new Vecteur2D(); }
public PlayerMissile(Vecteur2D origin) : base(origin, Image.FromFile("../../Resources/shoot2.png"), CollisionTag.PLAYERMISSILE) { PositionComponent startPos = GetComponent(typeof(PositionComponent)) as PositionComponent; startPos.Position = origin; }
public Player(Vecteur2D p, Double s, int hp) : base(p, s, hp) { sprite = GameSprites.PlayerSprite; }