Example #1
0
        public void CollisionCheck()
        {
            var gameObjectsToRemove = new HashSet <ILaneObject>();

            foreach (var monster in MonsterCollection)
            {
                foreach (var bullet in BulletCollection)
                {
                    if (monster.LanePosition <= bullet.LanePosition)
                    {
                        if (monster.Color == bullet.Color)
                        {
                            gameObjectsToRemove.Add(monster);

                            // Killed a monster => scored
                            Score.UpdateScore(
                                Score.MonsterKilledPoints);
                        }

                        gameObjectsToRemove.Add(bullet);
                    }
                }
            }

            // Remove the objects
            MonsterCollection.RemoveWhere(
                monster => gameObjectsToRemove.Contains(monster));
            BulletCollection.RemoveWhere(
                bullet => gameObjectsToRemove.Contains(bullet));
        }
Example #2
0
    public GameScreen()
    {
        Game.GameSocket.OnDisconnectionEvent += DisconnectWhenError;

        NextScreen  = ScreenType.None;
        map         = new Map();
        localPlayer = new LocalPlayer(Game.PlayerSelectedType);
        bullets     = new BulletCollection();
        players     = new PlayerCollection();
        camera      = new Camera((ushort)Hardware.ScreenWidth,
                                 (ushort)Hardware.ScreenHeight);
        cameraController = new SpectatorCameraController();

        teamButtons = new Button[3];
        teamButtons[RED_TEAM_BUTTON]       = new Button(ButtonType.RedTeamButton);
        teamButtons[SPECTATOR_TEAM_BUTTON] = new Button(ButtonType.SpectatorTeamButton);
        teamButtons[BLUE_TEAM_BUTTON]      = new Button(ButtonType.BlueTeamButton);
        //Sets the positions of the buttons to change the team
        teamButtons[RED_TEAM_BUTTON].SetPos(100,
                                            Hardware.ScreenHeight / 2 - Button.SPRITE_HEIGHT / 2);
        teamButtons[SPECTATOR_TEAM_BUTTON].SetPos
            (Hardware.ScreenWidth / 2 - Button.SPRITE_WIDTH / 2,
            Hardware.ScreenHeight / 2 - Button.SPRITE_HEIGHT / 2);
        teamButtons[BLUE_TEAM_BUTTON].SetPos
            (Hardware.ScreenWidth - Button.SPRITE_WIDTH - 100,
            Hardware.ScreenHeight / 2 - Button.SPRITE_HEIGHT / 2);

        isChangingTeam            = true;
        messageBuffer             = "";
        CurrentUpdateGameFunction = UpdateGameStateSpectator;
        CurrentRenderGameFunction = RenderGameDead;
        deltaTime = 1;
    }
Example #3
0
 public Level(int level, Canvas canvas)
 {
     Game    = true;
     bullets = new BulletCollection();
     key     = PressedKey.None;
     new LevelLoader(level).LoadField(out gameField, out player, out enemies);
     Level.canvas = canvas;
 }
Example #4
0
 public Level(int level)
 {
     Console.CursorVisible = false;
     Game = true;
     StartThread();
     bullets = new BulletCollection();
     new LevelLoader(level).LoadField(out gameField, out player, out enemies);
 }
Example #5
0
 public Server()
 {
     messageQueue = new Queue <string>();
     map          = new Map();
     players      = new PlayerCollection();
     players.OnPlayerDisconnectEvent += DisconnectPlayer;
     bullets   = new BulletCollection();
     gameState = "";
 }
Example #6
0
 public void MoveBullets()
 {
     foreach (var bullet in BulletCollection)
     {
         bullet.LanePosition += 1;
     }
     BulletCollection.RemoveWhere(
         bullet => !IsInsideLane(bullet));
 }
Example #7
0
 public GameData(ContentManager Content, GraphicsDevice device, AudioManager audio, World world)
 {
     player = new Player(world, Content, audio, device);
     mods = new ModCollection();
     npcs = new NPCCollection(world, Content, player, device, audio);
     bullets = new BulletCollection(Content, device);
     missions = new MissionCollection(world, npcs);
     this.world = world;
     this.audio = audio;
 }
Example #8
0
        public void ChangeLanesLength(int newLength)
        {
            Length = newLength;

            // Remove all Bullets outside the lane
            MonsterCollection.RemoveWhere(
                monster => !IsInsideLane(monster));

            // Remove all Bullets outside the lane
            BulletCollection.RemoveWhere(
                bullet => !IsInsideLane(bullet));
        }
Example #9
0
 internal Map(List <Texture2D> textures, Texture2D background, int[,] map, List <GameObject> objects, string ambientAudio, DoorCollection <Door> doors, ActorCollection <Actor> actors, SecretCollection <Secret> secrets, Vector2 spawnPoint)
 {
     Textures            = textures;
     Background          = background;
     this.ObjectDatabase = objects;
     WorldMap            = map;
     AmbientAudio        = ambientAudio;
     Doors      = doors;
     SpawnPoint = spawnPoint;
     Actors     = actors;
     Secrets    = secrets;
     CreatePathFinder(map);
     Bullets = new BulletCollection <Bullet>();
 }
Example #10
0
        public void ShootBullet(Bullet bullet)
        {
            bullet.LanePosition = 1;

            // Check if the space is occupied by another bullet
            // Don't add the new one in this case.
            foreach (var otherBullet in BulletCollection)
            {
                if (otherBullet.LanePosition == bullet.LanePosition)
                {
                    return;
                }
            }

            BulletCollection.Add(bullet);
        }
Example #11
0
 public int AddUpdate(BulletCollection Collection, string SessionUser)
 {
     using (var connection = new SqlConnection(base.ConnectionString))
     {
         return(Task.FromResult(connection.ExecuteScalar <int>("spBulletCollectionAddUpdate",
                                                               new
         {
             @BULLETCOLLECTIONID = Collection.BulletCollectionId,
             @NAME = Collection.Name,
             @ISAMMODEFAULT = Collection.IsAmmoDefault,
             @SESSIONUSERID = SessionUser
         },
                                                               null,
                                                               null,
                                                               CommandType.StoredProcedure)).Result);
     }
 }
Example #12
0
            public void Behavior(Field field, BulletCollection bullets)
            {
                Random rnd = new Random();

                Thread.Sleep(1);
                int doActions = rnd.Next(0, 2);

                if (doActions == 0)
                {
                    int doStep = rnd.Next(0, 2);
                    if (doStep == 0)
                    {
                        int stepDirection = rnd.Next(0, 4);
                        int dx = 0, dy = 0;
                        switch (stepDirection)
                        {
                        case 0:
                            dx--;
                            break;

                        case 1:
                            dy--;
                            break;

                        case 2:
                            dx++;
                            break;

                        case 3:
                            dy++;
                            break;
                        }
                        Rotate(dx, dy);
                        if (field.CanMakeStep(X + dx, Y + dy))
                        {
                            MakeStep(dx, dy);
                        }
                    }

                    int doShot = rnd.Next(0, 3);
                    if (doShot == 0)
                    {
                        bullets.Add(new Bullet(X, Y, direction, true));
                    }
                }
            }
Example #13
0
        public void update(BulletCollection bullets, Vector3 position, Vector3 direction, bool canShoot)
        {
            if (ammo < maxAmmo + mod_acp && recharge <= 0)
            {
                ammo++;
                recharge = maxRechrg - mod_rcg;
            }

            if (cooldown <= 0 && ammo > 0
                && (Keyboard.GetState().IsKeyDown(Keys.Space) || Mouse.GetState().LeftButton == ButtonState.Pressed)
                && canShoot && Mouse.GetState().RightButton == ButtonState.Released)
            {
                cooldown = maxCooldn - mod_cdn;

                bullets.generate(true, position + direction * .5f, direction, 1 + mod_spd, 20, 20 + mod_str, (byte)mod_elm, (byte) mod_typ);
                ammo--;

                audio.playShoot(true);
            }

            cooldown = Math.Max(cooldown - 1, 0);
            recharge = Math.Max(recharge - 1, 0);
        }
Example #14
0
 public int AddUpdate(BulletCollection Collection, string SessionUser)
 {
     return(_collectionRepository.AddUpdate(Collection, SessionUser));
 }
Example #15
0
File: NPC.cs Project: kayorga/3DSP
        public bool update(GameTime gameTime, BulletCollection bullets, Camera camera, Player p, Mission m)
        {
            #region npc death
            //die and grant xp
            if (health <= 0 && !isDead)
            {
                int exp = (int)(XP * (float)level / (float)p.level);
                exp = Math.Min(exp,(int) (XP * 1.5f));
                exp = Math.Max(exp, 1);
                if (p.lv == 50) exp = 0;
                else p.getEXP(exp);
                m.update(kind, exp);
                isDead = true;
                isHit = false;
                hitTimer = 0;
                explosion.Position = Position + new Vector3(0, 0.5f, 0);
                explosion.Initialize(camera);
            }

            //Explosion Update if NPC is down
            if (isDead && active)
            {
                hitTimer++;
                explosion.Update(gameTime, camera);
                if (hitTimer > 25)
                {
                    active = false;
                    isDead = false;
                    this.explosion.Clear();
                    dmgNumbers.Clear();
                    return false;
                }
            }
            #endregion

            #region shoot

            //shoot if player is within shooting distance and not on cooldown
            if (playerDistance <= world.shootDistance && cooldown == 0)
            {
                cooldown = maxCooldn;
                Vector3 dir = (p.position - position);
                dir.Normalize();
                bullets.generate(false, position + dir, dir, 1, world.shootDistance * 2, strength, element);
                audio.playShoot(false);
            }

            if (cooldown > 0) cooldown--;
            #endregion

            #region move
            //if (moving)
                //move();
            //else

            if (!moving || !move())
            {
                {
                    pathFinder.setup(new Point((int)Math.Round((-1 * position.X + world.size - 1)), (int)Math.Round((-1 * position.Z + world.size - 1))), p);
                    target = pathFinder.findPath(kind == Constants.NPC_BOSS);
                    newTarget = true;
                    direction = target - position;
                    if (direction.Length() != 0) direction.Normalize();
                    moving = true;
                    //move();
                }
            }

            #endregion

            #region get hit billboard/dmg number
            //Hit Notification
            if (isHit)
            {
                hitTimer++;
                billboardEngine.AddBillboard(this.position + new Vector3(0, 2, 0), Color.Red, 1.5f);
                if (hitTimer == 70)
                {
                    isHit = false;
                    hitTimer = 0;
                }
            }
            #endregion

            //Rotate Model
            double rotationAngle = Math.Acos((Vector3.Dot(direction, -1 * Vector3.UnitX)) / (direction.Length()));
            rotationAngle = (p.Position.Z < this.Position.Z) ? rotationAngle * -1.0f : rotationAngle;
            rotationAngle += (this.kind == Constants.NPC_BOSS) ? Math.PI / 2 : -Math.PI / 2;
            model.Rotation = new Vector3(0, (float)(rotationAngle), 0);

            //Update PlayerDistance
            playerDistance = (p.Position - this.Position).Length();

            if (playerDistance < 4)
            {
                target = position;
                direction = p.Position - this.Position;
            }

            return true;
        }
Example #16
0
    public void PowerUp(int powerId)
    {
        if (Ship != null)
        {
            switch (powerId)
            {
            case 1:
                Nukes++;
                break;

            case 2:
                bulletDamageMult += 0.1f;
                Shot Dmg = Ship.GetComponentInChildren <Shot>();
                if (Dmg != null)
                {
                    Dmg.damageMultiplier = bulletDamageMult;
                }
                break;

            case 3:
                bulletSpeedMult += 0.01f;
                Shot Spd = Ship.GetComponentInChildren <Shot>();
                if (Spd != null)
                {
                    Spd.speedMultiplier = bulletDamageMult;
                }
                break;

            case 4:
                bulletFirerateMult += 0.1f;
                Shot Frt = Ship.GetComponentInChildren <Shot>();
                if (Frt != null)
                {
                    Frt.fireMultiplier = bulletFirerateMult;
                }
                break;

            case 5:
                HpControl lifes = Ship.GetComponentInChildren <HpControl>();
                if (lifes != null)
                {
                    lifes.extraLife();
                }
                break;

            case 6:
                HpControl baseHealth = Base.GetComponent <HpControl>();
                if (baseHealth != null)
                {
                    baseHealth.GainHealth(30);
                }
                break;

            case 7:
                HpControl shpHealth = Ship.GetComponentInChildren <HpControl>();
                if (shpHealth != null)
                {
                    shpHealth.GainHealth(30);
                }
                break;

            case 8:
                Shot Sprd = Ship.GetComponentInChildren <Shot>();
                if (Sprd != null)
                {
                    Sprd.SpreadLevelUp();
                }
                break;

            case 9:
                BulletCollection bullLvl = Ship.GetComponentInChildren <BulletCollection>();
                bullLvl.LevelUp();
                break;

            default:
                break;
            }
        }
    }
Example #17
0
        public bool update(GameTime gameTime, NPCCollection npcs, BulletCollection bullets, Camera camera, bool canShoot)
        {
            if (Mouse.GetState().RightButton == ButtonState.Released && rightButton) charge.Clear();
            rightButton = (Mouse.GetState().RightButton == ButtonState.Pressed);

            if (lastMapID != world.mapID)
            {
                reset();
                return true;
            }

            if (health <= 0) return false;

            restore = (byte) Math.Max(restore - 1, 0);
            hitDelay = (byte) Math.Max(hitDelay - 1, 0);

            if (health < maxHealth && hitDelay == 0
                && Mouse.GetState().RightButton == ButtonState.Pressed)
            {
                charging = true;
                charge.Update(gameTime, camera, this.Position);
                if (restore <= 0)
                {
                    int h = Math.Max((int)(maxHealth * .01f), 1);
                    health = Math.Min(health + h, maxHealth);
                    restore = maxRest;
                }
            }
            else charging = false;

            /*if (Mouse.GetState().RightButton == ButtonState.Pressed)
            {
                charging = true;
                charge.Update(gameTime, camera, this.Position);
            }*/

            model.Rotation = new Vector3(0, -camera.Phi,0);

            Vector3 front = new Vector3(camera.Direction.X, 0, camera.Direction.Z);
            front.Normalize();
            float forward = (Keyboard.GetState().IsKeyDown(Keys.W) ? 1.0f : 0.0f) - (Keyboard.GetState().IsKeyDown(Keys.S) ? 1.0f : 0.0f);

            Vector3 sideVec = Vector3.Cross(front, new Vector3(0,1,0));
            float side = (Keyboard.GetState().IsKeyDown(Keys.D) ? 1.0f : 0.0f) - (Keyboard.GetState().IsKeyDown(Keys.A) ? 1.0f : 0.0f);

            this.direction = front * forward + sideVec * side;
            if (this.direction != Vector3.Zero) this.direction.Normalize();

            moveAndCollide(npcs);

            if (invincibleTimer > 0)
                invincibleTimer--;

            if (world.mapID != 0)
                weapon.update(bullets, position, front, canShoot);
            return true;
        }