//Initializes the world data given its initial state public void initWorldData(string filePath = "", int width = 0, int height = 0, string behavior = null, List <ActorData> actors = null) { this.worldName = ResourceComponent.getKeyFromPath(filePath); this.filePath = ResourceComponent.getFullPathFromKey(filePath); this.worldBehaviorKey = behavior; this.worldTileData = new TileData[1, width, height]; this.worldActorData = actors; if (this.worldActorData == null) { this.worldActorData = new List <ActorData>(); } if (this.worldBehaviorKey == null) { this.worldBehaviorKey = ""; } //Construct tiles for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { worldTileData[0, x, y] = new TileData(""); } } }
internal ILoadable resource; //Resource that this handle represents /* Handle constructor * * Initialize the handle. Sets up the internal data, but does not actually perform loading from disk. * * @param rc The engine resource component object * @param s The relative path to the resource (see key above) * */ public Handle(ResourceComponent rc, string s) { this.rc = rc; //In order to load the resource from disk, we need the full path to it. this.fullPath = ResourceComponent.getFullPathFromKey(s); if (s.Length < 1) { key = ""; return; } //Makes sure the key is well-formed to be a handle-key this.key = ResourceComponent.getKeyFromPath(s); }
/* * Global run method. * Initializes the engine and game, runs the game loop, and unloads all content afterword * * @return return value for main() */ public int run() { // Initialize the engine if (Sdl.SDL_Init(0) == -1) { throw new Exception("Could not initialize SDL: " + Sdl.SDL_GetError()); } graphicsComponent.SetIcon(ResourceComponent.getFullPathFromKey("GameIcon.bmp"), true); // should be called before initialize() -- see method initialize(); loadContent(); //Jump to Treequake if no world if (world == null) { newWorld(DEFAULTMAPWIDTH, DEFAULTMAPHEIGHT); editorComponent.swap(); editorComponent.selectTool(editorComponent.newMapTool); editorComponent.selectTool(editorComponent.editorSettingsTool); } //Game loop while (true) { //Handle Events and Quit when appropriate if (inputComponent.pollEvents() || quit) { break; } //Update the world if there is time bool isRunningSlowly = false; int curTime = Sdl.SDL_GetTicks(); if (curTime - lastTickTime > MINTICK - lastRendTime) { //Debug.WriteLine("World: " + (curTime - lastTickTime)); isRunningSlowly = curTime - lastTickTime > MINTICK * 3; if (!paused) { world.Update(); physicsComponent.Update(); } if (editorComponent.isActive) { editorComponent.Update(); } lastTickTime = curTime; } //Draw the screen if not running slow int beginRendTime = Sdl.SDL_GetTicks(); if (!isRunningSlowly) { graphicsComponent.draw(); } int endRendTime = Sdl.SDL_GetTicks(); lastRendTime = endRendTime - beginRendTime; } //End the engine unloadContent(); Sdl.SDL_Quit(); return(0); }