player.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package main
  2. import "math/rand"
  3. func (g *Game) drawPlayer(game *Game) {
  4. game.screen.SetContent(game.player.position.x, game.player.position.y, '@', nil, game.style)
  5. }
  6. func (g *Game) movePlayer(game *Game, press int) {
  7. if press == Left {
  8. if game.player.position.x != 2 {
  9. game.player.position.x--
  10. game.player.moves++
  11. }
  12. } else if press == Right {
  13. if game.player.position.x != 78 {
  14. game.player.position.x++
  15. game.player.moves++
  16. }
  17. } else if press == Up {
  18. if game.player.position.y != 1 {
  19. game.player.position.y--
  20. game.player.moves++
  21. }
  22. } else if press == Down {
  23. if game.player.position.y != 22 {
  24. game.player.position.y++
  25. game.player.moves++
  26. }
  27. } else if press == upleft {
  28. if game.player.position.x != 2 && game.player.position.y != 1 {
  29. game.player.position.x--
  30. game.player.position.y--
  31. game.player.moves++
  32. }
  33. } else if press == upright {
  34. if game.player.position.x != 78 && game.player.position.y != 1 {
  35. game.player.position.x++
  36. game.player.position.y--
  37. game.player.moves++
  38. }
  39. } else if press == downright {
  40. if game.player.position.x != 78 && game.player.position.y != 22 {
  41. game.player.position.x++
  42. game.player.position.y++
  43. game.player.moves++
  44. }
  45. } else if press == downleft {
  46. if game.player.position.x != 2 && game.player.position.y != 22 {
  47. game.player.position.x--
  48. game.player.position.y++
  49. game.player.moves++
  50. }
  51. } else if press == teleport {
  52. game.teleport(game)
  53. game.player.teleports++
  54. }
  55. }
  56. func (g *Game) teleport(game *Game) {
  57. // Draw something nice
  58. game.player.position.x = rand.Intn(80)
  59. game.player.position.y = rand.Intn(24)
  60. }