Advertisement
joseleeph

Untitled

Dec 29th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. Class = require 'class'
  2. push = require 'push'
  3. require 'Paddle'
  4. require 'Ball'
  5. WINDOW_WIDTH = 1280
  6. WINDOW_HEIGHT = 720
  7. VIRUTAL_WIDTH = 432
  8. VIRTUAL_HEIGHT = 243
  9. PADDLE_SPEED = 200
  10. function love.load()
  11. math.randomseed(os.time())
  12. love.graphics.setDefaultFilter('nearest', 'nearest')
  13. smallFont= love.graphics.newFont('Retro Gaming.ttf', 8)
  14. scoreFont = love.graphics.newFont('Retro Gaming.ttf', 32)
  15. player1Score = 0
  16. player2Score = 0
  17. love.graphics.setFont(smallFont)
  18. push:setupScreen(VIRUTAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
  19. fullscreen = false,
  20. vsync = true,
  21. resizeable = false
  22. })
  23. paddle1 = Paddle(5, 20, 5, 20)
  24. paddle2 = Paddle(VIRUTAL_WIDTH - 10, VIRTUAL_HEIGHT - 30, 5, 20)
  25. ball = Ball(VIRUTAL_WIDTH/2-2, VIRTUAL_HEIGHT/2-2, 5, 5)
  26. gameState = 'play'
  27. end
  28. function love.update(dt)
  29. paddle1:update(dt)
  30. paddle2:update(dt)
  31. if love.keyboard.isDown('w') then
  32. paddle1.dy = -PADDLE_SPEED
  33. elseif love.keyboard.isDown('s') then
  34. paddle1.dy = PADDLE_SPEED
  35. else
  36. paddle1.dy = 0
  37. end
  38. if love.keyboard.isDown('up') then
  39. paddle2.dy = -PADDLE_SPEED
  40. elseif love.keyboard.isDown('down') then
  41. paddle2.dy = PADDLE_SPEED
  42. else
  43. paddle2.dy = 0
  44. end
  45.  
  46. if gameState == 'play' then
  47. ball:update(dt)
  48. end
  49. end
  50. function love.keypressed(key)
  51. if key == 'escape' then
  52. love.event.quit()
  53. elseif key == 'enter' or key == 'return' then
  54. if gameState == 'start' then
  55. gameState = 'play'
  56. else
  57. gameState = 'start'
  58. ball:reset()
  59. end
  60. end
  61. end
  62. function love.draw()
  63. push:apply('start')
  64. love.graphics.clear(40/255, 45/255, 52/255, 255/255)
  65. love.graphics.setFont(smallFont)
  66. if gameState == 'start' then
  67. love.graphics.printf("Hello Start State!", 0, 20, VIRUTAL_WIDTH, 'center')
  68. elseif gameState == 'play' then
  69. love.graphics.printf('Hello Play State!', 0, 20 , VIRUTAL_WIDTH, 'center')
  70. end
  71. love.graphics.setFont(scoreFont)
  72. love.graphics.print(player1Score, VIRUTAL_WIDTH/2-50, VIRTUAL_HEIGHT/3)
  73. love.graphics.print(player2Score, VIRUTAL_WIDTH/2 + 30, VIRTUAL_HEIGHT/3)
  74. paddle1:render()
  75. paddle2:render()
  76. ball:render()
  77. push:apply('end')
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement