Esempio n. 1
0
        void generateAliens()
        {
            if (numOfTargets >= numOfTargetsMax)
            {
                mgState = 3; return;
            }
            ;

            if (rnd.Next(0, 1000) < genAliensPercent * 10 && numOfTargets < numOfTargetsMax)
            {
                numOfTargets++;
                float   xx = rnd.Next(innerRectangle.X, (int)(innerRectangle.X + innerRectangle.Width - actualTargetSize.X));
                float   yy = innerRectangle.Y - actualTargetSize.Y / 2;
                Sprite3 s  = new Sprite3(true, targetTex, xx, yy);
                s.setWidthHeight(actualTargetSize.X, actualTargetSize.Y);
                s.setBBToTexture();

                //s.setWidthHeightOfTex(1536, 384);
                //s.setXframes(16);
                //s.setYframes(4);
                s.setDeltaSpeed(new Vector2(0, 1));
                //s.setBB(10, 10, 48 - 20, 48 - 20);

                //int frames = 12;
                //Vector2[] anim = new Vector2[frames];
                //for (int i = 0; i < frames; i++)
                //{
                //    anim[i].X = i; anim[i].Y = 0;
                //}
                //s.setAnimationSequence(anim, 0, frames - 1, 3);
                //s.animationStart();
                targets.addSpriteReuse(s);
                AI_xxx = s.getPosX() + s.getWidth() / 2;
            }
        }
Esempio n. 2
0
        public void NewBall(float x, float y)
        {
            Sprite3 ball = new Sprite3(true, texBall, x, y);

            ball.setBBandHSFractionOfTexCentered(0.4f);

            ball.setPos(paddle.getPos() + ballOffset);
            ball.setDeltaSpeed(new Vector2(7, 0));

            ballList.addSpriteReuse(ball);
        }
Esempio n. 3
0
        public void NewEnemy(float x, float y)
        {
            Sprite3 enemy = new Sprite3(true, texEnemy, x, (float)enemyYY.NextDouble() * y);

            enemy.setWidth(texEnemy.Width * 0.7f);
            enemy.setHeight(texEnemy.Height * 0.7f);
            enemy.setBBToTexture();
            enemy.hitPoints = 3;

            enemy.setDeltaSpeed(new Vector2((float)enemySpeed.NextDouble() * -10, 0));
            enemyList.addSpriteReuse(enemy);
        }
Esempio n. 4
0
        public override void Update(GameTime gameTime)
        {
            ticks++;

            //load animation
            //anmiation1.animationTick();
            dragonList.animationTick();
            if (scrolling1.rectangle.X + scrolling1.texture.Width <= 0)
            {
                scrolling1.rectangle.X = scrolling2.rectangle.X + scrolling2.texture.Width;
            }
            if (scrolling2.rectangle.X + scrolling2.texture.Width <= 0)
            {
                scrolling2.rectangle.X = scrolling1.rectangle.X + scrolling1.texture.Width;
            }

            scrolling1.Update();
            scrolling2.Update();

            for (int i = 0; i < dragonList.count(); i++)
            {
                Sprite3 s = dragonList.getSprite(i);
                if (s == null)
                {
                    continue;
                }
                if (!s.active)
                {
                    continue;
                }
                if (!s.visible)
                {
                    continue;
                }
                if (ball.getBoundingBoxAA().Intersects(s.getBoundingBoxAA()))
                {
                    baz.Play();
                    s.setActive(false);
                    scoure++;
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(1, -1));
                    setSys5();
                    p.Update(gameTime);
                }
            }

            if (k.IsKeyDown(Keys.B) && prevK.IsKeyUp(Keys.B)) // ***
            {
                showbb = !showbb;
            }
            k = Keyboard.GetState();

            if (k.IsKeyDown(Keys.Right))
            {
                if (paddle.getPosX() < rhs - texpaddle.Width)
                {
                    paddle.setPosX(paddle.getPosX() + paddleSpeed);
                }
            }

            if (k.IsKeyDown(Keys.Left))
            {
                if (paddle.getPosX() > lhs)
                {
                    paddle.setPosX(paddle.getPosX() - paddleSpeed);
                }
            }

            if (ballStuck)
            {
                ball.setPos(paddle.getPos() + ballOffset);
            }

            //if (ballStuck)
            //{
            //    ball.setPos(paddle.getPos() + ballOffset);
            //    if (k.IsKeyDown(Keys.Space) && prevK.IsKeyUp(Keys.Space))
            //    {
            //        ballStuck = false;
            //        ball.setDeltaSpeed(new Vector2(1, -3));
            //    }
            //}
            else
            {
                // move ball
                ball.savePosition();
                ball.moveByDeltaXY();
            }

            if (ballStuck)
            {
                ball.setPos(paddle.getPos() + ballOffset);
                if (k.IsKeyDown(Keys.Space) && prevK.IsKeyUp(Keys.Space))
                {
                    ballStuck = false;
                    ball.setDeltaSpeed(new Vector2(2, -3));
                }
            }
            else
            {
                // move ball
                ball.savePosition();
                ball.moveByDeltaXY();
                Rectangle ballbb = ball.getBoundingBoxAA();

                if (ballbb.X + ballbb.Width > rhs)
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(-1, 1));
                }

                if (ballbb.X < lhs)
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(-1, 1));
                }

                if (ballbb.Y < top)
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(1, -1));
                }

                //pedal intersects

                if (ballbb.Intersects(paddle.getBoundingBoxAA()))

                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(1, -1));
                }
            }
            if (k.IsKeyDown(Keys.P))
            {
                gameStateManager.setLevel(0);
            }
            if (k.IsKeyDown(Keys.M))
            {
                gameStateManager.setLevel(0);
                ball.setPos(xx, yy);
                paddle.setPos(xx, bot - texpaddle.Height);
                scoure = 0;
                //ball.setDeltaSpeed(new Vector2(0,0));
                for (int i = 0; i < dragonList.count(); i++)
                {
                    Sprite3 s = dragonList.getSprite(i);
                    s.setActive(true);
                }
            }


            if (ball.getPosY() > bot)
            {
                gameStateManager.setLevel(5);
                ball.setPos(xx, yy);
                paddle.setPos(xx, bot - texpaddle.Height);
                scoure = 0;
                //ball.setDeltaSpeed(new Vector2(0,0));
                for (int i = 0; i < dragonList.count(); i++)
                {
                    Sprite3 s = dragonList.getSprite(i);
                    s.setActive(true);
                    // p.Update(gameTime);
                }
            }
            // next leve condition
            if (scoure >= 15)
            {
                gameStateManager.setLevel(0);
                limSound.playSound();
            }
            ballPos = new Vector2(ball.getPosX(), ball.getPosY());
            if (p != null)
            {
                p.Update(gameTime);
            }
            base.Update(gameTime);
        }
Esempio n. 5
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            LineBatch.init(GraphicsDevice);

            // load all fonts for the splash screen and levels
            llFont = Content.Load <SpriteFont>("Large");
            mmFont = Content.Load <SpriteFont>("Medium");
            ssFont = Content.Load <SpriteFont>("Small");

            // load  textures from local content directory
            kcTexPath   = @"/Users/jfc/Desktop/CrazyCat_Assignment_GPT/GPT_Assignment/GPT_Assignment/Content/kittyCat.png";
            kittyCatTex = Util.texFromFile(GraphicsDevice, kcTexPath);

            bbTexPath     = @"/Users/jfc/Desktop/CrazyCat_Assignment_GPT/GPT_Assignment/GPT_Assignment/Content/Background.png";
            backgroundTex = Util.texFromFile(GraphicsDevice, bbTexPath);

            playerTexPath = @"/Users/jfc/Desktop/CrazyCat_Assignment_GPT/GPT_Assignment/GPT_Assignment/Content/KittyCatFrames.png";
            playerTex     = Util.texFromFile(GraphicsDevice, playerTexPath);

            doggyTexPath = @"/Users/jfc/Desktop/CrazyCat_Assignment_GPT/GPT_Assignment/GPT_Assignment/CrazyDogFrames.png";
            doggyTex     = Util.texFromFile(GraphicsDevice, doggyTexPath);

            yarnTex = Content.Load <Texture2D>("Yarn");

            // position vector for the cat sprite on main splash screen
            kittyCatVec   = new Vector2(275, 50);
            titleVec      = new Vector2(100, 300);
            sloganVec     = new Vector2(290, 400);
            instructVec   = new Vector2(315, 425);
            levelIntroVec = new Vector2(250, 200);
            playerVec     = new Vector2(600, 400);
            doggyVec      = new Vector2(0, 400);


            // make the cat sprite for the main splash screen
            kittyCat = new Sprite3(true, kittyCatTex, kittyCatVec.X, kittyCatVec.Y);

            // prepare the crazy dog for level 2
            crazyDog = new Sprite3(false, doggyTex, doggyVec.X, doggyVec.Y);



            // color for the level text and alpha value
            ltCol = new Color(0, 255, 0, 1);
            // level text initialization
            levelText = new TextRenderable("Blabla", levelIntroVec, llFont, Color.Red);


            // source and destination rectangles for the scrolling background
            backgroundDest   = new Rectangle(0, 0, 800, 600);
            backgroundSource = new Rectangle(0, 0, 800, 600);

            // draw background
            background = new ScrollBackGround(backgroundTex, backgroundDest, backgroundSource, 5.0f, 2);

            // player vector and player texture

            playerSprite = new Sprite3(true, playerTex, playerVec.X, playerVec.Y);

            // initialize frame vector
            playerFrames = new Vector2[10];

            // frame vector values 1280x128

            playerFrames[0].X = 0; playerFrames[0].Y = 0;
            playerFrames[1].X = 1; playerFrames[1].Y = 0;
            playerFrames[2].X = 2; playerFrames[2].Y = 0;
            playerFrames[3].X = 3; playerFrames[3].Y = 0;
            playerFrames[4].X = 4; playerFrames[4].Y = 0;
            playerFrames[5].X = 5; playerFrames[5].Y = 0;
            playerFrames[6].X = 6; playerFrames[6].Y = 0;
            playerFrames[7].X = 7; playerFrames[7].Y = 0;
            playerFrames[8].X = 8; playerFrames[8].Y = 0;
            playerFrames[9].X = 9; playerFrames[9].Y = 0;

            // set all the parameters for the cute little kitty cat
            playerSprite.setWidthHeight(64, 64);
            playerSprite.setWidthHeightOfTex(1280, 128);
            playerSprite.setXframes(10);
            playerSprite.setYframes(0);
            playerSprite.setBB(0, 0, 128, 128);
            playerSprite.setAnimationSequence(playerFrames, 0, 9, 15);
            playerSprite.animationStart();

            // the parameters for the player sprite jumping
            playerJump      = false;
            playerJumpSpeed = 0;

            // store the initial positions of the player sprite
            prevPos.Y = playerVec.Y;
            prevPos.X = playerVec.X;

            // initialize sounds for the game
            jumpo      = Content.Load <SoundEffect>("Sounds/Boing");
            jumpoSound = new LimitSound(jumpo, 1);

            success      = Content.Load <SoundEffect>("Sounds/Success");
            successSound = new LimitSound(success, 1);

            barko      = Content.Load <SoundEffect>("Sounds/Growl");
            barkoSound = new LimitSound(barko, 1);

            kaching      = Content.Load <SoundEffect>("Sounds/Kaching");
            kachingSound = new LimitSound(kaching, 1);

            yowlin      = Content.Load <SoundEffect>("Sounds/Yowl");
            yowlinSound = new LimitSound(yowlin, 1);

            easterEgg = Content.Load <SoundEffect>("Sounds/OhWhatever");
            eeSound   = new LimitSound(easterEgg, 1);


            /// yarn ball sprite list
            ///
            ///
            ///
            ///
            ///
            ///

            yarnBalls = new SpriteList();

            Sprite3 yb;

            for (int i = 0; i < maxYarnBalls; i++)
            {
                // temporarily set to doggyVec for positioning - change later?
                yb = new Sprite3(true, yarnTex, doggyVec.X + i * 50, doggyVec.Y - i * 50);
                yb.setDeltaSpeed(new Vector2((float)(1 + rnd.NextDouble()), 0));
                yb.setWidthHeight(32, 32);
                yb.setWidthHeightOfTex(32, 32);
                yb.setHSoffset(new Vector2(32, 32));
                yb.setBBToTexture();
                yb.setMoveSpeed(2.1f);

                yarnBalls.addSpriteReuse(yb);
            }



            // initialize frame vector for dog
            doggyFrames = new Vector2[8];


            doggyFrames[0].X = 0; doggyFrames[0].Y = 0;
            doggyFrames[1].X = 1; doggyFrames[1].Y = 0;
            doggyFrames[2].X = 2; doggyFrames[2].Y = 0;
            doggyFrames[3].X = 3; doggyFrames[3].Y = 0;
            doggyFrames[4].X = 4; doggyFrames[4].Y = 0;
            doggyFrames[5].X = 5; doggyFrames[5].Y = 0;
            doggyFrames[6].X = 6; doggyFrames[6].Y = 0;
            doggyFrames[7].X = 7; doggyFrames[7].Y = 0;

            crazyDog.setWidthHeight(64, 64);
            crazyDog.setWidthHeightOfTex(1024, 128);
            crazyDog.setXframes(8);
            crazyDog.setYframes(0);
            crazyDog.setBB(0, 0, 128, 128);
            crazyDog.setAnimationSequence(playerFrames, 0, 7, 15);
            crazyDog.animationStart();
        }
Esempio n. 6
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            prevK = k;
            k     = Keyboard.GetState();

            if (k.IsKeyDown(Keys.B) && prevK.IsKeyUp(Keys.B)) // ***
            {
                showbb = !showbb;
            }

            if (k.IsKeyDown(Keys.Right))
            {
                if (paddle.getPosX() < rhs - texpaddle.Width)
                {
                    paddle.setPosX(paddle.getPosX() + paddleSpeed);
                }
            }

            if (k.IsKeyDown(Keys.Left))
            {
                if (paddle.getPosX() > lhs)
                {
                    paddle.setPosX(paddle.getPosX() - paddleSpeed);
                }
            }
            if (ballStuck)
            {
                ball.setPos(paddle.getPos() + ballOffset);
                if (k.IsKeyDown(Keys.Space) && prevK.IsKeyUp(Keys.Space))
                {
                    ballStuck = false;
                    ball.setDeltaSpeed(new Vector2(2, -3));
                }
            }

            else
            {
                // move ball
                ball.savePosition();
                ball.moveByDeltaXY();
                Rectangle ballbb = ball.getBoundingBoxAA();

                if (ballbb.X + ballbb.Width > rhs)
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(-1, 1));
                }

                if (ballbb.X < lhs)
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(-1, 1));
                }

                if (ballbb.Y < top)
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(1, -1));
                }

                if (ballbb.Intersects(paddle.getBoundingBoxAA()))
                {
                    ball.setDeltaSpeed(ball.getDeltaSpeed() * new Vector2(1, -1));
                }
            }



            // TODO: Add your update logic here

            base.Update(gameTime);
        }