Example #1
0
 public Camera2D(RabbitPlatform instance)
 {
     this.game   = instance;
     translation = new Vector3(0, 0, 0);
     followed    = null;
     cameraLimit = null;
 }
Example #2
0
 public GUI(RabbitPlatform instance)
 {
     this.game          = instance;
     this.gameScreen    = new GameScreen(this);//new GameScreen(this);
     this.currentScreen = gameScreen;
     //f = new Forms.Form(this);
 }
Example #3
0
        public static Texture2D fromStream(RabbitPlatform game, Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);
            MemoryStream mem    = new MemoryStream(reader.ReadBytes(reader.ReadInt32()));

            return(Texture2D.FromStream(game.GraphicsDevice, mem));
        }
Example #4
0
        public static TileSet loadTileSet(RabbitPlatform game, string setFileName)
        {
            TileSetInfo info;
            TileSet     ts;
            TileSetFile file = new TileSetFile(setFileName);

            TileMask[] masks;

            if (file.ReadMagic() != "TS")
            {
                throw new FileLoadException("Wrong file format!", file.path);
            }

            info  = new TileSetInfo(file.ReadUInt32(), file.ReadUInt32(), file.ReadByte());
            masks = new TileMask[info.Width * info.Height];
            Texture2D texture = TileGraphicsFilePart.fromStream(game, file.BaseStream);

            for (int y = 0; y < info.Height; y++)
            {
                for (int x = 0; x < info.Width; x++)
                {
                    masks[x + y * info.Width] = TileMaskFilePart.fromStream(file.BaseStream);
                }
            }

            ts = TileSet.loadFromTexture(texture, info, masks);
            return(ts);
        }
Example #5
0
 public Resolution(RabbitPlatform instance)
 {
     this.game = instance;
     matrix    = Matrix.Identity;
     stretch   = false;
     enabled   = false;
 }
Example #6
0
        public World(RabbitPlatform instance)
        {
            this.game        = instance;
            this.worldCamera = new Camera2D(game);
            this.random      = new Random();

            this.entityManager    = new Entity.EntityManager(this);
            this.collisionManager = new CollisionManager(this);

            this.playerController = new PlayerController(this);

            this.enabled = false;
        }
Example #7
0
        public static void generate(RabbitPlatform game, byte tileSize, string tileSetPath, string tileMasksPath, string output)
        {
            FileStream   stream = new FileStream(TileSet_Directory + output, FileMode.Create);
            Texture2D    texture = game.TextureLoader.FromFile(TileSet_Directory + tileSetPath);
            Texture2D    masks = game.TextureLoader.FromFile(TileSet_Directory + tileMasksPath);
            BinaryWriter writer = new BinaryWriter(stream);
            uint         width = (uint)texture.Width / tileSize, height = (uint)texture.Height / tileSize;

            writer.Write(ASCIIEncoding.ASCII.GetBytes("TS"));
            writer.Write(width);
            writer.Write(height);
            writer.Write(tileSize);
            TileGraphicsFilePart.toStream(texture, stream);
            TileMaskFilePart.toStream(game, stream, masks);
            writer.Close();
        }
Example #8
0
        public InputManager(RabbitPlatform instance, bool defaults)
        {
            this.game  = instance;
            actionKeys = new Dictionary <ActionKeyType, ActionKey>();

            if (defaults)
            {
                actionKeys.Add(ActionKeyType.GO_LEFT, new KeyboardActionKey(Keys.Left));
                actionKeys.Add(ActionKeyType.GO_RIGHT, new KeyboardActionKey(Keys.Right));
                actionKeys.Add(ActionKeyType.JUMP, new KeyboardActionKey(Keys.LeftControl));
                actionKeys.Add(ActionKeyType.RUN, new KeyboardActionKey(Keys.LeftShift));
            }

            keyboardManager = new KeyboardManager();
            mouseManager    = new MouseManager();
        }
Example #9
0
        public EditorWorld(RabbitPlatform instance)
            : base(instance)
        {
            InputManager.MouseManager.MouseWheel += new EventHandler <Input.MouseEvent>(MouseManager_MouseWheel);
            InputManager.MouseManager.MouseDown  += new EventHandler <Input.MouseEvent>(MouseManager_MouseDown);
            InputManager.KeyboardManager.KeyDown += new EventHandler <Input.KeyboardEvent>(KeyboardManager_KeyDown);
            tiledata   = 0;
            layeredit  = 0;
            normaldraw = false;

            def              = instance.GraphicsDevice.Viewport;
            lefthalf         = instance.GraphicsDevice.Viewport;
            lefthalf.Width  /= 2;
            righthalf        = instance.GraphicsDevice.Viewport;
            righthalf.Width /= 2;
            righthalf.X      = lefthalf.Width;
        }
Example #10
0
        public static Level loadLevel(RabbitPlatform game, string levelName, bool editor = false)
        {
            if (game.CurrentWorld == null)
            {
                throw new NullReferenceException("You are unable to load level when without any world.");
            }

            LevelFile file = new LevelFile(levelName);

            if (file.ReadMagic() != "LV")
            {
                throw new FormatException();
            }

            //if (!editor)
            //    world = new World(game);
            //else
            //    world = new Editor.EditorWorld(game);

            string  tileset = file.ReadString();
            TileSet ts      = TileSetFile.loadTileSet(game, tileset);

            ushort layers   = file.ReadUInt16();
            ushort entLayer = file.ReadUInt16();

            Level level = new Level(game.CurrentWorld, layers, entLayer);

            //world.prepareWorld(layers, entLayer);
            TileMapInfo info;

            for (int i = 0; i < layers; i++)
            {
                info = TileMapFilePart.fromStream(level, file.BaseStream, ts);
                level.initializeLayer(info, i);
            }

            //world.createWorld();

            file.Close();

            return(level);
        }
Example #11
0
        public static void toStream(RabbitPlatform game, Stream stream, Texture2D texture)
        {
            RenderTarget2D target = new RenderTarget2D(game.GraphicsDevice, Tile.STANDARD_GTILE_WIDTH, Tile.STANDARD_GTILE_HEIGHT);
            SpriteBatch    sb = new SpriteBatch(game.GraphicsDevice);
            int            w = texture.Width / Tile.STANDARD_GTILE_WIDTH, h = texture.Height / Tile.STANDARD_GTILE_HEIGHT;

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    game.GraphicsDevice.SetRenderTarget(target);
                    game.GraphicsDevice.Clear(Color.White);
                    sb.Begin();
                    sb.Draw(texture, new Rectangle(0, 0, Tile.STANDARD_GTILE_WIDTH, Tile.STANDARD_GTILE_HEIGHT), new Rectangle(x * Tile.STANDARD_GTILE_WIDTH, y * Tile.STANDARD_GTILE_HEIGHT, Tile.STANDARD_GTILE_WIDTH, Tile.STANDARD_GTILE_HEIGHT), Color.White);
                    sb.End();
                    game.GraphicsDevice.SetRenderTarget(null);

                    toStream(stream, TileMask.fromTexture(target));
                }
            }
        }
Example #12
0
        public static TileMap loadFromStream(RabbitPlatform game, Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            string tileset = Utility.readToBrakpoint(reader);

            tileset = tileset.Substring(1);
            int width  = int.Parse(Utility.readToBrakpoint(reader));
            int height = int.Parse(Utility.readToBrakpoint(reader));

            TileMap map = new TileMap(width, height, Engine.Files.TileSetFile.loadTileSet(game, tileset));//TileSet.loadFromTexture(TextureManager.Instance.groundTileSet, TileSetInfo.loadFromStream(new FileStream("TSInfo.txt", FileMode.Open))));

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    map.setTile(x, y, new TileData(int.Parse(Utility.readToBrakpoint(reader))));
                }
            }

            return(map);
        }
Example #13
0
        public static AnimatedTexture FromContent(RabbitPlatform instance, string name, int startX, int startY, int frameWidth, int frameHeight, int frameCount, int frameSwap = -1)
        {
            Texture2D main = instance.Content.Load <Texture2D>(name);

            return(new AnimatedTexture(main, startX, startY, frameCount, frameWidth, frameHeight, frameSwap));
        }
Example #14
0
 public TextureManager(RabbitPlatform instance)
 {
     this.game  = instance;
     myInstance = this;
 }