public static void NewGame(int sc)
        {
            gameOver = false;
            newLevel = true;
            score = sc;

            elf1Tex = new Texture2D("/Application/assets/elf1.png", false);
            elf2Tex = new Texture2D("/Application/assets/elf2.png", false);
            treeTex = new Texture2D("/Application/assets/tree.png", false);
            Texture2D bgTex = new Texture2D ("/Application/assets/snow.png", false);
            Texture2D catTex = new Texture2D ("/Application/assets/santa.png", false);
            Texture2D starTex= new Texture2D ("/Application/assets/house.png", false);
            Texture2D meteorTex= new Texture2D ("/Application/assets/car.png", false);
            Texture2D saucerTex= new Texture2D ("/Application/assets/police.png", false);
            Texture2D clawTex= new Texture2D ("/Application/assets/up_present.png", false);
            Texture2D meowTex = new Texture2D("/Application/assets/left_present.png", false);
            Texture2D hairballTex = new Texture2D("/Application/assets/right_present.png", false);
            gameOverTex = new Texture2D("/Application/assets/game_over.png", false);
            alphabetTex = new Texture2D("/Application/assets/alphabet.png", false);
            selectorTex = new Texture2D("/Application/assets/selector.png", false);

            alpha = new Sprite(graphics, alphabetTex);
            alpha.Position = new Vector3((graphics.Screen.Rectangle.Width / 2 - alpha.Width / 2)+340,
                                      graphics.Screen.Rectangle.Height / 2 - alpha.Height / 2, 0);
            selector = new Sprite(graphics, selectorTex);
            selector.Position = new Vector3((graphics.Screen.Rectangle.Width / 2 - selector.Width / 2) - 175,
                                      graphics.Screen.Rectangle.Height / 2 - selector.Height / 2, 0);

            go = new Sprite (graphics, gameOverTex);
            bg = new Sprite (graphics, bgTex);
            pieces = new List<GameObj> ();
            waiting = new List<Weapon> (); //weapons waiting to be rendered
            p = new Player (graphics, catTex, new Vector3 (30, 450, 0));
            pieces.Add (p);

            //add the enemies
            for( int i=0; i<3;i++){
                pieces.Add (new Star (graphics, starTex, new Vector3 (gen.Next(200,900),gen.Next(200,400),0), p));
                pieces.Add (new Star (graphics, starTex, new Vector3 (gen.Next(200,900),gen.Next(200,400),0), p));
                pieces.Add (new Meteor (graphics, meteorTex, new Vector3(gen.Next(200,900),gen.Next(200,400),0), p));
            }
            pieces.Add (new Saucer (graphics, saucerTex, new Vector3(gen.Next(200,900),gen.Next(200,400),0), p));

            //add weapons to the screne
            cl = new Claw(graphics, clawTex, new Vector3(gen.Next(200,900),gen.Next(200,400),0));
            cl.isActive = false;
            pieces.Add (cl);

            m = new SonicMeow(graphics, meowTex, new Vector3(gen.Next(200,900),gen.Next(200,400),0), new Vector3(0,0,0));
            m.isActive = false;
            pieces.Add (m);

            hb = new HairBall(graphics, hairballTex, new Vector3(gen.Next(200,900),gen.Next(200,400),0));
            hb.isActive = false;
            pieces.Add (hb);

            //to display the score
            UISystem.Initialize (graphics);
            Scene scene = new Scene ();

            scoreLabel = new Label (); //current score
            scoreLabel.X = 320;
            scoreLabel.Y = 10;
            scoreLabel.Width = 300;
            scoreLabel.Text = "Score: " + score;
            scene.RootWidget.AddChildLast (scoreLabel);

            LoadHighScore ();
            hsLabel = new Label (); //high score
            hsLabel.X = 620;
            hsLabel.Y = 10;
            hsLabel.Width = 300;
            hsLabel.Text = "High Score: " + highscore;
            scene.RootWidget.AddChildLast (hsLabel);

            UISystem.SetScene (scene, null);
        }
Beispiel #2
0
        public override void Update()
        {
            pos = new Vector3(sprite.Position.X, sprite.Position.Y, 0);

            foreach(GameObj g in AppMain.pieces)
            {
                if(g is Star && g.isAlive())
                {
                    if(Vector3.Distance (pos, g.Pos) < 30)
                    {
                        AppMain.gameOver = true;
                    }
                }
            }

            if(Vector3.Distance (pos, AppMain.hb.Pos) < 30)
            {
                canUseHairball = true;
                AppMain.hb.die();
            }

            if(Vector3.Distance (pos, AppMain.cl.Pos) < 30)
            {
                canUseClaw = true;
                AppMain.cl.die();
            }

            if(Vector3.Distance (pos, AppMain.m.Pos) < 30)
            {
                canUseMeow = true;
                AppMain.m.die();
            }

            var gamePadData = GamePad.GetData (0);
            if ((gamePadData.Buttons & GamePadButtons.Left) != 0) {
                sprite.Position.X-=speed;
            }
            if ((gamePadData.Buttons & GamePadButtons.Right) != 0) {
                sprite.Position.X+=speed;
            }
            if ((gamePadData.Buttons & GamePadButtons.Up) != 0) {
                sprite.Position.Y-=speed;
            }
            if ((gamePadData.Buttons & GamePadButtons.Down) != 0) {
                sprite.Position.Y+=speed;
            }

            if (coolDown <= 0) //to prevent the user from using weapons too often
            {
                if ((gamePadData.Buttons & GamePadButtons.Square) != 0){
                    if(canUseClaw)
                    {
                        Claw c = new Claw(graphics, clawTex, pos);
                        c.isActive = true;
                        Use (c);
                        AppMain.presentSoundPlayer.Play();
                    }
                }
                if ((gamePadData.Buttons & GamePadButtons.Triangle) != 0){
                    if(canUseMeow)
                    {
                        SonicMeow m1 = new SonicMeow(graphics, meowTex, pos, new Vector3(-1, 0, 0));
                        m1.isActive = true;
                        Use (m1);
                        AppMain.presentSoundPlayer.Play();
                    }
                }
                if ((gamePadData.Buttons & GamePadButtons.Circle) != 0){
                    if(canUseHairball)
                    {
                        HairBall h = new HairBall(graphics, hairballTex, pos);
                        h.isActive = true;
                        Use (h);
                        AppMain.presentSoundPlayer.Play();
                    }
                }
                coolDown = 25;
            }
            coolDown--;
        }