Пример #1
0
func NewPipe(screenWidth, screenHeight int) *Pipe {
	y := rand.Intn(screenHeight-300) + 100
	height := 100
	width := 30
	speed := 2
	pipe := utils.TextureFromFile("./pipe.png")
	rim := utils.TextureFromFile("./rim.png")

	return &Pipe{
		screenWidth, y,
		height,
		width,
		screenHeight,
		speed,
		false,
		pipe,
		rim,
	}
}
Пример #2
0
func NewBird(x, y int) *Bird {
	texFile := "./head.png"
	t := utils.TextureFromFile(texFile)
	return &Bird{
		x, y,
		40, 40,
		3,
		t,
	}
}
Пример #3
0
func main() {
	sdl.Init(sdl.INIT_VIDEO)
	ttf.Init()
	screen := sdl.SetVideoMode(480, 560, 16, sdl.OPENGL|sdl.RESIZABLE)
	sdl.WM_SetCaption("Flappy Bird", "")
	bg := utils.TextureFromFile("./bg.png")
	font := utils.LoadFont("/usr/share/fonts/truetype/DroidSans.ttf", 32)
	reshape(int(screen.W), int(screen.H))

	renderBackground(screen, bg)
	font.Printf(110, 50, "Click to play")
	sdl.GL_SwapBuffers()
	for {
	OuterLoop:
		for {
			e := sdl.WaitEvent()
			switch e.(type) {
			case *sdl.MouseButtonEvent:
				if e.(*sdl.MouseButtonEvent).Type == sdl.MOUSEBUTTONUP {
					break OuterLoop
				}
			}
		}

		score, quit := playGame(screen, bg, font)
		if quit {
			break
		}

		quit = gameOverScreen(screen, strconv.Itoa(score), bg, font)
		if quit {
			break
		}
	}

	screen.Free()
	ttf.Quit()
	sdl.Quit()
	return
}