Пример #1
0
func handleEvents(disp *allegro.Display) {
	sources := [...]*allegro.EventSource{
		disp.GetEventSource(),
		allegro.GetKeyboardEventSource(),
		allegro.GetMouseEventSource()}
	ch := allegro.GetEvents(sources[:])
	for ev := range ch {
		switch ev := ev.(type) {
		case allegro.DisplayResizeEvent:
			disp.AcknowledgeResize()
		case allegro.MouseButtonDown:
			alFuncs <- DisplayColor
		case allegro.DisplayCloseEvent:
			return
		case allegro.KeyDownEvent:
			if ev.Keycode == allegro.KEY_ESCAPE {
				return
			}
		}
	}
}
Пример #2
0
func (g *GameEngine) eventHandler() {
	src := g.displayEngine.Display.GetEventSource()
	defer src.StopGetEvents()
	es := []*allegro.EventSource{src,
		allegro.GetKeyboardEventSource(),
		allegro.GetMouseEventSource()}
	queue := allegro.GetEvents(es)
	stopped := false
	for !stopped {
		ev := <-queue
		switch tev := ev.(type) {
		case allegro.KeyCharEvent:
			g.handleKeyChar(tev)
		case allegro.MouseButtonDown:
			g.handleMouseDown(tev)
		}
		g.statusLock.RLock()
		stopped = g.stopped
		g.statusLock.RUnlock()
	}
}