Пример #1
0
 public void setSpear(SpearClass spr)
 {
     spear = spr;
     if (spear != null)
     {
         spear.setOwner(this);
     }
 }
Пример #2
0
        public void LoadContent(ContentManager Content)
        {
            Vector2 negPos = new Vector2(-100, -100);
            activePlayers = 0;
            if (playersInGame[0]) {
                players[0] = player1;
                activePlayers++;
            }
            else
                player1.active = false;
            if (playersInGame[1]) {
                players[1] = player2;
                activePlayers++;
            }
            else
                player2.active = false;
            if (playersInGame[2]) {
                players[2] = player3;
                activePlayers++;
            }
            else
                player3.active = false;
            if (playersInGame[3]) {
                players[3] = player4;
                activePlayers++;
            }
            else
                player4.active = false;

            Vector2 offset = new Vector2(-4, -4);
            Texture2D bar = Content.Load<Texture2D>("bar");
            Texture2D dust = Content.Load<Texture2D>("Dust_Trail");
            Texture2D dustPoof = Content.Load<Texture2D>("Dust_Poof");
            control_diagram = Content.Load<Texture2D>("controller");
            scores_bg = Content.Load<Texture2D>("scores");
            Texture2D powerup = Content.Load<Texture2D>("powerups");

            for(int i = 0; i < 4; i++)
            {
                if (players[i] != null && players[i].active)
                {
                    players[i].Initialize(Content.Load<Texture2D>(playerTexts[i]), negPos, screenSize, null, players, playerOffsets[playerCharNums[i]], bar, charWidths[playerCharNums[i]]);
                    players[i].moveFrames = charFrameData[playerCharNums[i],0];
                    players[i].idles = idleAnim[playerCharNums[i]];
                    players[i].frameLength = charFrameData[playerCharNums[i], 1];
                    players[i].armOffset = new Vector2(charFrameData[playerCharNums[i], 2], charFrameData[playerCharNums[i], 3]);
                    players[i].shoulder = new Vector2(charFrameData[playerCharNums[i], 4], charFrameData[playerCharNums[i], 5]);
                    players[i].throwWidth = charFrameData[playerCharNums[i], 6];
                    players[i].throwHeight = charFrameData[playerCharNums[i], 7];
                    players[i].flipOff = charFrameData[playerCharNums[i], 8];
                    players[i].flipOrigin = charFrameData[playerCharNums[i], 9];
                }
            }

            //Setup for common player resources
            foreach (PlayerClass p in players)
            {
                if (p != null)
                {
                    p.deadText = Content.Load<Texture2D>("spriteDead");

                    p.Death_Sound = Content.Load<SoundEffect>("audio/sfx/Player_Death").CreateInstance();

                    p.Jump_Sound = Content.Load<SoundEffect>("audio/sfx/Player_Jump").CreateInstance();

                    p.Blink_Sound = Content.Load<SoundEffect>("audio/sfx/Player_Blink").CreateInstance();

                    p.Unblink_Sound = Content.Load<SoundEffect>("audio/sfx/Player_Blink").CreateInstance();

                    p.dustEffect = dust;

                    p.dustPoof = dustPoof;

                    p.aniList = animations;

                }
            }

            Texture2D spearTex = Content.Load<Texture2D>("spearsprite");
            Texture2D indicator = Content.Load<Texture2D>("spearIndicator");

            spear1 = new SpearClass(player1, spearTex, indicator, screenSize, null, players);
            spear2 = new SpearClass(player2, spearTex, indicator, screenSize, null, players);
            spear3 = new SpearClass(player3, spearTex, indicator, screenSize, null, players);
            spear4 = new SpearClass(player4, spearTex, indicator, screenSize, null, players);

            //Setup for common spear resources
            Throw_Sound = Content.Load<SoundEffect>("audio/sfx/Spear_Throw");
            Hit_Player_Sound = Content.Load<SoundEffect>("audio/sfx/Spear_Player_Hit");
            Hit_Wall_Sound = Content.Load<SoundEffect>("audio/sfx/Spear_Wall_Hit");
            Stab_Sound = Content.Load<SoundEffect>("audio/sfx/Spear_Attack");
            foreach (SpearClass s in spears)
            {
                s.Throw_Sound = Throw_Sound.CreateInstance();
                s.Hit_Player_Sound = Hit_Player_Sound.CreateInstance();
                s.Hit_Wall_Sound = Hit_Wall_Sound.CreateInstance();
                s.Stab_Sound = Stab_Sound.CreateInstance();
            }

            StreamReader[] mapData = new StreamReader[5];
            for(int i = 0; i < 5; i++) {
                mapData[i] = File.OpenText("Content/MapData/"+maps.Maps()[i]+".map");
                mapObs[i] = new Map();
                mapObs[i].Initialize(Content.Load<Texture2D>("MapData/"+maps.Maps()[i]+"Color"), mapData[i].ReadToEnd(), 32, 50, 30, players, powerup);
            }
            font = Content.Load<SpriteFont>("miramo30");

            resetMap();
        }
Пример #3
0
        public void Update(KeyboardState input, GamePadState padState, GameTime gameTime)
        {
            //Update move animation, this will have to be separated into Roth and Bat as Bat doesn't stop moving her wings when still.
            if (idles)
            {
                next();
            }

            if (!active)
            {
                return;
            }
            //debug stuff goes here
            if ((input.IsKeyDown(Keys.Q)))
            {
                this.bounce = !this.bounce;
            }
            if (blinkBlocked)
            {
                if ((float)gameTime.TotalGameTime.TotalSeconds - blockTime > DEATHTIMER)
                {
                    blinkBlocked = false;
                }
            }
            if (blinked)
            {
                if (velocity.X != 0 && atRest)
                {
                    dustTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (dustTimer < 0)
                    {
                        Animation poof = new Animation(dustEffect, new Vector2(playerRect.X - 30, playerRect.Y + playerRect.Height - 16), 20f, 6, aniList, directionFacing);
                        dustTimer = TRAILTIMER;
                    }
                }
                if (deathTimer < -1)
                {
                    blinkJuice -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (blinkJuice <= 0)
                    {
                        blinkJuice = 0;
                        Boolean blocked = inPlayer();
                        if (!blocked)
                        {
                            blocked = inWall();
                        }
                        if (!blocked)
                        {
                            blinked       = false;
                            curMultiplier = 1f;
                            Unblink_Sound.Play();
                            blinkCoolDown = BLINKCOOL;
                            stunTimer     = STUNTIME;
                            deathTimer    = -2;
                        }
                        else
                        {
                            deathTimer = DEATHTIMER;
                        }
                    }
                }
                else
                {
                    deathTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds;

                    if (deathTimer <= 0)
                    {
                        setDead(true, null, "EXPIRE");
                        blinked = false;
                        Unblink_Sound.Play();
                        curMultiplier = 1f;
                    }
                }
            }
            else
            {
                if (blinkJuice < MAXBLINKJUICE)
                {
                    blinkJuice += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (blinkJuice > MAXBLINKJUICE)
                    {
                        blinkJuice = MAXBLINKJUICE;
                    }
                }
            }

            if (blinkCoolDown > 0)
            {
                blinkCoolDown -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            if (stunTimer > 0)
            {
                stunTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            //Blink
            if ((input.IsKeyDown(Keys.LeftAlt) || padState.IsButtonDown(Buttons.LeftShoulder)) && !blinkKeyDown && !blinkBlocked)
            {
                blink();
            }
            else if (blinkKeyDown && (input.IsKeyUp(Keys.LeftAlt) && padState.IsButtonUp(Buttons.LeftShoulder)))
            {
                blinkKeyDown = false;
            }
            // Use Powerup
            if (inventory != PowerupEnum.none && (padState.IsButtonDown(Buttons.Y) || input.IsKeyDown(Keys.C)) && !dead)
            {
                //Use powerup here !
                switch (inventory)
                {
                case PowerupEnum.spearCatch:
                    spearCatch = true;
                    break;

                case PowerupEnum.shield:
                    shield = true;
                    break;

                case PowerupEnum.bombSpear:
                    //not fully
                    bombSpear = true;
                    break;

                case PowerupEnum.backupSpear:
                    backupSpear = true;
                    break;

                case PowerupEnum.unblinker:
                    unblinkEveryone((float)gameTime.TotalGameTime.TotalSeconds);
                    break;
                }
                inventory = PowerupEnum.none;
            }


            //Implicit Aim
            if (padState.ThumbSticks.Left.Length() > 0.85f)
            {
                spearVector = padState.ThumbSticks.Left;
            }

            bool moveEnd = moving;

            moving = false;
            //Are we aiming?
            if ((!(padState.IsButtonDown(Buttons.B)) && !(padState.IsButtonDown(Buttons.X))) || !hasSpear)
            {
                //Horizontal movement

                if ((input.IsKeyDown(Keys.Right) || padState.IsButtonDown(Buttons.LeftThumbstickRight)) && !dead && !victory && stunTimer <= 0)
                {
                    next();
                    moving = true;
                    if (velocity.X < ACC_CAP * curMultiplier)
                    {
                        velocity.X += SPEED * curMultiplier;
                        if (velocity.X < -SPEED)
                        {
                            velocity.X += SPEED * curMultiplier / 2;
                        }
                    }
                }
                else if ((input.IsKeyDown(Keys.Left) || padState.IsButtonDown(Buttons.LeftThumbstickLeft)) && !dead && !victory && stunTimer <= 0)
                {
                    next();
                    moving = true;
                    if (velocity.X > -ACC_CAP * curMultiplier)
                    {
                        velocity.X -= SPEED * curMultiplier;
                        if (velocity.X > SPEED)
                        {
                            velocity.X -= SPEED * curMultiplier / 2;
                        }
                    }
                }

                if (moveEnd && !moving)
                {
                    curFrame  = 0;
                    nextFrame = frameLength;
                }

                //Initiating a melee attack!
                if (attackKeyDown && spear != null)
                {
                    spear.isInUse = true;
                    //animate attack
                    attackFrameWait = attackAnimationFrames;
                    attackType      = 0;
                    attackKeyDown   = false;
                }
                //Initiating a thrown attack!
                else if (throwKeyDown && spear != null)
                {
                    throwKeyDown = false;
                    spear.setThrownBy(this);
                    spear.throwSpear();
                }
            }
            else
            {
                if (padState.IsButtonDown(Buttons.B))
                {
                    attackKeyDown = true;
                }
                if (padState.IsButtonDown(Buttons.X))
                {
                    throwKeyDown = true;
                }
                if (padState.ThumbSticks.Left.Length() > 0.85f)
                {
                    directionFacing = VectorMath.rotationFromVector(spearVector) > Math.PI || VectorMath.rotationFromVector(spearVector) < 0 ? 0 : 1;
                }
            }



            //Friction
            if (velocity.X != 0 && !padState.IsButtonDown(Buttons.LeftThumbstickRight) && !padState.IsButtonDown(Buttons.LeftThumbstickLeft) && !input.IsKeyDown(Keys.Left) && !input.IsKeyDown(Keys.Right))
            {
                float fric = curFriction;
                if (!atRest)
                {
                    fric = airFriction;
                }
                if (velocity.X < 0)
                {
                    if (velocity.X > -fric)
                    {
                        velocity.X = 0;
                    }
                    else
                    {
                        velocity.X += fric;
                    }
                }
                else
                {
                    if (velocity.X < fric)
                    {
                        velocity.X = 0;
                    }
                    else
                    {
                        velocity.X -= fric;
                    }
                }
            }

            if (victory)
            {
                if (atRest && !dead)
                {
                    velocity.Y -= (JUMP / 2);
                    atRest      = false;
                }
            }
            else
            {
                //Jump
                if ((input.IsKeyDown(Keys.LeftControl) || padState.IsButtonDown(Buttons.A) || bounce) && atRest && !dead && stunTimer <= 0)
                {
                    velocity.Y -= JUMP * curMultiplier;
                    atRest      = false;
                    Jump_Sound.Play();
                }
            }

            //Velocity applications
            int footing = arena.checkFooting(new Vector2(playerRect.X, playerRect.Y));

            if ((atRest && footing < 10) || (atRest && footing >= 20 && blinked))
            {
                atRest = false;
            }

            if (footing == 11 || footing == 21)
            {
                curFriction = iceFriction;
                SPEED       = ICESPEED;
            }
            else
            {
                curFriction = groundFriction;
                SPEED       = GROUNDSPEED;
            }


            applyMove(velocity.X < 0, velocity.Y < 0);

            //Is there an attack animation in progress?
            if (attackFrameWait > 0)
            {
                //Melee?
                if (attackType == 0 && spear != null)
                {
                    spear.meleeCheck(attackFrameWait);
                }
                attackFrameWait--;
            }
            else
            if (spear != null && spear.isInUse)
            {
                spear.isInUse = false;
            }



            blockDataUpdate();
            // Look for power up
            if (inventory == PowerupEnum.none)
            {
                inventory = arena.checkPowerup(playerRect);
            }
            arena.updatePowerup(gameTime);
            //give spear if not holding one and player has backupspear effect
            if (backupSpear && !hasSpear)
            {
                backupSpear = false;
                SpearClass s = new SpearClass(this, StateGame.spearSprite, SCREENSIZE, arena, players);
                s.Throw_Sound      = StateGame.Throw_Sound.CreateInstance();
                s.Hit_Player_Sound = StateGame.Hit_Player_Sound.CreateInstance();
                s.Hit_Wall_Sound   = StateGame.Hit_Wall_Sound.CreateInstance();
                s.Stab_Sound       = StateGame.Stab_Sound.CreateInstance();
                StateGame.spears.Add(s);
            }
            //Gravity
            if (!atRest && velocity.Y < TERMINAL_V)
            {
                velocity.Y += GRAVITY;
            }

            //Check whether player is moving left/right
            if (velocity.X > 0)
            {
                directionFacing = 1;
            }
            else if (velocity.X < 0)
            {
                directionFacing = 0;
            }
        }