Exemplo n.º 1
0
func main() {
	window, renderer = tools.Start("planets", int(SCREEN_W), int(SCREEN_H))
	wideView := tools.ViewBox{tools.Vector{-SCREEN_SCALE / 2 / float64(SCREEN_H) * float64(SCREEN_W),
		-SCREEN_SCALE / 2},
		SCREEN_SCALE / float64(SCREEN_H) * float64(SCREEN_W),
		SCREEN_SCALE}
	defer window.Destroy()
	defer renderer.Destroy()
	sprite = tools.LoadTextureTransparent(renderer, "resources/sprites.png", 0, 0xFF, 0xFF)

	bodies := []*tools.Body{&Sun, &Earth, &Mars, &Ecc}

	quit := false
	curView := &wideView
	for !quit {
		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch t := e.(type) {
			case *sdl.QuitEvent:
				quit = true
			case *sdl.KeyDownEvent:
				switch t.Keysym.Sym {
				case sdl.K_UP:
					auto := tools.GetAutoView(
						[]tools.Vector{
							bodies[0].Position,
							bodies[1].Position},
						SCREEN_RATIO)
					curView = &auto
				case sdl.K_DOWN:
					curView = &wideView
				case sdl.K_q:
					quit = true
				}
				// fmt.Println("View:", curView)
			}

		}
		// Draw background
		renderer.SetDrawColor(0xFF, 0xFF, 0xFF, 0xFF)
		renderer.Clear()

		renderer.SetDrawColor(0, 0, 0, 0xFF)

		tools.UpdateBodiesSeconds(bodies, 60*60*24*7)
		DrawBodies(bodies, *curView)

		renderer.Present()
		//fmt.Println(earth.Position, sun.Position)
	}
}
Exemplo n.º 2
0
func main() {
	window, renderer = tools.Start("flip", int(W), int(H))
	defer window.Destroy()
	defer renderer.Destroy()

	arrow := tools.LoadTexture(renderer, "resources/arrow.png")
	back := tools.LoadTexture(renderer, "resources/background.png")

	angle := 0.0
	var flip = sdl.RendererFlip(sdl.FLIP_NONE)

	quit := false
	for !quit {
		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch t := e.(type) {
			case *sdl.QuitEvent:
				quit = true
			case *sdl.KeyDownEvent:
				switch t.Keysym.Sym {
				case sdl.K_LEFT:
					angle += 30.0
				case sdl.K_RIGHT:
					angle -= 30.0
				case sdl.K_q:
					flip ^= sdl.FLIP_HORIZONTAL
				case sdl.K_w:
					flip ^= sdl.FLIP_VERTICAL
				}

			}
		}

		renderer.SetDrawColor(0xFF, 0xFF, 0xFF, 0xFF)
		renderer.Clear()

		renderer.Copy(back, nil, nil)
		renderer.CopyEx(arrow, nil, &sdl.Rect{300, 400, 100, 100},
			angle, &sdl.Point{50, 50}, flip)

		renderer.Present()
	}
}