Example #1
0
        public static bool IsPlayerInSight(Enemy enemy, Player.Player player, GameWorld gameWorld, out List<Rectangle> rects)
        {
            Rectangle rect = new Rectangle(enemy.GetCollRectangle().Center.X, enemy.GetCollRectangle().Center.Y, 1, 1);
            rects = new List<Rectangle>();

            double xVector = (double)(player.GetCollRectangle().Center.X - rect.Center.X);
            double yVector = (double)(player.GetCollRectangle().Center.Y - rect.Center.Y);

            Vector2 maxVelocity = new Vector2(30, 30);
            double magnitude = Math.Sqrt((Math.Pow(xVector, 2.0)) + (Math.Pow(yVector, 2.0)));
            Vector2 newVelocity = new Vector2(maxVelocity.X * (float)(xVector / magnitude), maxVelocity.Y * (float)(yVector / magnitude));

            for (int i = 0; i < 10; i++)
            {
                rects.Add(rect);

                int index = (int)(rect.Y / Main.Tilesize * gameWorld.WorldData.LevelWidth) + (int)(rect.X / Main.Tilesize);

                if (rect.Intersects(player.GetCollRectangle()))
                    return true;
                if (index > GameWorld.Instance.TileArray.Length - 1 || index < 0)
                    return false;
                if (gameWorld.TileArray[index].IsSolid)
                    return false;

                rect.X += (int)newVelocity.X;
                rect.Y += (int)newVelocity.Y;
            }
            return false;
        }
Example #2
0
 public void CheckOnTop(Tile[] array, GameWorld gameWorld)
 {
     //this.gameWorld = gameWorld;
     //int indexAbove = TileIndex - gameWorld.worldData.LevelWidth;
     //if (array[indexAbove].ID == 0)
     //{
     //    this.isOnTop = true;
     //}
 }
Example #3
0
        public void ExtractTo(GameWorld gameWorld)
        {
            for (int i = 0; i < _positions.Length; i++)
            {
                if (i > gameWorld.Entities.Count)
                {
                    Console.WriteLine("There is no entity number {0} in this gameworld. There are only {1}", i, gameWorld.Entities.Count);
                    break;
                }

                gameWorld.Entities[i].UpdateFromPacket(_positions[i], _velocities[i]);
            }
        }
Example #4
0
        /// <summary>
        /// Creates a new entity packet from the current gameworld.
        /// </summary>
        /// <param name="gameWorld"></param>
        /// <returns></returns>
        public EntityPacket(GameWorld gameWorld)
        {
            Entity[] entities = gameWorld.Entities.ToArray();

            _positions = new Vector2[entities.Length];
            _velocities = new Vector2[entities.Length];

            for (int i = 0; i < entities.Length; i++)
            {
                _positions[i] = new Vector2(entities[i].GetCollRectangle().X, entities[i].GetCollRectangle().Y);
                _velocities[i] = entities[i].GetVelocity();
            }
        }
Example #5
0
        public GameWorld(Main game1)
        {
            _instance = this;

            this.Game1 = game1;

            _placeNotification = new PlaceNotification();
            RandGen = new Random();
            SpriteSheet = ContentHelper.LoadTexture("Tiles/spritemap_20");
            UiSpriteSheet = ContentHelper.LoadTexture("Tiles/ui_spritemap");
            ParticleSpriteSheet = ContentHelper.LoadTexture("Tiles/particles_spritemap");

            LightEngine = new LightEngine();
            WorldData = new WorldData();

            //tilesThread = new Thread(new ThreadStart(UpdateVisibleIndexes));
            //tilesThread.IsBackground = true;
            //tilesThread.Start();
        }
Example #6
0
        public void Update(GameTime gameTime, Player.Player player, GameWorld map)
        {
            this._gameTime = gameTime;
            this._player = player;
            this._gameWorld = map;

            AnimateHeart();
            RotateHeart();
            PumpHeart();

            if (_currentHealth < player.Health)
            {
                _currentHealth++;
            }
            if (_currentHealth > player.Health)
            {
                _currentHealth--;
            }

            if (_maxHealth < player.MaxHealth)
            {
                _maxHealth++;
            }
            if (_maxHealth > player.MaxHealth)
            {
                _maxHealth--;
            }

            if (_oldCurrentHealth < player.Health)
            {
                GameWorld.ParticleSystem.Add(new SplashNumber(player, player.Health - _oldCurrentHealth, Color.Green));
                _oldCurrentHealth = player.Health;
            }

            if (_oldCurrentHealth > player.Health)
            {
                GameWorld.ParticleSystem.Add(new SplashNumber(player, player.Health - _oldCurrentHealth, Color.Red));
                _oldCurrentHealth = player.Health;
            }
        }
Example #7
0
        public void Update(GameTime gameTime, GameMode currentLevel)
        {
            GameWorld.Instance.Player.Health = GameWorld.Instance.Player.MaxHealth;

            SoundtrackManager.PlayLevelEditorTheme();

            _gameWorld = GameWorld.Instance;
            _tileScroll.Update();
            _entityScroll.Update();
            ActionBar.Update();
            Brush.Update();
            _tileDescription.Update();

            CheckIfOnInventory();
            CheckIfPositioningPlayer();
            CheckIfChangedToWallMode();

            const float deltaOpacity = .05f;

            if (!OnInventory)
            {
                CheckForCameraMovement();
                CheckForInput();

                _blackScreenOpacity -= deltaOpacity;
            }
            else
            {
                _blackScreenOpacity += deltaOpacity;
            }

            if (_blackScreenOpacity > .7) _blackScreenOpacity = .7f;
            if (_blackScreenOpacity < 0) _blackScreenOpacity = 0;

            // Auto-save functionality.
            if (_idleTimerForSave.TimeElapsedInSeconds > 1 && _hasChangedSinceLastSave)
            {
                _hasChangedSinceLastSave = false;
                DataFolder.SaveLevel();
            }
        }
Example #8
0
        public ParabolicProjectile(Enemy enemy, GameWorld map, ProjectileSource currentProjectileSource)
        {
            this.CurrentProjectileSource = currentProjectileSource;
            this.Enemy = enemy;

            switch (currentProjectileSource)
            {
                case ProjectileSource.Snake:
                    Texture = ContentHelper.LoadTexture("Projectiles/venom_dark");
                    CollRectangle = new Rectangle(enemy.GetCollRectangle().X, enemy.GetCollRectangle().Y, 32, 32);
                   // animation = new Animation(Texture, collRectangle, 200, 0, AnimationType.Loop);
                    if (!enemy.IsFacingRight)
                    {
                        Velocity = new Vector2(-10, -15);
                        //animation.isFlipped = true;
                    }
                    else Velocity = new Vector2(10, -15);
                    break;
            }
        }
Example #9
0
        protected override void Initialize()
        {
            Camera = new Camera(GraphicsDevice.Viewport);
            _menu = new Menu(this);
            _gameWorld = new GameWorld(this);
            Player = new Player.Player(this);
            _overlay = new Overlay();
            _cutscene = new Cutscene();
            Dialog = new Dialog();
            ObjectiveTracker = new ObjectiveTracker();
            MessageBox = new MessageBox();
            TextInputBox = new TextInputBox();

            DefaultTexture = ContentHelper.LoadTexture("Tiles/temp tile");
            GraphicsDeviceInstance = _graphics.GraphicsDevice;

            //Initialize the game render target
            _mainRenderTarget = new RenderTarget2D(GraphicsDevice, DefaultResWidth, DefaultResHeight, false,
                GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24,
                GraphicsDevice.PresentationParameters.MultiSampleCount, RenderTargetUsage.PreserveContents);
            _lightingRenderTarget = new RenderTarget2D(GraphicsDevice, DefaultResWidth, DefaultResHeight, false,
                GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24,
                GraphicsDevice.PresentationParameters.MultiSampleCount, RenderTargetUsage.PreserveContents);

            SpriteBatch = new SpriteBatch(GraphicsDevice);

            _lightBlendState = new BlendState
            {
                AlphaSourceBlend = Blend.DestinationColor,
                ColorSourceBlend = Blend.DestinationColor,
                ColorDestinationBlend = Blend.Zero
            };

            base.Initialize();
        }
Example #10
0
        public void Update()
        {
            _gameWorld = GameWorld.Instance;
            _levelEditor = _gameWorld.LevelEditor;

            if (_box.Y < _originalY)
            {
                _box.Y = _originalY;
                _velocityY = 0;
            }

            if (_levelEditor.OnInventory)
            {
                _velocityY = (_originalY - _box.Y) / 5;

            }
            else
            {
                int hidingPlace = Main.UserResHeight + 200;
                _velocityY += .3f;
                if (_box.Y > hidingPlace)
                {
                    _box.Y = hidingPlace;
                    _velocityY = 0;
                }
            }

            _box.Y += (int)_velocityY;

            foreach (FunctionButton b in _buttons)
            {
                b.Update(_box);
            }
        }
Example #11
0
 public void CreateLavaParticle(Liquid lava, GameWorld map)
 {
     CurrentParticle = ParticleType.Lava;
     //texture = ContentHelper.LoadTexture("Effects/lava");
     Texture = GameWorld.ParticleSpriteSheet;
     CollRectangle = new Rectangle(lava.GetCollRectangle().Center.X - 8, lava.GetCollRectangle().Center.Y - 8, 8, 8);
     SourceRectangle = new Rectangle(0, 0, 8, 8);
     Velocity.Y = -10f;
     Position = new Vector2(CollRectangle.X, CollRectangle.Y);
     Opacity = 1f;
     light = new Lights.DynamicPointLight(this, 1, true, Color.Orange, .3f);
     GameWorld.Instance.LightEngine.AddDynamicLight(light);
 }
Example #12
0
 public void CreateBloodEffect(Player.Player player, GameWorld map)
 {
     CurrentParticle = ParticleType.Blood;
     Texture = ContentHelper.LoadTexture("Effects/blood");
     CollRectangle = new Rectangle(player.GetCollRectangle().Center.X, player.GetCollRectangle().Center.Y, 8, 8);
     SourceRectangle = new Rectangle(GameWorld.RandGen.Next(0, 4) * 8, 0, 8, 8);
     CollRectangle = CollRectangle;
     Velocity = new Vector2(GameWorld.RandGen.Next(-10, 10), GameWorld.RandGen.Next(-10, 10));
     Position = new Vector2(CollRectangle.X, CollRectangle.Y);
 }
Example #13
0
        public void Update(Main game1, Player.Player player, GameWorld map, bool isOnDebug)
        {
            if (!isOnDebug)
            {
                _textString = "";
                IsWritingCommand = false;
                map.IsOnDebug = false;
                return;
            }

            if (!IsWritingCommand)
            {
                map.IsOnDebug = false;
                if (Keyboard.GetState().IsKeyDown(Keys.LeftControl)
                    && Keyboard.GetState().IsKeyDown(Keys.LeftShift)
                    && Keyboard.GetState().IsKeyDown(Keys.C))
                {
                    IsWritingCommand = true;
                    _textString = "";
                    return;
                }
                else return;
            }
            else
            {
                map.IsOnDebug = true;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.LeftControl)
                    && Keyboard.GetState().IsKeyDown(Keys.LeftShift)
                    && Keyboard.GetState().IsKeyDown(Keys.C))
            {
                _textString = "";
            }

            if (_textString == "No command found" && Keyboard.GetState().IsKeyDown(Keys.Back))
                _textString = "";

            this._game1 = game1;
            this._player = player;

            _oldKeyboardState = _currentKeyboardState;
            _currentKeyboardState = Keyboard.GetState();

            InputHelper.TryLinkToKeyboardInput(ref _textString, _currentKeyboardState, _oldKeyboardState);
            if (InputHelper.IsKeyDown(Keys.Enter) &&!_definitionFound)
            {
                AnalyzeText();
            }
        }
Example #14
0
 public void Update(GameTime gameTime, Player.Player player, GameWorld map)
 {
     _animation.Update(gameTime);
 }
Example #15
0
        public void Update(GameTime gameTime, Player.Player player, GameWorld map)
        {
            _heart.Update(gameTime, player, map);
            _coin.Update(player, gameTime);

            if (_fadeIn)
            {
                _blackOpacity -= .03f;
                if (_blackOpacity <= 0)
                    _fadeIn = false;
            }
            if (_fadeOut)
            {
                _blackOpacity += .03f;
                if (_blackOpacity >= 1)
                    _fadeOut = false;
            }
        }
Example #16
0
 /// <summary>
 /// Sends an entity packet to all clients.
 /// </summary>
 /// <param name="gameWorld"></param>
 public void SendEntityPacket(GameWorld gameWorld)
 {
     EntityPacket en = new EntityPacket(gameWorld);
     byte[] packet = CalcHelper.ToByteArray(en);
     SendToClients(packet);
 }