Exemplo n.º 1
0
        public override void Move(SFML.System.Vector2f velocity)
        {
            Vector2f vel = velocity;

            if (velocity.X > 0 && Position.X >= Program.WINDOW_WIDTH - 150)
            {
                vel.X = 0;
            }

            if (velocity.X < 0 && Position.X < 50)
            {
                vel.X = 0;
            }

            if (velocity.Y > 0 && Position.Y >= Program.WINDOW_HEIGHT - 150)
            {
                vel.Y = 0;
            }

            if (velocity.Y < 0 && Position.Y < 50)
            {
                vel.Y = 0;
            }

            base.Move(vel);
        }
Exemplo n.º 2
0
        public void ResolveShadows(LightArea Area, bool attenuateShadows, Texture mask = null)
        {
            Texture     shadowCastersTexture = Area.RenderTarget.Texture;
            RenderImage Result = Area.RenderTarget;

            SFML.System.Vector2f LightPosition = Area.LightPosition;
            Texture  MaskTexture  = mask == null ? Area.Mask.Texture : mask;
            Vector4f MaskProps    = Vector4f.Zero;
            Vector4f diffuseColor = Vector4f.One;

            //Debug.DebugRendertarget(Area.RenderTarget);
            ExecuteTechnique(Area.RenderTarget, distancesRT, "ComputeDistances");
            //Debug.DebugRendertarget(distancesRT);
            ExecuteTechnique(distancesRT, distortRT, "Distort");
            //Debug.DebugRendertarget(distortRT);

            // Working now
            ApplyHorizontalReduction(distortRT, shadowMap);

            //only DrawShadows needs these vars
            resolveShadowsEffectTechnique["DrawShadows"].SetParameter("AttenuateShadows", attenuateShadows ? 0 : 1);
            resolveShadowsEffectTechnique["DrawShadows"].SetParameter("MaskProps", MaskProps);
            resolveShadowsEffectTechnique["DrawShadows"].SetParameter("DiffuseColor", diffuseColor);

            var         maskSize   = MaskTexture.Size;
            RenderImage MaskTarget = new RenderImage("MaskTarget", maskSize.X, maskSize.Y);

            //Debug.DebugRendertarget(shadowMap, "ShadowMap");
            ExecuteTechnique(MaskTarget, Result, "DrawShadows", shadowMap);
            //Debug.DebugRendertarget(Result, "DrawShadowsResult");

            resolveShadowsEffectTechnique["DrawShadows"].ResetCurrentShader();
        }
Exemplo n.º 3
0
 /// <summary>Initializes a new instance of Vector4.</summary>
 /// <param name="value">A vector containing the values to initialize x and y components with.</param>
 /// <param name="z">Initial value for the z-component of the vector.</param>
 /// <param name="w">Initial value for the w-component of the vector.</param>
 public Vector4f(SFML.System.Vector2f value, float z, float w)
 {
     X = value.X;
     Y = value.Y;
     Z = z;
     W = w;
 }
Exemplo n.º 4
0
 public ThirdLevel(Font newFont, SFML.System.Vector2f WindowSize)
 {
     LevelData.initialNumberOfBacteria = 15;
     LevelData.initialTime             = 9;
     secondLevel     = new SecondLevel(newFont, WindowSize);
     this.WindowSize = WindowSize;
 }
Exemplo n.º 5
0
        private void AddMoisture(Tile t, int radius)
        {
            int     startx = MathHelper.Mod(t.X - radius, Width);
            int     endx   = MathHelper.Mod(t.X + radius, Width);
            Vector2 center = new Vector2(t.X, t.Y);
            int     curr   = radius;

            while (curr > 0)
            {
                int x1 = MathHelper.Mod(t.X - curr, Width);
                int x2 = MathHelper.Mod(t.X + curr, Width);
                int y  = t.Y;

                AddMoisture(Tiles[x1, y], 0.025f / (center - new Vector2(x1, y)).Length());

                for (int i = 0; i < curr; i++)
                {
                    AddMoisture(Tiles[x1, MathHelper.Mod(y + i + 1, Height)], 0.025f / (center - new Vector2(x1, MathHelper.Mod(y + i + 1, Height))).Length());
                    AddMoisture(Tiles[x1, MathHelper.Mod(y - (i + 1), Height)], 0.025f / (center - new Vector2(x1, MathHelper.Mod(y - (i + 1), Height))).Length());

                    AddMoisture(Tiles[x2, MathHelper.Mod(y + i + 1, Height)], 0.025f / (center - new Vector2(x2, MathHelper.Mod(y + i + 1, Height))).Length());
                    AddMoisture(Tiles[x2, MathHelper.Mod(y - (i + 1), Height)], 0.025f / (center - new Vector2(x2, MathHelper.Mod(y - (i + 1), Height))).Length());
                }
                curr--;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a Sprite from RenderImage Texture and draws it to the screen
        /// </summary>
        /// <param name="Position"> Position of Texture </param>
        /// <param name="Size"> Size of the Texture </param>
        /// <param name="color"> Global color of object </param>
        public void Blit(SFML.System.Vector2f position, SFML.System.Vector2f Size, SFML.Graphics.Color color)
        {
            isStillDrawing();
            blitsprite          = new SFML.Graphics.Sprite(Texture);
            blitsprite.Position = position;
            blitsprite.Color    = color;
            var bounds = blitsprite.GetLocalBounds();

            if (Mode == BlitterSizeMode.Scale)
            {
                SFML.System.Vector2f scale = new SFML.System.Vector2f((Size.X / bounds.Width), (Size.Y / bounds.Height));
                blitsprite.Scale = scale;
            }
            else if (Mode == BlitterSizeMode.Crop)
            {
                IntRect crop = new IntRect((int)position.X, (int)position.Y, (int)Size.X, (int)Size.Y);
                blitsprite.TextureRect = crop;
            }


            if (CluwneLib.CurrentRenderTarget == this)
            {
                return;
            }

            blitsprite.Draw();
        }
Exemplo n.º 7
0
        public WorldView(IWorld world)
        {
            _background = new Sfg.RectangleShape(new Sfs.Vector2f(300f, 480f))
            {
                FillColor        = Sfg.Color.Black,
                OutlineThickness = 20f,
                OutlineColor     = new Sfg.Color(212, 175, 55)
            };
            _views   = new List <Sfg.RectangleShape>();
            Position = new Sfs.Vector2f(-100, -100);
            for (var y = 0; y < World.WorldBounds.Y; y++)
            {
                for (var x = 0; x < World.WorldBounds.X; x++)
                {
                    if (!world.Matrix[y, x])
                    {
                        continue;
                    }

                    var position = new Sfs.Vector2f(x * 30, y * 30);
                    var view     = new Sfg.RectangleShape(new Sfs.Vector2f(28f, 28f))
                    {
                        FillColor        = Sfg.Color.White,
                        Position         = position,
                        OutlineThickness = 2f,
                        OutlineColor     = Sfg.Color.Black
                    };
                    _views.Add(view);
                }
            }
        }
Exemplo n.º 8
0
 public void Update(SFML.System.Vector2f newPos, IEnumerable <Bullet> bullets)
 {
     UpdatePosition(newPos);
     foreach (Bullet b in bullets)
     {
         CheckColision(b);
     }
 }
Exemplo n.º 9
0
 public override void Update()
 {
     Position += new SFML.System.Vector2f(dx * Speed, dy * Speed);
     if (s.ElapsedMilliseconds > Lifetime || Position.Y <= 30)
     {
         Destroy();
     }
 }
Exemplo n.º 10
0
 public SecondLevel(Font newFont, SFML.System.Vector2f WindowSize)
 {
     LevelData.initialNumberOfBacteria = 13;
     LevelData.initialTime             = 10;
     timeBetweenNewBacteria            = 3;
     this.font       = newFont;
     this.WindowSize = WindowSize;
 }
Exemplo n.º 11
0
        private Sfg.RectangleShape CreateBlock(Sfg.Color color, int x, int y)
        {
            var position = new Sfs.Vector2f(x * 30, y * 30);

            return(new Sfg.RectangleShape(new Sfs.Vector2f(28f, 28f))
            {
                FillColor = color,
                Position = position,
                OutlineThickness = 2f,
                OutlineColor = Sfg.Color.Black
            });
        }
Exemplo n.º 12
0
 internal GUI(Engine context, RenderWindow window)
 {
     _context           = context;
     _context2          = context;
     _window            = window;
     _spritesDisplayed  = new Dictionary <SFML.System.Vector2f, Sprite>();
     _spritesDisplayed2 = new Dictionary <SFML.System.Vector2f, Sprite>();
     _background        = new SFML.Graphics.Sprite();
     _moveTheMapOf      = new SFML.System.Vector2f(0, 0);
     _moveTheMapOf2     = new SFML.System.Vector2f(0, 0);
     _hpBar             = new SFML.Graphics.Sprite();
     _rect1             = new SFML.Graphics.Sprite();
     _spDegats          = new List <Stopwatch>();
 }
Exemplo n.º 13
0
        void UpdatePosition(SFML.System.Vector2f newPos)
        {
            var oldPos = this.Position;

            /*Check intersection with borders newPos - coordinats of upper left conner of the ship
             * so we add half of the ship size*/
            if (gameInterface.GetTile(newPos.X + (float)SIZE * SIZE_FACTOR / 2,
                                      newPos.Y + (float)SIZE * SIZE_FACTOR / 2) == null)
            {
                Position = newPos;
            }
            else
            {
                isDead = true;
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Creates a Sprite from RenderImage Texture and draws it to the screen
        /// </summary>
        /// <param name="Position"> Position of Texture </param>
        /// <param name="Size"> Size of the Texture </param>
        /// <param name="color"> Global color of object </param>
        public void Blit(SFML.System.Vector2f position, SFML.System.Vector2f Size, SFML.Graphics.Color color)
        {
            isStillDrawing();
            blitsprite = new SFML.Graphics.Sprite(Texture);
            blitsprite.Position = position;
            blitsprite.Color = color;
            var bounds = blitsprite.GetLocalBounds();

            if (Mode == BlitterSizeMode.Scale)
            {
                SFML.System.Vector2f scale = new SFML.System.Vector2f(( Size.X / bounds.Width ),( Size.Y / bounds.Height ));
                blitsprite.Scale = scale;

            }
            else if (Mode == BlitterSizeMode.Crop)
            {
                IntRect crop = new IntRect((int)position.X, (int)position.Y, (int)Size.X, (int)Size.Y);
                blitsprite.TextureRect = crop;

            }

            if (CluwneLib.CurrentRenderTarget == this)
                return;

            blitsprite.Draw();
        }
Exemplo n.º 15
0
 public TimerBase(Font newFont, SFML.System.Vector2f WindowSize) : base(newFont, WindowSize)
 {
 }
Exemplo n.º 16
0
 public LevelTimer(Font newFont, SFML.System.Vector2f WindowSize, int newLevelDuration) : base(newFont, WindowSize)
 {
     Text.Scale    = new Vector2f(1.5f, 1.5f);
     levelDuration = newLevelDuration;
     SetNewTimer();
 }
Exemplo n.º 17
0
        /// <summary>
        /// Actualiza la nave del jugador
        /// </summary>
        /// <param name="dt">Incremento de tiempo desde la última actualización</param>
        /// <remarks>
        /// Ya nadie puede heredarla
        /// </remarks>
        override sealed protected void UpdateCurrent(SFML.System.Time dt)
        {
            // No es necesario llamar a la función del padre ya que la actualización la realiza el comando
          //  base.UpdateCurrent(dt);

            float posX;

            posX = Position.X < _worldBounds.Left ? _worldBounds.Left : Position.X;
            posX = posX > _worldBounds.Width ? _worldBounds.Width : posX; 
                
            Position = new SFML.System.Vector2f(posX, Position.Y);
        }
Exemplo n.º 18
0
 public void UpdatePosition(Vector2f vecNewPosition)
 {
     Position            = vecNewPosition;
     recBody.Position    = vecNewPosition;
     buttonText.Position = vecNewPosition;
 }
Exemplo n.º 19
0
        internal void Events2()
        {
            //Graphics
            if (_context.GetGame.GetPlayer.IsAttack)
            {
                _context.GetGame.GetPlayer.Attack();
            }

            if (_context.GetGame.GetPlayer.HurtPlayer)
            {
                foreach (Monster monster in _context.GetGame.GetMonsters)
                {
                    monster.GetAttack.HurtPlayerAnimation();
                }
            }

            // Manette
            Joystick.Update();
            if (Joystick.IsConnected(0)) //Controller connected
            {
                // Actions
                for (uint i = 0; i < Joystick.GetButtonCount(0); i++) //Test tous les btn
                {
                    if (Joystick.IsButtonPressed(0, i))
                    {
                        switch (i)
                        {
                        case 0:     //A - Jump
                            if (_context.GetGame.GetPlayer.RealPosition.Y < _context.GetGame.GetMapObject.GetLimitMax.Y && _context.GetGame.GetPlayer.IsOnTheGround)
                            {
                                _context.GetGame.GetPlayer.Jump();
                            }
                            break;

                        case 1:     //B - Attack
                            _context.GetGame.GetPlayer.IsAttack = true;
                            _context.GetGame.GetPlayer.Attack();
                            break;
                        }
                    }
                }
                // Moves
                if (Joystick.GetAxisPosition(0, Joystick.Axis.X) >= 80) // Droite
                {
                    _moveTheMapOf += _context.GetGame.GetPlayer.MoveRight((float)_window.Size.X);
                }
                else if (Joystick.GetAxisPosition(0, Joystick.Axis.X) <= -80) // Gauche
                {
                    _moveTheMapOf -= _context.GetGame.GetPlayer.MoveLeft((float)_window.Size.X);
                }
                else if (_context.GetGame.GetPlayer.IsOnTheGround && !_context.GetGame.GetPlayer.IsAttack)
                {
                    _context.GetGame.GetPlayer.GetPlayerSprite.DefaultAnimation();
                }
            }
            else
            {
                if (Keyboard.IsKeyPressed(Keyboard.Key.Escape))
                {
                    //_context.GetGame.GetPlayer.GetLife.CurrentPoint = 0; // TEMPORARYYYYYYYYYYYYYYYYYY
                }
                else if (Keyboard.IsKeyPressed(_RightAction))
                {
                    _moveTheMapOf += _context.GetGame.GetPlayer.MoveRight((float)_window.Size.X);
                }
                else if (Keyboard.IsKeyPressed(_LeftAction))
                {
                    _moveTheMapOf -= _context.GetGame.GetPlayer.MoveLeft((float)_window.Size.X);
                }

                if (Keyboard.IsKeyPressed(_JumpAction))
                {
                    if (_context.GetGame.GetPlayer.RealPosition.Y < _context.GetGame.GetMapObject.GetLimitMax.Y && _context.GetGame.GetPlayer.IsOnTheGround)
                    {
                        _context.GetGame.GetPlayer.Jump();
                    }
                }

                if (Keyboard.IsKeyPressed(_AttackAction)) // ATTACK
                {
                    _context.GetGame.GetPlayer.IsAttack = true;
                    _context.GetGame.GetPlayer.Attack();
                }

                if (!Keyboard.IsKeyPressed(_LeftAction) && !Keyboard.IsKeyPressed(_RightAction) && !Keyboard.IsKeyPressed(_JumpAction) && !_context.GetGame.GetPlayer.IsAttack && !_context.GetGame.GetPlayer.HurtPlayer)
                {
                    _context.GetGame.GetPlayer.GetPlayerSprite.DefaultAnimation();
                }
            }
            // ------------------------------PLAYER 2
            //Graphics
            if (_context2.GetGame2.GetPlayer2.IsAttack2)
            {
                _context2.GetGame2.GetPlayer2.Attack2();
            }

            if (_context2.GetGame2.GetPlayer2.HurtPlayer2)
            {
                foreach (Monster monster in _context2.GetGame2.GetMonsters2)
                {
                    monster.GetAttack2.HurtPlayerAnimation2();
                }
            }
            else
            {
                if (Keyboard.IsKeyPressed(Keyboard.Key.Escape))
                {
                    //_context.GetGame.GetPlayer.GetLife.CurrentPoint = 0; // TEMPORARYYYYYYYYYYYYYYYYYY
                }
                else if (Keyboard.IsKeyPressed(_RightAction2))
                {
                    _moveTheMapOf2 += _context2.GetGame2.GetPlayer2.MoveRight2((float)_window.Size.X);
                }
                else if (Keyboard.IsKeyPressed(_LeftAction2))
                {
                    _moveTheMapOf2 -= _context2.GetGame2.GetPlayer2.MoveLeft2((float)_window.Size.X);
                }

                if (Keyboard.IsKeyPressed(_JumpAction2))
                {
                    if (_context2.GetGame2.GetPlayer2.RealPosition2.Y2 < _context2.GetGame2.GetMapObject2.GetLimitMax2.Y2 && _context2.GetGame2.GetPlayer2.IsOnTheGround2)
                    {
                        _context2.GetGame2.GetPlayer2.Jump2();
                    }
                }

                if (Keyboard.IsKeyPressed(_AttackAction2)) // ATTACK
                {
                    _context2.GetGame2.GetPlayer2.IsAttack2 = true;
                    _context2.GetGame2.GetPlayer2.Attack2();
                }

                if (!Keyboard.IsKeyPressed(_LeftAction2) && !Keyboard.IsKeyPressed(_RightAction2) && !Keyboard.IsKeyPressed(_JumpAction2) && !_context2.GetGame2.GetPlayer2.IsAttack2 && !_context2.GetGame2.GetPlayer2.HurtPlayer2)
                {
                    _context2.GetGame2.GetPlayer2.GetPlayerSprite2.DefaultAnimation2();
                }
            }
        }
Exemplo n.º 20
0
 public NewBactieriaTimer(Font newFont, SFML.System.Vector2f WindowSize, int timeBetweenNewBacteria) : base(newFont, WindowSize)
 {
     this.timeBetweenNewBacteria = timeBetweenNewBacteria;
     SetNewTimer();
 }