Exemple #1
0
// Init initializes this gamestate
func (is *IntroState) Init() {
	// Create colors
	is.bgColor = sdl.MapRGB(gamecontext.GContext.PixelFormat, 60, 160, 60)
	is.fontNormalColor = sdl.Color{R: 255, G: 255, B: 255, A: 255}
	is.fontHighlightColor = sdl.Color{R: 255, G: 255, B: 0, A: 255}

	is.assetManager = assetmanager.New()

	err := is.assetManager.LoadJSON("introassets.json")
	if err != nil {
		panic(fmt.Sprintf("introassets.json: %v", err))
	}

	is.buildScene()
}
Exemple #2
0
func LoadTextureTransparent(renderer *sdl.Renderer, path string, r, g, b uint8) *sdl.Texture {
	bmp, err := img.Load(path)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to load image %s! SDL Error: %s\n", path, img.GetError())
	} else {
		if bmp.SetColorKey(1, sdl.MapRGB(bmp.Format, r, g, b)) != 0 {
			fmt.Fprintf(os.Stderr, "Unable to set Color Key %s! SDL Error: %s\n", path, sdl.GetError())
		}
		texture, err := renderer.CreateTextureFromSurface(bmp)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Unable to create texture %s! SDL Error: %s\n", path, sdl.GetError())
		}
		bmp.Free()
		return texture
	}
	return nil
}
Exemple #3
0
// Init initializes this gamestate
func (ps *PlayState) Init() {
	ps.initChix()
	ps.initEggs()

	// Create colors
	ps.bgColor = sdl.MapRGB(gamecontext.GContext.PixelFormat, 133, 187, 234)
	ps.fontNormalColor = sdl.Color{R: 255, G: 255, B: 255, A: 255}
	ps.fontHighlightColor = sdl.Color{R: 255, G: 255, B: 0, A: 255}

	ps.assetManager = assetmanager.New()
	ps.assetManager.SetOuterSurface(gamecontext.GContext.MainSurface)

	err := ps.assetManager.LoadJSON("playassets.json")
	if err != nil {
		panic(fmt.Sprintf("playassets.json: %v", err))
	}
	ps.buildScene()
}
Exemple #4
0
func main() {
	sdl.Init(sdl.INIT_VIDEO)
	defer sdl.Quit()
	window, err := sdl.CreateWindow("Tank", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, windowWidth, windowHeight, 0)
	if err != nil {
		panic(err)
	}
	defer window.Destroy()

mainloop:
	for {
		for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
			switch event.(type) {
			case *sdl.QuitEvent:
				break mainloop
			}
		}
		windowSurface, _ := window.GetSurface()
		windowSurface.FillRect(nil, sdl.MapRGB(windowSurface.Format, 0, 0, 0))

		window.UpdateSurface()
		sdl.Delay(1000)
	}
}