render.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package main
  2. import "strconv"
  3. // drawBox Draw the outline of the box the snake can move in
  4. func (g *Game) drawBox(game *Game) {
  5. // Assuming we will always have this
  6. x1 := 0
  7. y1 := 0
  8. x2 := 79
  9. y2 := 23
  10. // Fill background
  11. for row := y1; row <= y2; row++ {
  12. for col := x1; col <= x2; col++ {
  13. game.screen.SetContent(col, row, ' ', nil, game.style)
  14. }
  15. }
  16. // Draw borders
  17. for col := x1; col <= x2; col++ {
  18. game.screen.SetContent(col, y1, '═', nil, game.style)
  19. game.screen.SetContent(col, y2, '═', nil, game.style)
  20. }
  21. for row := y1 + 1; row < y2; row++ {
  22. game.screen.SetContent(x1, row, '║', nil, game.style)
  23. game.screen.SetContent(x2, row, '║', nil, game.style)
  24. }
  25. // Only draw corners if necessary
  26. if y1 != y2 && x1 != x2 {
  27. game.screen.SetContent(x1, y1, '╔', nil, game.style)
  28. game.screen.SetContent(x2, y1, '╗', nil, game.style)
  29. game.screen.SetContent(x1, y2, '╚', nil, game.style)
  30. game.screen.SetContent(x2, y2, '╝', nil, game.style)
  31. }
  32. }
  33. // drawCoords Print the coordinates of the head of the snake
  34. func (g *Game) drawCoords(game *Game) {
  35. var x, y int = 25, 24
  36. for _, r := range []rune("[ x:" + strconv.FormatInt(int64(game.player.position.x), 10) + " y: " + strconv.FormatInt(int64(game.player.position.y), 10) + " ]") {
  37. game.screen.SetContent(x, y-1, r, nil, game.style)
  38. x++
  39. }
  40. }