Ejemplo n.º 1
0
func (is *IntroState) buildScene() {
	am := is.assetManager // asset manager

	rootEntity := scenegraph.NewEntity(nil)
	rootEntity.W = gamecontext.GContext.MainSurface.W
	rootEntity.H = gamecontext.GContext.MainSurface.H

	titleEntity := scenegraph.NewEntity(am.Surfaces["titleText"])

	mColor := is.fontNormalColor
	mHiColor := is.fontHighlightColor

	menuItems := []menu.Item{
		{AssetFontID: "menuFont", Text: "Play!", Color: mColor, HiColor: mHiColor},
		{AssetFontID: "menuFont", Text: "Quit", Color: mColor, HiColor: mHiColor},
	}

	is.menu = menu.New(am, "introMenu", menuItems, 60, menu.MenuJustifyCenter)

	scenegraph.CenterEntityInParent(is.menu.RootEntity, rootEntity)
	is.menu.RootEntity.Y = 200

	rootEntity.AddChild(titleEntity, is.menu.RootEntity)

	is.rootEntity = rootEntity

	// position title
	scenegraph.CenterEntityInSurface(titleEntity, gamecontext.GContext.MainSurface)
	titleEntity.Y = 40

}
Ejemplo n.º 2
0
// newEgg creates a new egg and adds it to the egg container
func (ps *PlayState) newEgg() *scenegraph.Entity {
	egg := scenegraph.NewEntity(ps.assetManager.Surfaces["eggImage"])
	egg.Visible = false
	ps.eggContainer.AddChild(egg)

	return egg
}
Ejemplo n.º 3
0
// Construct the pause menu
func (ps *PlayState) buildPauseMenu() {
	am := ps.assetManager // asset manager

	mainW := gamecontext.GContext.MainSurface.W
	mainH := gamecontext.GContext.MainSurface.H

	// Build pause menu shade background
	pauseBGSurface, err := util.MakeFillSurfaceAlpha(mainW, mainH, 0, 0, 0, 127)
	if err != nil {
		panic(fmt.Sprintf("Pause bgSurface: %v", err))
	}

	ps.pauseMenuEntity = scenegraph.NewEntity(pauseBGSurface)
	ps.pauseMenuEntity.Visible = false

	// Build pause menu
	mColor := ps.fontNormalColor
	mHiColor := ps.fontHighlightColor

	menuItems := []menu.Item{
		{AssetFontID: "menuFont", Text: "Return to Game", Color: mColor, HiColor: mHiColor},
		{AssetFontID: "menuFont", Text: "Main Menu", Color: mColor, HiColor: mHiColor},
	}

	ps.menu = menu.New(am, "playMenu", menuItems, 60, menu.MenuJustifyCenter)

	ps.menu.RootEntity.Y = 200

	ps.pauseMenuEntity.AddChild(ps.menu.RootEntity)
}
Ejemplo n.º 4
0
// New constructs the menu
func New(am *assetmanager.AssetManager, id string, items []Item, spacing int32, justification int) *Menu {
	// TODO: do these even need to be registered with any asset manager? just use util.RenderText?
	menu := &Menu{items: items, spacing: spacing, justification: justification}

	menuEntity := scenegraph.NewEntity(nil)

	maxH := int32(0)
	maxW := int32(0)

	idNum := 0

	for i, item := range menu.items {
		var err error
		var surface, surfaceHi *sdl.Surface
		var entity, entityHi *scenegraph.Entity

		if surface, err = am.RenderText(fmt.Sprintf("%s-%d", id, idNum), item.AssetFontID, item.Text, item.Color); err != nil {
			panic(fmt.Sprintf("Menu render font: %v", err))
		}

		idNum++

		if surfaceHi, err = am.RenderText(fmt.Sprintf("%s-%d", id, idNum), item.AssetFontID, item.Text, item.HiColor); err != nil {
			panic(fmt.Sprintf("Intro render font: %v", err))
		}

		idNum++

		entity = scenegraph.NewEntity(surface)
		entity.Visible = i > 0
		entityHi = scenegraph.NewEntity(surfaceHi)
		entityHi.Visible = i == 0

		menuEntity.AddChild(entity, entityHi)

		if entity.W > maxW {
			maxW = entity.W
		}

		entity.Y = maxH
		entityHi.Y = maxH

		maxH += menu.spacing
	}

	menuEntity.W = maxW
	menuEntity.H = maxH

	// position everything now that we have sizes known
	for i := range menu.items {

		entity := menuEntity.GetChild(i * 2)
		entityHi := menuEntity.GetChild(i*2 + 1)

		switch menu.justification {
		case MenuJustifyLeft:
			entity.X = 0
			entityHi.X = 0
		case MenuJustifyCenter:
			scenegraph.CenterEntityInParent(entity, menuEntity)
			scenegraph.CenterEntityInParent(entityHi, menuEntity)
		case MenuJustifyRight:
			scenegraph.RightJustifyEntityInParent(entity, menuEntity)
			scenegraph.RightJustifyEntityInParent(entityHi, menuEntity)
		}
	}

	menu.RootEntity = menuEntity

	return menu
}