コード例 #1
0
ファイル: Level.cs プロジェクト: eriksk/Ludum-Dare-48
        public bool Cleared(Character character, InputManager input)
        {
            //Check surrounding cells.
            int col = (int)Math.Floor(character.position.X / (CELL_SIZE * 2f));
            int row = (int)Math.Floor(character.position.Y / (CELL_SIZE * 2f));

            if (col > -1 && col < grid.GetLength(0) &&
                row > -1 && row < grid.GetLength(1))
            {
                Cell cell = (Cell)grid[col, row];
                tempRect.X = col * (CELL_SIZE * 2);
                tempRect.Y = row * (CELL_SIZE * 2);
                tempRect.Width = CELL_SIZE * 2;
                tempRect.Height = CELL_SIZE * 2;
                switch (cell)
                {
                    case Cell.End: //Door
                        if (character.CollRect.Intersects(tempRect))
                        {
                            if (input.KeyClicked(Keys.Space))
                            {
                                return true;
                            }
                        }
                        break;
                }
            }
            return false;
        }
コード例 #2
0
ファイル: Character.cs プロジェクト: eriksk/Ludum-Dare-48
        public void Update(float time, InputManager input, Level level)
        {
            if (alive)
            {
                //Gravity
                if (inAir)
                {
                    velocity.Y += 0.003f * time;
                }
                //Friction
                float maxSpeed = 0.4f;
                float friction = 0.003f;
                if (velocity.X > 0f)
                {
                    velocity.X -= friction * time;
                    if (velocity.X < 0f)
                    {
                        velocity.X = 0;
                        SetAnim("idle");
                    }
                }
                if (velocity.X < 0f)
                {
                    velocity.X += friction * time;
                    if (velocity.X > 0f)
                    {
                        velocity.X = 0;
                        SetAnim("idle");
                    }
                }
                position.X += velocity.X * time;
                collRect.X = (int)position.X;
                collRect.Y = (int)position.Y;
                level.DoXCollision(this);
                position.Y += velocity.Y * time;
                collRect.X = (int)position.X;
                collRect.Y = (int)position.Y;
                level.DoYCollision(this);

                if (!inAir)
                {
                    if (!level.HasFloor(this))
                    {
                        FallOff();
                    }
                }

                current += time;
                if (current > interval)
                {
                    current = 0;
                    currentFrame++;
                    if (currentFrame > animations[currentAnim].Length - 1)
                    {
                        currentFrame = 0;
                    }
                }

                if (input.KeyDown(Keys.Left))
                {
                    flipped = true;
                    velocity.X -= speed;
                    if (!inAir)
                    {
                        SetAnim("walk");
                    }
                    if (velocity.X < -maxSpeed)
                    {
                        velocity.X = -maxSpeed;
                    }
                }
                if (input.KeyDown(Keys.Right))
                {
                    flipped = false;
                    velocity.X += speed;
                    if (!inAir)
                    {
                        SetAnim("walk");
                    }
                    if (velocity.X > maxSpeed)
                    {
                        velocity.X = maxSpeed;
                    }
                }
                if (input.KeyClicked(Keys.Space))
                {
                    Jump();
                }
            }
        }
コード例 #3
0
ファイル: Game1.cs プロジェクト: eriksk/Ludum-Dare-48
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            logoTex = Content.Load<Texture2D>(@"gfx/logo");
            input = new InputManager();
            audio = new AudioManager();
            audio.LoadContent(Content.RootDirectory + "/audio/");

            Thread loadThread = new Thread(LoadAssets);
            loadThread.Start();
        }