joseleeph

Untitled

Dec 26th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. WINDOW_WIDTH = 1280
  2. WINDOW_HEIGHT = 720
  3.  
  4. VIRTUAL_WIDTH = 432
  5. VIRTUAL_HEIGHT = 243
  6.  
  7. PADDLE_SPEED = 200
  8. --[[
  9. define a class and specify objects of that class
  10. we will tie our paddles together with classes and objects
  11. ]]
  12. Class = require 'class'
  13.  
  14.  
  15. require 'Ball'
  16. require 'Paddle'
  17.  
  18. function love.load()
  19. math.randomseed(os.time())
  20. love.graphics.setDefaultFilter('nearest','nearest')
  21.  
  22.  
  23.  
  24. paddle1 = Paddle(5, 20, 5, 20)
  25. paddle2 = Paddle(VIRTUAL_WIDTH - 10, VIRTUAL_HEIGHT - 30, 5, 20)
  26. ball = Ball(VIRTUAL_WIDTH/2 - 2, VIRTUAL_HEIGHT/2 - 2, 5, 5)
  27.  
  28.  
  29.  
  30. gameState = 'start'
  31. smallFont = love.graphics.newFont('04B_30__.ttf',8)
  32. scoreFont = love.graphics.newFont('TitilliumText22L005-webfont.ttf',14)
  33.  
  34. love.graphics.setFont(smallFont)
  35.  
  36. push:setupScreen(VIRTUAL_WIDTH,VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
  37. fullscreen = false,
  38. vsync = true,
  39. resizeable = false
  40. })
  41.  
  42. player1Score = 0
  43. player2Score = 0
  44. end
  45. function love.draw()
  46. push:apply('start')
  47. love.graphics.clear(40/255,45/255,52/255,255/255) -- map values to 0-1
  48. scoreFont = love.graphics.newFont('TitilliumText22L005-webfont.ttf',20)
  49. love.graphics.setFont(smallFont)
  50. if gameState == 'start' then
  51. love.graphics.printf('Hello Start State!', 0,20, VIRTUAL_WIDTH, 'center')
  52. elseif gameState == 'play' then
  53. love.graphics.printf('Hello Play State!', 0, 20, VIRTUAL_WIDTH, 'center')
  54. end
  55. love.graphics.setFont(scoreFont)
  56. love.graphics.print(player1Score, VIRTUAL_WIDTH/2 - 50, VIRTUAL_HEIGHT /3)
  57. love.graphics.print(player2Score, VIRTUAL_WIDTH/2+30, VIRTUAL_HEIGHT/3)
  58. ball:render()--love.graphics.rectangle('fill', ballX, ballY, 4, 4)
  59. paddle1:render() -- paddle1 render() is now a function stored in Paddle.lua
  60. paddle2:render()
  61.  
  62. end
  63.  
  64. function love.update(dt)
  65.  
  66. paddle1:update(dt)
  67. paddle2:update(dt)
  68.  
  69. ball:render()
  70.  
  71. -- player 1 movement
  72. if love.keyboard.isDown('w') then
  73. paddle1.dy = -PADDLE_SPEED -- is up
  74. elseif love.keyboard.isDown('s') then
  75. paddle1.dy = PADDLE_SPEED
  76. else
  77. paddle1.dy = 0 -- if neither is true, the paddle speed is 0
  78. end
  79. -- player 2 movement
  80. if love.keyboard.isDown('up') then
  81. paddle2.dy = -PADDLE_SPEED
  82. elseif love.keyboard.isDown('down') then
  83. paddle2.dy = PADDLE_SPEED
  84. else
  85. paddle2.dy = 0
  86. end
  87. if gameState == 'play' then
  88. ball:update(dt)
  89. --ballX = ballX + ballDX * dt these will instead be done with update
  90. --ballY = ballY + ballDY * dt
  91. end
  92. end
  93. function love.keypressed(key)
  94. if key == 'escape' then
  95. love.event.quit()
  96. elseif key == 'enter' or key == 'return' then
  97. if gameState == 'start' then
  98. gameState = 'play'
  99. --elseif gameState == 'play' then
  100. else
  101. ball:reset()
  102. end
  103. end
  104. end
Advertisement
Add Comment
Please, Sign In to add comment