Ejemplo n.º 1
0
        public static bool IsSticking(FloatRect rect1, FloatRect rect2)
        {
            if (rect2.Intersects(rect1))
            {
                return(true);
            }

            rect1.Left += 0.1f;
            rect1.Top  += 0.1f;

            if (rect2.Intersects(rect1))
            {
                return(true);
            }

            rect1.Left -= 0.2f;
            rect1.Top  -= 0.2f;

            if (rect2.Intersects(rect1))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        private void Query(FloatRect bounds, QuadNode node, List <T> results)
        {
            lock (syncLock)
            {
                if (node == null)
                {
                    return;
                }

                if (bounds.Intersects(node.Bounds))
                {
                    foreach (T quadObject in node.Objects)
                    {
                        if (bounds.Intersects(quadObject.Bounds))
                        {
                            results.Add(quadObject);
                        }
                    }

                    foreach (QuadNode childNode in node.Nodes)
                    {
                        Query(bounds, childNode, results);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void CheckCharacterCollisions(Entity e)
        {
            for (int x = 0; x < Entities.Count; x++)
            {
                Entity c = (Entity)Entities[x];
                if (c.IsStatic || c.IgnoreAllCollisions)
                {
                    continue;
                }

                if (c.ID != e.ID)
                {
                    FloatRect entityRect = e.sprite.GetGlobalBounds();
                    FloatRect area       = new FloatRect();
                    FloatRect boundBox   = c.sprite.GetGlobalBounds();
                    boundBox.Top    = boundBox.Top + boundBox.Height + 1;
                    boundBox.Height = 1;

                    if (boundBox.Intersects(entityRect))
                    {
                        e.OnCharacterCollision(c, Direction.DOWN);
                        continue;
                    }

                    boundBox        = c.sprite.GetGlobalBounds();
                    boundBox.Top    = boundBox.Top - 1;
                    boundBox.Height = 1;

                    if (boundBox.Intersects(entityRect, out area))
                    {
                        e.OnCharacterCollision(c, Direction.UP);
                        continue;
                    }

                    boundBox       = c.sprite.GetGlobalBounds();
                    boundBox.Left  = boundBox.Left + boundBox.Width;
                    boundBox.Width = 1;

                    if (boundBox.Intersects(entityRect))
                    {
                        e.OnCharacterCollision(c, Direction.LEFT);
                        c.OnCharacterCollision(e, Direction.RIGHT);
                        continue;
                    }

                    boundBox       = c.sprite.GetGlobalBounds();
                    boundBox.Width = 1;

                    if (boundBox.Intersects(entityRect))
                    {
                        e.OnCharacterCollision(c, Direction.RIGHT);
                        c.OnCharacterCollision(e, Direction.LEFT);
                        continue;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public bool checkCollision(Entity ent)
        {
            FloatRect rect1 = this.Sprite.GetGlobalBounds();
            FloatRect rect2 = ent.getGlobalBound();

            return(rect1.Intersects(rect2));
        }
Ejemplo n.º 5
0
        //Get a list of items that intersect a certain rectangle
        public List <int> GetItems(FloatRect colRect)
        {
            List <int> itemsFound = new List <int>();

            if (rect.Intersects(colRect))
            {
                // test the point in each item
                for (int i = 0; i < items.Count; i++)
                {
                    if (!Game.states[Game.currentState].netState.Entities.ContainsKey(items[i]))
                    {
                        RemoveItem(i);
                        continue;
                    }
                    if (Game.states[Game.currentState].netState.Entities[items[i]].rect.GetGlobalBounds().Intersects(colRect))
                    {
                        itemsFound.Add(items[i]);
                    }
                }

                // query all subtrees
                if (isPartitioned)
                {
                    itemsFound.AddRange(topLeftNode.GetItems(colRect));
                    itemsFound.AddRange(topRightNode.GetItems(colRect));
                    itemsFound.AddRange(bottomLeftNode.GetItems(colRect));
                    itemsFound.AddRange(bottomRightNode.GetItems(colRect));
                }
            }
            return(itemsFound);
        }
Ejemplo n.º 6
0
            public bool Intersects(Room other)
            {
                var currentRect = new FloatRect((Vector2f)Position - Size / 2f, Size);
                var otherRect   = new FloatRect((Vector2f)other.Position - other.Size / 2f, other.Size);

                return(currentRect.Intersects(otherRect));
            }
Ejemplo n.º 7
0
        public bool Colision(Jugador jugador)
        {
            FloatRect limitePelota  = _pelota.GetGlobalBounds();
            FloatRect limiteJugador = jugador.Rectangulo.GetGlobalBounds();

            return(limitePelota.Intersects(limiteJugador));
        }
Ejemplo n.º 8
0
        bool updateCollision(FloatRect rectNPC, FloatRect rectTile, DirectionType direction, ref Vector2f pos)
        {
            if (rectNPC.Intersects(rectTile))
            {
                if (direction == DirectionType.Up)
                {
                    pos = new Vector2f(pos.X, rectTile.Top + rectTile.Height - 1);
                }
                else if (direction == DirectionType.Down)
                {
                    pos = new Vector2f(pos.X, rectTile.Top - rectNPC.Height + 1);
                }
                else if (direction == DirectionType.Left)
                {
                    pos = new Vector2f(rectTile.Left + rectTile.Width - 1, pos.Y);
                }
                else if (direction == DirectionType.Right)
                {
                    pos = new Vector2f(rectTile.Left - rectNPC.Width + 1, pos.Y);
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 9
0
        static bool IsPlayerOverFood(FloatRect player, FloatRect food)
        {
            bool result = false;

            if (player.Intersects(food) == true)
            {
                result = true;
                Console.WriteLine("YUM-YUM!");
            }

            return(result);
        }
Ejemplo n.º 10
0
 private bool SiChocoConLava(ref int valor, FloatRect pjGB)
 {
     for (int i = 0; i < mapa.GetIndice(); i++)
     {
         if (pjGB.Intersects(mapa.GetRectangle(i).GetGlobalBounds()))
         {
             valor = i;
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 11
0
        static bool IsPlayerOverEnemy(FloatRect player, FloatRect enemy)
        {
            bool result = false;

            if (player.Intersects(enemy) == true)
            {
                result = true;
                Console.WriteLine("You Go Die-Die!!");
            }

            return(result);
        }
Ejemplo n.º 12
0
 public bool Collide(FloatRect player)
 {
     foreach (var item in _collide)
     {
         if (player.Intersects(item))
         {
             // Console.WriteLine("Collide");
             return(true);
         }
     }
     // Console.WriteLine("Non Collide");
     return(false);
 }
Ejemplo n.º 13
0
        public void DrawIn(RenderWindow window, ref FloatRect boundsView)
        {
            FloatRect entityHitBox;

            foreach (AEntity2D entity2D in this.entitiesToEntities2D.Values)
            {
                entityHitBox = entity2D.ObjectSprite.GetGlobalBounds();

                if (boundsView.Intersects(entityHitBox))
                {
                    entity2D.DrawIn(window, ref boundsView);
                }
            }
        }
Ejemplo n.º 14
0
        public T[] QueryRange(FloatCircle boundary)
        {
            var rect = new FloatRect(
                boundary.X - boundary.Radius,
                boundary.Y - boundary.Radius,
                boundary.Radius,
                boundary.Radius
                );

            if (!_boundary.Intersects(rect))
            {
                return(Array.Empty <T>());
            }

            var inRange = new List <T>();

            _data.ForEach(datum =>
            {
                if (boundary.Contains(datum.Point.X, datum.Point.Y))
                {
                    inRange.Add(datum.Data);
                }
            });

            if (_northWest == null)
            {
                return(inRange.ToArray());
            }

            inRange.AddRange(_northEast.QueryRange(boundary));
            inRange.AddRange(_northWest.QueryRange(boundary));
            inRange.AddRange(_southEast.QueryRange(boundary));
            inRange.AddRange(_southWest.QueryRange(boundary));

            return(inRange.ToArray());
        }
Ejemplo n.º 15
0
        bool IsColliding(float deltaTime, FloatRect other)
        {
            // Naively check collisions; we don't need anything fancy (I hope)
            Vector2f oldPosition = collider.Position;

            collider.Position = new Vector2f(collider.Position.X, collider.Position.Y + YVelocity * deltaTime);
            FloatRect bounds = collider.GetGlobalBounds();

            if (bounds.Intersects(other))
            {
                collider.Position = oldPosition;
                return(true);
            }

            collider.Position = oldPosition;
            return(false);
        }
Ejemplo n.º 16
0
        private void NoCaerALaLava(float deltaTiempo)
        {
            FloatRect pjGB  = personaje.GetSprite().GetGlobalBounds();
            int       valor = 0;

            //Si choco
            if (!SiChocoConLava(ref valor, pjGB))
            {
                return;
            }
            FloatRect rect = mapa.GetRectangle(valor).GetGlobalBounds();

            if (pjGB.Intersects(rect))
            {
                DondeChocaPj(personaje.ESTADO_AHORA_PJ, deltaTiempo);
            }
        }
Ejemplo n.º 17
0
        private void CheckPadCollision()
        {
            bool padCollisioned = false;

            if (Speed > 0.0f)
            {
                FloatRect myBounds = GetGlobalBounds();

                var pad = Engine.Get.Scene.GetFirst <Pad>();
                if (pad != null)
                {
                    if (myBounds.Intersects(pad.GetGlobalBounds()))
                    {
                        padCollisioned = true;
                        float x    = myBounds.Left + myBounds.Width / 2.0f;
                        float padX = pad.Position.X;

                        float d = (x - padX) / pad.GetLocalBounds().Width;
                        Forward  = (new Vector2f(0.0f, -1.0f)).Rotate(90.0f * d);
                        Position = new Vector2f(Position.X, pad.GetGlobalBounds().Top - pad.GetLocalBounds().Height / 2.0f);
                    }
                }
            }

            // SONIDOS DE LA PELOTA CON LAS PAREDES
            if (padCollisioned == true)
            {
                Random alea = new Random();
                switch (alea.Next(1, 4))
                {
                case 1:
                    ballSFX = new Sound(sfBall_01);
                    break;

                case 2:
                    ballSFX = new Sound(sfBall_02);
                    break;

                case 3:
                    ballSFX = new Sound(sfBall_03);
                    break;
                }
                ballSFX.Play();
            }
        }
Ejemplo n.º 18
0
        bool updateCollision(FloatRect rectNPC, FloatRect rectTile, DirectionType direction, ref Vector2f pos)
        {
            if (rectNPC.Intersects(rectTile))
            {
                switch (direction)
                {
                case DirectionType.Up: pos = new Vector2f(pos.X, rectTile.Top + rectTile.Height - 1); break;

                case DirectionType.Down: pos = new Vector2f(pos.X, rectTile.Top - rectNPC.Height + 1); break;

                case DirectionType.Left: pos = new Vector2f(rectTile.Left + rectTile.Width - 1, pos.Y); break;

                case DirectionType.Right: pos = new Vector2f(rectTile.Left - rectNPC.Width + 1, pos.Y); break;
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 19
0
        private void TeclasAtaque(EstadosPj estadosPj, float deltaTiempo)
        {
            if (!Keyboard.IsKeyPressed(Keyboard.Key.R))
            {
                enemigo.GetSprite().Color = colorEnem;
            }
            else
            {
                FloatRect per        = personaje.GetSprite().GetGlobalBounds();
                FloatRect enem       = enemigo.GetSprite().GetGlobalBounds();
                EstadosPj estadoPj   = personaje.ESTADO_AHORA_PJ;
                EstadosPj estadoEnem = enemigo.ESTADO_AHORA_PJ;
                if (per.Intersects(enem))
                {
                    textoDamage.setIsActivo(true);
                    switch (estadoPj)
                    {
                    case EstadosPj.MoverArriba:
                        personaje.ESTADO_AHORA_PJ = EstadosPj.AtacarArriba;
                        break;

                    case EstadosPj.MoverIzquierda:
                        personaje.ESTADO_AHORA_PJ = EstadosPj.AtacarIzquierda;
                        break;

                    case EstadosPj.MoverAbajo:
                        personaje.ESTADO_AHORA_PJ = EstadosPj.AtacarAbajo;
                        break;

                    case EstadosPj.MoverDerecha:
                        personaje.ESTADO_AHORA_PJ = EstadosPj.AtacarDerecha;
                        break;
                    }
                    personaje.Actualizar(deltaTiempo);
                }
                enemigo.GetSprite().Color = Color.Red;
                enemigo.RecibeDano(personaje.DANIO);
                //Rematar(enemigo, EstaMuerto(enemigo));
            }
        }
Ejemplo n.º 20
0
        public void DrawIn(RenderWindow window, ref FloatRect boundsView)
        {
            //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

            //sw.Start();

            foreach (LandChunk2D landChunk2D in this.landChunksDictionary.Values)
            {
                FloatRect bounds = new FloatRect(landChunk2D.Position, new SFML.System.Vector2f(landChunk2D.Width, landChunk2D.Height));

                if (bounds.Intersects(boundsView))
                {
                    landChunk2D.DrawIn(window, ref boundsView);
                }
            }

            this.entity2DManager.DrawIn(window, ref boundsView);

            //sw.Stop();

            //Console.WriteLine("time consume = " + sw.Elapsed);
        }
Ejemplo n.º 21
0
        public bool PlaceFree(FloatRect r, CollisionCondition cond = null)
        {
            var tileSize = GameOptions.TileSize;

            var minX     = Math.Max(0, ((int)r.Left / tileSize) - 1);
            var minY     = Math.Max(0, ((int)r.Top / tileSize) - 1);
            var maxX     = Math.Min(Width, minX + ((int)r.Width / tileSize) + 3);
            var maxY     = Math.Min(Height, minY + ((int)r.Height / tileSize) + 3);
            var testRect = new FloatRect(0, 0, tileSize, tileSize);

            for (var yy = minY; yy < maxY; yy++)
            {
                for (var xx = minX; xx < maxX; xx++)
                {
                    if (!tiles[xx, yy].Solid)
                    {
                        continue;
                    }

                    testRect.Left = xx * tileSize;
                    testRect.Top  = yy * tileSize;

                    if (!r.Intersects(testRect))
                    {
                        continue;
                    }
                    if (cond == null)
                    {
                        return(false);
                    }
                    if (cond(tiles[xx, yy], testRect, r))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 22
0
        public override void DrawIn(RenderWindow window, ref FloatRect boundsView)
        {
            LandCase2D[,] layer2D = this.landObjects2DLayers.FirstOrDefault();

            if (layer2D == null)
            {
                return;
            }

            for (int i = 0; i < layer2D.GetLength(0); i++)
            {
                for (int j = 0; j < layer2D.GetLength(1); j++)
                {
                    FloatRect bounds = new FloatRect(this.Position.X + j * MainWindow.MODEL_TO_VIEW, this.Position.Y + i * MainWindow.MODEL_TO_VIEW, MainWindow.MODEL_TO_VIEW, MainWindow.MODEL_TO_VIEW);

                    /*if (bounds.Left < boundsView.Left + boundsView.Width
                     *  && bounds.Left + bounds.Width > boundsView.Left
                     *  && bounds.Top < boundsView.Top + boundsView.Height
                     *  && bounds.Top + bounds.Height > boundsView.Top)
                     * {*/
                    if (bounds.Intersects(boundsView))
                    {
                        bool firstCaseDrawn = false;

                        foreach (LandCase2D[,] landObject2DsArray in this.landObjects2DLayers)
                        {
                            LandCase2D landObjectsList = landObject2DsArray[i, j];

                            if (landObjectsList != null)
                            {
                                landObjectsList.DrawIn(window, ref boundsView);

                                firstCaseDrawn = landObjectsList.IsValid;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 23
0
        private bool ChequeoColision(float deltaTiempo)
        {
            FloatRect per        = personaje.GetSprite().GetGlobalBounds();
            FloatRect enem       = enemigo.GetSprite().GetGlobalBounds();
            EstadosPj estadoPj   = personaje.ESTADO_AHORA_PJ;
            EstadosPj estadoEnem = enemigo.ESTADO_AHORA_PJ;

            if (per.Intersects(enem))
            {
                Clock tiempoCombate = new Clock();
                enemigo.CONTACTO = true;
                isActivo         = true;
                seChocan         = true;
                DondeChocaPj(estadoPj, deltaTiempo);
                DondeChocaEnem(estadoEnem, deltaTiempo);
                TeclasAtaque(estadoPj, deltaTiempo);
            }
            else
            {
                seChocan = false;
            }
            return(seChocan);
        }
Ejemplo n.º 24
0
        private bool CheckTile(TilePositionType tilePositionType)
        {
            var playerCoordinates = GetPlayerCoordinates();
            var tileCoordinates   = GetTileCoordinates(playerCoordinates, tilePositionType);
            var tile = gameBoard.GetTile(tileCoordinates);

            if (tile == null)
            {
                return(false);
            }

            if (tile.Type == TileType.DESTROYED_BLOCK || tile.Type == TileType.INDESTRUCTIBLE_BLOCK)
            {
                var floatPlayerRect = new FloatRect(Position.X, Position.Y, Tile.TileSize, Tile.TileSize);
                var floatTileRect   = new FloatRect(tileCoordinates.X * Tile.TileSize, tileCoordinates.Y * Tile.TileSize, Tile.TileSize, Tile.TileSize);

                if (!floatPlayerRect.Intersects(floatTileRect))
                {
                    return(true);
                }
                return(false);
            }
            return(true);
        }
Ejemplo n.º 25
0
        public void Draw(RenderTarget rt, int layerMask)
        {
            View      view       = rt.GetView();
            Vector2f  viewOrigin = view.Center - view.Size / 2f;
            Vector2f  viewSize   = view.Size;
            FloatRect viewRect   = new FloatRect(viewOrigin.X, viewOrigin.Y, viewSize.X, viewSize.Y);

            screenShadowMap.SetView(view);

            int count = 0;

            _lightSprite.Texture = lightAtlas.Texture;

            // Draw self-illuminated elements
            world.graphics.Render(screenShadowMap, RenderMode.LIGHT_MAP, layerMask);

            // Draw lights
            foreach (Light light in lights)
            {
                FloatRect rect = light.bounds;

                if (viewRect.Intersects(rect))
                {
                    if (light.needUpdate)
                    {
                        light.UpdateLight();
                        light.needUpdate = false;
                        lightAtlas.Display();
                    }

                    if (!Mathf.IsZero(light.intensity))
                    {
                        int framesX = ATLAS_SIZE / ATLAS_FRAME_SIZE;
                        //int framesY = ATLAS_SIZE / ATLAS_FRAME_SIZE;

                        _lightSprite.Origin      = new Vector2f(ATLAS_FRAME_SIZE / 2, ATLAS_FRAME_SIZE / 2);
                        _lightSprite.Position    = light.worldPosition;
                        _lightSprite.TextureRect = new IntRect(
                            ATLAS_FRAME_SIZE * (light.atlasIndex % framesX),
                            ATLAS_FRAME_SIZE * (light.atlasIndex / framesX),
                            ATLAS_FRAME_SIZE,
                            ATLAS_FRAME_SIZE
                            );
                        _lightSprite.Scale = new Vector2f(
                            2f * light.radius / (float)ATLAS_FRAME_SIZE,
                            2f * light.radius / (float)ATLAS_FRAME_SIZE
                            );
                        byte c = (byte)(light.intensity * 255f);
                        _lightSprite.Color = new Color(c, c, c, 255);

                        screenShadowMap.Draw(_lightSprite, new RenderStates(BlendMode.Add));

                        ++count;
                    }
                }
            }

            // Update lightmap rt
            screenShadowMap.Display();

            // Blends the light map on the base render
            _screenShadowSprite.Position = viewOrigin;
            _screenShadowSprite.Texture  = screenShadowMap.Texture;

            DebugOverlay.instance.Line("Render lights", count);
            DebugOverlay.instance.Line("Screen size", screenShadowMap.Size.X + "x" + screenShadowMap.Size.Y);

            _screenShadowSprite.Color = Color.White;
            rt.Draw(_screenShadowSprite, new RenderStates(BlendMode.Multiply));
            if (jamFlash)
            {
                rt.Draw(_screenShadowSprite, new RenderStates(BlendMode.Add));
            }
            //_screenLightSprite.Color = new Color(32,32,32);
            //rt.Draw(_screenLightSprite, new RenderStates(BlendMode.Add));

            screenShadowMap.Clear(Color.White);
        }
Ejemplo n.º 26
0
 private bool CheckCollisionMove(FloatRect targetBounds, FloatRect collisionBounds)
 {
     return collisionBounds.Intersects(targetBounds);
 }
Ejemplo n.º 27
0
        private bool characterPaneTestPoint(Vector2f point, int slot)
        {
            FloatRect pointRect = new FloatRect(point.X, point.Y, 1f, 1f);
            FloatRect highlightRect = _characterButtonHighlights[slot].GetGlobalBounds();
            FloatRect slotRect = new FloatRect(highlightRect.Left + 8f, highlightRect.Top + 8f, highlightRect.Width - 16f, highlightRect.Height - 16f);

            return pointRect.Intersects(slotRect);
        }
Ejemplo n.º 28
0
        static void Main(string[] args)
        {
            //работо с окном и консолью

            window             = new RenderWindow(new VideoMode(1280, 640), "Real Time Code");
            window.Closed     += CloseWindow;
            window.KeyPressed += KeyPressed;

            window.Position = new Vector2i(0, 0);

            //загрузка рожи
            faceTexture         = new Texture("face.png");
            faceSprite          = new Sprite(faceTexture);
            faceSprite.Position = new Vector2f(320, 0);

            //загрузка врага
            enemyTexture = new Texture("enemy.png");

            //загрузка  пламени
            flameTexture = new Texture("ass_flame.png");
            flameSprite  = new Sprite(flameTexture);

            //загрузка волны
            waveTexture = new Texture("ass_wave.png");
            waveSprite  = new Sprite(waveTexture);


            for (int i = 0; i < numberWave * countEnemies; i++)
            {
                enemySprites.Add(new Sprite(enemyTexture));

                enemySprites[i].Position =
                    new Vector2f(rnd.Next(320, 960 - 32),
                                 rnd.Next(320, 640 - 32));
            }

            //работа с шришфотом и подложкой
            Font font = new Font("arial.ttf");
            Text textRight;
            Text textLeft;

            RectangleShape consoleRight = new RectangleShape(new Vector2f(320, 640));

            consoleRight.FillColor = new Color(76, 145, 89);
            consoleRight.Position  = new Vector2f(960, 0);


            RectangleShape consoleLeft = new RectangleShape(new Vector2f(320, 640));

            consoleLeft.FillColor = new Color(234, 67, 56);
            consoleLeft.Position  = new Vector2f(0, 0);


            //игровой цикл
            while (window.IsOpen)
            {
                window.DispatchEvents();

                if (playGame == true)
                {
                    deltaTime = clk.Restart().AsSeconds();

                    //отрисовка кода
                    textRight          = new Text(inputKeybordRight, font, 24);
                    textRight.Position = new Vector2f(960, 0);
                    textRight.Color    = Color.Yellow;

                    textLeft          = new Text(inputKeybordLeft, font, 24);
                    textLeft.Position = new Vector2f(0, 0);
                    textLeft.Color    = Color.Yellow;

                    if (rightPlayer == true)
                    {
                        consoleRight.OutlineThickness = -3;
                        consoleRight.OutlineColor     = Color.Yellow;

                        consoleLeft.OutlineThickness = 0;
                    }
                    else
                    {
                        consoleLeft.OutlineThickness = -3;
                        consoleLeft.OutlineColor     = Color.Yellow;

                        consoleRight.OutlineThickness = 0;
                    }

                    EnemyMove();
                    PlayerMove();

                    if (countKills > 99)
                    {
                        window.Clear(new Color((byte)rnd.Next(0, 255), (byte)rnd.Next(0, 255), (byte)rnd.Next(0, 255), 255));
                    }

                    window.Clear();
                    for (int i = 0; i < enemySprites.Count; i++)
                    {
                        window.Draw(enemySprites[i]);
                    }

                    if (assFlameShoot == true)
                    {
                        FloatRect flameRect = new FloatRect();

                        switch (playerDirection)
                        {
                        case MoveDirections.left:
                            flameSprite.Rotation = 0f;
                            flameSprite.Position = new Vector2f(faceSprite.Position.X + 32, faceSprite.Position.Y);

                            flameRect = new FloatRect(faceSprite.Position.X + 32, faceSprite.Position.Y, 280, 32);

                            break;

                        case MoveDirections.right:
                            flameSprite.Rotation = 180f;
                            flameSprite.Position = new Vector2f(faceSprite.Position.X, faceSprite.Position.Y + 32);

                            flameRect = new FloatRect(faceSprite.Position.X, faceSprite.Position.Y, -280, 32);

                            break;

                        case MoveDirections.down:
                            flameSprite.Rotation = 270f;
                            flameSprite.Position = new Vector2f(faceSprite.Position.X, faceSprite.Position.Y);

                            flameRect = new FloatRect(faceSprite.Position.X, faceSprite.Position.Y, 32, -280);

                            break;

                        case MoveDirections.up:
                            flameSprite.Rotation = 90f;
                            flameSprite.Position = new Vector2f(faceSprite.Position.X + 32, faceSprite.Position.Y + 32);

                            flameRect = new FloatRect(faceSprite.Position.X, faceSprite.Position.Y + 32, 32, 280);
                            break;
                        }

                        shootDelay -= deltaTime;
                        if (shootDelay <= 0)
                        {
                            assFlameShoot = false;
                        }

                        window.Draw(flameSprite);

                        for (int i = 0; i < enemySprites.Count; i++)
                        {
                            FloatRect currentEnemy = new FloatRect(enemySprites[i].Position.X, enemySprites[i].Position.Y, 32, 32);

                            if (flameRect.Intersects(currentEnemy) == true)
                            {
                                enemySprites.RemoveAt(i);
                                i = -1;

                                countKills++;
                            }
                        }
                    }

                    if (waveShoot == true)
                    {
                        waveDelay -= deltaTime;
                        if (waveDelay <= 0)
                        {
                            waveShoot = false;
                        }


                        waveSprite.Position =
                            new Vector2f(
                                faceSprite.Position.X - (200 - 32) / 2, faceSprite.Position.Y - (200 - 32) / 2);

                        window.Draw(waveSprite);

                        float xcFace = faceSprite.Position.X + 16;
                        float ycFace = faceSprite.Position.Y + 16;

                        for (int i = 0; i < enemySprites.Count; i++)
                        {
                            float xcEnemy = enemySprites[i].Position.X + 16;
                            float ycEnemy = enemySprites[i].Position.Y + 16;

                            float distance = (float)Math.Sqrt
                                             (
                                (xcEnemy - xcFace) * (xcEnemy - xcFace) + (ycEnemy - ycFace) * (ycEnemy - ycFace)
                                             );

                            if (distance <= 116)
                            {
                                enemySprites.RemoveAt(i);
                                i = -1;

                                countKills++;
                            }
                        }
                    }

                    if (enemySprites.Count == 0)
                    {
                        numberWave++;

                        for (int i = 0; i < numberWave * countEnemies; i++)
                        {
                            enemySprites.Add(new Sprite(enemyTexture));

                            enemySprites[i].Position =
                                new Vector2f(rnd.Next(320, 960 - 32),
                                             rnd.Next(320, 640 - 32));
                        }
                    }

                    FloatRect faceRect = new FloatRect(faceSprite.Position.X, faceSprite.Position.Y, 32, 32);

                    for (int i = 0; i < enemySprites.Count; i++)
                    {
                        FloatRect currentEnemyRect = new FloatRect(enemySprites[i].Position.X, enemySprites[i].Position.Y, 32, 32);

                        if (faceRect.Intersects(currentEnemyRect))
                        {
                            playGame = false;
                        }
                    }

                    window.Draw(faceSprite);

                    window.Draw(consoleRight);
                    window.Draw(consoleLeft);

                    window.Draw(textRight);
                    window.Draw(textLeft);

                    window.Display();
                }
                else
                {
                    string infoGameOver = String.Format("You killed {0} enemies\n and survived {1} waves", countKills, numberWave);
                    Text   textGameOver = new Text(infoGameOver, font, 24);

                    textGameOver.Position = new Vector2f(500, 320);
                    textGameOver.Color    = Color.Red;

                    window.Draw(textGameOver);
                    window.Display();
                }
            }
        }
Ejemplo n.º 29
0
        public bool testPoint(Vector2f point)
        {
            FloatRect pointRect = new FloatRect(point.X, point.Y, 1, 1);

            if (pointRect.Intersects(_buttonShape.GetGlobalBounds()))
            {
                return true;
            }

            if (pointRect.Intersects(_firstLetter.GetGlobalBounds()))
            {
                return true;
            }

            if (pointRect.Intersects(_word.GetGlobalBounds()))
            {
                return true;
            }

            return false;
        }
Ejemplo n.º 30
0
 public static bool RectPointCollision(FloatRect rect, Vector2f pt)
 {
     return rect.Intersects(new FloatRect(pt.X, pt.Y, 1.0f, 1.0f));
 }
Ejemplo n.º 31
0
 public static bool RectRectCollision(FloatRect r1, FloatRect r2)
 {
     return r1.Intersects(r2);
 }
Ejemplo n.º 32
0
        public bool ColidiuCom(GameObject outro)
        {
            FloatRect minhaCaixa = new FloatRect(position + offset, tamanho), outraCaixa = new FloatRect(outro.position + outro.offset, outro.tamanho);

            return(minhaCaixa.Intersects(outraCaixa));
        }
Ejemplo n.º 33
0
        private void UpdatePhysicsWall(FloatRect playerRect, int pX, int pY)
        {
            List <Tile> walls = new List <Tile>
            {
                // Left
                world.GetTile(pX - 1, pY),
                world.GetTile(pX - 1, pY - 1),
                world.GetTile(pX - 1, pY + 1),
                // Right
                world.GetTile(pX + 1, pY),
                world.GetTile(pX + 1, pY - 1),
                world.GetTile(pX + 1, pY + 1),
                // Top
                world.GetTile(pX, pY - 1),
                world.GetTile(pX - 1, pY - 1),
                world.GetTile(pX + 1, pY - 1),
                // Down
                world.GetTile(pX, pY),
                world.GetTile(pX - 1, pY),
                world.GetTile(pX + 1, pY),
            };

            //for (int i = 0; i < AwesomeGame.PlayerTiles.Count; i++)
            //{
            //    walls.Add(AwesomeGame.PlayerTiles[i]);
            //    AwesomeGame.PlayerTiles[i].Position = AwesomeGame.Players[i].Position;
            //}

            foreach (var tile in walls)
            {
                if (tile == null || tile.type == TileType.GROUND)
                {
                    continue;
                }

                FloatRect tileRect = new FloatRect(tile.Position, new Vector2f(Tile.TILE_SIZE, Tile.TILE_SIZE));
                DebugRender.AddRectangle(tileRect, Color.Yellow);

                if (playerRect.Intersects(tileRect))
                {
                    Vector2f offset = new Vector2f(playerRect.Left - tileRect.Left, playerRect.Top - tileRect.Top);
                    offset.X /= Math.Abs(offset.X);
                    offset.Y /= Math.Abs(offset.Y);

                    float speed = Math.Abs(movement.X);

                    // Left walls
                    if (offset.X > 0)
                    {
                        // Sends the player one tile away
                        Position   = new Vector2f(tileRect.Left + tileRect.Width + playerRect.Width * 0.5f, Position.Y);
                        movement.X = 0;
                        velocity.X = 0;
                    }
                    // Right walls
                    else if (offset.X < 0)
                    {
                        Position   = new Vector2f(tileRect.Left - playerRect.Width * 0.5f, Position.Y);
                        movement.X = 0;
                        velocity.X = 0;
                        //Position = new Vector2f(Position.X - 2, Position.Y);
                    }
                    // Top walls
                    else if (offset.Y > 0)
                    {
                        Position   = new Vector2f(Position.X, tileRect.Top + tileRect.Height + playerRect.Height * 0.5f);
                        movement.Y = 0;
                        velocity.Y = 0;
                        //Position = new Vector2f(Position.X, Position.Y + 2);
                    }
                    // Down walls
                    else if (offset.Y < 0)
                    {
                        Position   = new Vector2f(Position.X, tileRect.Top - playerRect.Height * 0.5f);
                        movement.Y = 0;
                        velocity.Y = 0;
                        //Position = new Vector2f(Position.X, Position.Y - 2);
                    }

                    OnWallCollided();
                }
            }
        }
Ejemplo n.º 34
0
        public bool PlaceFree(FloatRect r, CollisionCondition cond = null)
        {
            var tileSize = GameOptions.TileSize;

            var minX = Math.Max(0, ((int)r.Left / tileSize) - 1);
            var minY = Math.Max(0, ((int)r.Top / tileSize) - 1);
            var maxX = Math.Min(Width, minX + ((int)r.Width / tileSize) + 3);
            var maxY = Math.Min(Height, minY + ((int)r.Height / tileSize) + 3);
            var testRect = new FloatRect(0, 0, tileSize, tileSize);

            for (var yy = minY; yy < maxY; yy++)
            {
                for (var xx = minX; xx < maxX; xx++)
                {
                    if (!tiles[xx, yy].Solid)
                        continue;

                    testRect.Left = xx * tileSize;
                    testRect.Top = yy * tileSize;

                    if (!r.Intersects(testRect))
                        continue;
                    if (cond == null)
                        return false;
                    if (cond(tiles[xx, yy], testRect, r))
                        return false;
                }
            }

            return true;
        }
Ejemplo n.º 35
0
 public static bool RectRectCollision(FloatRect r1, FloatRect r2)
 {
     return(r1.Intersects(r2));
 }
Ejemplo n.º 36
0
 public static bool RectPointCollision(FloatRect rect, Vector2f pt)
 {
     return(rect.Intersects(new FloatRect(pt.X, pt.Y, 1.0f, 1.0f)));
 }