Exemplo n.º 1
0
func main() {
	gotAttrs, initAttrs := console.GetScreenBufferInfo()
	if gotAttrs {
		defer console.SetScreenBufferInfo(initAttrs)
	}

	rCon := setup()
	console.SetCursorProperties(1, false)
	console.ClearScreen(80, 25)

	sprite := new(rc.Sprite)
	sprite.X = 4
	sprite.Y = 3

	spriteChars := rc.StringToArray(2, 2, "SSS ")
	rc.Replace(&spriteChars, ' ', rc.TransparancyChar)
	spriteColors := rc.FillArrayI(2, 2, console.ChFgCyan)
	spriteColors[0][1] = console.ChFgGreen | console.ChBgDarkMagenta
	sprite.SetGraphics(spriteChars, spriteColors)

	rCon.RegisterSprite(sprite, 0)

	rCon.Draw()

	for {
		isHit, char := console.GetKey()
		if isHit {

			char = strings.ToLower(char)
			switch char {
			case "w":
				if sprite.Y > 0 {
					sprite.Y--
				}
			case "a":
				if sprite.X > 0 {
					sprite.X--
				}
			case "s":
				if sprite.Y < rCon.EnvHeight {
					sprite.Y++
				}
			case "d":
				if sprite.X < rCon.EnvWidth {
					sprite.X++
				}
			case "q":
				return
			}

			rCon.Draw()
		}
	}
}
Exemplo n.º 2
0
func (btn *Button) draw() {
	btn.sprite.X = btn.x
	btn.sprite.Y = btn.y

	rectWidth := len(btn.text) + (btn.xPadding * 2)
	rectHeight := (btn.yPadding * 2) + 1

	//+1 for the shadow
	rBuffer := rc.FillArrayR(rectWidth+1, rectHeight+1, rc.TransparancyChar)
	cBuffer := rc.FillArrayI(rectWidth+1, rectHeight+1, 0)

	//draw the shadow
	if !btn.isPressed {
		for i := 1; i <= rectWidth; i++ {
			rBuffer[rectHeight][i] = ' '
			cBuffer[rectHeight][i] = btn.shadowColor
		}

		for i := 1; i <= rectHeight; i++ {
			rBuffer[i][rectWidth] = ' '
			cBuffer[i][rectWidth] = btn.shadowColor
		}
	}

	//draw the box
	rectOffset := 0
	if btn.isPressed {
		rectOffset = 1
	}

	fgColor := btn.enabledTextColor
	bgColor := btn.enabledBgColor

	if btn.hasFocus {
		bgColor = btn.focusedBGColor
	}

	if !btn.isEnabled {
		fgColor = btn.disabledTextColor
		bgColor = btn.disabledBgColor
	}

	rectColor := fgColor | bgColor

	for row := 0; row < rectHeight; row++ {
		for col := 0; col < rectWidth; col++ {
			rBuffer[row+rectOffset][col+rectOffset] = ' '
			cBuffer[row+rectOffset][col+rectOffset] = rectColor
		}
	}

	textRow := btn.yPadding + rectOffset
	textIndent := btn.xPadding + rectOffset
	textSlice := []rune(btn.text)

	for i := 0; i < len(textSlice); i++ {
		rBuffer[textRow][textIndent+i] = textSlice[i]
	}

	btn.sprite.SetGraphics(rBuffer, cBuffer)
	btn.owner.InvalidateVisual()
}
Exemplo n.º 3
0
func setup() *rc.RogueConsole {
	con := rc.NewRogueConsole(25, 9, 25, 9)

	redArray := rc.FillArrayI(25, 9, console.ChFgRed)
	greenArray := rc.FillArrayI(25, 9, console.ChFgGreen)
	blueArray := rc.FillArrayI(25, 9, console.ChFgBlue)
	yellowArray := rc.FillArrayI(25, 9, console.ChFgYellow)

	bg1 := rc.StringToArray(25, 9,
		"┌───────────────────────┐"+
			"│                       │"+
			"│                       │"+
			"│                       │"+
			"│                       │"+
			"│                       │"+
			"│                       │"+
			"│                       │"+
			"└───────────────────────┘")

	bg2 := rc.StringToArray(25, 9,
		"                         "+
			"                         "+
			"  /─\\                    "+
			"  \\─/                    "+
			"                         "+
			"          1234           "+
			"                         "+
			"                         "+
			"                         ")

	fg1 := rc.StringToArray(25, 9,
		"                         "+
			"                         "+
			"  ab                     "+
			"                         "+
			"                         "+
			"                         "+
			"                         "+
			"                         "+
			"                         ")

	fg2 := rc.StringToArray(25, 9,
		"                         "+
			"                         "+
			"  c                      "+
			"  d                      "+
			"                         "+
			"                         "+
			"                         "+
			"                         "+
			"                         ")

	rc.Replace(&bg1, ' ', rc.TransparancyChar)
	rc.Replace(&bg2, ' ', rc.TransparancyChar)
	rc.Replace(&fg1, ' ', rc.TransparancyChar)
	rc.Replace(&fg2, ' ', rc.TransparancyChar)

	con.AddBackground(bg1, redArray)
	con.AddBackground(bg2, greenArray)
	con.AddForeground(fg1, blueArray)
	con.AddForeground(fg2, yellowArray)

	con.CameraX = 0
	con.CameraY = 0

	return con
}