Beispiel #1
0
func main() {
	h := hge.New()

	// Set desired system states and initialize HGE
	h.SetState(hge.LOGFILE, "tutorial08.log")
	h.SetState(hge.FRAMEFUNC, frame)
	h.SetState(hge.RENDERFUNC, render)
	h.SetState(hge.TITLE, "HGE Tutorial 08 - The Big Calm")
	h.SetState(hge.USESOUND, false)
	h.SetState(hge.WINDOWED, true)
	h.SetState(hge.SCREENWIDTH, SCREEN_WIDTH)
	h.SetState(hge.SCREENHEIGHT, SCREEN_HEIGHT)
	h.SetState(hge.SCREENBPP, 32)

	if err := h.Initiate(); err == nil {
		defer h.Shutdown()

		fnt = font.New("font1.fnt")

		if !InitSimulation() {
			// If one of the data files is not found, display an error message and shutdown
			fmt.Println("Error: Can't load resources. See log for details.\n")
			return
		}

		h.Start()
	}

	return
}
Beispiel #2
0
func main() {
	h = hge.Create(VERSION)
	defer h.Release()

	// Set desired system states and initialize HGE
	h.System_SetState(LOGFILE, "tutorial07.log")
	h.System_SetState(FRAMEFUNC, frame)
	h.System_SetState(RENDERFUNC, render)
	h.System_SetState(TITLE, "HGE Tutorial 07 - Thousand of Hares")
	h.System_SetState(USESOUND, false)
	h.System_SetState(WINDOWED, true)
	h.System_SetState(SCREENWIDTH, SCREEN_WIDTH)
	h.System_SetState(SCREENHEIGHT, SCREEN_HEIGHT)
	h.System_SetState(SCREENBPP, 32)

	if h.System_Initiate() {
		defer h.System_Shutdown()
		// Load textures
		bgtex = h.Texture_Load("bg2.png")
		tex = h.Texture_Load("zazaka.png")
		if bgtex == nil || tex == nil {
			fmt.Println("Error: Can't load bg2.png or zazaka.png\n")
			return
		}
		// Delete created objects and free loaded resources
		defer h.Texture_Free(tex)
		defer h.Texture_Free(bgtex)

		// Load font, create sprites
		fnt = font.New("font1.fnt")
		spr = sprite.New(tex, 0, 0, 64, 64)
		spr.SetHotSpot(32, 32)

		bgspr = sprite.New(bgtex, 0, 0, 800, 600)
		bgspr.SetBlendMode(BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_NOZWRITE)
		bgspr.SetColor(0xFF000000, 0)
		bgspr.SetColor(0xFF000000, 1)
		bgspr.SetColor(0xFF000040, 2)
		bgspr.SetColor(0xFF000040, 3)

		// Initialize objects list
		objects = 1000

		for i := 0; i < MAX_OBJECTS; i++ {
			objs[i].x = h.Random_Float(0, SCREEN_WIDTH)
			objs[i].y = h.Random_Float(0, SCREEN_HEIGHT)
			objs[i].dx = h.Random_Float(-200, 200)
			objs[i].dy = h.Random_Float(-200, 200)
			objs[i].scale = h.Random_Float(0.5, 2.0)
			objs[i].dscale = h.Random_Float(-1.0, 1.0)
			objs[i].rot = h.Random_Float(0, Pi*2)
			objs[i].drot = h.Random_Float(-1.0, 1.0)
		}

		setBlend(0)

		// Let's rock now!
		h.System_Start()
	}
}
Beispiel #3
0
func main() {
	h := New()
	defer h.Free()

	h.SetState(LOGFILE, "tutorial05.log")
	h.SetState(FRAMEFUNC, FrameFunc)
	h.SetState(RENDERFUNC, RenderFunc)
	h.SetState(TITLE, "HGE Tutorial 05 - Using distortion mesh")
	h.SetState(WINDOWED, true)
	h.SetState(SCREENWIDTH, 800)
	h.SetState(SCREENHEIGHT, 600)
	h.SetState(SCREENBPP, 32)
	h.SetState(USESOUND, false)

	if err := h.Initiate(); err == nil {
		defer h.Shutdown()
		tex = LoadTexture("texture.jpg")
		if tex == nil {
			fmt.Println("Error: Can't load texture.jpg")
			return
		}
		defer tex.Free()

		dis = dist.New(cols, rows)
		dis.SetTexture(tex)
		dis.SetTextureRect(0, 0, 512, 512)
		dis.SetBlendMode(BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_ZWRITE)
		dis.Clear(Dword(0xFF000000))

		// Load a font
		fnt = font.New("font1.fnt")

		if fnt == nil {
			fmt.Println("Error: Can't load font1.fnt or font1.png")
			return
		}

		// Let's rock now!
		h.Start()
	}
}
Beispiel #4
0
func main() {
	h := hge.New()
	h.SetState(hge.LOGFILE, "tutorial06.log")
	h.SetState(hge.FRAMEFUNC, frame)
	h.SetState(hge.RENDERFUNC, render)
	h.SetState(hge.TITLE, "HGE Tutorial 06 - Creating menus")
	h.SetState(hge.WINDOWED, true)
	h.SetState(hge.SCREENWIDTH, 800)
	h.SetState(hge.SCREENHEIGHT, 600)
	h.SetState(hge.SCREENBPP, 32)

	if err := h.Initiate(); err != nil {
		fmt.Println("Error: ", h.GetErrorMessage())
	} else {
		defer h.Shutdown()

		quad.Texture = LoadTexture("bg.png")

		if quad.Texture == nil {
			fmt.Println("Error loading bg.png")
			return
		}

		snd := NewEffect("menu.ogg")

		if snd == nil {
			fmt.Println("Error loading menu.ogg")
			return
		}

		cursorTex := LoadTexture("cursor.png")

		if cursorTex == nil {
			fmt.Println("Error loading cursor.png")
			return
		}

		// Set up the quad we will use for background animation
		quad.Blend = BLEND_ALPHABLEND | BLEND_COLORMUL | BLEND_NOZWRITE

		for i := 0; i < 4; i++ {
			// Set up z-coordinate of vertices
			quad.V[i].Z = 0.5
			// Set up color. The format of DWORD col is 0xAARRGGBB
			quad.V[i].Color = 0xFFFFFFFF
		}

		quad.V[0].X, quad.V[0].Y = 0, 0
		quad.V[1].X, quad.V[1].Y = 800, 0
		quad.V[2].X, quad.V[2].Y = 800, 600
		quad.V[3].X, quad.V[3].Y = 0, 600

		fnt = font.New("font1.fnt")

		if fnt == nil {
			fmt.Println("Error loading font1.fnt")
			return
		}

		cursor := sprite.New(cursorTex, 0, 0, 32, 32)
		GUI = gui.New()

		GUI.AddCtrl(NewGUIMenuItem(1, fnt, snd, 400, 200, 0.0, "Play"))
		GUI.AddCtrl(NewGUIMenuItem(2, fnt, snd, 400, 240, 0.1, "Options"))
		GUI.AddCtrl(NewGUIMenuItem(3, fnt, snd, 400, 280, 0.2, "Instructions"))
		GUI.AddCtrl(NewGUIMenuItem(4, fnt, snd, 400, 320, 0.3, "Credits"))
		GUI.AddCtrl(NewGUIMenuItem(5, fnt, snd, 400, 360, 0.4, "Exit"))

		GUI.SetNavMode(gui.GUI_UPDOWN | gui.GUI_CYCLED)
		GUI.SetCursor(&cursor)
		GUI.SetFocus(1)
		GUI.Enter()

		h.Start()
	}

}
Beispiel #5
0
// An example of using closures
func main() {
	func() {
		const (
			speed    = 90.0
			friction = 0.98
		)

		var (
			spr sprite.Sprite
			fnt *font.Font
			par *particle.ParticleSystem

			snd *Effect

			x  = 100.0
			y  = 100.0
			dx = 0.0
			dy = 0.0
		)

		hge := New()

		hge.SetState(LOGFILE, "tutorial03.log")
		hge.SetState(TITLE, "HGE Tutorial 03 - Using helper classes")
		hge.SetState(FPS, 100)
		hge.SetState(WINDOWED, true)
		hge.SetState(SCREENWIDTH, 800)
		hge.SetState(SCREENHEIGHT, 600)
		hge.SetState(SCREENBPP, 32)
		hge.SetState(FRAMEFUNC, func() int {
			dt := float64(Delta())

			boom := func() {
				pan := int((x - 400) / 4)
				pitch := (dx*dx+dy*dy)*0.0005 + 0.2
				snd.PlayEx(100, pan, pitch)
			}

			// Process keys
			if NewKey(K_ESCAPE).State() {
				return 1
			}
			if NewKey(K_LEFT).State() {
				dx -= speed * dt
			}
			if NewKey(K_RIGHT).State() {
				dx += speed * dt
			}
			if NewKey(K_UP).State() {
				dy -= speed * dt
			}
			if NewKey(K_DOWN).State() {
				dy += speed * dt
			}

			// Do some movement calculations and collision detection
			dx *= friction
			dy *= friction
			x += dx
			y += dy
			if x > 784 {
				x = 784 - (x - 784)
				dx = -dx
				boom()
			}
			if x < 16 {
				x = 16 + 16 - x
				dx = -dx
				boom()
			}
			if y > 584 {
				y = 584 - (y - 584)
				dy = -dy
				boom()
			}
			if y < 16 {
				y = 16 + 16 - y
				dy = -dy
				boom()
			}

			// Update particle system
			par.Info.Emission = (int)(dx*dx+dy*dy) * 2
			par.MoveTo(x, y)
			par.Update(dt)

			return 0
		})

		hge.SetState(RENDERFUNC, func() int {
			BeginScene()
			Clear(0)
			par.Render()
			spr.Render(x, y)
			fnt.Printf(5, 5, font.TEXT_LEFT, "dt:%.3f\nFPS:%d (constant)", Delta(), GetFPS())
			EndScene()

			return 0
		})

		if err := hge.Initiate(); err == nil {
			defer hge.Shutdown()

			snd = NewEffect("menu.ogg")
			tex := LoadTexture("particles.png")
			if snd == nil || tex == nil {
				fmt.Printf("Error: Can't load one of the following files:\nmenu.ogg, particles.png, font1.fnt, font1.png, trail.psi\n")
				return
			}

			spr = sprite.New(tex, 96, 64, 32, 32)
			spr.SetColor(0xFFFFA000)
			spr.SetHotSpot(16, 16)

			if fnt = font.New("font1.fnt"); fnt == nil {
				fmt.Println("Error loading font1.fnt")
				return
			}

			spt := sprite.New(tex, 32, 32, 32, 32)
			spt.SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE)
			spt.SetHotSpot(16, 16)

			par = particle.New("trail.psi", spt)
			if par == nil {
				fmt.Println("Error loading trail.psi")
				return
			}
			par.Fire()

			hge.Start()
		}
	}()

	for i := 0; i < 10; i++ {
		fmt.Println("Sleeping")
		time.Sleep(1 * time.Second)
		runtime.GC()
	}
}
Beispiel #6
0
func main() {
	h := hge.New()

	h.SetState(hge.LOGFILE, "tutorial04.log")
	h.SetState(hge.FRAMEFUNC, FrameFunc)
	h.SetState(hge.RENDERFUNC, RenderFunc)
	h.SetState(hge.GFXRESTOREFUNC, RestoreFunc)
	h.SetState(hge.TITLE, "HGE Tutorial 04 - Using render targets")
	h.SetState(hge.FPS, 100)
	h.SetState(hge.WINDOWED, true)
	h.SetState(hge.SCREENWIDTH, 800)
	h.SetState(hge.SCREENHEIGHT, 600)
	h.SetState(hge.SCREENBPP, 32)

	if err := h.Initiate(); err == nil {
		defer h.Shutdown()
		snd = NewEffect("menu.ogg")
		tex = LoadTexture("particles.png")
		if snd == nil || tex == nil {
			// If one of the data files is not found, display
			// an error message and shutdown.
			fmt.Printf("Error: Can't load one of the following files:\nmenu.ogg, particles.png, font1.fnt, font1.png, trail.psi\n")
			return
		}

		// Delete created objects and free loaded resources
		defer snd.Free()
		defer tex.Free()

		spr = sprite.New(tex, 96, 64, 32, 32)
		spr.SetColor(0xFFFFA000)
		spr.SetHotSpot(16, 16)

		fnt = font.New("font1.fnt")

		if fnt == nil {
			fmt.Println("Error: Can't load font1.fnt or font1.png")
			return
		}

		spt = sprite.New(tex, 32, 32, 32, 32)
		spt.SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE)
		spt.SetHotSpot(16, 16)
		par = particle.New("trail.psi", spt)

		if par == nil {
			fmt.Println("Error: Cannot load trail.psi")
			return
		}
		par.Fire()

		// Create a render target and a sprite for it
		target = NewTarget(512, 512, false)
		defer target.Free()
		tar = sprite.New(target.Texture(), 0, 0, 512, 512)
		tar.SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE)

		// Let's rock now!
		h.Start()
	}
}