func (s *SceneSwitcherSystem) Update(e *ecs.Entity, dt float32) { s.secondsWaited += dt if float64(s.secondsWaited) > s.WaitTime.Seconds() { s.secondsWaited = 0 // Change the world to s.NextScene, and don't override / force World re-creation engi.SetSceneByName(s.NextScene, false) fmt.Println("Switched to", s.NextScene) } }
func (m *Menu) New(w *ecs.World) { m.System = ecs.NewSystem() m.World = w specificLevel := &MenuItem{Text: "Play specific level ..."} callbackGenerator := func(l *Level) func() { msg := MazeMessage{LevelName: l.Name} return func() { engi.SetSceneByName("BCIGame", true) engi.Mailbox.Dispatch(msg) } } specificLevel.Callback = func() { specificLevel.SubItems = make([]*MenuItem, 0) for _, l := range ActiveMazeSystem.levels { specificLevel.SubItems = append(specificLevel.SubItems, &MenuItem{Text: l.Name, Callback: callbackGenerator(&l)}) } } e := ecs.NewEntity([]string{m.Type()}) m.AddEntity(e) m.items = []*MenuItem{ {Text: "Random Level", Callback: func() { engi.SetSceneByName("BCIGame", true) }}, specificLevel, {Text: "Start Experiment", Callback: func() { engi.SetSceneByName("BCIGame", true) var msg MazeMessage if rand.Intn(2) == 0 { msg.Sequence = SequenceAscending } else { msg.Sequence = SequenceDescending } engi.Mailbox.Dispatch(msg) }}, {Text: "Calibrate", Callback: func() { engi.SetSceneByName("CalibrateScene", false) }}, {Text: "Exit", Callback: func() { engi.Exit() }}, } // TODO: handle resizing of window menuWidth := (engi.Width() - 2*menuPadding) m.focusBackground = helpers.GenerateSquareComonent( MenuColorItemBackgroundFocus, MenuColorItemBackgroundFocus, menuWidth-2*menuItemPadding, menuItemHeight, engi.HUDGround+2, ) m.defaultBackground = helpers.GenerateSquareComonent( MenuColorItemBackground, MenuColorItemBackground, menuWidth-2*menuItemPadding, menuItemHeight, engi.HUDGround+2, ) m.openMenu() }
func (m *MenuListener) Update(entity *ecs.Entity, dt float32) { if engi.Keys.Get(engi.Escape).JustPressed() { previousScene = engi.CurrentScene() engi.SetSceneByName("MenuScene", true) } }