Exemplo n.º 1
0
 public override void Update(GameTime gameTime)
 {
     base.Update(gameTime);
     if (waitTime > 0)
     {
         waitTime -= (float)gameTime.ElapsedGameTime.TotalSeconds;
         if (waitTime <= 0.0f)
         {
             TurnAround();
         }
     }
     else
     {
         TileField tiles = GameWorld.Find("tiles") as TileField;
         float     posX  = BoundingBox.Left;
         if (!Mirror)
         {
             posX = BoundingBox.Right;
         }
         int tileX = (int)Math.Floor(posX / tiles.CellWidth);
         int tileY = (int)Math.Floor(position.Y / tiles.CellHeight);
         if (tiles.GetTileType(tileX, tileY - 1) == TileType.Normal ||
             tiles.GetTileType(tileX, tileY) == TileType.Background)
         {
             waitTime   = 0.5f;
             velocity.X = 0.0f;
         }
     }
     CheckPlayerCollision();
     CheckBombCollision();
 }
    /// <summary>Load the level.</summary>
    public void LoadTiles(string path)
    {
        this.path = path;
        List <string> textlines  = new List <string>();
        StreamReader  fileReader = new StreamReader(path);
        string        line       = fileReader.ReadLine(); // first row of the level

        width = line.Length;                              // calculated level width
        while (line != null)
        {
            // read all lines
            textlines.Add(line);
            line = fileReader.ReadLine();
        }
        height = textlines.Count - 2;

        // add the hint
        GameObjectList hintfield = new GameObjectList(100);

        Add(hintfield);
        SpriteGameObject hint_frame = new SpriteGameObject("Overlays/spr_frame_hint", 1); // hint background

        hintfield.Position = new Vector2((GameEnvironment.Screen.X - hint_frame.Width) / 2, 10);
        hintfield.Add(hint_frame);
        TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2); // hint text

        hintText.Text     = textlines[textlines.Count - 2];                // last line in the level descriptor
        hintText.Position = new Vector2(120, 25);
        hintText.Color    = Color.Black;
        hintfield.Add(hintText);
        VisibilityTimer hintTimer = new VisibilityTimer(hintfield, 1, "hintTimer"); // timeout

        Add(hintTimer);

        TimerGameObject timer = new TimerGameObject(101, "timer");

        timer.Position = new Vector2(25, 30);
        timer.TimeLeft = TimeSpan.FromSeconds(double.Parse(textlines[textlines.Count - 1]));
        Add(timer);

        // construct the level
        TileField tiles = new TileField(height, width, 1, "tiles");

        Add(tiles);
        // tile dimentions
        tiles.CellWidth = 72;
        cellWidth       = 72;

        tiles.CellHeight = 55;
        cellHeight       = 55;

        for (int x = 0; x < width; ++x)
        {
            for (int y = 0; y < height; ++y)
            {
                Tile t = LoadTile(textlines[y][x], x, y);
                tiles.Add(t, x, y);
            }
        }
    }
Exemplo n.º 3
0
    public void LoadTiles(string path)
    {
        int           width;
        List <string> textlines  = new List <string>();
        StreamReader  fileReader = new StreamReader(path);
        string        line       = fileReader.ReadLine();

        width = line.Length;
        while (line != null)
        {
            textlines.Add(line);
            line = fileReader.ReadLine();
        }
        TileField tiles = new TileField(textlines.Count - 1, width, 1, "tiles");

        this.Add(tiles);
        tiles.CellWidth  = 72;
        tiles.CellHeight = 55;
        for (int x = 0; x < width; ++x)
        {
            for (int y = 0; y < 16 - 1; ++y)
            {
                Tile t = LoadTile(textlines[y][x], x, y);
                tiles.Add(t, x, y);
            }
        }
    }
Exemplo n.º 4
0
    //TODO: BUG, CHANGE ALGORITHM
    bool IWallVerifier.HasVerticalWall(Safe2DArray fields, TileField currentField, bool isWhiteTurn)
    {
        var currentPieceType = isWhiteTurn ? ColorType.WHITE : ColorType.BLACK;

        for (int i = 0; i < 5; i++)
        {
            int positiveIndex = currentField.Coordinates.x + i;
            if (positiveIndex <= 4)
            {
                if (!(currentPieceType == fields[positiveIndex, currentField.Coordinates.y].Piece?.type))
                {
                    return(false);
                }
            }

            int negativeIndex = currentField.Coordinates.x - i;
            if (negativeIndex >= 0)
            {
                if (!(currentPieceType == fields[negativeIndex, currentField.Coordinates.y].Piece?.type))
                {
                    return(false);
                }
            }
        }

        return(true);
    }
    /// <summary>Update the projectile.</summary>
    /// <param name="tiles">The field of the level.</param>
    public void Update(GameTime gameTime, TileField tiles)
    {
        if (!active)
        {
            return;
        }
        base.Update(gameTime);

        // check bounds
        int x_floor = (int)position.X / tiles.CellWidth;
        int y_floor = (int)position.Y / tiles.CellHeight;

        for (int y = y_floor - 1; y <= y_floor + 1; y++)
        {
            for (int x = x_floor - (mirrored ? 1 : 0); x <= x_floor + (mirrored ? 0 : 1); x++)
            {
                TileType tileType = tiles.GetTileType(x, y);
                if (tileType == TileType.Normal || tileType == TileType.Platform)
                {
                    Rectangle tileBounds = new Rectangle(x * tiles.CellWidth, y * tiles.CellHeight,
                                                         tiles.CellWidth, tiles.CellHeight);
                    if (tileBounds.Intersects(BoundingBox))
                    {
                        hit = true;
                    }
                }
            }
        }
        if (hit)
        {
            active = false;
        }
    }
Exemplo n.º 6
0
 //checks if the current field formed a wall
 public void VerifyWall(TileField currentField, Movement movement)
 {
     if (_wallVerifier.HasWall(currentField, movement))
     {
         _eventManager.OnGameEnd(currentField.Piece.type, "Pequena");
     }
 }
Exemplo n.º 7
0
    private void HandleCollisions(bool movingThroughPlatform)
    {
        isOnTheGround = false;
        walkingOnIce  = false;
        walkingOnHot  = false;

        TileField tiles  = GameWorld.Find("tiles") as TileField;
        int       xFloor = (int)position.X / tiles.CellWidth;
        int       yFloor = (int)position.Y / tiles.CellHeight;

        for (int y = yFloor - 2; y <= yFloor + 1; ++y)
        {
            for (int x = xFloor - 1; x <= xFloor + 1; ++x)
            {
                TileType tileType = tiles.GetTileType(x, y);
                if (tileType == TileType.Background)
                {
                    continue;
                }
                Tile      currentTile = tiles.Get(x, y) as Tile;
                Rectangle tileBounds  = new Rectangle(x * tiles.CellWidth, y * tiles.CellHeight,
                                                      tiles.CellWidth, tiles.CellHeight);
                Rectangle boundingBox = this.BoundingBox;
                boundingBox.Height += 1;
                if (((currentTile != null && !currentTile.CollidesWith(this)) || currentTile == null) && !tileBounds.Intersects(boundingBox))
                {
                    continue;
                }
                Vector2 depth = Collision.CalculateIntersectionDepth(boundingBox, tileBounds);
                if (Math.Abs(depth.X) < Math.Abs(depth.Y))
                {
                    if (tileType == TileType.Normal)
                    {
                        position.X += depth.X;
                    }
                    continue;
                }
                if (previousYPosition <= tileBounds.Top && tileType != TileType.Background)
                {
                    if (tileType == TileType.Platform && movingThroughPlatform)
                    {
                        continue;
                    }
                    isOnTheGround = true;
                    velocity.Y    = 0;
                    if (currentTile != null)
                    {
                        walkingOnIce = walkingOnIce || currentTile.Ice;
                        walkingOnHot = walkingOnHot || currentTile.Hot;
                    }
                }
                if (tileType == TileType.Normal || isOnTheGround)
                {
                    position.Y += depth.Y + 1;
                }
            }
        }
        position          = new Vector2((float)Math.Floor(position.X), (float)Math.Floor(position.Y));
        previousYPosition = position.Y;
    }
Exemplo n.º 8
0
    // Update is called once per frame
    void Update()
    {
        if (!EditorManager.Instance.currentState.Editable())
        {
            return;
        }

        currentMousePositionIndex = TileField.IndexOfPosition(Camera.main.ScreenToWorldPoint(Input.mousePosition), tileWidth, tileHeight);

        if (lastDrawnIndex != currentMousePositionIndex)
        {
            lastDrawnIndex = currentMousePositionIndex;
            //redo by event
            UIManager.Instance.lineDrawer.DrawIsoRectangle(lastDrawnIndex, tileWidth, tileHeight);
            if (Input.GetMouseButton(0))
            {
                //actionsArgument.indexArgument = currentMousePositionIndex;
                //currentAction.Execute(currentMousePositionIndex, actionsArgument);
                Debug.Log("Tile coord:" + currentMousePositionIndex);
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            //actionsArgument.indexArgument = currentMousePositionIndex;
            //currentAction.Execute(currentMousePositionIndex, actionsArgument);
            Debug.Log("Tile coord:" + currentMousePositionIndex);
        }
        if (Input.GetMouseButton(1))
        {
            Debug.Log(currentMousePositionIndex);
            Debug.Log("Real mouse pos: " + Camera.main.ScreenToWorldPoint(Input.mousePosition));
        }
    }
Exemplo n.º 9
0
    public void UpdateBoard(TileField currentField, TileField lastField)
    {
        var movement = new Movement(currentField, lastField);

        _gameFinisher.VerifyWall(currentField, movement);
        _gameFinisher.VerifyCaptures(currentField, movement);
    }
Exemplo n.º 10
0
    private void Deselect()
    {
        TileField field;
        var       coor   = new Coordinates(m_HighlightedTile);
        var       fields = _fieldProvider.GetField();

        field = fields[coor.up];
        if (field?.IsHighlighting == true)
        {
            field.OnDeselect();
        }

        field = fields[coor.right];
        if (field?.IsHighlighting == true)
        {
            field.OnDeselect();
        }

        field = fields[coor.down];
        if (field?.IsHighlighting == true)
        {
            field.OnDeselect();
        }

        field = fields[coor.left];
        if (field?.IsHighlighting == true)
        {
            field.OnDeselect();
        }

        m_HighlightedTile = null;
    }
Exemplo n.º 11
0
    //TODO: BUG, CHANGE ALGORITHM
    private bool HasHorizontalWall(TileField currentField)
    {
        var fields = _fieldProvider.GetField();

        for (int i = 0; i < 5; i++)
        {
            int positiveIndex = currentField.Coordinates.y + i;
            if (positiveIndex <= 4)
            {
                if (!(currentField.Piece.type == fields[currentField.Coordinates.x, positiveIndex].Piece?.type))
                {
                    return(false);
                }
            }

            int negativeIndex = currentField.Coordinates.y - i;
            if (negativeIndex >= 0)
            {
                if (!(currentField.Piece.type == fields[currentField.Coordinates.x, negativeIndex].Piece?.type))
                {
                    return(false);
                }
            }
        }

        return(true);
    }
Exemplo n.º 12
0
    public override void Update(GameTime gameTime)
    {
        base.Update(gameTime);
        if (!Finished && IsAlive)
        {
            if (IsOnTheGround)
            {
                if (velocity.X == 0)
                {
                    this.PlayAnimation("idle");
                }
                else
                {
                    this.PlayAnimation("run");
                }
            }
            else if (velocity.Y < 0)
            {
                this.PlayAnimation("jump");
            }

            TileField tiles = GameWorld.Find("tiles") as TileField;
            if (BoundingBox.Top >= tiles.Rows * tiles.CellHeight)
            {
                this.Die(true);
            }
        }

        DoPhysics();
    }
Exemplo n.º 13
0
    public void SetSettings(SO_GameSettings gameSettings)
    {
        this.tileWidth  = gameSettings.tileWidth;
        this.tileHeight = gameSettings.tileHeight;
        intToTileTypes  = new Dictionary <int, SO_Tile>();

        TileField.AddTilesToDict(intToTileTypes, gameSettings.allTileTypes);
    }
Exemplo n.º 14
0
    public void UpdateBoard(TileField currentField, TileField lastField)
    {
        bool movedVertically = currentField.Coordinates.x > lastField.Coordinates.x || currentField.Coordinates.x < lastField.Coordinates.x;

        VerifyWall(currentField, movedVertically);
        _captureVerifier.VerifyCapture(_fieldProvider.GetField(), currentField, _turnManager.GetCurrentTurn());
        //vERIFY kILLS
    }
Exemplo n.º 15
0
    private Tile LoadStartTile(int x, int y)
    {
        TileField tiles         = this.Find("tiles") as TileField;
        Vector2   startPosition = new Vector2(((float)x + 0.5f) * tiles.CellWidth, (y + 1) * tiles.CellHeight);
        Player    player        = new Player(startPosition);

        this.Add(player);
        return(new Tile("", TileType.Background));
    }
Exemplo n.º 16
0
    int ICaptureVerifier.VerifyCapture(TileField currentField, Movement movement)
    {
        var kills       = 0;
        var fields      = _fieldProvider.GetField();
        var coordinates = new Coordinates(currentField);

        Coordinates[] coordsToVerify = { coordinates.up, coordinates.right, coordinates.down, coordinates.left };

        for (int i = 0; i < coordsToVerify.Length; i++)
        {
            //Verifying the piece adjacent to the currentField
            //[farTile][inBetweenTile][currentTile]
            var farCoordinates = coordsToVerify[i];
            var inBetweenTile  = fields[coordsToVerify[i]];

            if (currentField.Coordinates.x > coordsToVerify[i].x)
            {
                farCoordinates.x--;
            }
            else if (currentField.Coordinates.x < coordsToVerify[i].x)
            {
                farCoordinates.x++;
            }
            else if (currentField.Coordinates.y < coordsToVerify[i].y)
            {
                farCoordinates.y++;
            }
            else if (currentField.Coordinates.y > coordsToVerify[i].y)
            {
                farCoordinates.y--;
            }

            var farTile = fields[farCoordinates];

            //Verifying the adjacent tile is an enemy
            if (inBetweenTile != null &&
                inBetweenTile.Piece != null &&
                inBetweenTile.Piece.type != currentField.Piece.type)
            {
                //Veryfying if the far tile is an ally
                if (farTile != null &&
                    farTile.Piece != null &&
                    farTile.Piece.type == currentField.Piece.type)
                {
                    //if the inBetweenPiece is on the middle, it can't be captured
                    if (inBetweenTile.Coordinates.x != 2 ||
                        inBetweenTile.Coordinates.y != 2)
                    {
                        inBetweenTile.Capture();
                        kills++;
                    }
                }
            }
        }

        return(kills);
    }
Exemplo n.º 17
0
 private bool TrySelect(TileField tile)
 {
     if (tile != null && tile.Piece == null)
     {
         tile.OnSelect();
         return(true);
     }
     return(false);
 }
Exemplo n.º 18
0
    public void LoadTiles(string path)
    {
        //Haalt de tekst uit tekstfile
        int width;
        List<string> textlines = new List<string>();
        StreamReader fileReader = new StreamReader(path);
        string line = fileReader.ReadLine();
        width = line.Length;
        while (line != null)
        {
            textlines.Add(line);
            line = fileReader.ReadLine();
        }

        //Tijdslimiet i wordt afgelezen uit tekstfile
        int i = int.Parse(textlines[textlines.Count - 1]);
        SpriteGameObject timerBackground = new SpriteGameObject("Sprites/spr_timer", 100, "timerBackground");
        timerBackground.Position = new Vector2(10, 10);
        this.Add(timerBackground);
        TimerGameObject timer = new TimerGameObject(i, 101, "timer");
        timer.Position = new Vector2(25, 30);
        this.Add(timer);

        int height = textlines.Count - 2;

        //Creëert het speelveld
        TileField tiles = new TileField(textlines.Count - 2, width, 1, "tiles");

        //Plaatst de hintbutton
        GameObjectList hintfield = new GameObjectList(100, "hintfield");
        this.Add(hintfield);
        string hint = textlines[textlines.Count - 2];
        SpriteGameObject hint_frame = new SpriteGameObject("Overlays/spr_frame_hint", 1, "hint_frame");
        hintfield.Position = new Vector2((GameEnvironment.Screen.X - hint_frame.Width) / 2, 10);
        hintfield.Add(hint_frame);
        TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2, "hintText");
        hintText.Text = hint;
        hintText.Position = new Vector2(120, 25);
        hintText.Color = Color.Black;
        hintfield.Add(hintText);
        VisibilityTimer hintTimer = new VisibilityTimer(hintfield, 1, "hintTimer");
        this.Add(hintTimer);

        //Vult het speelveld met de goede tiles
        this.Add(tiles);
        tiles.CellWidth = 72;
        tiles.CellHeight = 55;
        for (int x = 0; x < width; ++x)
            for (int y = 0; y < textlines.Count - 2; ++y)
            {
                Tile t = LoadTile(textlines[y][x], x, y);
                tiles.Add(t, x, y);
            }

        levelwidth = width * tiles.CellWidth;
        levelheight = height * tiles.CellHeight;
    }
Exemplo n.º 19
0
    private Tile LoadRocketTile(int x, int y, bool moveToLeft)
    {
        GameObjectList enemies       = this.Find("enemies") as GameObjectList;
        TileField      tiles         = this.Find("tiles") as TileField;
        Vector2        startPosition = new Vector2(((float)x + 0.5f) * tiles.CellWidth, (y + 1) * tiles.CellHeight);
        Rocket         enemy         = new Rocket(moveToLeft, startPosition);

        enemies.Add(enemy);
        return(new Tile());
    }
Exemplo n.º 20
0
    private Tile LoadEndTile(int x, int y)
    {
        TileField        tiles   = this.Find("tiles") as TileField;
        SpriteGameObject exitObj = new SpriteGameObject("Sprites/spr_goal", 1, "exit");

        exitObj.Position = new Vector2(x * tiles.CellWidth, (y + 1) * tiles.CellHeight);
        exitObj.Origin   = new Vector2(0, exitObj.Height);
        this.Add(exitObj);
        return(new Tile());
    }
Exemplo n.º 21
0
    private Tile LoadRocketTile(bool moveToLeft, Vector2 startposition)
    {
        GameObjectList enemies = this.Find("enemies") as GameObjectList;
        TileField      tiles   = this.Find("tiles") as TileField;
        Rocket         r       = new Rocket(moveToLeft, new Vector2(startposition.X * tiles.CellWidth, startposition.Y * tiles.CellHeight - 10) + new Vector2(tiles.CellWidth, tiles.CellHeight) / 2);

        r.Origin = r.Center;
        enemies.Add(r);
        return(new Tile());
    }
Exemplo n.º 22
0
    private Tile LoadSparkyTile(int x, int y)
    {
        GameObjectList enemies = this.Find("enemies") as GameObjectList;
        TileField      tiles   = this.Find("tiles") as TileField;
        Sparky         enemy   = new Sparky((y + 1) * tiles.CellHeight - 100f);

        enemy.Position = new Vector2(((float)x + 0.5f) * tiles.CellWidth, (y + 1) * tiles.CellHeight - 100f);
        enemies.Add(enemy);
        return(new Tile());
    }
    /// <summary>Add the goal of the level.</summary>
    private Tile LoadEndTile(int x, int y)
    {
        TileField        tiles   = Find("tiles") as TileField;
        SpriteGameObject exitObj = new SpriteGameObject("Sprites/spr_goal", 1, "exit", 0, SpriteGameObject.Backgroundlayer.foreground);

        exitObj.Position = new Vector2(x * tiles.CellWidth, (y + 1) * tiles.CellHeight);
        exitObj.Origin   = new Vector2(0, exitObj.Height);
        Add(exitObj);
        return(new Tile());
    }
Exemplo n.º 24
0
    private Tile LoadTurtleTile(int x, int y)
    {
        GameObjectList enemies = Find("enemies") as GameObjectList;
        TileField      tiles   = Find("tiles") as TileField;
        Turtle         enemy   = new Turtle();

        enemy.Position = new Vector2(((float)x + 0.5f) * tiles.CellWidth, (y + 1) * tiles.CellHeight + 25.0f);
        enemies.Add(enemy);
        return(new Tile());
    }
Exemplo n.º 25
0
    bool ICaptureVerifier.VerifyCapture(Safe2DArray fields, TileField currentField, ColorType allyColor)
    {
        var coordinates = new Coordinates(currentField);

        Coordinates[] coordsToVerify = { coordinates.up, coordinates.right, coordinates.down, coordinates.left };

        for (int i = 0; i < coordsToVerify.Length; i++)
        {
            //Verifying the piece adjacent to the currentField
            //[farTile][inBetweenTile][currentTile]
            var farCoordinates = coordsToVerify[i];
            var inBetweenTile  = fields[coordsToVerify[i]];

            if (currentField.Coordinates.x > coordsToVerify[i].x)
            {
                farCoordinates.x--;
            }
            else if (currentField.Coordinates.x < coordsToVerify[i].x)
            {
                farCoordinates.x++;
            }
            else if (currentField.Coordinates.y < coordsToVerify[i].y)
            {
                farCoordinates.y++;
            }
            else if (currentField.Coordinates.y > coordsToVerify[i].y)
            {
                farCoordinates.y--;
            }

            var farTile = fields[farCoordinates];

            //Verifying the adjacent tile is an enemy
            if (inBetweenTile != null &&
                inBetweenTile.Piece != null &&
                inBetweenTile.Piece.type != allyColor)
            {
                //Veryfying if the far tile is an ally
                if (farTile != null &&
                    farTile.Piece != null &&
                    farTile.Piece.type == allyColor)
                {
                    //if the inBetweenPiece is on the middle, it can't be captured
                    if (inBetweenTile.Coordinates.x != 2 ||
                        inBetweenTile.Coordinates.y != 2)
                    {
                        inBetweenTile.Capture();
                        return(true);
                    }
                }
            }
        }

        return(false);
    }
Exemplo n.º 26
0
    public void LoadTiles(string path)
    {
        List <string> textLines  = new List <string>();
        StreamReader  fileReader = new StreamReader(path);
        string        line       = fileReader.ReadLine();
        int           width      = line.Length;

        while (line != null)
        {
            textLines.Add(line);
            line = fileReader.ReadLine();
        }
        TileField      tiles     = new TileField(textLines.Count - 1, width, 1, "tiles");
        int            height    = textLines.Count - 1;
        GameObjectList hintField = new GameObjectList(100);

        Add(hintField);
        string           hint      = textLines[textLines.Count - 2];
        SpriteGameObject hintFrame = new LockedSpriteGameObject("Overlays/spr_frame_hint", 1);

        hintField.Position = new Vector2((GameEnvironment.Screen.X - hintFrame.Width) / 2, 10);
        hintField.Add(hintFrame);
        TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2);

        hintText.Text     = textLines[textLines.Count - 2];
        hintText.Position = new Vector2(120, 25);
        hintText.Color    = Color.Black;
        hintField.Add(hintText);
        int timerTime = int.Parse(textLines[textLines.Count - 1]);

        timer.SetTime = timerTime;
        VisibilityTimer hintTimer = new VisibilityTimer(hintField, 1, "hintTimer");

        Add(hintTimer);

        Add(tiles);
        tiles.CellWidth  = 72;
        tiles.CellHeight = 55;
        this.width       = width * tiles.CellWidth;
        this.height      = height * tiles.CellHeight;
        for (int x = 0; x < width; x++)
        {
            Tile t = new Tile();
            tiles.Add(t, x, 0);
        }
        for (int x = 0; x < width; ++x)
        {
            for (int y = 1; y < textLines.Count - 1; ++y)
            {
                Tile t = LoadTile(textLines[y - 1][x], x, y);
                tiles.Add(t, x, y);
            }
        }
    }
    /// <summary>Add a water tile.</summary>
    private Tile LoadWaterTile(int x, int y)
    {
        GameObjectList waterdrops = Find("waterdrops") as GameObjectList;
        TileField      tiles      = Find("tiles") as TileField;
        WaterDrop      w          = new WaterDrop();

        w.Origin   = w.Center;
        w.Position = new Vector2((x + 0.5f) * tiles.CellWidth, (y + 0.5f) * tiles.CellHeight - 10);
        waterdrops.Add(w);
        return(new Tile());
    }
Exemplo n.º 28
0
 /// <summary>
 /// Update the graphics of the walls so adjacent wall tiles look like they are connected.
 /// </summary>
 public override void UpdateGraphicsToMatchSurroundings()
 {
     int sheetIndex = 0;
     int x = Location.X;
     int y = Location.Y;
     TileField tileField = Parent as TileField;
     if (tileField.GetTile(x, y - 1) is WallTile) sheetIndex += 1;
     if (tileField.GetTile(x + 1, y) is WallTile) sheetIndex += 2;
     if (tileField.GetTile(x, y + 1) is WallTile) sheetIndex += 4;
     if (tileField.GetTile(x - 1, y) is WallTile) sheetIndex += 8;
     sprite = new SpriteSheet(GetAssetNamesFromTileType(TileType.Wall)[0], sheetIndex);
 }
    private Tile LoadSpeedTile(int x, int y)
    {
        GameObjectList waterdrops = Find("waterdrops") as GameObjectList;
        TileField      tiles      = Find("tiles") as TileField;
        SpeedObject    s          = new SpeedObject();

        s.Origin    = s.Center;
        s.Position  = new Vector2(x * tiles.CellWidth, y * tiles.CellHeight - 10);
        s.Position += new Vector2(tiles.CellWidth, tiles.CellHeight) / 2;
        waterdrops.Add(s);
        return(new Tile());
    }
Exemplo n.º 30
0
    public override void Update(GameTime gameTime)
    {
        base.Update(gameTime);

        if (!finished && isAlive)
        {
            if (isOnTheGround)
            {
                if (velocity.X == 0)
                {
                    PlayAnimation("idle");
                }
                else
                {
                    PlayAnimation("run");
                }
            }
            else if (velocity.Y < 0)
            {
                PlayAnimation("jump");
            }

            TimerGameObject timer = GameWorld.Find("timer") as TimerGameObject;
            if (walkingOnHot)
            {
                timer.Multiplier = 2;
            }
            else if (walkingOnIce)
            {
                timer.Multiplier = 0.5;
            }
            else
            {
                timer.Multiplier = 1;
            }

            TileField tiles = GameWorld.Find("tiles") as TileField;
            if (BoundingBox.Top >= tiles.Rows * tiles.CellHeight)
            {
                Die(true);
            }
            if (Clock <= 0f)                //Update de clock
            {
                isShooting = false;
            }
            else if (Clock > 0f)            // Clock voorwaarde
            {
                Clock -= 1f;
            }
        }

        DoPhysics();
    }
Exemplo n.º 31
0
    private Tile LoadZenyTile(int x, int y)
    {
        GameObjectList ZenyS = this.Find("ZenyS") as GameObjectList;
        TileField      tiles = this.Find("tiles") as TileField;
        Zeny           w     = new Zeny();

        w.Origin    = w.Center;
        w.Position  = new Vector2(x * tiles.CellWidth, y * tiles.CellHeight - 10);
        w.Position += new Vector2(tiles.CellWidth, tiles.CellHeight) / 2;
        ZenyS.Add(w);
        return(new Tile());
    }
Exemplo n.º 32
0
    /// <summary>Load the level.</summary>
    public void LoadTiles(string path)
    {
        this.path = path;
        List<string> textlines = new List<string>();
        StreamReader fileReader = new StreamReader(path);
        string line = fileReader.ReadLine(); // first row of the level
        width = line.Length; // calculated level width
        while (line != null)
        {
            // read all lines
            textlines.Add(line);
            line = fileReader.ReadLine();
        }
        height = textlines.Count - 2;

        // add the hint
        GameObjectList hintfield = new GameObjectList(100);
        Add(hintfield);
        SpriteGameObject hint_frame = new SpriteGameObject("Overlays/spr_frame_hint", 1); // hint background
        hintfield.Position = new Vector2((GameEnvironment.Screen.X - hint_frame.Width) / 2, 10);
        hintfield.Add(hint_frame);
        TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2); // hint text
        hintText.Text = textlines[textlines.Count - 2]; // last line in the level descriptor
        hintText.Position = new Vector2(120, 25);
        hintText.Color = Color.Black;
        hintfield.Add(hintText);
        VisibilityTimer hintTimer = new VisibilityTimer(hintfield, 1, "hintTimer"); // timeout
        Add(hintTimer);

        TimerGameObject timer = new TimerGameObject(101, "timer");
        timer.Position = new Vector2(25, 30);
        timer.TimeLeft = TimeSpan.FromSeconds(double.Parse(textlines[textlines.Count - 1]));
        Add(timer);

        // construct the level
        TileField tiles = new TileField(height, width, 1, "tiles");
        Add(tiles);
        // tile dimentions
        tiles.CellWidth = 72;
        cellWidth = 72;

        tiles.CellHeight = 55;
        cellHeight = 55;
        
        for (int x = 0; x < width; ++x)
            for (int y = 0; y < height; ++y)
            {
                Tile t = LoadTile(textlines[y][x], x, y);
                tiles.Add(t, x, y);
            }
    }
Exemplo n.º 33
0
    public void LoadTiles(string path)
    {
        int width;
        List<string> textlines = new List<string>();
        StreamReader fileReader = new StreamReader(path);
        string line = fileReader.ReadLine();
        width = line.Length;
        while (line != null)
        {
            textlines.Add(line);
            line = fileReader.ReadLine();
        }
        TileField tiles = new TileField(textlines.Count - 2, width, 1, "tiles");

        GameObjectList hintfield = new GameObjectList(100);
        this.Add(hintfield);
        string hint = textlines[textlines.Count - 1];
        SpriteGameObject hint_frame = new SpriteGameObject("Overlays/spr_frame_hint", 1);
        hintfield.Position = new Vector2((GameEnvironment.Screen.X - hint_frame.Width) / 2, 10);
        hint_frame.Meebewegen();
        hintfield.Add(hint_frame);
        TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2);
        hintText.Text = textlines[textlines.Count - 2];
        hintText.Position = new Vector2(120, 25);
        hintText.Color = Color.Black;
        hintfield.Add(hintText);
        VisibilityTimer hintTimer = new VisibilityTimer(hintfield, 1, "hintTimer");
        this.Add(hintTimer);

        GameObject.lvltimer = Convert.ToDouble(textlines[textlines.Count - 1]); // de laatste lijn in de textfile heeft de tijd

        this.Add(tiles);
        tiles.CellWidth = 72;
        tiles.CellHeight = 55;
        for (int x = 0; x < width; ++x)
            for (int y = 0; y < textlines.Count - 2; ++y)
            {
                Tile t = LoadTile(textlines[y][x], x, y);
                tiles.Add(t, x, y);
            }
    }
Exemplo n.º 34
0
    /// <summary>Update the projectile.</summary>
    /// <param name="tiles">The field of the level.</param>
    public void Update(GameTime gameTime, TileField tiles)
    {
        if (!active)
            return;
        base.Update(gameTime);

        // check bounds 
        int x_floor = (int)position.X / tiles.CellWidth;
        int y_floor = (int)position.Y / tiles.CellHeight;
        for (int y = y_floor - 1; y <= y_floor + 1; y++)
            for (int x = x_floor - (mirrored ? 1 : 0); x <= x_floor + (mirrored ? 0 : 1); x++)
            {
                TileType tileType = tiles.GetTileType(x, y);
                if (tileType == TileType.Normal || tileType == TileType.Platform)
                {
                    Rectangle tileBounds = new Rectangle(x * tiles.CellWidth, y * tiles.CellHeight,
                                                            tiles.CellWidth, tiles.CellHeight);
                    if (tileBounds.Intersects(BoundingBox))
                    { hit = true; }
                }
            }
        if (hit)
            active = false;
    }
Exemplo n.º 35
0
        public TileFieldTest()
        {
            this.Width = DefaultWidth;
            this.Height = DefaultHeight;

            new[]
            {
                Colors.White,
                Colors.Blue,
                Colors.Red,
                Colors.Yellow
            }.ToGradient(DefaultHeight / 4).ForEach(
                (c, i) =>
                new Rectangle
                {
                    Fill = new SolidColorBrush(c),
                    Width = DefaultWidth,
                    Height = 5,
                }.MoveTo(0, i * 4).AttachTo(this)
            );

            var t = new TextBox
            {
                AcceptsReturn = true,
                Background = Brushes.White,
                BorderThickness = new Thickness(0),
                Text = "hello world" + Environment.NewLine,
                Width = DefaultWidth / 2,
                Height = DefaultHeight / 4
            }.AttachTo(this).MoveTo(DefaultWidth / 4, 4);

            var OverlayCanvas = new Canvas
            {
                Width = DefaultWidth,
                Height = DefaultHeight
            };

            var OverlayRectangle = new Rectangle
            {
                Width = DefaultWidth,
                Height = DefaultHeight,
                Fill = Brushes.Black,
                Opacity = 0
            }.AttachTo(OverlayCanvas);

            var field = new TileField(8, 6);
            var field_x = 64;
            var field_y = 200;

            field.Container.MoveTo(field_x, field_y).AttachTo(this);
            field.Overlay.MoveTo(field_x, field_y).AttachTo(OverlayCanvas);

            var WaterFlow = new Queue<Action>();

            #region pipes
            {

                var pipe = new Pipe.PumpToLeft();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 5, field_y + Tile.ShadowBorder + 52 * 0 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i =>
                        WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            Enumerable.Range(0, 2).ForEach(
                ix_ =>
                {
                    var ix = 4 - ix_;

                    var pipe = new Pipe.LeftToRight();

                    pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * ix, field_y + Tile.ShadowBorder + 52 * 0 - 12).AttachTo(this);

                    pipe.Water.ForEachReversed(
                        i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                    );

                }

            );

            {

                var pipe = new Pipe.RightToBottom();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 2, field_y + Tile.ShadowBorder + 52 * 0 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            Enumerable.Range(1, 2).ForEach(
                iy =>
                {

                    var pipe = new Pipe.TopToBottom();

                    pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 2, field_y + Tile.ShadowBorder + 52 * iy - 12).AttachTo(this);

                    pipe.Water.ForEach(
                        i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                    );

                }
            );

            {

                var pipe = new Pipe.TopToRight();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 2, field_y + Tile.ShadowBorder + 52 * 3 - 12).AttachTo(this);

                pipe.Water.ForEach(
                                i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                            );

            }

            Enumerable.Range(3, 3).ForEach(
                ix =>
                {

                    var pipe = new Pipe.LeftToRight();

                    pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * ix, field_y + Tile.ShadowBorder + 52 * 3 - 12).AttachTo(this);

                    pipe.Water.ForEach(
                        i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                    );

                }
            );

            field[3, 2].Drain.Visibility = Visibility.Visible;

            {

                var pipe = new Pipe.LeftToDrain();

                field[6, 3].Drain.Visibility = Visibility.Visible;

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 6, field_y + Tile.ShadowBorder + 52 * 3 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            {

                var pipe = new Pipe.PumpToRight();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 0, field_y + Tile.ShadowBorder + 52 * 1 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i =>
                        WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            {

                var pipe = new Pipe.LeftToRight();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 1, field_y + Tile.ShadowBorder + 52 * 1 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            {

                var pipe = new Pipe.LeftToRightBent();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 2, field_y + Tile.ShadowBorder + 52 * 1 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            Enumerable.Range(3, 4).ForEach(
                ix =>
                {

                    var pipe = new Pipe.LeftToRight();

                    pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * ix, field_y + Tile.ShadowBorder + 52 * 1 - 12).AttachTo(this);

                    pipe.Water.ForEach(
                        i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                    );

                }
            );

            {

                var pipe = new Pipe.LeftToBottom();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 7, field_y + Tile.ShadowBorder + 52 * 1 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            Enumerable.Range(2, 2).ForEach(
                iy =>
                {

                    var pipe = new Pipe.TopToBottom();

                    pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 7, field_y + Tile.ShadowBorder + 52 * iy - 12).AttachTo(this);

                    pipe.Water.ForEach(
                        i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                    );

                }
            );

            {

                var pipe = new Pipe.TopToLeft();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 7, field_y + Tile.ShadowBorder + 52 * 4 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }

            Enumerable.Range(0, 3).ForEach(
                ix_ =>
                {
                    var ix = 6 - ix_;

                    var pipe = new Pipe.LeftToRight();

                    pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * ix, field_y + Tile.ShadowBorder + 52 * 4 - 12).AttachTo(this);

                    pipe.Water.ForEachReversed(
                        i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                    );

                }
            );

            {

                var pipe = new Pipe.RightToDrain();

                pipe.Container.MoveTo(field_x + Tile.ShadowBorder + Tile.Size * 3, field_y + Tile.ShadowBorder + 52 * 4 - 12).AttachTo(this);

                pipe.Water.ForEach(
                    i => WaterFlow.Enqueue(() => i.Visibility = Visibility.Visible)
                );

            }
            #endregion

            field[3, 4].Drain.Visibility = Visibility.Visible;

            OverlayCanvas.AttachTo(this).MoveTo(0, 0);

            var Navigationbar = new AeroNavigationBar();

            Navigationbar.Container.MoveTo(4, 4).AttachTo(this);

            var c1 = new ArrowCursorControl
            {

            };

            c1.Container.MoveTo(32, 32).AttachTo(this);
            c1.Red.Opacity = 0.7;

            OverlayCanvas.MouseMove +=
                (sender, e) =>
                {
                    var p = e.GetPosition(OverlayCanvas);

                    c1.Container.MoveTo(32 + p.X, 32 + p.Y);
                };

            OverlayCanvas.MouseLeave +=
                delegate
                {
                    c1.Container.Visibility = Visibility.Hidden;
                };

            OverlayCanvas.MouseEnter +=
                delegate
                {
                    c1.Container.Visibility = Visibility.Visible;
                };

            foreach (var n in KnownAssets.Default.FileNames)
            {
                t.AppendTextLine(n);
            }

            3000.AtDelay(
                delegate
                {
                    (1000 / 10).AtIntervalWithTimer(
                        ttt =>
                        {
                            if (WaterFlow.Count == 0)
                            {
                                ttt.Stop();
                                return;
                            }

                            WaterFlow.Dequeue()();
                        }
                    );
                }
            );
        }