Example #1
0
    public OptionsMenuState()
    {
        // add a background
        SpriteGameObject background = new SpriteGameObject("Sprites/spr_background_options");

        gameObjects.AddChild(background);
    }
Example #2
0
        public GetBallOverlay() : base()
        {
            giftBox = new AnimatedGameObject(Depth.GiftBox);
            giftBox.LoadAnimation("Sprites/Animations/spr_animation_getball@4x3", "box", false, 0.05f);
            giftBox.PlayAnimation("box", true);
            giftBox.SetOriginToCenter();
            giftBox.LocalPosition = new Vector2(320, 600);
            AddChild(giftBox);

            glowing = new AnimatedGameObject(Depth.OverlayButton2);
            glowing.LoadAnimation("Sprites/Animations/spr_animation_glowing@5x2", "glowing", true, 0.1f);
            glowing.PlayAnimation("glowing", true);
            glowing.SetOriginToCenter();
            glowing.LocalPosition = new Vector2(350, 500);
            AddChild(glowing);

            background = new SpriteGameObject("Sprites/Backgrounds/spr_getball", Depth.OverlayBackground2);
            AddChild(background);

            message = new TextGameObject("Fonts/GetBall", Depth.OverlayMessage, Color.White, TextGameObject.HorizontalAlignment.Center, TextGameObject.VerticalAlignment.Center);
            AddChild(message);
            message.Visible       = false;
            message.Text          = "Click to get ball";
            message.LocalPosition = new Vector2(350, 900);

            fireWorkMaker = new ListStar(Depth.RandomBall + 0.001f);
            AddChild(fireWorkMaker);
            Reset();
        }
Example #3
0
    private void LoadButtons()
    {
        Vector2 startposition = new Vector2((GameEnvironment.Screen.X / 30) * 8, (GameEnvironment.Screen.Y / 13) * 4);
        Vector2 newPosition;
        int     xOffset = (int)(GameEnvironment.Screen.X / 30) * 5;
        int     yOffset = (int)(GameEnvironment.Screen.Y / 4);

        for (int y = 0; y < 3; y++)
        {
            newPosition = new Vector2(startposition.X, startposition.Y + yOffset * y);
            for (int x = 0; x < 3; x++)
            {
                Button button = new Button("Sprites/Menu/Select_Button", 109);
                buttonList.Add(button);
                button.Sprite.Size = new Vector2(0.6f, 0.6f);
                button.Position    = new Vector2(startposition.X + x * xOffset, newPosition.Y);
                RootList.Add(button);
                int nummer             = (3) * y + x + 1;
                SpriteGameObject level = new SpriteGameObject("Sprites/Menu/Level_Button_" + nummer, 110);
                levelList.Add(level);
                level.Sprite.Size = new Vector2(0.6f, 0.6f);
                level.Position    = new Vector2(startposition.X + x * xOffset, newPosition.Y - 150);
                RootList.Add(level);
            }
        }
        returnButton          = new Button("Sprites/Menu/Return_Button", 101);
        returnButton.Position = new Vector2(GameEnvironment.Screen.X / 2 - returnButton.Width / 2, (GameEnvironment.Screen.Y - returnButton.Height) / 16 * 15);
        RootList.Add(returnButton);
    }
    public bool CollidesWith(SpriteGameObject obj)
    {
        if (!visible || !obj.visible || !BoundingBox.Intersects(obj.BoundingBox))
        {
            return(false);
        }
        if (!PerPixelCollisionDetection)
        {
            return(true);
        }
        Rectangle b = Collision.Intersection(BoundingBox, obj.BoundingBox);

        for (int x = 0; x < b.Width; x++)
        {
            for (int y = 0; y < b.Height; y++)
            {
                int thisx = b.X - (int)(GlobalPosition.X - origin.X) + x;
                int thisy = b.Y - (int)(GlobalPosition.Y - origin.Y) + y;
                int objx  = b.X - (int)(obj.GlobalPosition.X - obj.origin.X) + x;
                int objy  = b.Y - (int)(obj.GlobalPosition.Y - obj.origin.Y) + y;
                if (sprite.IsTranslucent(thisx, thisy) && obj.sprite.IsTranslucent(objx, objy))
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Example #5
0
        public TitleScreenState()
        {
            background = new SpriteGameObject("background");


            this.Add(background);
        }
        public LevelMenuState()
        {
            SpriteGameObject levelMenu = new SpriteGameObject("Sprites/spr_background_levelselect");

            gameObjects.AddChild(levelMenu);

            backButton          = new Button("Sprites/UI/spr_button_back");
            backButton.Position = new Vector2(415, 720);
            gameObjects.AddChild(backButton);

            int numberOfLevels = PenguinPairs.NumberOfLevels;

            levelButtons = new LevelButton[numberOfLevels];

            Vector2   gridOffset          = new Vector2(155, 230);
            const int buttonsPerRow       = 5;
            const int spaceBetweenColumns = 30;
            const int spaceBetweenRows    = 5;

            for (int i = 0; i < numberOfLevels; i++)
            {
                LevelButton levelButton = new LevelButton(i + 1, PenguinPairs.GetLevelStatus(i + 1));

                int row    = i / buttonsPerRow;
                int column = i % buttonsPerRow;
                levelButton.Position = gridOffset + new Vector2(
                    column * (levelButton.Width + spaceBetweenColumns),
                    row * (levelButton.Height + spaceBetweenRows));

                gameObjects.AddChild(levelButton);
                levelButtons[i] = levelButton;
            }
        }
Example #7
0
 public GameOverState()
 {
     playingState = GameEnvironment.GameStateManager.GetGameState("playingState");
     overlay = new SpriteGameObject("Overlays/spr_gameover");
     overlay.Position = new Vector2(GameEnvironment.Screen.X, GameEnvironment.Screen.Y) / 2 - overlay.Center;
     this.Add(overlay);
 }
Example #8
0
 public override void HandleInput(InputHelper inputHelper)
 {
     base.HandleInput(inputHelper);
     if (inputHelper.MousePosition.X < this.Position.X + 58 && inputHelper.MousePosition.X > this.Position.X + 22 && inputHelper.MousePosition.Y < this.Position.Y + 15 && inputHelper.MousePosition.Y > this.Position.Y)
     {
         if (inputHelper.MouseLeftButtonPressed())
         {
             GameObjectList level = this.parent as GameObjectList;
             UI             ui    = level.Find("ui") as UI;
             if (!active)
             {
                 this.Sprite = new SpriteSheet("Sprites/homeActive", 0);
                 active      = true;
                 SpriteGameObject buffer = ui.Find("buffer") as SpriteGameObject;
                 buffer.Visible = false;
                 GameEnvironment.AssetManager.PlaySound("Sounds/snd_switch");
             }
             else
             {
                 this.Sprite = new SpriteSheet("Sprites/home", 0);
                 active      = false;
                 SpriteGameObject buffer = ui.Find("buffer") as SpriteGameObject;
                 buffer.Visible = true;
                 GameEnvironment.AssetManager.PlaySound("Sounds/snd_switch");
             }
         }
     }
 }
Example #9
0
    public LevelMenuState()
    {
        PlayingState playingState = GameEnvironment.GameStateManager.GetGameState("playingState") as PlayingState;
        List <Level> levels       = playingState.Levels;

        // add a background
        SpriteGameObject background = new SpriteGameObject("Backgrounds/spr_levelselect", 0, "background");

        Add(background);

        // add the level buttons
        for (int i = 0; i < 12; i++)
        {
            int         row    = i / 4;
            int         column = i % 4;
            LevelButton level  = new LevelButton(i + 1, levels[i], 1);
            level.Position = new Vector2(column * (level.Width + 20), row * (level.Height + 20)) + new Vector2(390, 180);
            Add(level);
        }

        // add a back button
        backButton          = new Button("Sprites/spr_button_back", 1);
        backButton.Position = new Vector2((GameEnvironment.Screen.X - backButton.Width) / 2, 750);
        Add(backButton);
    }
Example #10
0
        public StatusBar()
            : base()
        {
            clickableObjects = new GameObjectList();

            background = new SpriteGameObject("spr_bar");

            overHeadArrowsIcon = new ClickableSpriteGameObject("arrow_raining", IconType.OverheadArrowsIcon);
            rollingBoulderIcon = new ClickableSpriteGameObject("bolder_powerupp", IconType.RollingBoulderIcon);
            boilingOilIcon = new ClickableSpriteGameObject("spr_keuze_mage", IconType.BoilingOilIcon);

            moneyCount = new TextGameObject("GameFont");

            overHeadArrowsIcon.Position = new Vector2(975, 30);
            rollingBoulderIcon.Position = new Vector2(1075, 30);
            boilingOilIcon.Position = new Vector2(1175, 30);

            moneyCount.Position = new Vector2(800, 30);
            moneyCount.Text = "";

            clickableObjects.Add(overHeadArrowsIcon);
            clickableObjects.Add(rollingBoulderIcon);
            clickableObjects.Add(boilingOilIcon);

            Add(background);

            Add(overHeadArrowsIcon);
            Add(rollingBoulderIcon);
            Add(boilingOilIcon);
            Add(moneyCount);
        }
Example #11
0
    /// <summary>Create the level.</summary>
    /// <param name="levelIndex">The index of the level.</param>
    public Level(int levelIndex)
    {
        // load the backgrounds
        GameObjectList backgrounds = new GameObjectList(0, "backgrounds");
        SpriteGameObject background_main = new SpriteGameObject("Backgrounds/spr_sky");
        background_main.Position = new Vector2(0, GameEnvironment.Screen.Y - background_main.Height);
        backgrounds.Add(background_main);

        Add(new GameObjectList(1, "waterdrops"));
        Add(new GameObjectList(2, "enemies"));

        LoadTiles("Content/Levels/" + levelIndex + ".txt");

        // add a few random mountains
        for (int i = 0; i < 5; i++)
        {
            SpriteGameObject mountain = new SpriteGameObject("Backgrounds/spr_mountain_" + (GameEnvironment.Random.Next(2) + 1), 1, "", 0, SpriteGameObject.Backgroundlayer.background);
            mountain.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * (width * cellWidth) - mountain.Width / 2,
                (height * cellHeight) - mountain.Height);
            backgrounds.Add(mountain);
        }

        Clouds clouds = new Clouds(2, "", this);
        backgrounds.Add(clouds);
        Add(backgrounds);

        SpriteGameObject timerBackground = new SpriteGameObject("Sprites/spr_timer", 100);
        timerBackground.Position = new Vector2(10, 10);
        Add(timerBackground);
        
        quitButton = new Button("Sprites/spr_button_quit", 100);
        quitButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 10);
        Add(quitButton);
        
    }
Example #12
0
    public PlayingState()
    {
        // add a background
        SpriteGameObject background = new SpriteGameObject("Sprites/spr_background_level");

        gameObjects.AddChild(background);

        // add a "hint" button
        hintButton = new Button("Sprites/UI/spr_button_hint");
        hintButton.LocalPosition = new Vector2(916, 20);
        gameObjects.AddChild(hintButton);

        // add a "retry" button, initially invisible
        retryButton = new Button("Sprites/UI/spr_button_retry");
        retryButton.LocalPosition = new Vector2(916, 20);
        retryButton.Visible       = false;
        gameObjects.AddChild(retryButton);

        // add a "quit" button
        quitButton = new Button("Sprites/UI/spr_button_quit");
        quitButton.LocalPosition = new Vector2(1058, 20);
        gameObjects.AddChild(quitButton);

        // add an overlay image
        completedOverlay = new SpriteGameObject("Sprites/spr_level_finished");
        gameObjects.AddChild(completedOverlay);
    }
 /// <summary>Update the clouds.</summary>
 public override void Update(GameTime gameTime)
 {
     base.Update(gameTime);
     foreach (GameObject obj in gameObjects)
     {
         SpriteGameObject c = obj as SpriteGameObject;
         if ((c.Velocity.X < 0 && c.Position.X + c.Width < 0) || (c.Velocity.X > 0 && c.Position.X > level.Width))
         {
             Remove(c);
             SpriteGameObject cloud = new SpriteGameObject("Backgrounds/spr_cloud_" + (GameEnvironment.Random.Next(5) + 1), 0, "", 0, SpriteGameObject.Backgroundlayer.middle);
             cloud.Velocity = new Vector2((float)((GameEnvironment.Random.NextDouble() * 2) - 1) * 20, 0);
             float cloudHeight = (float)GameEnvironment.Random.NextDouble() * level.Height - cloud.Height / 2;
             if (cloud.Velocity.X < 0)
             {
                 cloud.Position = new Vector2(level.Width, cloudHeight);
             }
             else
             {
                 cloud.Position = new Vector2(-cloud.Width, cloudHeight);
             }
             Add(cloud);
             return;
         }
     }
 }
Example #14
0
 public void CheckConnection()
 {
     if (placed && !connected)
     {
         SpriteGameObject home = GameWorld.Find("home") as SpriteGameObject;
         if (this.CollidesWith(home))
         {
             connected = true;
         }
         GameObjectList    towerList = GameWorld.Find("towerlist") as GameObjectList;
         List <GameObject> towers    = towerList.Objects;
         foreach (Tower tower in towers)
         {
             if (this.CollidesWith(tower) && tower.Connected)
             {
                 this.connected = true;
             }
         }
         if (connected)
         {
             GameObjectList    towerList2 = GameWorld.Find("towerlist") as GameObjectList;
             List <GameObject> towers2    = towerList2.Objects;
             foreach (Tower tower2 in towers2)
             {
                 tower2.CheckConnection();
             }
         }
     }
 }
Example #15
0
 public override void Update(GameTime gameTime)
 {
     base.Update(gameTime);
     foreach (GameObject obj in children)
     {
         SpriteGameObject c = obj as SpriteGameObject;
         if ((c.Velocity.X < 0 && c.Position.X + c.Width < 0) || (c.Velocity.X > 0 && c.Position.X > GameEnvironment.Screen.X))
         {
             Remove(c);
             SpriteGameObject cloud = new HalfLockedSpriteGameObject("Backgrounds/spr_cloud_" + (GameEnvironment.Random.Next(5) + 1), scalingFactor: scalingFactor);
             cloud.Velocity = new Vector2((float)((GameEnvironment.Random.NextDouble() * 2) - 1) * 20, 0);
             float cloudHeight = ((float)GameEnvironment.Random.NextDouble() * (layerHeight - cloud.Height * 1.3f) + minHeight - 10);
             if (cloud.Velocity.X < 0)
             {
                 cloud.Position = new Vector2(GameEnvironment.Screen.X, cloudHeight);
             }
             else
             {
                 cloud.Position = new Vector2(-cloud.Width, cloudHeight);
             }
             Add(cloud);
             return;
         }
     }
 }
Example #16
0
    public Level(int levelIndex)
    {
        GameObjectList   backgrounds     = new GameObjectList(0, "backgrounds");
        SpriteGameObject background_main = new SpriteGameObject("Backgrounds/spr_sky");

        background_main.Position = new Vector2(0, GameEnvironment.Screen.Y - background_main.Sprite.SheetHeight);
        backgrounds.Add(background_main);

        for (int i = 0; i < 5; i++)
        {
            SpriteGameObject mountain = new SpriteGameObject("Backgrounds/spr_mountain_" + (GameEnvironment.Random.Next(2) + 1), 1);
            mountain.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.X - mountain.Sprite.SheetWidth / 2, GameEnvironment.Screen.Y - mountain.Sprite.SheetHeight);
            backgrounds.Add(mountain);
        }

        Clouds clouds = new Clouds(2);

        backgrounds.Add(clouds);
        this.Add(backgrounds);

        QuitButton          = new Button("Sprites/spr_button_back", 100);
        QuitButton.Position = new Vector2(10, 10);
        this.Add(QuitButton);

        this.Add(new GameObjectList(1, "ZenyS"));

        this.LoadTiles("Content/Levels/" + levelIndex + ".txt");

        GameObjectList ZenyS = this.Find("ZenyS") as GameObjectList;

        GameScore          = new Score(ZenyS);
        GameScore.Position = new Vector2(GameEnvironment.Screen.X - 60, 10);
        this.Add(GameScore);
    }
Example #17
0
    public Level(int levelIndex)
    {
        // load the backgrounds
        GameObjectList   backgrounds   = new GameObjectList(0, "backgrounds");
        SpriteGameObject backgroundSky = new SpriteGameObject("Backgrounds/spr_sky");

        backgroundSky.Position = new Vector2(0, GameEnvironment.Screen.Y - backgroundSky.Height);
        backgrounds.Add(backgroundSky);

        // add a few random mountains
        for (int i = 0; i < 9; i++)                                                                                                             //9 mountains in 9 layers for now
        {
            SpriteGameObject mountain = new SpriteGameObject("Backgrounds/spr_mountain_" + (GameEnvironment.Random.Next(2) + 1), i);            //changed 1 to i
            mountain.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * (GameEnvironment.Screen.X + 600) - mountain.Width / 2, //+600 för nu
                                            GameEnvironment.Screen.Y - mountain.Height);
            if (mountain.Layer <= 2)                                                                                                            //9 mountains into 3 different layers with 3 different speeds
            {
                mountain.Layer  = 0;                                                                                                            //scroll is to illustrate the speed of the mountains
                mountain.Scroll = 0.1f;
            }
            else if (mountain.Layer <= 5)
            {
                mountain.Layer  = 1;
                mountain.Scroll = 0.05f;
            }
            else
            {
                mountain.Layer  = 2;
                mountain.Scroll = 0.01f;
            }
            backgrounds.Add(mountain);

            /*  SpriteGameObject mountain = new SpriteGameObject("Backgrounds/spr_mountain_" + (GameEnvironment.Random.Next(2) + 1), 1);
             * mountain.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.X - mountain.Width / 2,
             *    GameEnvironment.Screen.Y - mountain.Height);
             * backgrounds.Add(mountain); */
        }
        //  Clouds clouds = new Clouds(2);
        //  backgrounds.Add(clouds);
        Add(backgrounds);

        SpriteGameObject timerBackground = new SpriteGameObject("Sprites/spr_timer", 100);

        timerBackground.Position = new Vector2(10, 10);
        Add(timerBackground);
        TimerGameObject timer = new TimerGameObject(101, "timer");

        timer.Position = new Vector2(25, 30);
        Add(timer);

        quitButton          = new Button("Sprites/spr_button_quit", 100);
        quitButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 10);
        Add(quitButton);


        Add(new GameObjectList(1, "waterdrops"));
        Add(new GameObjectList(2, "enemies"));

        LoadTiles("Content/Levels/" + levelIndex + ".txt");
    }
Example #18
0
    public Level(int levelIndex)
    {
        // load the backgrounds
        GameObjectList   backgrounds   = new GameObjectList(0, "backgrounds");
        SpriteGameObject backgroundSky = new SpriteGameObject("Backgrounds/spr_sky", 1);

        backgroundSky.Position = new Vector2(0, GameEnvironment.Screen.Y - backgroundSky.Height);
        backgrounds.Add(backgroundSky);

        // add a few random mountains
        for (int i = 0; i < 5; i++)
        {
            SpriteGameObject mountain = new SpriteGameObject("Backgrounds/spr_mountain_" + (GameEnvironment.Random.Next(2) + 1), (GameEnvironment.Random.Next(3, 5)));
            mountain.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.X - mountain.Width / 2,
                                            GameEnvironment.Screen.Y - mountain.Height);
            backgrounds.Add(mountain);
        }

        Clouds clouds = new Clouds(4);

        backgrounds.Add(clouds);
        Add(backgrounds);

        quitButton          = new Button("Sprites/spr_button_quit", 100);
        quitButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 10);
        Add(quitButton);

        Add(new GameObjectList(6, "waterdrops"));
        Add(new GameObjectList(7, "enemies"));

        LoadTiles("Content/Levels/" + levelIndex + ".txt");
    }
        public PlayingState()
        {
            background = new SpriteGameObject("spr_Background", 0, "", 0, 80);
            this.Add(background);
            Cursor cursor = new Cursor(2);

            map = new MapV2(scale, new Point(50, 50));
            world.Add(map);

            player = new BaseEntity("spr_Humanoid", scale, map.RandomFreePositionInMap(), map, world, true, cursor);
            //Buffs player because else it is to hard
            player.movementSpeed *= 3;
            player.maxHealth     *= 4;
            player.health        *= 4;

            world.Add(player);
            //Adds enemies
            for (int i = 0; i < map.Columns / 5; i++)
            {
                world.Add(new BaseEntity("spr_Humanoid", scale, map.RandomFreePositionInMap(), map, world, false, player));
            }
            this.Add(world);
            this.Add(new MiniMap(map, player, world, new Point(42, 42), 1, MiniMap.ViewLoc.TopRight));

            hud = new HUD(player);
            this.Add(hud);
            this.Add(cursor);
        }
Example #20
0
    public LevelMenuState()
    {
        int buttonSpacing = 20;

        // add a background
        SpriteGameObject background = new SpriteGameObject("Backgrounds/spr_levelselect", 0, "background");

        this.Add(background);

        // add the level button
        LevelButton levelButton = new LevelButton(1, "Sprites/spr_level_solved");

        levelButton.Position = new Vector2(390, 180);
        this.Add(levelButton);

        // add the level button
        LevelButton levelButton2 = new LevelButton(2, "Sprites/spr_level_solved");

        levelButton2.Position = new Vector2(390 + buttonSpacing + levelButton.Width, 180);
        this.Add(levelButton2);

        // add a back button
        backButton          = new Button("Sprites/spr_button_back", 1);
        backButton.Position = new Vector2((GameEnvironment.Screen.X - backButton.Width) / 2, 750);
        this.Add(backButton);
    }
        public PainterGameWorld()
        {
            background = new SpriteGameObject("spr_background");

            scoreBar = new SpriteGameObject("spr_scorebar");

            cannon = new Cannon();

            canSprites = new GameObjectList();
            canSprites.Add(new PaintCan(450f, Color.Red));
            canSprites.Add(new PaintCan(575f, Color.Green));
            canSprites.Add(new PaintCan(700f, Color.Blue));

            scoreText = new TextGameObject("GameFont");
            scoreText.Position = new Vector2(5, 7);

            livesSprites = new GameObjectList();
            for(int iLife = 0; iLife < MAX_LIVES; iLife++)
            {
                SpriteGameObject life = new SpriteGameObject("spr_lives", 0, iLife.ToString());
                life.Position = new Vector2(iLife * life.BoundingBox.Width, scoreBar.Position.Y + scoreBar.BoundingBox.Height + 15);
                livesSprites.Add(life);
            }

            //Add the background sprite to the gameworld
            Add(background);
            Add(scoreBar);
            Add(cannon);
            Add(canSprites);
            Add(scoreText);
            Add(livesSprites);

            Reset();
        }
Example #22
0
 public HumanityBaseMenu(Tile tile)
     : base(10, "barracksMenu")
 {
     actionString        = null;
     actionSent          = false;
     this.tile           = tile;
     background          = new SpriteGameObject("button", 0, "background", 4);
     background.Position = new Vector2(GameData.Cursor.CurrentTile.Position.X, GameData.Cursor.CurrentTile.Position.Y + (new Tile().Height * 3 / 2));
     background.Origin   = background.Sprite.Center;
     this.Add(background);
     button1          = new Button("checkBox", "", "", 0, "", 4);
     button1.Position = background.Position + new Vector2(-120, 0);
     button2          = new Button("workerhButton", "", "", 0, "", 4);
     button2.Position = button1.Position + new Vector2(button1.Width + 30, 0);
     button3          = new Button("woodcutterButton", "", "", 0, "", 4);
     button3.Position = button2.Position + new Vector2(button1.Width + 30, 0);
     addButton(button1);
     addButton(button2);
     addButton(button3);
     for (int i = 0; i < GameData.LevelObjects.Objects.Count; i++)
     {
         if (GameData.LevelObjects.Objects[i] is Player)
         {
             player = GameData.LevelObjects.Objects[i] as Player;
             return;
         }
     }
 }
Example #23
0
 public override void Update(GameTime GameTime)
 {
     base.Update(GameTime);
     foreach (GameObject obj in gameObjects)
     {
         SpriteGameObject c = obj as SpriteGameObject;
         if ((c.Velocity.X < 0 && c.Position.X + c.Sprite.SheetWidth < 0) || (c.Velocity.X > 0 && c.Position.X > GameEnvironment.Screen.X))
         {
             this.Remove(c);
             SpriteGameObject cloud = new SpriteGameObject("Backgrounds/spr_cloud_" + (GameEnvironment.Random.Next(5) + 1));
             cloud.Velocity = new Vector2((float)((GameEnvironment.Random.NextDouble() * 2) - 1) * 20, 0);
             float cloudHeight = (float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.Y - cloud.Sprite.SheetHeight / 2;
             if (cloud.Velocity.X < 0)
             {
                 cloud.Position = new Vector2(GameEnvironment.Screen.X, cloudHeight);
             }
             else
             {
                 cloud.Position = new Vector2(-cloud.Sprite.SheetWidth, cloudHeight);
             }
             this.Add(cloud);
             return;
         }
     }
 }
 /// <summary>Create the level finished state.</summary>
 public LevelFinishedState()
 {
     playingState = GameEnvironment.GameStateManager.GetGameState("playingState");
     SpriteGameObject overlay = new SpriteGameObject("Overlays/spr_welldone");
     overlay.Position = new Vector2(GameEnvironment.Screen.X, GameEnvironment.Screen.Y) / 2 - overlay.Center;
     Add(overlay);
 }
Example #25
0
        /// <summary>
        /// Returns on which side of this object a collision takes place.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public CollisionResult CollisionSide(SpriteGameObject other)
        {
            float distanceToLeftEdge  = GlobalPosition.X - Origin.X + Width - other.GlobalPosition.X - other.Origin.X;
            float distanceToRightEdge = other.GlobalPosition.X - other.Origin.X + other.Width - GlobalPosition.X - Origin.X;
            float xOverlap            = distanceToLeftEdge < 0 || distanceToRightEdge < 0 ? 0 :
                                        distanceToLeftEdge <= distanceToRightEdge?Math.Abs(distanceToLeftEdge) : Math.Abs(distanceToRightEdge);

            float distanceToTopEdge    = GlobalPosition.Y - Origin.Y + Height - other.GlobalPosition.Y - other.Origin.Y;
            float distanceToBottomEdge = other.GlobalPosition.Y - other.Origin.Y + other.Height - GlobalPosition.Y - Origin.Y;
            float yOverlap             = distanceToTopEdge < 0 || distanceToBottomEdge < 0 ? 0 :
                                         distanceToTopEdge <= distanceToBottomEdge?Math.Abs(distanceToTopEdge) : Math.Abs(distanceToBottomEdge);

            if (xOverlap < yOverlap)
            {
                if (GlobalPosition.X - Origin.X < other.GlobalPosition.X - other.Origin.X)
                {
                    return(CollisionResult.RIGHT);
                }
                else
                {
                    return(CollisionResult.LEFT);
                }
            }
            else
            {
                if (GlobalPosition.Y - Origin.Y < other.GlobalPosition.Y - other.Origin.Y)
                {
                    return(CollisionResult.BOTTOM);
                }
                else
                {
                    return(CollisionResult.TOP);
                }
            }
        }
Example #26
0
        public PlayingState()
        {
            SpriteGameObject background = new SpriteGameObject("Sprites/spr_background_level");

            gameObjects.AddChild(background);

            // Adding the hintButton
            hintButton = new Button("Sprites/UI/spr_button_hint")
            {
                Position = new Vector2(916, 20)
            };
            gameObjects.AddChild(hintButton);

            // Adding the retryButton
            retryButton = new Button("Sprites/UI/spr_button_retry")
            {
                Position = new Vector2(916, 20),
                Visible  = false
            };
            gameObjects.AddChild(retryButton);

            // Adding the quitButton
            quitButton = new Button("Sprites/UI/spr_button_quit")
            {
                Position = new Vector2(1058, 20)
            };
            gameObjects.AddChild(quitButton);

            completedOverlay = new SpriteGameObject("Sprites/spr_level_finished");
            gameObjects.AddChild(completedOverlay);
        }
Example #27
0
    public bool CollidesWithBottomOfOther(SpriteGameObject obj)
    {
        if (!PerPixelCollisionDetection)
        {
            Rectangle otherBotBoundingBox = new Rectangle(obj.BoundingBox.Left, obj.BoundingBox.Top, obj.Width, 1);
            return(otherBotBoundingBox.Intersects(obj.BoundingBox));
        }
        Rectangle b = Collision.Intersection(BoundingBox, obj.BoundingBox);

        for (int x = 0; x < b.Width; x++)
        {
            for (int y = 0; y < b.Height; y++)
            {
                int thisx = b.X - (int)(GlobalPosition.X - origin.X) + x;
                int thisy = b.Y - (int)(GlobalPosition.Y - origin.Y) + y;
                int objx  = b.X - (int)(obj.GlobalPosition.X - obj.origin.X) + x;
                int objy  = b.Y - (int)(obj.GlobalPosition.Y - obj.origin.Y) + y;
                if (sprite.IsTranslucent(thisx, thisy) && obj.sprite.IsTranslucent(objx, objy) && objy > b.Height)
                {
                    return(true);
                }
                if (sprite.IsTranslucent(thisx, thisy) && obj.sprite.IsTranslucent(objx, objy) && thisy < 1)
                {
                    return(true);
                }
                else if (sprite.IsTranslucent(thisx, thisy) && objy < obj.Height / 8 && obj.sprite.IsTranslucent(objx, objy) && !obj.sprite.IsTranslucent(objx, objy + 1) && !sprite.IsTranslucent(thisx, thisy - 1))
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Example #28
0
    /// <summary>
    /// Adds game objects that show the level's general information: two text objects and a background image.
    /// </summary>
    /// <param name="title">The title of the level.</param>
    /// <param name="description">The one-line description of the level.</param>
    void AddLevelInfoObjects(string title, string description)
    {
        // - background box
        SpriteGameObject infoBackground = new SpriteGameObject("Sprites/spr_level_info");

        infoBackground.SetOriginToCenter();
        infoBackground.LocalPosition = new Vector2(600, 820);
        AddChild(infoBackground);

        // - title text
        TextGameObject titleText = new TextGameObject("Fonts/HelpFont", Color.Blue, TextGameObject.Alignment.Center);

        titleText.Text          = LevelIndex + " - " + title;
        titleText.LocalPosition = new Vector2(600, 786);
        AddChild(titleText);

        // - description text
        TextGameObject descriptionText = new TextGameObject("Fonts/HelpFont", Color.DarkBlue, TextGameObject.Alignment.Center);

        descriptionText.Text          = description;
        descriptionText.LocalPosition = new Vector2(600, 820);
        AddChild(descriptionText);

        // - number of pairs
        pairList = new PairList(targetNumberOfPairs);
        pairList.LocalPosition = new Vector2(20, 20);
        AddChild(pairList);
    }
Example #29
0
    public LevelFinishedState()
    {
        playingState = GameEnvironment.GameStateManager.GetGameState("playingState") as PlayingState;
        SpriteGameObject overlay = new SpriteGameObject("Sprites/Starbackground");

        star1 = new SpriteGameObject("Sprites/Star");
        star2 = new SpriteGameObject("Sprites/Star");
        star3 = new SpriteGameObject("Sprites/Star");

        overlay.Position = new Vector2(GameEnvironment.Screen.X, GameEnvironment.Screen.Y) / 2 - overlay.Center;
        star1.Position   = overlay.Position + new Vector2(star1.Width / 2, star1.Height / 5);
        star3.Position   = overlay.Position + new Vector2(star2.Width * 3, star1.Height / 5);
        star2.Position   = overlay.Position + new Vector2(overlay.Width / 2 - 50, star1.Height / 5);

        this.Add(overlay);
        this.Add(star1);
        this.Add(star2);
        this.Add(star3);
        star2.Visible       = false;
        star3.Visible       = false;
        quitButton          = new Button("Sprites/spr_button_quit", 100);
        quitButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 10);
        this.Add(quitButton);
        nextButton          = new Button("Sprites/spr_button_next", 100);
        nextButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 130);
        this.Add(nextButton);
    }
Example #30
0
    public override void Update(GameTime gameTime)     //de locatie van het packet blijven updaten
    {
        base.Update(gameTime);



        if (inBuffer)
        {
            SpriteGameObject buffer = GameWorld.Find("buffer") as SpriteGameObject;
            if (!buffer.Visible)
            {
                this.remove  = true;
                bufferAmount = 0;
            }
            else if (this.CollidesWith(buffer))
            {
                this.Velocity = -this.Velocity;
            }
        }
        else if (StageIndex != Path.Count - 1)
        {
            velocity  = Directions[StageIndex] * Speed;
            StagePos += (float)gameTime.ElapsedGameTime.TotalSeconds * Speed;

            if (StagePos > Lengths[StageIndex])
            {
                StageIndex++;
                StagePos = 0;
            }
        }
    }
        public PlayingState()
            : base()
        {
            SpriteGameObject background = new SpriteGameObject("calligraphy");

            this.Add(background);
            balls = new GameObjectList(0, "balls");

            Random random = new Random();


            for (int i = 0; i < 20; i++)
            {
                int    randomsprite = random.Next(1, 4);
                string assetName    = "spr_ball_green";
                if (randomsprite == 1)
                {
                    assetName = "spr_ball_green";
                }
                if (randomsprite == 2)
                {
                    assetName = "spr_ball_blue";
                }
                if (randomsprite == 3)
                {
                    assetName = "spr_ball_red";
                }

                Vector2 aPositon  = new Vector2(random.Next(100, 700), random.Next(100, 500));
                Vector2 aVelocity = new Vector2(((float)random.NextDouble() - 0.5f) * 10, ((float)random.NextDouble() - 0.5f) * 10);

                balls.Add(new Ball(assetName, aPositon, aVelocity, Vector2.Zero, new Vector2(0, EARTH_GRAVITY), random.FloatBetween(8, 23), 0.85f));
            }
            this.Add(balls);
        }
Example #32
0
    public void CreatePlayers()
    {
        int count = 0;

        foreach (LobbyPlayer lobbyplayer in playerlist.playerlist)
        {
            if (MyIP().ToString() != lobbyplayer.ip.ToString())
            {
                if (count == 0)
                {
                    SpriteGameObject player1 = new SpriteGameObject("Sprites/Player/Wizzard/spr_walking_0@8", id: "player1");
                }
                else if (count == 1)
                {
                    SpriteGameObject player2 = new SpriteGameObject("Sprites/Player/Wizzard/spr_walking_0@8", id: "player2");
                }
                else if (count == 2)
                {
                    SpriteGameObject player3 = new SpriteGameObject("Sprites/Player/Wizzard/spr_walking_0@8", id: "player3");
                }
                else if (count == 3)
                {
                    SpriteGameObject player4 = new SpriteGameObject("Sprites/Player/Wizzard/spr_walking_0@8", id: "player4");
                }
            }
            count++;
        }
    }
Example #33
0
    protected override void LoadContent()
    {
        DrawingHelper.Initialize(this.GraphicsDevice);
        spriteBatch = new SpriteBatch(GraphicsDevice);

        spritemouse = new SpriteGameObject("Sprites/Menu/spr_mouse", 200);
    }
Example #34
0
    public BarracksMenu(Tile tile) : base(4, "barracksMenu")
    {
        this.tile           = tile;
        actionSent          = false;
        background          = new SpriteGameObject("button", 0, "background", 4);
        background.Position = new Vector2(GameData.Cursor.CurrentTile.Position.X, GameData.Cursor.CurrentTile.Position.Y + (new Tile().Height * 3 / 2));
        background.Origin   = background.Sprite.Center;
        this.Add(background);
        this.actionString = null;

        if (tile is NatureBarracks)
        {
            CreateNatureMenu();
        }
        else
        {
            CreateHumanityMenu();
        }

        for (int i = 0; i < GameData.LevelObjects.Objects.Count; i++)
        {
            if (GameData.LevelObjects.Objects[i] is Player)
            {
                player = GameData.LevelObjects.Objects[i] as Player;
                return;
            }
        }
    }
Example #35
0
    public bool CollidesWith(SpriteGameObject obj)
    {
        if (!this.Visible || !obj.Visible || !BoundingBox.Intersects(obj.BoundingBox))
        {
            return(false);
        }
        Rectangle b = Collision.Intersection(BoundingBox, obj.BoundingBox);

        for (int x = 0; x < b.Width; x++)
        {
            for (int y = 0; y < b.Height; y++)
            {
                int thisx = b.X - (int)(GlobalPosition.X - Origin.X) + x;
                int thisy = b.Y - (int)(GlobalPosition.Y - Origin.Y) + y;
                int objx  = b.X - (int)(obj.GlobalPosition.X - obj.Origin.X) + x;
                int objy  = b.Y - (int)(obj.GlobalPosition.Y - obj.Origin.Y) + y;
                if (Sprite.GetPixelColor(thisx, thisy).A != 0 &&
                    obj.Sprite.GetPixelColor(objx, objy).A != 0)
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Example #36
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;
    }
Example #37
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();
 }
Example #38
0
        public HelpState()
        {
            SpriteGameObject background = new SpriteGameObject("Backgrounds/spr_help", 0, "background");
            Add(background);

            backButton = new Button("Sprites/spr_button_back", 1);
            backButton.Position = new Vector2((GameEnvironment.Screen.X - backButton.Width) / 2, 750);
            Add(backButton);
        }
Example #39
0
 public Clouds(int layer = 0, string id = "")
     : base(layer, id)
 {
     for (int i = 0; i < 3; i++)
     {
         SpriteGameObject cloud = new SpriteGameObject("Backgrounds/spr_cloud_" + (GameEnvironment.Random.Next(5) + 1), 2);
         cloud.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.X - cloud.Width / 2, (float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.Y - cloud.Height / 2);
         cloud.Velocity = new Vector2(((float)(GameEnvironment.Random.NextDouble() * 2) - 1) * 20, 0);
         Add(cloud);
     }
 }
Example #40
0
 /// <summary>Add the cloud layer.</summary>
 /// <param name="level">The level the cloud layer is in.</param>
 public Clouds(int layer = 0, string id = "", Level level = null) : base(layer, id)
 {
     this.level = level;
     
     for (int i = 0; i < 10; i++)
     {
         SpriteGameObject cloud = new SpriteGameObject("Backgrounds/spr_cloud_" + (GameEnvironment.Random.Next(5) + 1), 2, "", 0, SpriteGameObject.Backgroundlayer.middle);
         cloud.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * level.Width - cloud.Width / 2, (float)GameEnvironment.Random.NextDouble() * level.Height - cloud.Height / 2);
         cloud.Velocity = new Vector2((float)((GameEnvironment.Random.NextDouble() * 2) - 1) * 20, 0);
         Add(cloud);
     }
 }
        public TitleMenuState()
        {
            SpriteGameObject titleScreen = new SpriteGameObject("Backgrounds/spr_title", 0, "background");
            Add(titleScreen);

            playButton = new Button("Sprites/spr_button_play", 1);
            playButton.Position = new Vector2((GameEnvironment.Screen.X - playButton.Width) / 2, 540);
            Add(playButton);

            helpButton = new Button("Sprites/spr_button_help", 1);
            helpButton.Position = new Vector2((GameEnvironment.Screen.X - helpButton.Width) / 2, 600);
            Add(helpButton);
        }
    /// <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);
            }
    }
Example #43
0
        public GameWorld()
        {
            //soundeffecten inladen
            InsaneKillerArcher.AssetManager.PlayMusic("background_music");

            //laat bovenaan staan, is aleen de achtergrond.
            Add(new SpriteGameObject("background"));

            statusBar = new StatusBar();
            Add(statusBar);

            castle = new Castle();
            groundList = new GameObjectList();

            for (int i = 0; i < InsaneKillerArcher.Screen.X/32; i++)
            {
                ground = new SpriteGameObject("gras");
                ground.Position = new Vector2(i * ground.Width, InsaneKillerArcher.Screen.Y - ground.Height);
                groundList.Add(ground);
            }

            player = new Player();

            player.Position = new Vector2(50, InsaneKillerArcher.Screen.Y - castle.mainCastle.Height - player.Body.Height + 35);

            catapultBoulders = new GameObjectList();

            archers = new GameObjectList();
            catapults = new GameObjectList();

            Add(archers);
            Add(catapults);

            enemySpawner = new EnemySpawner(2, 5);

            arrows = new GameObjectList();
            archerArrows = new GameObjectList();
            animatedProjectiles = new GameObjectList();

            Add(castle);
            Add(enemySpawner);
            Add(player);
            Add(catapultBoulders);
            Add(arrows);
            Add(archerArrows);
            Add(animatedProjectiles);
            Add(groundList);
        }
Example #44
0
    public TitleMenuState()
    {
        // load the title screen
        SpriteGameObject title_screen = new SpriteGameObject("Backgrounds/spr_title", 0, "background");
        this.Add(title_screen);

        // add a play button
        playButton = new Button("Sprites/spr_button_play", 1);
        playButton.Position = new Vector2((GameEnvironment.Screen.X - playButton.Width) / 2, 540);
        this.Add(playButton);

        // add a help button
        helpButton = new Button("Sprites/spr_button_help", 1);
        helpButton.Position = new Vector2((GameEnvironment.Screen.X - helpButton.Width) / 2, 600);
        this.Add(helpButton);
    }
    /// <summary>Create a level button.</summary>
    /// <param name="levelIndex">The index of the level.</param>
    /// <param name="level">The level to start.</param>
    public LevelButton(int levelIndex, Level level, int layer = 0, string id = "") : base(layer, id)
    {
        this.levelIndex = levelIndex;
        this.level = level;

        levels_solved = new SpriteGameObject("Sprites/spr_level_solved", 0, "", levelIndex - 1);
        levels_unsolved = new SpriteGameObject("Sprites/spr_level_unsolved");
        spr_lock = new SpriteGameObject("Sprites/spr_level_locked", 2);
        Add(levels_solved);
        Add(levels_unsolved);
        Add(spr_lock);

        text = new TextGameObject("Fonts/Hud", 1);
        text.Text = levelIndex.ToString();
        text.Position = new Vector2(spr_lock.Width - text.Size.X - 10, 5);
        Add(text);
    }
 /// <summary>Is this object colliding with a given object?</summary>
 /// <param name="obj">The object to check collision with.</param>
 public bool CollidesWith(SpriteGameObject obj)
 {
     if (!Visible || !obj.Visible || !Collision.IsColliding(BoundingBox, obj.BoundingBox))
         return false;
     Rectangle b = Collision.Intersection(BoundingBox, obj.BoundingBox);
     for (int x = 0; x < b.Width; x++)
         for (int y = 0; y < b.Height; y++)
         {
             int thisx = b.X - (int)(GlobalPosition.X - origin.X) + x;
             int thisy = b.Y - (int)(GlobalPosition.Y - origin.Y) + y;
             int objx = b.X - (int)(obj.GlobalPosition.X - obj.origin.X) + x;
             int objy = b.Y - (int)(obj.GlobalPosition.Y - obj.origin.Y) + y;
             if (sprite.GetPixelColor(thisx, thisy).A != 0 &&
                 obj.sprite.GetPixelColor(objx, objy).A != 0)
                 return true;
         }
     return false;
 }
Example #47
0
    public Player(Vector2 start)
        : base(2, "player")
    {
        this.LoadAnimation("Sprites/Player/spr_idle", "idle", true);
        this.LoadAnimation("Sprites/Player/spr_run@13", "run", true, 0.05f);
        this.LoadAnimation("Sprites/Player/spr_jump@14", "jump", false, 0.05f);
        this.LoadAnimation("Sprites/Player/spr_celebrate@14", "celebrate", false, 0.05f);
        this.LoadAnimation("Sprites/Player/spr_die@5", "die", false);
        this.LoadAnimation("Sprites/Player/spr_explode@5x5", "explode", false, 0.04f);
        this.LoadAnimation("Sprites/Player/shield8@2", "shield", true, 0.04F);
        this.LoadAnimation("Sprites/Player/smoke", "smoke", false);

        for(int i = 0; i < smokeList.Length; i++)
        {
            smokeList[i] = new SpriteGameObject("smoke");
            smokeList[i].Position = Position;
        }
        startPosition = start;
        Reset();
    }
    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);
            }
    }
Example #49
0
 //Controleert of het object botst/overlapt met een ander object
 public bool CollidesWith(SpriteGameObject obj)
 {
     //Ze botsen/overlappen niet als sowieso een van de twee onzichtbaar is of als de twee boundingboxes niet overlappen
     if (!this.Visible || !obj.Visible || !BoundingBox.Intersects(obj.BoundingBox))
         return false;
     //Roept methode aan die controleert over welk gebied de twee boundingboxes met elkaar overlappen
     Rectangle b = Collision.Intersection(BoundingBox, obj.BoundingBox);
     //Gaat dit gebied af en controleert per pixel of er overlap is
     for (int x = 0; x < b.Width; x++)
         for (int y = 0; y < b.Height; y++)
         {
             int thisx = b.X - (int)(GlobalPosition.X - origin.X) + x;
             int thisy = b.Y - (int)(GlobalPosition.Y - origin.Y) + y;
             int objx = b.X - (int)(obj.GlobalPosition.X - obj.origin.X) + x;
             int objy = b.Y - (int)(obj.GlobalPosition.Y - obj.origin.Y) + y;
             if (sprite.GetPixelColor(thisx, thisy).A != 0
                 && obj.sprite.GetPixelColor(objx, objy).A != 0)
                 return true;
         }
     return false;
 }
Example #50
0
 public override void Update(GameTime gameTime)
 {
     base.Update(gameTime);
     foreach (GameObject obj in gameObjects)
     {
         SpriteGameObject c = obj as SpriteGameObject;
         if ((c.Velocity.X < 0 && c.Position.X + c.Width < 0) || (c.Velocity.X > 0 && c.Position.X > GameEnvironment.Screen.X))
         {
             this.Remove(c);
             SpriteGameObject cloud = new SpriteGameObject("Backgrounds/spr_cloud_" + (GameEnvironment.Random.Next(5) + 1));
             cloud.Velocity = new Vector2((float)((GameEnvironment.Random.NextDouble() * 2) - 1) * 20, 0);
             float cloudHeight = (float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.Y - cloud.Height / 2;
             if (cloud.Velocity.X < 0)
                 cloud.Position = new Vector2(GameEnvironment.Screen.X, cloudHeight);
             else
                 cloud.Position = new Vector2(-cloud.Width, cloudHeight);
             this.Add(cloud);
             return;
         }
     }
 }
        public LevelMenuState()
        {
            PlayingState playingState = GameEnvironment.GameStateManager.GetGameState("playingState") as PlayingState;
            List<Level> levels = playingState.Levels;

            SpriteGameObject background = new SpriteGameObject("Backgrounds/spr_levelselect", 0, "background");
            Add(background);

            for(int i = 0; i < 10; i++)
            {
                int row = i / 4;
                int column = i % 4;
                LevelButton level = new LevelButton(i + 1, levels[i], 1);
                level.Position = new Vector2(column * (level.Width + 20), row * (level.Height + 20)) + new Vector2(390, 180);
                Add(level);
            }

            backButton = new Button("Sprites/spr_button_back", 1);
            backButton.Position = new Vector2((GameEnvironment.Screen.X - backButton.Width) / 2, 750);
            Add(backButton);
        }
Example #52
0
        public Archer(Vector2 newPos)
        {
            body = new SpriteGameObject("spr_archer");
            body.Position = position;

            Add(body);

            weapon = new SpriteGameObject("spr_boog");
            weapon.Origin = weapon.Center;
            weapon.Position = new Vector2(position.X + 15, position.Y + 7);

            Add(weapon);

            angle = 0.0f;
            damage = 25.0f;

            shootDelay = 2.0f;
            timer = 0.0f;

            position = newPos;
        }
Example #53
0
    public Level(int levelIndex)
    {
        // load the backgrounds
        GameObjectList backgrounds = new GameObjectList(0, "backgrounds");
        SpriteGameObject background_main = new SpriteGameObject("Backgrounds/spr_sky");
        background_main.Position = new Vector2(0, GameEnvironment.Screen.Y - background_main.Height);
        backgrounds.Add(background_main);
        SpriteGameObject background_extended = new SpriteGameObject("Backgrounds/spr_sky");
        background_extended.Position = new Vector2(background_main.Width, GameEnvironment.Screen.Y - background_main.Height);
        backgrounds.Add(background_extended);

        // add a few random mountains
        for (int i = 0; i < 10; i++)
        {
            SpriteGameObject mountain = new SpriteGameObject("Backgrounds/spr_mountain_" + (GameEnvironment.Random.Next(2) + 1), GameEnvironment.Random.Next(4)+3);
            mountain.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * (2 * background_main.Width) - mountain.Width / 2, GameEnvironment.Screen.Y - mountain.Height);
            backgrounds.Add(mountain);
        }

        Clouds clouds = new Clouds(4);
        backgrounds.Add(clouds);
        this.Add(backgrounds);

        SpriteGameObject timerBackground = new SpriteGameObject("Sprites/spr_timer", 100);
        timerBackground.Position = new Vector2(10, 10);
        timerBackground.Meebewegen();
        this.Add(timerBackground);
        TimerGameObject timer = new TimerGameObject(101, "timer");
        timer.Position = new Vector2(25, 30);
        this.Add(timer);

        quitButton = new Button("Sprites/spr_button_quit", 100);
        quitButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 10);
        this.Add(quitButton);

        this.Add(new GameObjectList(1, "waterdrops"));
        this.Add(new GameObjectList(2, "enemies"));

        this.LoadTiles("Content/Levels/" + levelIndex + ".txt");
    }
Example #54
0
 public override void Update(GameTime gameTime)
 {
     base.Update(gameTime);
     foreach (GameObject obj in gameObjects)
     {
         SpriteGameObject c = obj as SpriteGameObject;
         //Als hij uit het scherm verdwenen is en hij zich uit het scherm blijft bewegen, wordt het wolkje verwijderd en een nieuw wolkje gevormd
         if ((c.Velocity.X < 0 && c.Position.X + c.Width < 0) || (c.Velocity.X > 0 && c.Position.X > GameEnvironment.Screen.X))
         {
             this.Remove(c);
             SpriteGameObject cloud = new SpriteGameObject("Backgrounds/spr_cloud_" + (GameEnvironment.Random.Next(5) + 1));
             cloud.Velocity = new Vector2((float)((GameEnvironment.Random.NextDouble() * 2) - 1) * 20, 0);
             float cloudHeight = (float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.Y - cloud.Height / 2;
             if (cloud.Velocity.X < 0)
                 cloud.Position = new Vector2(GameEnvironment.Screen.X, cloudHeight);
             else
                 cloud.Position = new Vector2(-cloud.Width, cloudHeight);
             this.Add(cloud);
             return;
         }
     }
 }
Example #55
0
        public Castle()
            : base()
        {
            mainCastle = new SpriteGameObject("spr_castle");
            mainCastle.Position = new Vector2(0, InsaneKillerArcher.Screen.Y - mainCastle.Height - 18);

            castlePart1 = new SpriteGameObject("spr_castle_medium_tower");
            castlePart2 = new SpriteGameObject("spr_castle_tower");

            castlePart1.Position = new Vector2(mainCastle.Position.X + 40, mainCastle.Position.Y - 115);
            castlePart2.Position = new Vector2(mainCastle.Position.X, mainCastle.Position.Y - 40);

            castlePart1.Visible = false;
            castlePart2.Visible = false;

            archerPositions = new Dictionary<Vector2, bool>();
            archerObjects = new Dictionary<Vector2, Archer>();

            catapultPositions = new Dictionary<Vector2, bool>();
            catapultObjects = new Dictionary<Vector2 , SpriteGameObject>();

            healthTexture = new SpriteGameObject("spr_bar");
            healthTexture.Position = mainCastle.Position + new Vector2(30, -50);

            archerPositions.Add(new Vector2(91, 917), false);
            catapultPositions.Add(new Vector2(142, 950), false);

            Add(MakeCatapult(new Vector2(110, 835)));
            //Add(MakeArcher(new Vector2(115, 860)));
            //Add(MakeArcher(new Vector2(145, 860)));
            Add(castlePart2);
            Add(MakeArcher(new Vector2(115, 860)));
            Add(MakeArcher(new Vector2(145, 860)));
            Add(castlePart1);
            Add(MakeCatapult(new Vector2(142, 950)));
            Add(MakeArcher(new Vector2(91, 917)));
            Add(mainCastle);
        }
Example #56
0
        public Level(int levelIndex)
            : base()
        {
            GameObjectList backgrounds = new GameObjectList(0, "backgrounds");
            SpriteGameObject background_main = new SpriteGameObject("Backgrounds/spr_sky");
            background_main.Position = new Vector2(0, GameEnvironment.Screen.Y - background_main.Height);
            backgrounds.Add(background_main);

            for(int i = 0; i < 5; i++)
            {
                SpriteGameObject mountain = new SpriteGameObject("Backgrounds/spr_mountain_" + (GameEnvironment.Random.Next(2) + 1), 1);
                mountain.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.X - mountain.Width / 2, GameEnvironment.Screen.Y - mountain.Height);
                backgrounds.Add(mountain);
            }

            Clouds clouds = new Clouds(2);
            backgrounds.Add(clouds);
            Add(backgrounds);

            SpriteGameObject timerBackground = new SpriteGameObject("Sprites/spr_timer", 100);
            timerBackground.Position = new Vector2(10, 10);
            Add(timerBackground);

            TimerGameObject timer = new TimerGameObject(0.5, 1, 101, "timer");
            timer.Position = new Vector2(25, 30);
            Add(timer);

            quitButton = new Button("Sprites/spr_button_quit", 100);
            quitButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 10);
            Add(quitButton);

            Add(new GameObjectList(1, "waterdrops"));
            Add(new GameObjectList(2, "enemies"));

            LoadTiles("Content/Levels/" + levelIndex + ".txt");
        }
 /// <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();
 }
Example #58
0
 public bool MouseOver(Vector2 mousePosition, SpriteGameObject icon)
 {
     return mousePosition.X >= icon.Position.X
         && mousePosition.X <= icon.Position.X + icon.Width
         && mousePosition.Y >= icon.Position.Y
         && mousePosition.Y <= icon.Position.Y + icon.Height;
 }
Example #59
0
 public override void Reset()
 {
     this.position = startPosition;
     this.velocity = Vector2.Zero;
     isOnTheGround = true;
     isAlive = true;
     exploded = false;
     finished = false;
     walkingOnIce = false;
     walkingOnHot = false;
     invincible = false;
     this.PlayAnimation("idle");
     previousYPosition = BoundingBox.Bottom;
     slowTimer = 0;
     Health = 3;
             for(int i = 0; i < Health; i++)
     {
         Healthblock = new SpriteGameObject("Sprites/Player/spr_idle", 2, "Health");
         //Healthblock.Position.Y = 20;
     }
 }