예제 #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
}
예제 #2
0
파일: gui.go 프로젝트: losinggeneration/hge
func (g GUI) GetCtrl(id int) *GUIObject {
	e := elementById(id, g.ctrls)

	if e == nil {
		hge.New().Log("No such GUI ctrl id (%d)", id)
		return nil
	}

	return e.Value.(*GUIObject)
}
예제 #3
0
func NewStream(filename string, size hge.Dword) *Stream {
	fname := C.CString(filename)
	defer C.free(unsafe.Pointer(fname))

	s := new(Stream)
	s.soundHGE = hge.New()
	s.stream = C.HGE_Stream_Load(s.soundHGE.HGE, fname, C.DWORD(size))

	runtime.SetFinalizer(s, func(stream *Stream) {
		stream.Free()
	})

	return s
}
예제 #4
0
func NewMusic(filename string, size hge.Dword) *Music {
	fname := C.CString(filename)
	defer C.free(unsafe.Pointer(fname))

	m := new(Music)
	m.soundHGE = hge.New()
	m.music = C.HGE_Music_Load(m.soundHGE.HGE, fname, C.DWORD(size))

	runtime.SetFinalizer(m, func(music *Music) {
		music.Free()
	})

	return m
}
예제 #5
0
func main() {
	h := hge.New()
	h.SetState(hge.LOGFILE, "tutorial01.log")
	h.SetState(hge.FRAMEFUNC, FrameFunc)
	h.SetState(hge.TITLE, "HGE Tutorial 01 - Minimal HGE application")
	h.SetState(hge.WINDOWED, true)
	h.SetState(hge.USESOUND, false)

	h.Log("Test")
	h.Log("Test vararg: %s %d", "test", 15)

	if err := h.Initiate(); err != nil {
		fmt.Fprintln(os.Stderr, "Error: ", err)
	} else {
		defer h.Shutdown()
		h.Log("Test")
		h.Log("Test vararg: %s %d", "test", 15)
		h.Start()
	}

	h.Log("Test")
}
예제 #6
0
func NewEffect(filename string, a ...interface{}) *Effect {
	fname := C.CString(filename)
	defer C.free(unsafe.Pointer(fname))

	size := hge.Dword(0)

	if len(a) == 1 {
		if s, ok := a[0].(hge.Dword); ok {
			size = s
		}
	}

	e := new(Effect)
	e.soundHGE = hge.New()
	e.effect = C.HGE_Effect_Load(e.soundHGE.HGE, fname, C.DWORD(size))

	runtime.SetFinalizer(e, func(effect *Effect) {
		effect.Free()
	})

	return e
}
예제 #7
0
func init() {
	resourceHGE = hge.New()
}
예제 #8
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()
	}

}
예제 #9
0
func New(filename string) *StringTable {
	st := new(StringTable)
	h := hge.New()

	st.stringsMap = make(map[string]string)

	f := LoadString(filename)

	if f == nil || !strings.HasPrefix(*f, strHEADERTAG) {
		h.Log(strFORMATERROR, filename)
		return nil
	}

	var (
		inComment, inIdentifier, inValue bool
		identifier, value                string
	)

	reader := strings.NewReader(*f)
	_, e := reader.Seek(int64(len(strHEADERTAG)), 0)

	if e != nil {
		h.Log("Unable to seek past header tag")
		return nil
	}

	for b, e := reader.ReadByte(); e == nil; b, e = reader.ReadByte() {
		// we ignore whitespace
		if b == '\n' {
			inComment = false
			inIdentifier = false
			continue
		}

		// just continue if we're in a comment
		if inComment {
			continue
		}

		if inIdentifier {
			// break from the identifier when we get to whitespace
			if b == ' ' {
				inIdentifier = false
				continue
			}
			identifier += string(b)
			continue
		}

		if inValue {
			// We've found a backslash, figure out what to do with it
			if b == '\\' {
				// We need the next byte
				b, e = reader.ReadByte()
				if e != nil {
					// but break on an error
					break
				}

				switch b {
				case 'n':
					// insert a literal \n as the value
					value += "\\n"
				case '"':
					// insert a literal " as the value
					value += "\""
				case '\\':
					// insert a literal \ in the value
					value += "\\"
				default:
					// we don't have a special backslash, so just put a
					// backslash and the byte
					value += "\\" + string(b)
				}
				continue
			}

			// We've found the end of the value
			if b == '"' {
				// So assign it to the stringsMap
				st.stringsMap[identifier] = value
				// clear the identifier and value
				identifier, value = "", ""
				inValue = false
				continue
			}
			value += string(b)
			continue
		}

		// We found a comment
		if b == ';' {
			inComment = true
			continue
		}

		// ignore whitespace around identifiers and values
		if b == ' ' {
			continue
		}

		// start of an identifier (an identifier starts with a letter and has
		// any other character in it's name except whitespace)
		if (b > 'a' && b < 'z') || (b > 'A' && b < 'Z') {
			identifier = string(b)
			inIdentifier = true
		}

		// We search until we find the start of the value
		if b == '=' {
			for b, e := reader.ReadByte(); e == nil; b, e = reader.ReadByte() {
				// This means we've found the start of the value
				if b == '"' {
					inValue = true
					break
				}
			}
		}
	}

	return st
}
예제 #10
0
파일: gfx.go 프로젝트: losinggeneration/hge
func init() {
	gfxHGE = hge.New()
}
예제 #11
0
func New(seed int) *Rand {
	return &Rand{seed, hge.New()}
}
예제 #12
0
파일: hge.go 프로젝트: losinggeneration/hge
// Creates a new instance of an HGE structure
func Create(ver int) *HGE {
	return &HGE{hge.New()}
}
예제 #13
0
func init() {
	inputHGE = hge.New()
}
예제 #14
0
파일: ini.go 프로젝트: losinggeneration/hge
func NewIni(section, name string) Ini {
	return Ini{section, name, hge.New()}
}
예제 #15
0
func init() {
	timerHGE = hge.New()
}
예제 #16
0
// Pause all sounds on all channels
func PauseAll() {
	C.HGE_Channel_PauseAll(hge.New().HGE)
}
예제 #17
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()
	}
}
예제 #18
0
// Resume all sounds on all channels
func ResumeAll() {
	C.HGE_Channel_ResumeAll(hge.New().HGE)
}
예제 #19
0
// Stop all sounds on all channels
func StopAll() {
	C.HGE_Channel_StopAll(hge.New().HGE)
}
예제 #20
0
func New(filename string, sprite sprite.Sprite, a ...interface{}) *ParticleSystem {
	ps := new(ParticleSystem)
	if len(a) == 1 {
		if fps, ok := a[0].(float64); ok {
			if fps != 0.0 {
				ps.updateSpeed = 1.0 / fps
			}
		}
	}

	ps.h = hge.New()
	ps.rand = rand.New(int(timer.Time()))
	ps.rand.Seed()

	ptr := resource.LoadBytes(filename)

	if ptr == nil {
		ps.h.Log("Particle file (%s) seems to be empty.", filename)
		return nil
	}

	// skip the first four bytes
	i := uintptr(4)

	// Ok, First we reflect the ParticleSystemInfo struct
	s := reflect.ValueOf(&ps.Info).Elem()

	// Then we loop through each element, skipping sprite for obvious reasons
	for j := 1; j < s.NumField(); j++ {
		// Then we get the field of the struct
		f := s.Field(j)

		// Here we examine the type
		switch f.Type().String() {
		case "float64":
			// Then we set the structure's field to the value at the current
			// byte(s)
			// We cast the value pointed to by the ptr[i] with unsafe.Pointer
			f.SetFloat(float64(*(*float32)(cast(&ptr[i]))))
			// Next we skip ahead based on the size of the data read
			i += unsafe.Sizeof(float32(0.0))

		case "int":
			f.SetInt(int64(*(*int32)(cast(&ptr[i]))))
			i += unsafe.Sizeof(int32(0))

		case "bool":
			f.SetBool(*(*bool)(cast(&ptr[i])))
			i += unsafe.Sizeof(bool(false))
			i += 3 // padding

		case "color.ColorRGB":
			for k := 0; k < 4; k++ {
				f.Field(k).SetFloat(float64(*(*float32)(cast(&ptr[i]))))
				i += unsafe.Sizeof(float32(0.0))
			}
		}
	}

	ps.Info.Sprite = sprite
	ps.age = -2.0

	ps.particles = make([]particle, hgeMAX_PARTICLES+1)

	return ps
}
예제 #21
0
func New(filename string, arg ...interface{}) *Font {
	mipmap := false

	if len(arg) == 1 {
		if m, ok := arg[0].(bool); ok {
			mipmap = m
		}
	}

	f := new(Font)

	h := hge.New()

	f.scale, f.proportion = 1.0, 1.0
	f.spacing = 1.0

	f.z = 0.5
	f.blend = gfx.BLEND_COLORMUL | gfx.BLEND_ALPHABLEND | gfx.BLEND_NOZWRITE
	f.color = 0xFFFFFFFF

	desc := resource.LoadString(filename)

	if desc == nil {
		h.Log("Font %s seems to be empty.", filename)
		return nil
	}

	lines := getLines(*desc)

	if len(lines) == 0 || lines[0] != fntHEADERTAG {
		h.Log("Font %s has incorrect format.", filename)
		return nil
	}

	// parse the font description
	for _, line := range lines {
		if line == fntHEADERTAG {
			continue
		}

		option, value, err := tokenizeLine(line)

		if err != nil || len(line) == 0 || len(option) == 0 || len(value) == 0 {
			h.Log("Unreadable line (%s) in font file: %s", line, filename)
			continue
		}

		if option == fntBITMAPTAG {
			f.texture = gfx.LoadTexture(value, 0, mipmap)
		} else if option == fntCHARTAG {
			chr, x, y, w, h, a, c := tokenizeChar(value)

			sprt := sprite.New(f.texture, x, y, w, h)

			f.letters[chr] = &sprt
			f.pre[chr] = a
			f.post[chr] = c
			f.height = h
		}
	}

	return f
}