Exemple #1
0
 public override void Interact(Player player, Inventaire inventaire, List <Entity> objets)
 {
     this.open = !open;
     if (open)
     {
         this.texture = side;
     }
     else
     {
         this.texture = front;
     }
 }
Exemple #2
0
 public override void Interact(Player player, Inventaire inventaire, List <Entity> objets)
 {
     this.open  = !open;
     this.solid = !solid;
     DebugConsole.addLine(this.solid.ToString());
     if (open)
     {
         this.texture = openTex;
     }
     else
     {
         this.texture = closeTex;
     }
 }
Exemple #3
0
 public override void Interact(Player player, Inventaire inventaire, List <Entity> objets)
 {
     player.addThirst(10);
     base.Interact(player, inventaire, objets);
 }
 public override void Destroy(Inventaire inventaire, List <Entity> objets, Entity entity)
 {
     inventaire.AddItem(new Item("graine", 1));
     base.Destroy(inventaire, objets, entity);
 }
 public override void Interact(Player player, Inventaire inventaire, List <Entity> objets)
 {
     player.addHunger(10);
     this.Destroy(inventaire, objets, this);
     base.Interact(player, inventaire, objets);
 }
Exemple #6
0
 public virtual void Destroy(Inventaire inventaire, List <Entity> objets, Entity entity)
 {
     objets.Remove(entity);
 }
Exemple #7
0
 public virtual void Interact(Player player, Inventaire inventaire, List <Entity> objets)
 {
 }
        public GameMenu() : base()
        {
            font  = Loader.Fonts["basic"];
            debug = false;

            floorTiles    = new Texture2D[6];
            floorTiles[0] = Loader.Images["grass"];
            floorTiles[1] = Loader.Images["grass2"];
            floorTiles[2] = Loader.Images["grass3"];
            floorTiles[3] = Loader.Images["flowers"];
            floorTiles[4] = Loader.Images["dirt"];
            floorTiles[5] = Loader.Images["woodTile"];

            DebugConsole.addLine("   -Debug Console-:");
            rectTex = Loader.Images["rect"];
            heart   = Loader.Images["heart"];
            water   = Loader.Images["water"];
            bread   = Loader.Images["bread"];

            player = new Player(new Vector2(256, 256), 100, "playerup");
            objets.Add(new Pancarte(new Vector2(14 * 16, 14 * 16), "panneau", 3, "Bienvenu sur Life In The Wild, il semblerait que vous ayez\n" +
                                    "atterit dans un terriroire inconnu. Avant de mourrir de faim,\nil est suggere de partir recuperer du bois et de la pierre\npour construire un abris et" +
                                    "de planter des graines pour\npouvoir subvenir a vos besoins." +
                                    " Les touches I et C de votre\nclavier devraient vous interesser...\nBonne Chance"));
            camera  = new Camera();
            chicken = new Chicken(new Vector2(256 + 16, 256 + 16), "chicken_left", 10);

            inventaire  = new Inventaire();
            crafting    = new Crafting(player);
            affPancarte = new AffichagePancarte();

            terrain = new Terrain(50, floorTiles);
            int mapSize = terrain.getMapSize();

            //fais apparaitre 70 arbres, buissons, cailloux...
            for (int i = 0; i <= 10000; i++)
            {
                objets.Add(new Arbre(new Vector2(rnd.Next(mapSize - 1) * 16, rnd.Next(mapSize - 1) * 16), "bush", 3));
                //objets.Add(new Rock(new Vector2(rnd.Next(mapSize-1) * 16, rnd.Next(mapSize-1) * 16), "rocks", 3));
                //objets.Add(new Arbre(new Vector2(rnd.Next(mapSize-1) * 16, rnd.Next(mapSize-1) * 16), "tree", 3));
                //objets.Add(new Arbre(new Vector2(rnd.Next(mapSize-1) * 16, rnd.Next(mapSize-1) * 16), "sapin", 3));
                //objets.Add(new Vegetable(new Vector2(rnd.Next(mapSize-1) * 16, rnd.Next(mapSize-1) * 16),"seed", "crop", 3));
            }

            //Géneration de barrieres autour du terrain

            /*for(int i = 0; i < 50; i++)
             * {
             *  objets.Add(new Arbre(new Vector2(i * 16, 0), "tree", 900));
             *  objets.Add(new Arbre(new Vector2(0, i * 16), "tree", 900));
             *  objets.Add(new Arbre(new Vector2(i * 16, 50 * 16), "tree", 900));
             *  objets.Add(new Arbre(new Vector2(50 * 16, i * 16), "tree", 900));
             * }*/

            //Vérifie qu'aucune entité n'est sur le joueur
            for (int i = 0; i < objets.Count; i++)
            {
                if (objets[i].getPosition() == player.getPosition())
                {
                    objets[i].Destroy(inventaire, objets, objets[i]);
                    DebugConsole.addLine("Destroying: " + objets[i]);
                }
            }
        }
        public virtual void Update(List <Entity> objets, int[,] map, Inventaire inventaire, Crafting crafting, AffichagePancarte affPancarte)
        {
            KeyboardState newState    = Keyboard.GetState();
            Vector2       newPosition = position;

            hunger -= .008f;
            thirst -= .008f;

            if (hunger >= 120)
            {
                hunger = 120;
            }
            if (thirst >= 120)
            {
                thirst = 120;
            }

            if (hunger <= 0 || thirst <= 0)
            {
                hp -= .05f;
            }
            else
            {
                hp = 100;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.S))
            {
                this.texture        = up;
                this.direction.Y    = 1;
                this.dir            = new Vector2(0, 1);
                this.newPosition.Y += 1;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Z))
            {
                this.texture        = down;
                this.direction.Y    = -1;
                this.dir            = new Vector2(0, -1);
                this.newPosition.Y -= 1;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Q))
            {
                this.texture        = left;
                this.direction.X    = -1;
                this.dir            = new Vector2(-1, 0);
                this.newPosition.X -= 1;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                this.texture        = right;
                this.direction.X    = 1;
                this.dir            = new Vector2(1, 0);
                this.newPosition.X += 1;
            }

            if (newState.IsKeyDown(Keys.Escape) && oldState.IsKeyUp(Keys.Escape))
            {
                if (affPancarte.getActive())
                {
                    affPancarte.Activate();
                }
                if (inventaire.getActive())
                {
                    inventaire.Activate();
                }
                if (crafting.getActive())
                {
                    crafting.Activate();
                }
            }

            // Interaction
            if (newState.IsKeyDown(Keys.E) && oldState.IsKeyUp(Keys.E))
            {
                if (CollisionManager(objets, newPosition + dir) is Entity theEntity)
                {
                    theEntity.Interact(this, inventaire, objets);
                }
            }

            // Menu inventaire
            if (newState.IsKeyDown(Keys.I) && oldState.IsKeyUp(Keys.I))
            {
                DebugConsole.addLine("Ouverture Inventaire");
                inventaire.Activate();
            }

            // Menu craft
            if (newState.IsKeyDown(Keys.C) && oldState.IsKeyUp(Keys.C))
            {
                DebugConsole.addLine("Ouverture Crafting");
                crafting.Activate();
            }

            // Labourer
            if (newState.IsKeyDown(Keys.L) && oldState.IsKeyUp(Keys.L))
            {
                map[(int)((this.position.Y + 8) / 16), (int)((this.position.X + 8) / 16)] = 4;
                mow.Play();//son
            }

            if (newState.IsKeyDown(Keys.Space) && oldState.IsKeyUp(Keys.Space))
            {
                if (CollisionManager(objets, position + dir * 4) != null)
                {
                    CollisionManager(objets, position + dir * 4).Damage(1);
                    hit.Play();
                }
                else//si on collisionne avec rien
                {
                    mow.Play();//son
                    switch (outil)
                    {
                    case 1:    //mur en pierre
                        spawnObject(objets, new Wall(new Vector2(0, 0), "wallFace", "flatrock", 2));
                        inventaire.removeItem(new Item("pierre", 1));
                        break;

                    case 2:    //puis
                        spawnObject(objets, new Well(new Vector2(0, 0), "well", 2));
                        inventaire.removeItem(new Item("pierre", 1));
                        break;

                    case 3:    //feu de camp
                        spawnObject(objets, new Arbre(new Vector2(0, 0), "campfire", 2));
                        inventaire.removeItem(new Item("bois", 1));
                        break;

                    case 4:    //porte
                        spawnObject(objets, new Door(new Vector2(0, 0), "door", "door_open", 2));
                        inventaire.removeItem(new Item("bois", 1));
                        break;

                    case 5:    //planter
                        if (map[(int)Math.Round((this.position.Y + (this.dir.Y * 16)) / 16), (int)Math.Round((this.position.X + (this.dir.X * 16)) / 16)] == 4)
                        {
                            spawnObject(objets, new Vegetable(new Vector2(0, 0), "seed", "crop", 2));
                            inventaire.removeItem(new Item("graine", 1));
                        }
                        else
                        {
                            DebugConsole.addLine(map[(int)Math.Round((this.position.X + (this.dir.X * 16)) / 16), (int)Math.Round((this.position.Y + (this.dir.Y * 16)) / 16)].ToString());
                        }
                        break;

                    case 6:    //enclume
                        spawnObject(objets, new Arbre(new Vector2(0, 0), "anvil", 2));
                        inventaire.removeItem(new Item("pierre", 1));
                        break;

                    case 7:    //parquet
                        map[(int)((this.position.Y + 8) / 16), (int)((this.position.X + 8) / 16)] = 5;
                        break;
                    }
                }
            }
            oldState = newState;
            //collision avec une pancarte
            if (CollisionManager(objets, newPosition + dir) is Pancarte thePancarte && affPancarte.getActive() == false)
            {
                affPancarte.Activate(thePancarte.getText());
            }
            base.Update(objets);
        }