Example #1
0
        public List <Entity> Render()
        {
            List <Entity> newEntities = new List <Entity>();

            BackSprites.Clear();

            int screenX = 0;
            int screenY = -1;

            for (int x = originXtile; x < _screenTilesPerRow + originXtile; x++)
            {
                for (int y = originYtile; y < _screenTilesPerColumn + originYtile + 2; y++)
                {
                    if (!_level.Tiles[x, y].Background)
                    {
                        if (_level.Tiles[x, y].Entity != "")
                        {
                            // If this tile contains an entity, add it to the return list
                            string entityName = _level.Tiles[x, y].Entity;

                            // Create a background tile to replace the entity
                            if (_level.Tiles[x, y].Static != true)
                            {
                                Tile t = new Tile();
                                t.Background       = true;
                                _level.Tiles[x, y] = t;
                            }

                            ScreenLocation sl = TileToScreen(x, y);
                            Entity         e2 = new Entity(this._gameObject);
                            e2.Name          = entityName;
                            e2.X             = sl.X;
                            e2.Y             = sl.Y;
                            e2.OriginTileRow = x;
                            e2.OriginTileCol = y;
                            newEntities.Add(e2);
                        }
                        else
                        {
                            // Get the texture resoruce for this map location, and assign to the sprite
                            spBack = new Sprite(ResourceManager.Instance.GetTexture(_level.Tiles[x, y].Resource));

                            // Set the sprite/tile location and draw it
                            int x1 = (_tileHeight * screenY) + yOffset;
                            int y1 = (_tileWidth * screenX) + xOffset;

                            spBack.Position = new Vector2f(x1, y1);
                            spBack.Draw(_gameObject.Window, RenderStates.Default);
                        }
                    }
                    screenY++;
                }

                screenY = -1;
                screenX++;
            }

            return(newEntities);
        }
Example #2
0
        public ScreenLocation TileToScreen(int row, int col)
        {
            ScreenLocation s = new ScreenLocation();

            s.Y = (row * tileHeight) * (originXtile + 1);
            s.X = (col * tileWidth) - ((originYtile + 1) * tileWidth);
            return(s);
        }
Example #3
0
        public List <Entity> Render()
        {
            List <Entity> newEntities = new List <Entity>();

            BackSprites.Clear();

            int screenX = 0;
            int screenY = -1;

            for (int x = originXtile; x < screenTilesPerRow + originXtile; x++)
            {
                for (int y = originYtile; y < screenTilesPerColumn + originYtile + 2; y++)
                {
                    if (!level.Tiles[x, y].Background)
                    {
                        if (level.Tiles[x, y].Entity != "")
                        {
                            string entityName = level.Tiles[x, y].Entity;
                            if (level.Tiles[x, y].Static != true)
                            {
                                Tile t = new Tile();
                                t.Background      = true;
                                level.Tiles[x, y] = t;
                            }

                            ScreenLocation sl = TileToScreen(x, y);
                            Entity         e2 = new Entity(this.gameObject);
                            e2.Name          = entityName;
                            e2.X             = sl.X;
                            e2.Y             = sl.Y;
                            e2.OriginTileRow = x;
                            e2.OriginTileCol = y;
                            newEntities.Add(e2);
                        }
                        else
                        {
                            spBack = new Sprite(ResourceManager.GetInstance().GetTexture(level.Tiles[x, y].Resource));
                            int x1 = (tileHeight * screenY) + yOffset;
                            int y1 = (tileWidth * screenX) + xOffset;
                            spBack.Position = new Vector2f(x1, y1);
                            spBack.Draw(gameObject.Window, RenderStates.Default);
                        }
                    }
                    screenY++;
                }

                screenY = -1;
                screenX++;
            }

            return(newEntities);
        }
Example #4
0
        public override void Update()
        {
            if (!Visible)
            {
                return;
            }

            if (!IsStatic)
            {
                if (IsAffectedByGravity)
                {
                    if (IsJumping)
                    {
                        Velocity += 5;
                    }
                    else
                    {
                        Velocity = 0;
                    }

                    Y = Y + Velocity;

                    IsJumping = true;
                }


                if (IsMoving)
                {
                    if (Facing == Direction.RIGHT)
                    {
                        X = X + Acceleration;

                        this.sprite.TextureRect = EntitySpriteSheet.GetNextSprite(Direction.RIGHT);
                    }

                    if (Facing == Direction.LEFT)
                    {
                        if (!AllowOffscreen)
                        {
                            if (X > 0)
                            {
                                X = X + Acceleration;
                            }
                        }
                        else
                        {
                            X = X + Acceleration;
                        }

                        this.sprite.TextureRect = EntitySpriteSheet.GetNextSprite(Direction.LEFT);
                    }
                }

                if (!IsMoving)
                {
                    if (Facing == Direction.NONE)
                    {
                        this.sprite.TextureRect = EntitySpriteSheet.GetFirstSprite(Direction.NONE);
                    }

                    if (Facing == Direction.RIGHT)
                    {
                        this.sprite.TextureRect = EntitySpriteSheet.GetFirstSprite(Direction.RIGHT);
                    }

                    if (Facing == Direction.LEFT)
                    {
                        this.sprite.TextureRect = EntitySpriteSheet.GetFirstSprite(Direction.LEFT);
                    }
                }

                if (Velocity != 0 && Facing == Direction.RIGHT)
                {
                    this.sprite.TextureRect = EntitySpriteSheet.GetFirstSprite(Direction.JUMPRIGHT);
                }

                if (Velocity != 0 && Facing == Direction.LEFT)
                {
                    this.sprite.TextureRect = EntitySpriteSheet.GetFirstSprite(Direction.JUMPLEFT);
                }
            }
            else
            {
                if (this.AutoCycleStaticSpriteSheet && this.entitySpriteSheet.TotalFrames > 1)
                {
                    this.sprite.TextureRect = EntitySpriteSheet.GetNextSprite(Direction.NONE);
                }


                Viewport       v  = _gameObject.SceneManager.CurrentScene.viewPort;
                ScreenLocation sl = v.TileToScreen(this.OriginTileRow, this.OriginTileCol);
                this.X = sl.X + v.yOffset;
                this.Y = sl.Y + Velocity;
            }

            base.Move();
        }