示例#1
0
文件: main.go 项目: fesenko/snake
func appMain(driver gxui.Driver) {
	theme = light.CreateTheme(driver)
	window = theme.CreateWindow(800, 600, "Snake")

	playGround = field.Create(800, 600, 20, 20)
	sn = snake.Create(math.Point{X: 380, Y: 200}, math.Point{X: 380, Y: 280}, 20)

	drawScene(driver)
	fmt.Println(sn.Direction())

	window.OnKeyUp(func(event gxui.KeyboardEvent) {
		dir := sn.Direction()
		key := event.Key

		switch {
		case key == gxui.KeyRight && dir == snake.Top:
			sn.TurnRight()
		case key == gxui.KeyRight && dir == snake.Bottom:
			sn.TurnLeft()
		case key == gxui.KeyLeft && dir == snake.Top:
			sn.TurnLeft()
		case key == gxui.KeyLeft && dir == snake.Bottom:
			sn.TurnRight()
		case key == gxui.KeyUp && dir == snake.Left:
			sn.TurnRight()
		case key == gxui.KeyUp && dir == snake.Right:
			sn.TurnLeft()
		case key == gxui.KeyDown && dir == snake.Left:
			sn.TurnLeft()
		case key == gxui.KeyDown && dir == snake.Right:
			sn.TurnRight()

		}
	})

	ticker := time.NewTicker(time.Millisecond * 200)

	go func() {
		for _ = range ticker.C {
			driver.Call(func() {
				(&sn).Move()
				drawScene(driver)
			})
		}
	}()

	window.OnClose(func() {
		driver.Terminate()
		ticker.Stop()
	})

}
示例#2
0
文件: ui.go 项目: Kapura/pixelart
func appMain(driver gxui.Driver) {
	data := make(map[string]*dataField)
	output := make(map[string]gxui.Label)

	theme := light.CreateTheme(driver)

	window := theme.CreateWindow(750, 512, "art")
	window.OnClose(driver.Terminate)

	h_layout := theme.CreateLinearLayout()
	h_layout.SetDirection(gxui.LeftToRight)
	window.AddChild(h_layout)

	v_layout := theme.CreateLinearLayout()
	v_layout.SetDirection(gxui.TopToBottom)
	v_layout.SetHorizontalAlignment(gxui.AlignRight)
	h_layout.AddChild(v_layout)

	ProgPic = theme.CreateImage()
	ProgPic.SetExplicitSize(math.Size{512, 512})
	h_layout.AddChild(ProgPic)

	for s := range FieldNames {
		df := makeDataField(theme, FieldNames[s])
		data[FieldNames[s]] = df
		v_layout.AddChild(df.layout)
	}
	initialise(data)

	run_button := theme.CreateButton()
	run_button.SetText("Run")
	run_button.OnClick(func(gxui.MouseEvent) { onRun(data, output) })

	label_3 := theme.CreateLabel()
	output["L3"] = label_3

	v_layout.AddChild(run_button)

	Driver = driver
}
示例#3
0
文件: flags.go 项目: xinhuang327/gxui
// CreateTheme creates and returns the theme specified on the command line.
// The default theme is dark.
func CreateTheme(driver gxui.Driver) gxui.Theme {
	if FlagTheme == "light" {
		return light.CreateTheme(driver)
	}
	return dark.CreateTheme(driver)
}