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
        //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;
        }
Example #3
0
        public void Draw(SpriteBatch spriteBatch, Vector2 Origin, Player player)
        {
            if (drawExclamationPoint)
            {
                exlcamationPoint.position = this.position - new Vector2(0, exlcamationPoint.getHeight() + 3);
                exlcamationPoint.Draw(spriteBatch, Origin);
            }
            else if (drawQuestionMark)
            {
                questionMark.position = this.position - new Vector2(0, questionMark.getHeight() + 3);
                questionMark.Draw(spriteBatch, Origin);
            }

            if (shouldFire)
            {
                Vector2 normalMeToHookForReal = Vector2.Normalize(this.position - player.position);
                if (player.position.X < this.position.X)
                {
                    lazerBeam.rotation = (float)Math.Acos(Vector2.Dot(normalMeToHookForReal, Vector2.Normalize(new Vector2(position.X, 0) - new Vector2(position.X, Level.ScreenH))));
                }
                else
                {
                    lazerBeam.rotation = -1f * (float)Math.Acos(Vector2.Dot(normalMeToHookForReal, Vector2.Normalize(new Vector2(position.X, 0) - new Vector2(position.X, Level.ScreenH))));
                }
                lazerBeam.position = (this.position + player.position)/2;
                lazerBeam.DrawScaled(spriteBatch, Origin, new Vector2(Beam.LAZER_WIDTH_SCALE, (player.position - this.position).Length() / lazerBeam.getHeight()));
            }
            if (facingRight) {
                base.Draw(spriteBatch, Origin);
            } else {
                spriteBatch.Draw(spriteTexture, position - Origin, Source, tint, rotation, origin, Scale,
                    SpriteEffects.FlipHorizontally, 0);
                }
        }