예제 #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()
		}
	}
}
예제 #2
0
func main() {
	numCols := 80
	numRows := 25

	console.SetTitle("lol I set the title too")
	console.ClearScreen(numCols, numRows)
	x, y := 0, 0
	console.MoveTo(x, y)
	sprite := "O"
	fmt.Print(sprite)
	console.MoveTo(numCols-1, numRows-1)
	_, info := console.GetScreenBufferInfo()

	for {
		isHit, event := console.GetKeyEX()
		if isHit && event.IsSpecial {
			console.MoveTo(x, y)
			fmt.Print(" ")

			switch event.SpecialChar {
			case console.ScArrowUp:
				y--
			case console.ScArrowLeft:
				x--
			case console.ScArrowDown:
				y++
			case console.ScArrowRight:
				x++
			case console.ScEsc:
				return
			}

			console.MoveTo(x, y)

			console.SetCharacterProperties(console.ChFgBlue | console.ChBgYellow | console.ChUnderline)
			fmt.Print(sprite)
			console.SetCharacterProperties(info.CharacterColor)

			console.MoveTo(numCols-1, numRows-1)
		}
	}
}