protected override void Update(float dt) { //scene.Update(dt); camera.Update(dt); physicsTester.Update(dt); MessageSystem.ProcessChanges(); }
public MainGame() : base("Zeldo") { glClearColor(0, 0, 0, 1); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPrimitiveRestartIndex(Constants.RestartIndex); glfwSetInputMode(window.Address, GLFW_CURSOR, GLFW_CURSOR_DISABLED); Language.Reload(Languages.English); canvas = new Canvas(); sb = new SpriteBatch(); mainTarget = new RenderTarget(Resolution.RenderWidth, Resolution.RenderHeight, RenderTargetFlags.Color | RenderTargetFlags.Depth); mainSprite = new Sprite(mainTarget, null, Alignments.Left | Alignments.Top); mainSprite.Mods = SpriteModifiers.FlipVertical; // The first loop is created manually. Others are created via gamestate messages. currentState = Gamestates.Gameplay; nextState = currentState; activeLoop = CreateLoop(currentState); MessageSystem.Subscribe(this, CoreMessageTypes.Keyboard, (messageType, data, dt) => { ProcessKeyboard((KeyboardData)data); }); MessageSystem.Subscribe(this, CoreMessageTypes.ResizeWindow, (messageType, data, dt) => { mainSprite.ScaleTo(Resolution.WindowWidth, Resolution.WindowHeight); }); MessageSystem.Subscribe(this, CustomMessageTypes.Gamestate, (messageType, data, dt) => { var state = (Gamestates)data; Debug.Assert(state != Gamestates.Splash, "Can't transition to the splash loop."); // This implementation means that if multiple gamestate messages are sent on a single frame, the last // state will take priority (although that should never happen in practice). if (state != currentState) { nextState = state; } }); // Calling this function here is required to ensure that all classes receive initial resize messages. MessageSystem.ProcessChanges(); MessageSystem.Send(CoreMessageTypes.ResizeRender, Resolution.RenderDimensions); MessageSystem.Send(CoreMessageTypes.ResizeWindow, Resolution.WindowDimensions); }
protected override void Update(float dt) { activeLoop.Update(dt); canvas.Update(dt); // Gamestate changes don't apply until the end of the current frame. if (nextState != currentState) { activeLoop = CreateLoop(nextState); currentState = nextState; } MessageSystem.ProcessChanges(); }
public MainGame() : base("Dungeon") { sb = new SpriteBatch(); camera = new Camera3D(); camera.IsOrthographic = true; camera.Orientation *= quat.FromAxisAngle(0, vec3.UnitX); camera.Position = new vec3(0, 0, 1) * camera.Orientation; mainTarget = new RenderTarget(Resolution.RenderWidth, Resolution.RenderHeight, RenderTargetFlags.Color | RenderTargetFlags.Depth); mainSprite = new Sprite(mainTarget, null, Alignments.Left | Alignments.Top); mainSprite.Mods = SpriteModifiers.FlipVertical; Player player = new Player(); player.UnlockSkill(PlayerSkills.Jump); scene = new Scene(); scene.Camera = camera; scene.Add(player); scene.ModelBatch.LightDirection = Utilities.Normalize(new vec3(1, -0.2f, 0)); renderTargetUsers = new List <IRenderTargetUser>(); renderTargetUsers.Add(scene.ModelBatch); physicsTester = new PhysicsTester(); MessageSystem.Subscribe(this, CoreMessageTypes.ResizeWindow, (messageType, data, dt) => { mainSprite.ScaleTo(Resolution.WindowWidth, Resolution.WindowHeight); }); MessageSystem.ProcessChanges(); MessageSystem.Send(CoreMessageTypes.ResizeRender, Resolution.RenderDimensions); MessageSystem.Send(CoreMessageTypes.ResizeWindow, Resolution.WindowDimensions); }