Ejemplo n.º 1
0
        public void render(Camera camera, SpriteBatch spriteBatch, int layer)
        {
            for (int i = 0; i < 3; i++)
            {
                Tile.layerColors[i] = Runner.player.getLayer() == i
                    ? Tile.baseLayerColors[i]
                    : Color.Lerp(Tile.baseLayerColors[i], Color.Black, 0.5F);
            }

            Player      player = Runner.player;
            const float min    = 0.5F;

            Tile.layerColors[1] = new Color(Tile.layerColors[1], min + (1 - min) * (1 - player.midPercentOcluded));
            Tile.layerColors[2] = new Color(Tile.layerColors[2], min + (1 - min) * (1 - player.frontPercentOcluded));

            Vector2 diff = camera.screenCenter / (camera.scale * camera.farMult(layer - 2));
            Point   from = chunkIndices(camera.pos - diff);
            Point   to   = chunkIndices(camera.pos + diff);

            for (int i = from.X; i <= to.X; i++)
            {
                for (int j = from.Y; j <= to.Y; j++)
                {
                    getChunk(new Point(i, j)).render(camera, spriteBatch, layer);
                }
            }
        }
Ejemplo n.º 2
0
        public static void render(Texture2D texture, Vector2 pos, Vector2 dimen, float zPos, float rotation, Camera camera, SpriteBatch spriteBatch, Color tint, Rectangle rect)
        {
            Vector2 textureSize = textureVec(texture);
            Vector2 scale       = dimen * camera.scale * camera.farMult(zPos) / textureSize;

            spriteBatch.Draw(texture, camera.toScreen(pos, zPos), rect, tint, rotation, new Vector2(rect.Width, rect.Height) / 2F, scale, SpriteEffects.None, 0);
        }
Ejemplo n.º 3
0
        public static void render(Texture2D texture, Vector2 pos, Vector2 dimen, float zPos, float rotation, Camera camera, SpriteBatch spriteBatch, Color tint)
        {
            Vector2 textureSize = textureVec(texture);
            Vector2 scale       = dimen * camera.scale * camera.farMult(zPos) / textureSize;

            spriteBatch.Draw(texture, camera.toScreen(pos, zPos), null, tint, rotation, textureSize / 2F, scale, SpriteEffects.None, 0);
        }
Ejemplo n.º 4
0
        public Rectangle drawLocation(Camera camera)
        {
            float mult = camera.farMult(zPos);

            Vector2 drawDimen = dimen * camera.scale * mult;
            Vector2 drawPos   = camera.screenCenter + (pos - camera.pos) * camera.scale * mult;

            return(Util.center(drawPos, drawDimen)); // hello josh
        }
Ejemplo n.º 5
0
        public void render(Camera camera, SpriteBatch spriteBatch)   // TODO: make more efficient
        {
            if (tileType == type.Air || tileType == type.NextStage)
            {
                return;
            }

            float   mult     = camera.farMult(zPos());
            int     drawSize = (int)Math.Round(camera.scale * mult);
            Vector2 drawPos  = camera.screenCenter + (pos - camera.pos) * camera.scale * mult;

            Rectangle rect = new Rectangle((int)Math.Round(drawPos.X), (int)Math.Round(drawPos.Y), drawSize, drawSize);

            spriteBatch.Draw(texture, rect, atlasRect, layerColors[layer]);
        }
Ejemplo n.º 6
0
        public void update(float deltaTime)
        {
            for (int layer = 0; layer < 3; layer++)
            {
                Camera  camera = Runner.camera;
                Vector2 diff   = camera.screenCenter / (camera.scale * camera.farMult(layer - 2));
                Point   from   = chunkIndices(camera.pos - diff);
                Point   to     = chunkIndices(camera.pos + diff);

                for (int i = from.X; i <= to.X; i++)
                {
                    for (int j = from.Y; j <= to.Y; j++)
                    {
                        getChunk(new Point(i, j)).update(deltaTime);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void removeBlock(Vector2 position, Vector2 vel, int layer)
        {
            Point blockInd = ChunkMap.blockIndices(position);

            var(blockX, blockY) = blockInd;

            Point block = new Point(Util.intMod(blockInd.X, Chunk.chunkSize),
                                    Util.intMod(blockInd.Y, Chunk.chunkSize));

            var(x, y) = block;

            if (blockX < 0 || blockX >= mapWidth() || blockY < 0 || blockY >= mapHeight())
            {
                return;
            }

            if (chunks.Keys.Contains(chunkIndices(position)))
            {
                Tile[,,] tiles = getChunk(position).tiles;

                Tile tile = tiles[x, y, layer];
                if (tile.tileType == Tile.type.Air)
                {
                    return;
                }

                Vector2 pos    = tiles[x, y, 0].pos;
                Camera  camera = Runner.camera;
                Vector2 diff   = camera.screenCenter / (camera.scale * camera.farMult(layer - 2));

                if (Util.between(pos, camera.pos - diff, camera.pos + diff))   // checks if on-screen before creating particle
                {
                    Runner.particles[layer].Add(new BlockParticle(tile, vel));
                }

                tiles[x, y, layer] = new Tile(Tile.type.Air, pos, layer);
            }

            int ID = (int)Tile.type.Air;

            Chunk.mapData[layer][blockX, blockY] = ID;
        }
Ejemplo n.º 8
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            float deltaTime = delta(gameTime);

            fpsCounter.update(deltaTime);
            if ((int)gameTime.TotalGameTime.TotalSeconds > secondsPassed)
            {
                secondsPassed = (int)gameTime.TotalGameTime.TotalSeconds;
                Window.Title  = "FPS: " + (int)fpsCounter.AverageFramesPerSecond;
            }

            KeyboardState keyState   = Keyboard.GetState();
            MouseState    mouseState = Mouse.GetState();

            KeyInfo   keys  = new KeyInfo(keyState, lastKeyState);
            MouseInfo mouse = new MouseInfo(mouseState, lastMouseState);

            lastKeyState   = keyState;
            lastMouseState = mouseState;

            if (keys.down(Keys.Escape))
            {
                exitGame();
            }


            if (uiScreen != null)
            {
                uiScreen.update(mouse, keys, deltaTime);
                return;
            }



            if (keys.pressed(Keys.L))
            {
                startEditMode();
            }

            if (keys.pressed(Keys.S) && keys.down(Keys.LeftControl))
            {
                wiringEditor?.saveWiring(levelName);
            }

            if (keys.pressed(Keys.T))
            {
                wiringEditor?.applyWiring();
            }

            if (keys.pressed(Keys.G))
            {
                player.godMode = !player.godMode;
            }

            if (keys.pressed(Keys.R))
            {
                restartRun();
            }


            // debug change level
            if (keys.pressed(Keys.Left))
            {
                lastLevel();
            }
            if (keys.pressed(Keys.Right))
            {
                nextLevel();
            }


            // UI
            for (int i = uiTransitions.Count - 1; i >= 0; i--)
            {
                UITransition transition = uiTransitions[i];

                if (transition.deleteFlag)
                {
                    uiTransitions.RemoveAt(i);
                    continue;
                }

                transition.update(deltaTime);
            }

            foreach (var element in uiElements)
            {
                element.update(mouse, keys, deltaTime);
            }

            if (keys.pressed(Keys.P))
            {
                if (!paused)
                {
                    paused     = true;
                    pauseTimer = 0;
                    uiElements = pauseUI;
                    UI.transitionAll(uiElements, element => new SlideIn(element)
                    {
                        endTime = pauseTransitionTime
                    });
                }
                else
                {
                    unPauseClicked();
                }
            }

            if (paused && endingPause && uiTransitions.Count == 0)
            {
                paused      = false;
                endingPause = false;
                uiElements  = gameUI;
            }

            if (paused)
            {
                if (endingPause)
                {
                    pauseTimer -= deltaTime;
                }
                else
                {
                    pauseTimer += deltaTime;
                }
            }

            pauseTimer = Math.Min(pauseTimer, pauseTransitionTime);


            // Must Be Un-paused to Run Following Code =======
            if (paused)
            {
                return;
            }

            if (!player.dead)
            {
                attemptTime += deltaTime;
            }

            adjustMusicFade();

            if (mouse.leftPressed && keys.down(Keys.LeftShift))
            {
                player.pos = camera.toWorld(mouse.pos, player.zPos);
            }

            player.input(keys, deltaTime);

            if (editMode)
            {
                wiringEditor?.input(mouse, keys, deltaTime);
            }

            updateEntities(deltaTime);

            updateParticles(deltaTime);

            map.update(deltaTime);

            camera.pos = player.pos - Vector2.UnitY * 5;
            // screen shake
            if (screenShakeTime > 0)
            {
                screenShakeTime -= deltaTime;
                camera.pos      += Util.polar(screenShakeIntensity * screenShakeTime / screenShakeStart, Util.randomAngle());
            }

            Vector2 diff = camera.screenCenter / (camera.scale * camera.farMult(-2));
            float   clampCameraBottom = ChunkMap.mapHeight() - 1 - diff.Y;
            float   clampCameraTop    = 1 + diff.Y;

            camera.pos.Y = Math.Clamp(camera.pos.Y, clampCameraTop, clampCameraBottom);

            for (int i = 0; i < entities.Length; i++)
            {
                entities[i] = new List <Entity>();
            }

            foreach (var entity in updatedEntities)
            {
                sortIntoEntities(entity);
            }
        }