Example #1
0
        /// <summary>
        /// The collision method will be called by objects inside the given list
        /// </summary>
        /// <param name="list"></param>
        public override void checkExternalCollisions(GameObjectList list)
        {
            int start = 0;

            for (int i = 0; i < Count; i++)
            {
                for (int j = start; j < list.Count; j++)
                {
                    IGameObject a = this[i];
                    IGameObject b = list[j];
                    GameLibrary.Global.DEBUG.comparisons++;

                    if (a.right < b.left)
                    {
                        break;
                    }
                    if (a.left > b.right)
                    {
                        start++;
                        continue;
                    }
                    if (a.top > b.bottom || a.bottom < b.top)
                    {
                        continue;
                    }
                    a.collisionWith(b);
                    b.collisionWith(a);
                }
            }
        }
Example #2
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);
        
    }
        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 #4
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 #5
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;
    }
    /// <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 #7
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);
        }
        public AudioEngine(ContentManager content, GameObjectList tempObjType)
        {
            objType = tempObjType;

            switch (objType)
            {
                case GameObjectList.Player:
                    jump1 = content.Load<SoundEffect>("Sounds/hup1");
                    jump2 = content.Load<SoundEffect>("Sounds/hup2");
                    jump3 = content.Load<SoundEffect>("Sounds/hup3");
                    dash = content.Load<SoundEffect>("Sounds/woosh");
                    break;
                default:

                    break;
            }
        }
    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 #10
0
        public override void Loaded()
        {
            if (objects == null)
                objects = new GameObjectList();
            else
            {
                foreach (GameObject obj in objects)
                {
                    if (obj.ID > objCount)
                        objCount = obj.ID;
                }
            }

            foreach (GameObject o in objects)
            {
                foreach (Component c in o.components)
                {
                    c.Loaded();
                }
            }
        }
Example #11
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 #12
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");
        }
Example #13
0
 public Scene()
 {
     name = "New scene";
     objects = new GameObjectList();
     data = new Dictionary<string, object>();
 }
 void Start()
 {
     InstanceObjectList = this;
 }
Example #15
0
 public PlayingState()
 {
     levels = new GameObjectList(0,"levels");
     levels.Add(new Level(1));
     this.Add(levels);
 }
 public static void SetGameObjectList(GameObjectList objectList)
 {
     gameObjectList = objectList;
 }
Example #17
0
    public override void Initialize()
    {
        base.Initialize();

        Objects = new ObservableList<VisibilityStruct>();

        var objectVisibilities = FindObjectsOfType<ObjectVisibility>();
        foreach (var objectVisibility in objectVisibilities)
        {
            objectVisibility.RestoreState();
            if (objectVisibility.Entries == null || objectVisibility.Entries.Length == 0)
                continue;

            var index = 0;
            foreach (var objectVisibilityInfo in objectVisibility.Entries)
            {
                var materialProperties = objectVisibilityInfo.GameObject.GetComponentsInChildren<MaterialProperties>();
                if (materialProperties == null || materialProperties.Length == 0)
                    continue;

                Objects.Add(new VisibilityStruct
                {
                    Name = objectVisibilityInfo.GameObject.name,
                    Opacity = materialProperties[0].Opacity,
                    Enabled = materialProperties[0].Enabled,
                    MatProps = materialProperties
                });
                index++;
            }
        }

        var go = GameObject.Find("Visibilities");
        if (go == null)
            return;
        GoList = go.GetComponentInChildren<GameObjectList>();

        UpdateVisibilities();
    }