Ejemplo n.º 1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Tile[][] map = LevelLoader.loadMap("Content/bytecode.doot");
            Texture2D sheet = Content.Load<Texture2D>("sheet");
            state = new GameState(Content, GraphicsDevice, map);

            // TODO: use this.Content to load your game content here
        }
Ejemplo n.º 2
0
        public override void Draw(SpriteBatch spriteBatch, GameState game)
        {
            current_animation.Draw(spriteBatch, GetDrawPos(game.camera), Color.White, spriteEffects, hitbox);
            current_animation.Update();

            if (untilFinished && current_animation.Done)
                untilFinished = false;
            if (untilTick && Tick == 0)
                untilTick = false;
            else
                Tick--;
        }
Ejemplo n.º 3
0
        protected void ShootDoot(Vector2 v, GameState game)
        {
            float offset_x = 0.5f;
            if (spriteEffects == SpriteEffects.FlipHorizontally)
            {
                offset_x *= -1;
                v.X *= -1f;
            }
            Vector2 p = new Vector2(
                pos.X + 0.5f + offset_x,
                pos.Y + 0.6f);

            game.AddDoot(p, v);
        }
Ejemplo n.º 4
0
        public override void Update(GameState game)
        {
            base.Update(game);

            old_keyboard = keyboard;
            keyboard = Keyboard.GetState();

            bool shoot = PressedKey(Keys.Space);

            if (touch_down.Base || onLadder())
            {
                if (touch_down.Instant)//cancel air animations
                    ForceAnimation();

                cam_Y = pos.Y;
                float speed_x = 0.15f;

                bool right = keyboard.IsKeyDown(Keys.Right);
                bool left = keyboard.IsKeyDown(Keys.Left);
                if (keyboard.IsKeyDown(Keys.Down))
                {
                    if (onLadder())
                    {
                        velocity.Y = 0.12f;
                    }
                    else
                    {
                        SetAnimation(crouch);
                        velocity.X = 0;
                    }

                    if (shoot)
                    {
                        ShootDoot(new Vector2(0.3f, -0.25f), game);
                        SetAnimation(crouch + doot);
                        PlayAnimationUntilFinished();
                    }
                }
                else
                {
                    if ((!right && !left) || (right && left))
                    {
                        velocity.X = 0;
                        SetAnimation(idle);
                    }
                    else
                    {
                        if (right)
                        {
                            velocity.X = speed_x;
                            if (surface_k * -speed_x > 0)
                                velocity.Y += surface_k * -speed_x;

                            spriteEffects = SpriteEffects.None;
                            if (current_animation_index == running + doot)
                                SetSyncAnimation(running);
                            else
                                SetAnimation(running);
                        }
                        if (left)
                        {
                            velocity.X = -speed_x;
                            if (surface_k * speed_x > 0)
                                velocity.Y += surface_k * speed_x;

                            spriteEffects = SpriteEffects.FlipHorizontally;
                            if (current_animation_index == running + doot)
                                SetSyncAnimation(running);
                            else
                                SetAnimation(running);
                        }
                    }
                    if (keyboard.IsKeyDown(Keys.Up))
                    {
                        velocity.Y = onLadder() ? -0.12f : -0.36f;
                        SetAnimation(jump);
                        ForceAnimation();
                    }
                    else
                    {
                        if (onLadder())
                        {
                            velocity.Y = 0;
                        }
                        if (shoot)
                        {
                            {
                                ShootDoot(new Vector2(0.3f, 0f), game);
                                if (velocity.X == 0)
                                {
                                    SetSyncAnimation(idle + doot);
                                    PlayAnimationUntilFinished();
                                }
                                else
                                {
                                    SetSyncAnimation(running + doot);
                                    PlayAnimationUntilTick(16);
                                }
                            }
                        }
                    }
                }
            }
            else if (Math.Abs(velocity.Y) > 0.1f)
            {
                SetAnimation(jump);
            }
            if (current_animation_index == jump)//jump
            {
                if (shoot)
                {
                    ShootDoot(new Vector2(0.3f, 0.25f), game);
                    SetSyncAnimation(jump + doot);
                    PlayAnimationUntilFinished();
                }
                else if (keyboard.IsKeyDown(Keys.Down))
                    SetAnimation(crouch);
            }
        }
Ejemplo n.º 5
0
        public virtual void Update(GameState game)
        {
            //gravity
            if ((surface_k == 0 || !touch_down.Base) && !onLadder())
            {
                velocity.Y += gravity;
            }

            //collision
            game.UpdatePhysicalObject(this);
        }
Ejemplo n.º 6
0
        public override void Update(GameState game)
        {
            base.Update(game);

            if (health <= 0)
                IsDead = true;
        }
Ejemplo n.º 7
0
        public override void Update(GameState game)
        {
            base.Update(game);

            if (touch_left.Instant)
            {
                velocity.X = speed;
            }
            if (touch_right.Instant)
            {
                velocity.X = -speed;
            }
        }
Ejemplo n.º 8
0
        public virtual void Draw(SpriteBatch spriteBatch, GameState game)
        {
            //set up position relative to camera
            Vector2 drawpos = GetDrawPos(game.camera);

            spriteBatch.Draw(texture, new Rectangle((int)drawpos.X, (int)drawpos.Y, texture.Width, texture.Height),
                new Rectangle(0,0,texture.Width, texture.Height), Color.White, 0f, origin, SpriteEffects.None, 0f);
        }
Ejemplo n.º 9
0
        public override void Update(GameState game)
        {
            base.Update(game);

            if (touch_down.Instant
                || touch_left.Instant
                || touch_right.Instant
                || touch_up.Instant)
            {
                if (gravity == 0)
                {
                    if (touch_down.Instant || touch_up.Instant)
                        velocity.Y = -start_vel.Y;
                    else
                        velocity.X = -start_vel.X;
                    gravity = 0.02f;

                    velocity /= 2f;
                }
                else
                    IsDead = true;
            }
        }