camera.go 963 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package main
  2. import door "git.red-green.com/RedGreen/doorgo"
  3. type Camera struct {
  4. Size *Vec2
  5. }
  6. func (c *Camera) debugView(at *Vec2, w *World) string {
  7. out := ""
  8. t := at.Clone()
  9. t.X -= c.Size.X / 2
  10. t.Y -= c.Size.Y / 2
  11. for y := range make([]byte, c.Size.Y) {
  12. for x := range make([]byte, c.Size.X) {
  13. id := w.Get(uint64(t.X)+uint64(x), uint64(t.Y)+uint64(y))
  14. if id == 0 {
  15. out += " "
  16. } else {
  17. out += w.TileIndex.Tiles[id].Symbol
  18. }
  19. }
  20. out += "\r\n"
  21. }
  22. return out
  23. }
  24. func (c *Camera) View(at *Vec2, offset *Vec2, w *World) string {
  25. out := ""
  26. t := at.Clone()
  27. t.X -= c.Size.X / 2
  28. t.Y -= c.Size.Y / 2
  29. for y := range make([]byte, c.Size.Y) {
  30. for x := range make([]byte, c.Size.X) {
  31. id := w.Get(uint64(t.X)+uint64(x), uint64(t.Y)+uint64(y))
  32. if id != 0 {
  33. out += door.GotoS(int(offset.X)+x, int(offset.Y)+y) + door.ColorTextS(w.TileIndex.Tiles[id].Color) + w.TileIndex.Tiles[id].Symbol + door.Reset
  34. }
  35. }
  36. }
  37. return out
  38. }