Beispiel #1
0
        public Player(Vector2 position,Sprite sprite,ScreenDebuger screenDebuger,ContentManager content,GraphicsDevice graphicsDevice,Level level)
        {
            this.content = content;
            this.screenDebuger = screenDebuger;
            playerSprite = sprite;
            this.position = position;
            playerSprite.Position = this.position;
            Spawn = position;
            this.level = level;
            this.platforms = level.Platforms;
            random = new Random();
            Health = 100;

            runningAnimation = new Animation(content.Load<Texture2D>("SpriteSheets/running"), position, 100, 100, 8, 150, 1f, true, graphicsDevice);
            currentAnimation = runningAnimation;
        }
Beispiel #2
0
        public void Draw(SpriteBatch spriteBatch)
        {
            SpriteEffects spriteEffect;
            if (velocity.X < 0)
            {
                spriteEffect = SpriteEffects.FlipHorizontally;
            }
            else { spriteEffect = SpriteEffects.None; }

            if (Math.Abs(velocity.X) < 30)
            {
                currentAnimation.Active = false;
                currentAnimation.currentFrame = 0;
                playerSprite.Flip = spriteEffect;
                playerSprite.Draw(spriteBatch);
            }
            else //we are running
            {
                currentAnimation.Active = true;
                currentAnimation = runningAnimation;
                currentAnimation.spriteEffects = spriteEffect;
                currentAnimation.Draw(spriteBatch);
            }

            spriteBatch.DrawRectangle(playerBounds, Color.Red);

             #if DEBUG
            spriteBatch.DrawRectangle(playerBounds,Color.Red);
             #endif
        }
Beispiel #3
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);

            // TODO: use this.Content to load your game content here
            map = Content.Load<Map>("desert");

            // Create a new simple point light texture to use for the lights
            this.lightTexture = LightTextureBuilder.CreatePointLight(this.GraphicsDevice, 512);

            // Load sprites
            playerImage = Content.Load<Texture2D>("player");
            gemImage = Content.Load<Texture2D>("gem");

            //Test Sprite
            testSprite = new Sprite(playerImage, new Vector2(100, -100), krypton);
            testSprite.Position = new Vector2(200, 20);
            testSprite.Velocity = new Vector2(0.2f, 0f);

            //Dont add it cuase
            sprites.Add(testSprite);

            //Create player
            player = new Player(Vector2.Zero,testSprite);
            // Load the player resources
            Animation playerAnimation = new Animation();
            Texture2D playerTexture = Content.Load<Texture2D>("shipAnimation");
            playerAnimation.Initialize(playerTexture, Vector2.Zero, 115, 69, 8, 45, Color.White, 1f, true, this.GraphicsDevice);
            player.Position = new Vector2(200, 200);
            //player.Velocity = new Vector2(0f, 0f);

            testSprite2 = new Sprite(playerImage, new Vector2(100, -100), krypton);
            testSprite2.Position = new Vector2(100, 20);
            testSprite2.Velocity = new Vector2(0f, 0.1f);
            sprites.Add(testSprite2);

            // Create a light we can control
            torch = new Light2D()
            {
                Texture = this.lightTexture,
                X = 0,
                Y = 0,
                Range = 600,
                Intensity = 0.5f,
                Color = Color.White,
                ShadowType = ShadowType.Illuminated,
                Fov = MathHelper.PiOver2 * (float)(0.5)
            };

            this.krypton.Lights.Add(this.torch);

            /*
            // Make some random lights!
            for (int i = 0; i < 9; i++)
            {
                byte r = (byte)(this.random.Next(255 - 32) + 32);
                byte g = (byte)(this.random.Next(255 - 32) + 32);
                byte b = (byte)(this.random.Next(255 - 32) + 32);

                Light2D light = new Light2D()
                {
                    Texture = lightTexture,
                    Range = (float)(this.random.NextDouble() * 200 + 100),
                    Color = new Color(r, g, b),
                    //Intensity = (float)(this.mRandom.NextDouble() * 0.25 + 0.75),
                    Intensity = 0.8f,
                    Angle = MathHelper.TwoPi * (float)this.random.NextDouble(),
                    X = (float)(this.random.NextDouble() * 500),
                    Y = (float)(this.random.NextDouble() * 500),
                };

                // Here we set the light's field of view
                if (i % 2 == 0)
                {
                    light.Fov = MathHelper.PiOver2 * (float)(this.random.NextDouble() * 0.75 + 0.25);
                }

                this.krypton.Lights.Add(light);
            }
             */

            /*
            int x = 10;
            int y = 10;
            float w = 1000;
            float h = 1000;

            // Make lines of lines of hulls!
            for (int j = 0; j < y; j++)
            {
                // Make lines of hulls!
                for (int i = 0; i < x; i++)
                {
                    var posX = (((i + 0.5f) * w) / x) - w / 2 + (j % 2 == 0 ? w / x / 2 : 0);
                    var posY = (((j + 0.5f) * h) / y) - h / 2; // +(i % 2 == 0 ? h / y / 4 : 0);

                    var hull = ShadowHull.CreateRectangle(Vector2.One * 10f);
                    hull.Position.X = posX;
                    hull.Position.Y = posY;
                    hull.Scale.X = (float)(this.random.NextDouble() * 2.75f + 0.25f);
                    hull.Scale.Y = (float)(this.random.NextDouble() * 2.75f + 0.25f);

                    krypton.Hulls.Add(hull);
                }
            }
            */ //Test lights
        }