Example #1
0
func InitSimulation() bool {
	// Load texture
	texObjects = LoadTexture("objects.png")
	if texObjects == nil {
		return false
	}

	rand = New(0)

	// Create sprites
	sky = sprite.New(nil, 0, 0, SCREEN_WIDTH, SKY_HEIGHT)
	sea = dist.New(SEA_SUBDIVISION, SEA_SUBDIVISION)
	sea.SetTextureRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-SKY_HEIGHT)

	sun = sprite.New(texObjects, 81, 0, 114, 114)
	sun.SetHotSpot(57, 57)
	moon = sprite.New(texObjects, 0, 0, 81, 81)
	moon.SetHotSpot(40, 40)
	star = sprite.New(texObjects, 72, 81, 9, 9)
	star.SetHotSpot(5, 5)

	glow = sprite.New(texObjects, 128, 128, 128, 128)
	glow.SetHotSpot(64, 64)
	glow.SetBlendMode(BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_NOZWRITE)
	seaglow = sprite.New(texObjects, 128, 224, 128, 32)
	seaglow.SetHotSpot(64, 0)
	seaglow.SetBlendMode(BLEND_COLORADD | BLEND_ALPHAADD | BLEND_NOZWRITE)

	// Initialize simulation state
	colWhite.SetHWColor(0xFFFFFFFF)
	timet = GetTime()
	speed = 0.0

	for i := 0; i < NUM_STARS; i++ { // star positions
		starX[i] = rand.Float64(0, SCREEN_WIDTH)
		starY[i] = rand.Float64(0, STARS_HEIGHT)
		starS[i] = rand.Float64(0.1, 0.7)
	}

	for i := 0; i < SEA_SUBDIVISION; i++ { // sea waves phase shifts
		seaP[i] = float64(i) + rand.Float64(-15.0, 15.0)
	}

	// Systems are ready now!
	return true
}
Example #2
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()
	}
}