示例#1
0
文件: main.go 项目: gtalent/starfish
func main() {
	runtime.GOMAXPROCS(1)
	runtime.LockOSThread()

	cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	//For a fullscreen at your screens native resolution, simply use this line instead:
	//if !gfx.OpenDisplay(0, 0, true) {
	if !gfx.OpenDisplay(800, 600, false) {
		return
	}
	gfx.SetDisplayTitle("starfish example")

	var pane Drawer
	if !pane.init() {
		return
	}
	gfx.AddDrawer(&pane)
	quit := func() {
		gfx.CloseDisplay()
		pane.box.Free()
		pane.text.Free()
	}
	input.AddQuitFunc(quit)
	input.AddMouseWheelFunc(func(e input.MouseWheelEvent) {
		if e.Up {
			fmt.Println("Mouse wheel scrolling up.")
		} else {
			fmt.Println("Mouse wheel scrolling down.")
		}
	})
	input.AddMousePressFunc(func(e input.MouseEvent) {
		fmt.Println("Mouse Press!")
	})
	input.AddMouseReleaseFunc(func(e input.MouseEvent) {
		fmt.Println("Mouse Release!")
	})

	input.AddKeyPressFunc(func(e input.KeyEvent) {
		fmt.Println("Key Press!")
		if e.Key == input.Key_Escape {
			quit()
		}
	})
	input.AddKeyReleaseFunc(func(i input.KeyEvent) {
		fmt.Println("Key Release!")
	})

	gfx.Main()
}
示例#2
0
文件: main.go 项目: RobWC/worldlord
func main() {
	runtime.GOMAXPROCS(4)
	runtime.LockOSThread()

	if !gfx.OpenDisplay(1024, 768, false) {
		return
	}
	gfx.SetDisplayTitle("Worldlord: Wrath of Chaos")

	var pane mainmenu.MainMenu
	pane.Init()
	fmt.Println(pane)
	gfx.AddDrawer(&pane)

	quit := func() {
		gfx.CloseDisplay()
		os.Exit(0)
	}

	go func() {
		for {
			time.Sleep(time.Second * 5)
			log.Println("Foos")
		}
	}()

	input.AddQuitFunc(quit)
	input.AddKeyPressFunc(func(e input.KeyEvent) {
		fmt.Println("Key Press ", e.Key)
		if e.Key == 1073742049 {
			pane.Cursor_mod = true
		}
		if e.Key == input.Key_Escape {
			quit()
		}
		if e.Key == input.Key_Down {
			pane.MoveDown()
		}
		if e.Key == input.Key_Up {
			pane.MoveUp()
		}
		if e.Key == input.Key_Left {
			pane.MoveLeft()
		}
		if e.Key == input.Key_Right {
			pane.MoveRight()
		}
	})
	input.AddKeyReleaseFunc(func(i input.KeyEvent) {
		fmt.Println("Key Release! ", i.Key)
		if i.Key == 1073742049 {
			pane.Cursor_mod = false
		}
	})

	log.Println("Start Worldlord")
	gfx.Main()
}