コード例 #1
0
ファイル: arkanoid.go プロジェクト: qeedquan/misc_utilities
func NewApp(conf Config) *App {
	runtime.LockOSThread()
	err := sdl.Init(sdl.INIT_EVERYTHING &^ sdl.INIT_AUDIO)
	ck(err)

	sdl.SetHint(sdl.HINT_RENDER_SCALE_QUALITY, "best")
	wflag := sdl.WINDOW_RESIZABLE
	if conf.Fullscreen {
		wflag |= sdl.WINDOW_FULLSCREEN_DESKTOP
	}
	window, renderer, err := sdl.CreateWindowAndRenderer(DisplayWidth, DisplayHeight, wflag)
	ck(err)

	window.SetTitle("Arkanoid")
	renderer.SetLogicalSize(DisplayWidth, DisplayHeight)

	return &App{
		window:   window,
		renderer: renderer,
	}
}
コード例 #2
0
func main() {
	runtime.LockOSThread()
	log.SetFlags(0)
	err := sdl.Init(sdl.INIT_VIDEO)
	ck(err)

	window, renderer, err = sdl.CreateWindowAndRenderer(W, H, sdl.WINDOW_RESIZABLE)
	ck(err)

	window.SetTitle("Cosine Palette")
	renderer.SetLogicalSize(W, H)

	texture, err = renderer.CreateTexture(sdl.PIXELFORMAT_ABGR8888, sdl.TEXTUREACCESS_STREAMING, W, H)
	ck(err)

	pixels = image.NewRGBA(image.Rect(0, 0, W, H))

	for {
		event()
		draw()
	}
}
コード例 #3
0
ファイル: catclock.go プロジェクト: qeedquan/misc_utilities
func main() {
	log.SetFlags(0)
	runtime.LockOSThread()
	flag.Parse()

	err := sdl.Init(sdl.INIT_VIDEO | sdl.INIT_TIMER)
	ck(err)
	defer sdl.Quit()

	sdl.SetHint(sdl.HINT_RENDER_SCALE_QUALITY, "best")
	window, renderer, err = sdl.CreateWindowAndRenderer(W, H, sdl.WINDOW_RESIZABLE)
	ck(err)

	renderer.SetLogicalSize(W, H)
	window.SetTitle("Cat Clock")

	cat = loadImage(catb)
	eyes = loadImage(eyesb)
	hand.minute = makeTexture(ML*2, ML*2)
	hand.hour = makeTexture(HL+5, HL+5)
	for i := 0; i <= C; i++ {
		tail = append(tail, renderTail(float64(i)*math.Pi/C))
		eye = append(eye, renderEye(float64(i)*math.Pi/C))
	}

	renderer.SetTarget(nil)
	ticker := time.Tick(FPS)
	for {
		event()
		select {
		case <-ticker:
			update()
		default:
		}
		draw()
	}
}
コード例 #4
0
ファイル: mole.go プロジェクト: qeedquan/misc_utilities
func NewDisplay(w, h int, flags sdl.WindowFlags) *Display {
	window, renderer, err := sdl.CreateWindowAndRenderer(w, h, flags)
	ck(err)
	return &Display{window, renderer}
}
コード例 #5
0
ファイル: gasket.go プロジェクト: qeedquan/misc_utilities
func main() {
	runtime.LockOSThread()

	err := sdl.Init(sdl.INIT_EVERYTHING)
	if err != nil {
		log.Fatalln(err)
	}

	defer sdl.Quit()

	window, renderer, err := sdl.CreateWindowAndRenderer(W, H, sdl.WINDOW_RESIZABLE)
	if err != nil {
		log.Fatalln(err)
	}
	texture, err := renderer.CreateTexture(sdl.PIXELFORMAT_ARGB8888, sdl.TEXTUREACCESS_STREAMING, W, H)
	if err != nil {
		log.Fatalln(err)
	}
	pixels := make([]uint32, W*H)
	window.SetTitle("Gasket")
	renderer.SetLogicalSize(W, H)

	v := []Vec2{
		{0.5, 0},
		{0, 1},
		{1, 1},
	}
	p := Vec2{0.5, 0.5}

loop:
	for {
		for {
			ev := sdl.PollEvent()
			if ev == nil {
				break
			}
			switch ev := ev.(type) {
			case sdl.QuitEvent:
				break loop
			case sdl.KeyDownEvent:
				switch ev.Sym {
				case sdl.K_ESCAPE:
					break loop
				}
			}
		}
		r, g, b := rand.Intn(256), rand.Intn(256), rand.Intn(256)

		n := rand.Intn(3)
		q := v[n].Add(p).Scale(.5)

		x := int(q[0] * W)
		y := int(q[1] * H)
		if y*W+x < len(pixels) {
			pixels[y*W+x] = 255<<24 | uint32(r)<<16 | uint32(g)<<8 | uint32(b)
		}
		p = q

		renderer.SetDrawColor(sdlcolor.Black)
		renderer.Clear()
		texture.Update(nil, pixels, W*4)
		renderer.Copy(texture, nil, nil)
		renderer.Present()
	}
}