Advertisement
joseleeph

Untitled

Dec 29th, 2020
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. Class = require 'class'
  2. push = require 'push'
  3. require 'Ball'
  4. require 'Paddle'
  5. WINDOW_WIDTH = 1280
  6. WINDOW_HEIGHT = 720
  7. VIRTUAL_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. --paddle1 = Paddle(5, 20, 5, 20)
  14. --paddle2 = Paddle(VIRTUAL_WIDTH - 10, VIRTUAL_HEIGHT - 30, 5, 20)
  15. --ball = Ball(VIRTUAL_WIDTH/2 - 2, VIRTUAL_HEIGHT/2 - 2, 5, 5)
  16. gameState = 'start'
  17. smallFont = love.graphics.newFont('04B_30__.ttf',8)
  18. scoreFont = love.graphics.newFont('TitilliumText22L005-webfont.ttf',14)
  19. player1Score = 0
  20. player2Score = 0
  21.  
  22. love.graphics.setFont(smallFont)
  23.  
  24. push:setupScreen(VIRTUAL_WIDTH,VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
  25. fullscreen = false,
  26. vsync = true,
  27. resizeable = false
  28. })
  29. paddle1 = Paddle(5, 20, 5, 20)
  30. paddle2 = Paddle(VIRTUAL_WIDTH - 10, VIRTUAL_HEIGHT - 30, 5, 20)
  31. ball = Ball(VIRTUAL_WIDTH/2 - 2, VIRTUAL_HEIGHT/2 - 2, 5, 5)
  32. gameState = 'play'
  33.  
  34. --player1Score = 0
  35. --player2Score = 0
  36. end
  37. function love.draw()
  38. push:apply('start')
  39. love.graphics.clear(40/255,45/255,52/255,255/255)
  40. scoreFont = love.graphics.newFont('TitilliumText22L005-webfont.ttf',20)
  41. smallFont = love.graphics.newFont('04B_30__.TTF',13)
  42. love.graphics.setFont(smallFont)
  43. if gameState == 'start' then
  44. love.graphics.printf('Hello Start State!', 0,20, VIRTUAL_WIDTH, 'center')
  45. elseif gameState == 'play' then
  46. love.graphics.printf('Hello Play State!', 0, 20, VIRTUAL_WIDTH, 'center')
  47. end
  48. love.graphics.setFont(scoreFont)
  49. love.graphics.print(player1Score, VIRTUAL_WIDTH/2 - 50, VIRTUAL_HEIGHT /3)
  50. love.graphics.print(player2Score, VIRTUAL_WIDTH/2+30, VIRTUAL_HEIGHT/3)
  51. ball:render()
  52. paddle1:render()
  53. paddle2:render()
  54. displayFPS()
  55. push:apply('end')
  56. end
  57.  
  58. function love.update(dt)
  59. paddle1:update(dt)
  60. paddle2:update(dt)
  61. ball:render()
  62. if love.keyboard.isDown('w') then
  63. paddle1.dy = -PADDLE_SPEED
  64. elseif love.keyboard.isDown('s') then
  65. paddle1.dy = PADDLE_SPEED
  66. else
  67. paddle1.dy = 0
  68. end
  69.  
  70. if love.keyboard.isDown('up') then
  71. paddle2.dy = -PADDLE_SPEED
  72. elseif love.keyboard.isDown('down') then
  73. paddle2.dy = PADDLE_SPEED
  74. else
  75. paddle2.dy = 0
  76. end
  77. if gameState == 'play' then
  78. ball:update(dt)
  79. end
  80. end
  81. function love.keypressed(key)
  82. if key == 'escape' then
  83. love.event.quit()
  84. elseif key == 'enter' or key == 'return' then
  85. if gameState == 'start' then
  86. gameState = 'play'
  87. else
  88. gameState = 'start'
  89. ball:reset()
  90. end
  91. end
  92. end
  93. function displayFPS()
  94. love.graphics.setColor(0,1,0,1)
  95. love.graphics.setFont(smallFont)
  96. love.graphics.print('FPS: ' .. tostring(love.timer.getFPS()), 40, 20)
  97. love.graphics.setColor(1, 1, 1, 1)
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement