Advertisement
joseleeph

Untitled

Dec 21st, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. WINDOW_WIDTH = 1280
  2. WINDOW_HEIGHT = 720
  3.  
  4. --[[ we want to use the push library to simulate that we are coding on a smaller raster size.
  5. nes was 240 p
  6. ]]
  7. VIRTUAL_WIDTH = 432
  8. VIRTUAL_HEIGHT = 243
  9.  
  10. PADDLE_SPEED = 200 -- pixels per second
  11.  
  12.  
  13. push = require 'push'
  14.  
  15.  
  16. function love.load()
  17.  
  18. love.graphics.setDefaultFilter('nearest','nearest')
  19.  
  20. smallFont = love.graphics.newFont('04B_30__.ttf',8)
  21. scoreFont = love.graphics.newFont('04B_30__.ttf',14)
  22.  
  23. love.graphics.setFont(smallFont)
  24.  
  25. push:setupScreen(VIRTUAL_WIDTH,VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
  26. fullscreen = false,
  27. vsync = true,
  28. resizeable = false
  29. })
  30.  
  31. player1Score = 0
  32. player2Score = 0
  33.  
  34. player1Y = 30
  35. player2Y = VIRTUAL_HEIGHT - 40
  36. end
  37.  
  38. function love.draw()
  39. push:apply('start')
  40. love.graphics.clear(40/255,45/255,52/255,255/255) -- map values to 0-1
  41. scoreFont = love.graphics.newFont('TitilliumText22L005-webfont.ttf',20)
  42. player1Y = 30
  43. player2Y = 40
  44. love.graphics.setFont(smallFont)
  45. love.graphics.printf('Hello Pong!', 0, 20, VIRTUAL_WIDTH, 'center')
  46.  
  47. love.graphics.setFont(scoreFont)
  48. love.graphics.print(player1Score, VIRTUAL_WIDTH/2 - 50, VIRTUAL_HEIGHT /3)
  49. love.graphics.print(player2Score, VIRTUAL_WIDTH/2+30, VIRTUAL_HEIGHT/3)
  50.  
  51. love.graphics.rectangle('fill', VIRTUAL_WIDTH/2 -2, VIRTUAL_WIDTH/2-2, 4, 4) -- center ball
  52.  
  53. love.graphics.rectangle('fill', 10, player1Y, 5, 20) -- left side
  54. love.graphics.rectangle('line', VIRTUAL_WIDTH - 10, player2Y, 5, 20) -- right side
  55. push:apply('end')
  56. end
  57.  
  58.  
  59. function love.update(dt)
  60. if love.keyboard.isDown('w') then
  61. player1Y = player1Y - PADDLE_SPEED * dt -- remember that higher numbers are down... dt is delta time
  62. elseif love.keyboard.isDown('s') then
  63. player1Y = player1Y + PADDLE_SPEED * dt
  64. end
  65. if love.keyboard.isDown('up') then
  66. player2Y = player2Y - PADDLE_SPEED * dt --down is positive
  67. elseif love.keyboard.isDown('down') then
  68. player2Y = player2Y + PADDLE_SPEED * dt -- up is negative
  69. end
  70. end
  71.  
  72. function love.keypressed(key)
  73. if key == 'escape' then -- can be accessed by string name
  74. love.event.quit() --quit() is a function love gives us to terminate
  75. end
  76. end
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement