Esempio n. 1
0
        public override bool interact(Player p)
        {
            if (xOffset != 0 || yOffset != 0)
            {
                return(false);
            }
            int x = this.x;
            int y = this.y;

            switch (p.dir)
            {
            case 0: x++; break;

            case 1: y--; break;

            case 2: x--; break;

            case 3: y++; break;
            }
            if (world.entityAt(x, y) == null)
            {
                if (world.getBlockAt(x, y) == 0 && world.getTileAt(x, y) != 0)
                {
                    WorldState w = p.getState() as WorldState;
                    if (w == null)
                    {
                        return(false);
                    }
                    if (w.getWaterPixel() > 0)
                    {
                        switch (p.dir)
                        {
                        case 0:
                            this.x++;
                            xOffset = -15;
                            break;

                        case 1:
                            this.y--;
                            yOffset = 15;
                            break;

                        case 2:
                            this.x--;
                            xOffset = 15;
                            break;

                        case 3:
                            this.y++;
                            yOffset = -15;
                            break;
                        }
                        SoundSystem.play("box move");
                    }
                    else
                    {
                        p.pushState(new TextBox(w, p, "A large box. You wonder if it would float."));
                    }
                }
            }
            return(true);
        }
Esempio n. 2
0
        //called every frame
        public static void run()
        {
            Player[] p = players; //because laz
            for (int i = 0; i < p.Length; i++)
            {
                if (p[i].getState() is WorldState)
                {
                    WorldState w = (WorldState)p[i].getState();
                    if (w.getWaterPixel() == 16)
                    {
                        w.WALK_SPEED = 1;
                    }
                    else
                    {
                        w.WALK_SPEED = 2;
                    }
                }
                if (p[i].isScuba)
                {
                    if (p[i].breath == 0)
                    {
                        if (i == 0)
                        {
                            lose(new string[] { "Humans aren't built for living underwater.", "The other player forgot how to breath." });
                        }
                        else
                        {
                            lose(new string[] { "The other player forgot how to breath.", "Humans aren't built for living underwater." });
                        }
                    }
                    else
                    {
                        p[i].breath--;
                    }
                }
                else
                {
                    if (p[i].breath < Player.MAX_BREATH)
                    {
                        p[i].breath++;
                    }
                }
                p[i].run();
            }
            bool canTick = false; //whether or not any worlds can tick, i.e. if any players are outside of menus

            for (int i = 0; i < p.Length; i++)
            {
                if (p[i].getState() is WorldState && !(p[i].getState() is WorldEditor))
                {
                    canTick = true;
                    p[i].world.tick(p[i]);
                }
            }
            if (canTick)
            {
                if (waterRising)
                {
                    if (WorldState.drainFrames == 0)
                    {
                        WorldState.waterLevel--;
                        if (WorldState.waterLevel == 0)
                        {
                            lose(new string[] { "Inundation complete. Might want to stop that next time." });
                            WorldState.waterLevel = WorldState.WATER_SPEED;
                        }
                        else if (WorldState.waterLevel % WorldState.WATER_SPEED == 0)
                        {
                            int level = WorldState.waterLevel / WorldState.WATER_SPEED;
                            if (level >= 0 && level < 4)
                            {
                                WorldState.pipeUsesLeft[level]--;
                                if (WorldState.pipeUsesLeft[level] == 0)
                                {
                                    lose(new string[] { "There was no hope for floor " + (level + 1) + "'s pipe any longer." });
                                }
                            }
                        }
                    }
                    else
                    {
                        WorldState.waterLevel++;
                        WorldState.drainFrames--;
                    }
                }
                frames++;
                List <World> tickedWorlds = new List <World>(); //worlds in this list have already ticked, needed so that they don't double up
                for (int i = 0; i < p.Length; i++)
                {
                    if (!tickedWorlds.Contains(p[i].world))
                    {
                        World w = p[i].world;
                        for (int j = 0; j < w.entities.Count; j++)
                        {
                            Entity e = w.entities[j];
                            e.tick();
                            if (e.needsRemoval())
                            {
                                w.entities.Remove(e);
                                j--;
                            }
                        }
                        tickedWorlds.Add(w);
                    }
                }
            }
        }