示例#1
0
func main() {

	paunch.SetWindowSize(640, 480)
	paunch.SetWindowTitle("Use the arrow keys to move the object!")

	err := paunch.Start()
	if err != nil {
		panic(err)
	}
	defer paunch.Stop()

	effect, err = paunch.NewEffectFromDirectory("./shader/")
	if err != nil {
		panic(err)
	}
	paunch.UseEffect(effect)

	player := NewPlayer(288, 208)

	eventManager = paunch.NewEventManager()
	eventManager.Objects = []interface{}{&player} // Add the Player object to the EventManager's object list.
	eventManager.GetUserEvents(true)              // Set the EventManager to automatically respond to user events.

	lastFrame := time.Now()

	for !paunch.ShouldClose() {

		effect.SetVariable2f("screen_size", 640, 480)
		effect.SetVariablei("tex_id", 0)

		paunch.Clear()

		// Only check for events 1/60th of a second. This operation is not
		// Paunch-specific, but effectively limits the physics framerate to
		// 60 FPS.
		if time.Since(lastFrame).Seconds() >= (1.0 / 60.0) {
			lastFrame = time.Now()
			paunch.UpdateEvents()
		}

		// Has the EventManager run a draw event, which calls the OnDraw
		// methods of it's objects.
		eventManager.RunDrawEvent()

		paunch.UpdateDisplay()
	}
}
示例#2
0
func main() {

	paunch.SetWindowSize(640, 480)
	paunch.SetWindowTitle("Test Window")

	err := paunch.Start()
	if err != nil {
		panic(err)
	}
	defer paunch.Stop()

	// Create an Effect object using the GLSL shader files found in the shader
	// directory
	effect, err = paunch.NewEffectFromDirectory("./shader/")
	if err != nil {
		panic(err)
	}
	paunch.UseEffect(effect) // Set the Effect object to be used

	// Create a new Sprite object for drawing test.png at x=288 y=208
	image, err = paunch.NewSpriteFromImage(288, 208, "./test.png", 1)
	if err != nil {
		panic(err)
	}

	for !paunch.ShouldClose() {

		// Send the necessary parameters to the GLSL shaders before drawing
		effect.SetVariable2f("screen_size", 640, 480)
		effect.SetVariablei("tex_id", 0)

		// Clear the screen of the last frame so that the new frame can be
		// drawn.
		paunch.Clear()

		// Draws the Sprite object
		image.Draw(0)

		paunch.UpdateDisplay()
		paunch.UpdateEvents()
	}
}
示例#3
0
文件: window.go 项目: velovix/paunch
func main() {

	// Sets some parameters for the window
	paunch.SetWindowSize(640, 480)
	paunch.SetWindowTitle("Test Window")

	// Starts Paunch, initializing things and opening the window
	err := paunch.Start()
	if err != nil {
		panic(err)
	}
	defer paunch.Stop()

	// Runs for as long as Paunch does not recieve a "close event" (i.e. if the
	// user attempts to close the window)
	for !paunch.ShouldClose() {

		// Updates the display and checks for events
		paunch.UpdateDisplay()
		paunch.UpdateEvents()
	}
}