示例#1
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)
}
示例#2
0
// renderJSONRects renders rectangles specified in the JSON assets file
func (am *AssetManager) renderJSONRects(jsonFile string, data interface{}) {
	var err error

	rectsArray := data.([]interface{})
	var color *sdl.Color

	for _, v := range rectsArray {
		rectInfo := v.(map[string]interface{})

		id, ok := rectInfo["Id"].(string)
		if !ok {
			loadJSONPanic(jsonFile, "", "Rect missing Id")
		}

		rgba, ok := rectInfo["Rgba"].([]interface{})
		if len(rgba) == 4 {
			color, err = sdlColorFromInterfaceArray(rgba)
		}
		if !ok || len(rgba) != 4 || err != nil {
			loadJSONPanic(jsonFile, id, "Rgba needs to be in form [R,G,B,A], 0-255 for each element")
		}

		var width, height int32

		width = am.ParseDimension(jsonFile, id, "W", rectInfo)
		height = am.ParseDimension(jsonFile, id, "H", rectInfo)

		surface, err := util.MakeFillSurfaceAlpha(width, height, color.R, color.G, color.B, color.A)
		if err != nil {
			loadJSONPanic(jsonFile, id, fmt.Sprintf("Error making rect: %v", err))
		}

		am.AddSurface(id, surface)
	}
}