Exemplo n.º 1
0
 private void addDank(Vector2 position, int start, int end, int detail, int gen)
 {
     for (int index = start; index <= end; index++)
     {
         Animation dankBullet = new Animation();
         dankBullet.Initialize(dankBulletTexture, position, (dankBulletTexture.Width / 20), dankBulletTexture.Height, 20, 1, Color.White, 1f, true);
         DankLaser dank = new DankLaser();
         dank.Initialize(GraphicsDevice.Viewport, dankBullet, position, (float)((Math.PI / detail) * index), gen);
         dankLasers.Add(dank);
     }
 }
Exemplo n.º 2
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)
        {
            // For Mobile devices, this logic will close the Game when the Back button is pressed
            // Exit() is obsolete on iOS
#if !__IOS__ && !__TVOS__
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
#endif

            //previousGamePadState = currentGamePadState;
            //previousKeyboardState = currentKeyboardState;

            // Read the current state of the keyboard and gamepad and store it
            currentKeyboardState = Keyboard.GetState();
            currentGamePadState  = GamePad.GetState(PlayerIndex.One);


            //Update the player
            if (!hasBooted)
            {
                if (currentKeyboardState.IsKeyDown(Keys.C))
                {
                    side      = 0;
                    hasBooted = true;
                    Initialize();
                    LoadContent();
                    network = new Network(gameTime, this);

                    network.StartClient(gameTime);
                }
                else if (currentKeyboardState.IsKeyDown(Keys.S))
                {
                    this.side = 1;
                    hasBooted = true;
                    Initialize();
                    LoadContent();
                    network = new Network(gameTime, this);

                    network.StartSever(gameTime);
                }
            }
            if (hasBooted)
            {
                if (side == 0)
                {
                    bgLayer1.Update();
                    bgLayer2.Update();
                    UpdateClient();
                    if (network.data != null && network.data.Count > 0)
                    {
                        List <SPoint> objs = new List <SPoint>();
                        while (!network.data.IsEmpty)
                        {
                            SPoint Out;
                            network.data.TryDequeue(out Out);
                            while (Out == null)
                            {
                                network.data.TryDequeue(out Out);
                                Thread.Sleep(1);
                            }
                            objs.Add(Out);
                        }

                        List <Enemy>      enemies     = new List <Enemy>();
                        List <Animation>  players     = new List <Animation>();
                        List <DankLaser>  lasers      = new List <DankLaser>();
                        List <MegaLaser>  megalasers  = new List <MegaLaser>();
                        List <Projectile> projectiles = new List <Projectile>();
                        List <Animation>  pops        = new List <Animation>();
                        List <Animation>  explosions  = new List <Animation>();
                        List <Animation>  friends     = new List <Animation>();

                        for (int index = 0; index < objs.Count; index++)
                        {
                            if (objs[index].id == 0)
                            {
                                Enemy     enemy   = new Enemy(false);
                                Animation animate = new Animation();
                                animate.Initialize(enemyTexture, new Vector2(objs[index].x, objs[index].y), 47, 61, 8, 30, Color.White, 1f, true);
                                for (int i = 0; i < objs[index].Frame; i++)
                                {
                                    animate.Update(gameTime);
                                }
                                enemy.Initialize(animate, new Vector2(objs[index].x, objs[index].y));
                                enemies.Add(enemy);
                            }

                            if (objs[index].id == 1)
                            {
                                Enemy     enemy   = new Enemy(true);
                                Animation animate = new Animation();
                                animate.Initialize(cloudStrip, new Vector2(objs[index].x, objs[index].y), 64, 64, 8, 30, Color.White, 1f, true);
                                for (int i = 0; i < objs[index].Frame; i++)
                                {
                                    animate.Update(gameTime);
                                }
                                enemy.Initialize(animate, new Vector2(objs[index].x, objs[index].y));
                                enemies.Add(enemy);
                            }
                            if (objs[index].id == 2)
                            {
                                Projectile projectile = new Projectile();
                                projectile.Initialize(GraphicsDevice.Viewport, projectileTexture, new Vector2(objs[index].x, objs[index].y));
                                projectiles.Add(projectile);
                            }
                            if (objs[index].id == 3)
                            {
                                Animation dankBullet = new Animation();
                                dankBullet.Initialize(dankBulletTexture, new Vector2(objs[index].x, objs[index].y), (dankBulletTexture.Width / 20), dankBulletTexture.Height, 20, 1, Color.White, 1f, true);
                                DankLaser dank = new DankLaser();
                                dank.Initialize(GraphicsDevice.Viewport, dankBullet, new Vector2(objs[index].x, objs[index].y), objs[index].theta, 1);
                                for (int i = 0; i < objs[index].Frame; i++)
                                {
                                    dankBullet.Update(gameTime);
                                }
                                lasers.Add(dank);
                            }
                            if (objs[index].id == 4)
                            {
                                Animation dankBullet = new Animation();
                                dankBullet.Initialize(psychBulletTexture, new Vector2(objs[index].x, objs[index].y), (psychBulletTexture.Width / 6), psychBulletTexture.Height, 6, 1, Color.White, 1f, true);
                                MegaLaser laser = new MegaLaser();
                                laser.Initialize(GraphicsDevice.Viewport, dankBullet, new Vector2(objs[index].x, objs[index].y), objs[index].theta, 1, 50, gameTime.TotalGameTime.TotalSeconds);
                                for (int i = 0; i < objs[index].Frame; i++)
                                {
                                    dankBullet.Update(gameTime);
                                }
                                megalasers.Add(laser);
                            }
                            if (objs[index].id == 5)
                            {
                                Animation pop = new Animation();
                                pop.Initialize(popStrip, new Vector2(objs[index].x, objs[index].y), popStrip.Width / 6, popStrip.Height, 6, 60, Color.White, 1f, false);
                                for (int i = 0; i < objs[index].Frame; i++)
                                {
                                    pop.Update(gameTime);
                                }
                                pops.Add(pop);
                            }
                            if (objs[index].id == 6)
                            {
                                Animation explosion = new Animation();
                                explosion.Initialize(explosionTexture, new Vector2(objs[index].x, objs[index].y), 134, 134, 12, 45, Color.White, 1f, false);
                                for (int i = 0; i < objs[index].Frame; i++)
                                {
                                    explosion.Update(gameTime);
                                }
                                explosions.Add(explosion);
                            }
                            if (objs[index].id == 7)
                            {
                                Animation animate = new Animation();
                                animate.Initialize(playerTexture, new Vector2(objs[index].x, objs[index].y), 115, 69, 8, 30, Color.White, 1f, true);
                                for (int i = 0; i < objs[index].Frame; i++)
                                {
                                    animate.Update(gameTime);
                                }
                                players.Add(animate);
                            }
                            if (objs[index].id == 8)
                            {
                                Animation animate = new Animation();
                                animate.Initialize(playerTexture, new Vector2(objs[index].x, objs[index].y), 115, 69, 8, 30, Color.White, .75f, true);
                                for (int i = 0; i < objs[index].Frame; i++)
                                {
                                    animate.Update(gameTime);
                                }
                                friends.Add(animate);
                            }
                        }
                        this.enemies     = enemies;
                        this.drawPlayers = players;
                        this.projectiles = projectiles;
                        this.dankLasers  = lasers;
                        this.megaLasers  = megalasers;
                        this.pops        = pops;
                        this.explosions  = explosions;
                        this.friends     = friends;
                    }


                    //UpdateClient();
                }
                else
                {
                    UpdatePlayer(gameTime);
                    UpdateEnemies(gameTime);
                    UpdateCollision();
                    UpdateProjectiles(gameTime);
                    UpdateExplosions(gameTime);
                    UpdatePops(gameTime);
                    List <SPoint> points = new List <SPoint>();
                    foreach (Enemy enemy in enemies)
                    {
                        int id = 0;
                        if (enemy.IsCloud)
                        {
                            id = 1;
                        }
                        points.Add(new SPoint(enemy.Position.X, enemy.Position.Y, 0, id, enemy.EnemyAnimation.CurrentFrame + 1));
                    }
                    foreach (Projectile bullet in projectiles)
                    {
                        points.Add(new SPoint(bullet.Position.X, bullet.Position.Y, 0, 2, 0));
                    }
                    foreach (DankLaser laser in dankLasers)
                    {
                        points.Add(new SPoint(laser.Texture.Position.X, laser.Texture.Position.Y, laser.Theta, 3, laser.Texture.CurrentFrame + 1));
                    }
                    foreach (MegaLaser laser in megaLasers)
                    {
                        points.Add(new SPoint(laser.Texture.Position.X, laser.Texture.Position.Y, laser.Theta, 4, laser.Texture.CurrentFrame + 1));
                    }
                    foreach (Animation pop in pops)
                    {
                        points.Add(new SPoint(pop.Position.X, pop.Position.Y, 0, 5, pop.CurrentFrame + 1));
                    }
                    foreach (Animation explosion in explosions)
                    {
                        points.Add(new SPoint(explosion.Position.X, explosion.Position.Y, 0, 6, explosion.CurrentFrame + 1));
                    }
                    foreach (Player player in players)
                    {
                        points.Add(new SPoint(player.Position.X, player.Position.Y, 0, 7, player.animation.CurrentFrame + 1));
                        points.Add(new SPoint(player.Friend.Position.X, player.Friend.Position.Y, 0, 8, player.animation.CurrentFrame + 1));
                    }
                    for (int index = 0; index < points.Count; index++)
                    {
                        network.data.Enqueue(points[index]);
                    }
                }
                base.Update(gameTime);
            }
        }