Beispiel #1
0
        public override void bonkY(Vector2 newPos)
        {
            bonk(newPos);

            if (vel.Y > 0)
            {
                Point from = ChunkMap.blockIndices(pos + new Vector2(-0.5F, 0.5F) * dimen);
                Point to   = ChunkMap.blockIndices(pos + new Vector2(0.5F, 0.5F) * dimen);

                bool allRubber = true;

                for (int i = from.X; i <= to.X; i++)
                {
                    for (int j = from.Y; j <= to.Y; j++)
                    {
                        Tile tile = Runner.map.getTile(new Point(i, j), getLayer(zPos));

                        if (tile.tileType != Tile.type.Rubber)
                        {
                            allRubber = false;
                            goto loopEnd;
                        }
                    }
                }
loopEnd:
                if (allRubber)
                {
                    vel.Y *= -0.9F;
                    return;
                }
            }

            vel.Y = 0;
        }
Beispiel #2
0
        public override void update(float deltaTime)
        {
            base.update(deltaTime);
            Player player = Runner.player;

            crushTimer += deltaTime * 2;

            float extend = dimen.Y / 2 - crusherDimen.Y / 2;
            float amount = crushAmount();

            topCrush    = new Vector2(pos.X, extend * amount);
            bottomCrush = new Vector2(pos.X, ChunkMap.mapHeight() - extend * amount);

            if (collidesWith(player, topCrush, crusherDimen))   // collides with top crusher
            {
                Runner.player.vel = Vector2.UnitY * 20;
                Runner.player.die();
            }
            else if (collidesWith(player, bottomCrush, crusherDimen))   // collides with top crusher
            {
                Runner.player.vel = -Vector2.UnitY * 20;
                Runner.player.die();
            }
            else if (collidesWith(player) && !collidesWith(player, pos, new Vector2(dimen.X, bottomCrush.Y - topCrush.Y)))   // collides with arm
            {
                Runner.player.vel = Vector2.UnitX * 20 * Math.Sign(player.pos.X - pos.X);
                Runner.player.die();
            }

            Point from = ChunkMap.blockIndices(topCrush - crusherDimen / 2);
            Point to   = ChunkMap.blockIndices(topCrush + crusherDimen / 2);

            int layer = getLayer();

            for (int x = from.X; x <= to.X; x++)
            {
                for (int y = from.Y; y <= to.Y; y++)
                {
                    Vector2 blockPos = new Vector2(x, y);
                    Runner.map.removeBlock(blockPos, new Vector2(10, 10), layer);
                }
            }
            from = ChunkMap.blockIndices(bottomCrush - crusherDimen / 2);
            to   = ChunkMap.blockIndices(bottomCrush + crusherDimen / 2);
            for (int x = from.X; x <= to.X; x++)
            {
                for (int y = from.Y; y <= to.Y; y++)
                {
                    Vector2 blockPos = new Vector2(x, y);
                    Runner.map.removeBlock(blockPos, new Vector2(10, -10), layer);
                }
            }


            if ((int)crushTimer > crushInc + 1)
            {
                crushInc = (int)crushTimer;
                //SoundPlayer.play("Explosion", 0.1F);
            }
        }
Beispiel #3
0
        public void checkOclusion()
        {
            Camera  camera = Runner.camera;
            Vector2 diff   = dimen / 2 * camera.scaleAt(zPos);
            Vector2 tl     = camera.toScreen(pos, zPos) - diff;
            Vector2 br     = tl + diff * 2;

            frontPercentOcluded = 0;
            midPercentOcluded   = 0;

            if (getLayer() == 2)
            {
                return;
            }

            Point from = ChunkMap.blockIndices(camera.toWorld(tl, 0));
            Point to   = ChunkMap.blockIndices(camera.toWorld(br, 0));

            int blockCount = (to.X - from.X + 1) * (to.Y - from.Y + 1);

            for (int i = from.X; i <= to.X; i++)
            {
                for (int j = from.Y; j <= to.Y; j++)
                {
                    Tile.type tileType = Runner.map.getTile(new Point(i, j), 2).tileType;

                    if (!Tile.nonFullBlock.Contains(tileType) && !Tile.transparent.Contains(tileType))
                    {
                        frontPercentOcluded += 1F / blockCount;
                    }
                }
            }

            if (getLayer() == 1)
            {
                return;
            }
            from       = ChunkMap.blockIndices(camera.toWorld(tl, -1));
            to         = ChunkMap.blockIndices(camera.toWorld(br, -1));
            blockCount = (to.X - from.X + 1) * (to.Y - from.Y + 1);

            for (int i = from.X; i <= to.X; i++)
            {
                for (int j = from.Y; j <= to.Y; j++)
                {
                    Tile.type tileType = Runner.map.getTile(new Point(i, j), 1).tileType;

                    if (!Tile.nonFullBlock.Contains(tileType) && !Tile.transparent.Contains(tileType))
                    {
                        midPercentOcluded += 1F / blockCount;
                    }
                }
            }
        }
Beispiel #4
0
        public DeathWall(float xPos, float zPos) : base(new Vector2(xPos, ChunkMap.mapHeight() / 2F), zPos)
        {
            vel          = Vector2.UnitX * 10;
            hasGravity   = false;
            hasCollision = false;

            crusher      = Textures.get("DeathWallCrusher");
            armSegment   = Textures.get("DeathWallArm");
            crusherDimen = Util.dimen(crusher);
            armDimen     = Util.dimen(armSegment);

            dimen = new Vector2(armDimen.X, ChunkMap.mapHeight());
        }
Beispiel #5
0
 public static void loadLevelMap()
 {
     Chunk.loadMapData(levelName);
     map = new ChunkMap();
     try {
         wiringEditor = DataSerializer.Deserialize <WiringEditor>(levelName + "Wiring");
     }
     catch (Exception e) {
         wiringEditor = new WiringEditor {
             rects       = new List <SelectRect>(),
             connections = new List <WireConnection>()
         };
     }
     wiringEditor.applyWiring();
 }
Beispiel #6
0
        public void collideTouching()   // includes inside blocks TODO: dont?
        {
            Vector2 diff = dimen / 2 + Vector2.One * 0.2F;
            Point   from = ChunkMap.blockIndices(pos - diff);
            Point   to   = ChunkMap.blockIndices(pos + diff);

            for (int i = from.X; i <= to.X; i++)
            {
                for (int j = from.Y; j <= to.Y; j++)
                {
                    Tile tile = Runner.map.getTile(new Point(i, j), getLayer(zPos));

                    if (tile.tileType != Tile.type.Air)
                    {
                        collideTouching(tile);
                    }
                }
            }
        }
Beispiel #7
0
        public void collideInsides()
        {
            Vector2 diff = dimen / 2;
            Point   from = ChunkMap.blockIndices(pos - diff);
            Point   to   = ChunkMap.blockIndices(pos + diff);

            for (int i = from.X; i <= to.X; i++)
            {
                for (int j = from.Y; j <= to.Y; j++)
                {
                    Tile tile = Runner.map.getTile(new Point(i, j), getLayer(zPos));

                    if (tile.tileType != Tile.type.Air)
                    {
                        collideInside(tile);
                    }
                }
            }
        }
Beispiel #8
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;
        }
Beispiel #9
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);
            }
        }
Beispiel #10
0
 public Point pointAt(Vector2 mousePos)
 {
     return(ChunkMap.blockIndices(Runner.camera.toWorld(mousePos, editLayer - 2)));
 }
Beispiel #11
0
        public override void update(float deltaTime)
        {
            hasCollision = !godMode;
            hasGravity   = !godMode;

            float rotMult      = (grounded) ? 1 : 0.5F;
            float toRotSpeed   = (vel.X / 20) * Maths.twoPI * rotMult;
            float rotAccelMult = (grounded) ? 10 : 3F;

            rotSpeed += (toRotSpeed - rotSpeed) * deltaTime * rotAccelMult;
            rotation += rotSpeed * deltaTime;

            deathTime -= deltaTime;
            if (dead && deathTime <= 0)
            {
                Runner.failLevel();
            }

            if (dead)
            {
                return;
            }

            base.update(deltaTime);

            collideInsides();
            collideTouching();

            if (pos.Y > ChunkMap.mapHeight() - 10)
            {
                vel = -Vector2.UnitY * 20;
                die();
            }

            if (pos.Y < 10)
            {
                vel = Vector2.UnitY * 20;
                die();
            }


            if (!dead)
            {
                animationTimer -= deltaTime;
                const float blinkStart = 0.4F;
                if (animationTimer > 0 && animationTimer < blinkStart)
                {
                    int index = (int)((blinkStart - animationTimer) / blinkStart * 5);
                    if (index > 2)
                    {
                        index = Math.Max(0, 5 - index);
                    }

                    texture = Textures.get("Blink" + index);
                }
                else
                {
                    texture = Textures.get("Player");

                    if (animationTimer < 0)
                    {
                        animationTimer = Util.random(3, 10);
                    }
                }
            }


            switchTime -= deltaTime;
            if (switchTime > 0)
            {
                float toZ = Util.revSinLerp(switchTime, switchTimeStart, switchFrom, switchTo);
                if (!tryMoveToZ(toZ))
                {
                    startSwitchTo(switchFrom);
                    SoundPlayer.play("Bonk", 0.5F);
                }
            }

            checkOclusion();
        }