Beispiel #1
0
        public Level(Game1 game)
        {
            actors = new List<Actor>();
            actors.Add(new Actor(game,new Vector2(50,50),"Actors\\zombie_sheet", "White"));
            actors.ElementAt(0).ControlCharacter();
            currentActor = actors.ElementAt(0);
            sanctuaryPos = new Vector2(279, 233);
            humans = new List<Human>();
            this.game = game;
            switchSfx = game.Content.Load<SoundEffect>("Sfx\\switch");
            zombieColors = new Color[] { Color.White, Color.Blue, Color.Red, Color.Green };

            levelDesc = new byte[H,W] {
                                        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                                        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                                        {0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
                                        {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
                                        {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
                                        {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
                                        {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
                                        {0,0,0,1,0,0,0,0,0,RTL,RTR,0,0,0,0,0,0,1,0,0,0},
                                        {0,0,0,1,0,0,0,0,0,RBL,RBR,0,0,0,0,0,0,1,0,0,0},
                                        {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
                                        {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
                                        {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
                                        {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
                                        {0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
                                        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                                        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                                      };

            ground = new Ground[H, W];

            this.Init();
        }
Beispiel #2
0
        public void Update(GameTime gameTime, Actor zombie, Vector2 sanctuaryPos)
        {
            if (!isDead)
            {
                if (isHit)
                {

                    bloodAnim.Update(gameTime);

                    if (bloodAnim.IsFinished())
                    {
                        isHit = false;
                    }
                }

                Vector2 distance = (zombie.getPos() - this.position);
                float len = distance.Length();

                if (len <= 50 || isFleeing)
                {

                    isFleeing = true;
                    this.animateSpr.Update(gameTime);

                    Vector2 dir = sanctuaryPos - position;

                    if (dir.Length() < 20)
                    {
                        this.isSafe = true;
                        isFleeing = false;
                    }
                    dir.Normalize();
                    this.angle = (float)Math.Atan2((double)dir.Y, (double)dir.X);

                    this.position.X += SPEED * dir.X;
                    this.position.Y += SPEED * dir.Y;

                }
                else if (!isFleeing)
                {

                    if (len >= 100)
                        isSafe = false;
                    if (!isSafe)
                    {
                        this.animateSpr.Update(gameTime);
                        Vector2 dir = destination - position;

                        if (dir.Length() < 100)
                        {
                            makeRandomDestination();
                            dir = destination - position;
                        }
                        dir.Normalize();

                        this.angle = (float)Math.Atan2((double)dir.Y, (double)dir.X);

                        this.position.X += SPEED * dir.X;
                        this.position.Y += SPEED * dir.Y;
                    }
                }

                this.bounds.X = (int)this.position.X;
                this.bounds.Y = (int)this.position.Y;
                this.healthBar.X = (int)this.position.X - 10;
                this.healthBar.Y = (int)this.position.Y - 10;
                this.healthBar.Width = health;
            }
        }
Beispiel #3
0
        private void EnableSwitchCharacter()
        {
            KeyboardState ks = Keyboard.GetState();

            if (ks.IsKeyDown(Keys.D1))
            {

                if (!actors.ElementAt(0).isControlled)
                {
                    switchSfx.Play();
                    currentActor.ReleaseCharacter();
                    currentActor = actors.ElementAt(0);
                    currentActor.ControlCharacter();
                }
            }
            else if (ks.IsKeyDown(Keys.D2))
            {
                if (actors.Count >= 2)
                {
                    if (!actors.ElementAt(1).isControlled)
                    {
                        switchSfx.Play();
                        currentActor.ReleaseCharacter();
                        currentActor = actors.ElementAt(1);
                        currentActor.ControlCharacter();
                    }
                }
            }

            else if (ks.IsKeyDown(Keys.D3))
            {
                if (actors.Count >= 3)
                {
                    if (!actors.ElementAt(2).isControlled)
                    {
                        switchSfx.Play();
                        currentActor.ReleaseCharacter();
                        currentActor = actors.ElementAt(2);
                        currentActor.ControlCharacter();
                    }
                }
            }
            else if (ks.IsKeyDown(Keys.D4))
            {
                if (actors.Count >= 4)
                {
                    if (!actors.ElementAt(3).isControlled)
                    {
                        switchSfx.Play();
                        currentActor.ReleaseCharacter();
                        currentActor = actors.ElementAt(3);
                        currentActor.ControlCharacter();
                    }
                }
            }
        }
Beispiel #4
0
        public void HandleColissions()
        {
            for (int i = 0; i < this.humans.Count; ++i)
            {

                if (this.currentActor.HasAttacked(humans[i]))
                {

                    humans[i].takeDamage();
                    if (humans[i].checkIfDead() && !humans[i].checkIfSafe())
                    {

                        if (actors.Count < 4)
                        {
                            string [] tmpnames = new string[]{"White", "Blue", "Red", "Green"};
                            Actor tmpActor = new Actor(this.game, humans[i].getPos(), "Actors\\zombie_sheet", tmpnames[actors.Count]);
                            tmpActor.setColor(zombieColors[actors.Count]);
                            actors.Add(tmpActor);
                            humans.RemoveAt(i);
                            humansLeft--;
                            break;
                        }
                        else
                        {
                            humansLeft--;
                            break;
                        }
                    }

                    break;

                }
            }
        }