Example #1
0
        public Level()
        {
            gameOver = false;
            levelCompleted = false;
            eastermode = false;
            //hooray for things being in the right place!
            this.player = new Player();
            crosshair = new Crosshair();
            enemies = new LinkedList<Enemy>();
            contentHolder = new Enemy(-1, -1);
            bullets = new Bullet[50];
            usedCoins = new LinkedList<Vector2>();
            usedButtons = new Dictionary<Vector2, int>();
            pipeEngine = new PipeEngine(128, 128, 3000, 0f);

            for (int i = 0; i < bullets.Length; i++)
            {
                bullets[i] = new Bullet(Vector2.Zero);
            }
        }
Example #2
0
 //does the actual firing
 private void fireBullet(Vector2 ray, Bullet[] bullets)
 {
     for (int i = 0; i < bullets.Length; i++)
     {
         if (!bullets[i].isVisible)
         {
             bullets[i].position = this.position;
             bullets[i].velocity = -1 * Bullet.BULLET_MAX_SPEED * Vector2.Normalize(ray);
             bullets[i].isVisible = true;
             break;
         }
     }
 }
Example #3
0
        //update things.  will eventually check line-of-sight, shooting, and walking
        public int Update(float dt, Player player, Bullet[] bullets,Tile[,] layout, Boolean noise,Boolean fallNoise, Tile[] nearby)
        {
            Vector2 playerPosition = player.position;
            int retval = -1;
            //if the guard is patrolling, let it patrol
            if (this.isPatrolling)
            {
                drawQuestionMark = false;
                if (patrolRange == 0 && Math.Abs(this.position.X - patrolStart) <= 5)
                {
                    velocity.X = 0;
                }
                else if (position.X >= patrolStart + patrolRange || this.collideRight)
                {
                    velocity.X = -patrolspeed;
                }
                else if (position.X <= patrolStart - patrolRange || this.collideLeft)
                {
                    velocity.X = patrolspeed;
                }

            }
            //if it can see the player, shoot at it!
            if (this.canSeePlayer(playerPosition, layout))
            {
                drawQuestionMark = false;
                drawExclamationPoint = true;
                //dont resume patrol if we can see the player!
                waitTimer = 0;
                if (weaponType == 1)
                {
                    timeSinceLastFire += dt;
                    if (timeSinceLastFire > fireInterval)
                    {
                        fireBullet(this.position - playerPosition, bullets);
                        timeSinceLastFire = 0;
                        retval = 1;
                    }
                }
                else if (weaponType == 2)
                {
                    if (!hasStartedLazer)
                    {
                        hasStartedLazer = true;
                        timeSinceLastFire = 0;
                        Particle_Engine.ParticleEngine.removeEmmiter(emitter);
                        emitter = new Particle_Engine.LazerChargeEmitter(this.position, lazerChargeTime);
                        Particle_Engine.ParticleEngine.addEmitter(emitter);
                    }
                    else
                    {
                        timeSinceLastFire += dt;
                        velocity.X = 0;
                        if (timeSinceLastFire > lazerChargeTime)
                        {
                            shouldFire = true;
                        }
                        if (timeSinceLastFire + 1 > lazerChargeTime) retval = 2;
                    }
                }
                isPatrolling = false;
                isInvestigating = true;
                destination = playerPosition;
            }
            else
            {
                if (hasStartedLazer) Particle_Engine.ParticleEngine.removeEmmiter(emitter);
                shouldFire = false;
                drawExclamationPoint = false;
                hasStartedLazer = false;
                timeSinceLastFire = fireInterval + LAZER_CHARGE_TIME + 100;
            }
            //if there is noise while patrolling
            if (noise)
            {
                Vector2 distance = player.theHook.position - this.position;
                //if the guard can actually hear it
                if (distance.Length() < soundRange)
                {
                    waitTimer = 0;
                    this.isPatrolling = false;
                    this.isInvestigating = true;
                    drawQuestionMark = true;
                    this.destination = player.theHook.position;
                }
            }
            if (fallNoise)
            {
                Vector2 distance = player.position - this.position;
                //if the guard can actually hear it
                if (distance.Length() < soundRange)
                {
                    waitTimer = 0;
                    this.isPatrolling = false;
                    drawQuestionMark = true;
                    this.isInvestigating = true;
                    this.destination = player.position;
                }
            }
            //if we're investigating something (like a noise, say)
            if (this.isInvestigating)
            {
                drawQuestionMark = true;
                Vector2 distance = this.destination - this.position;
                //if we're close or if the next tile isn't solid, stop or if we seem to have gotten stuck
                if (Math.Abs(distance.X) <= 5 || !this.nextTileIsSolid(nearby) || collideLeft || collideRight)
                {
                    this.velocity.X = 0;
                    waitTimer += dt;
                    if (waitTimer > investigateMaxWait)
                    {
                        isInvestigating = false;
                        drawQuestionMark = false;
                        isPatrolling = true;
                        this.velocity.X = -patrolspeed * ((this.position.X - this.patrolStart) / (Math.Abs(this.position.X - this.patrolStart)));
                        waitTimer = 0;
                    }
                }
                //otherwise continue (or start) moving at PATROLSPEED towards the noise
                else if (distance.X * velocity.X <= 0 && !hasStartedLazer)
                {
                    this.velocity.X = patrolspeed * (distance.X / Math.Abs(distance.X));
                }
            }
            if (this.hasStartedLazer)
            {
                if (timeSinceLastFire - lazerChargeTime >= lazerDuration)
                {
                    timeSinceLastFire = 0;
                    this.hasStartedLazer = false;
                }
            }
            if (velocity.X < -.1f) facingRight = false;
            if (velocity.X > .1f) facingRight = true;
            if (!nextTileIsSolid(nearby))
            {
                this.velocity.X *= -1;
            }
            applyGravity();
            base.Update(dt);
            return retval;
        }