joseleeph

Untitled

May 17th, 2021
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1.  
  2. function love.load()
  3. --Object = require "classic"
  4. require "cjrcle"
  5. windowwidth = 1000
  6. windowheight = 1000
  7. love.graphics.setBackgroundColor(1, 1, 1)
  8. sucess = love.window.setMode(windowwidth, windowheight) -- what does this line do? ... will work but the circle is offset
  9.  
  10. ctheta = math.pi/2
  11. x = 0
  12. y = 0
  13.  
  14. startposX = -500
  15. discr = 50
  16. hr = 10
  17.  
  18. speed = 1
  19.  
  20. thrown = false -- a variable to check if the hammer has been let go
  21.  
  22. -- hammer position
  23. hxpos = startposX + discr*math.cos(math.pi/2)
  24. hypos = y - discr*math.sin(math.pi/2)
  25. rv = 1 -- rotational velocity
  26. end
  27.  
  28.  
  29. function love.update(dt)
  30.  
  31. ctheta = ctheta - rv*math.pi*dt
  32. if speed < 10 then
  33. startposX = startposX + speed
  34. end
  35.  
  36.  
  37. hxpos = startposX + discr*math.cos(ctheta) -- this snippet of code calculates the hammer position for the next frame
  38. hypos = y - discr*math.sin(ctheta)
  39. -- once the hammer has been thrown you need to stop performing this calculation, and instead do the one that you currently have in love.keypressed
  40. if thrown == true then
  41.  
  42. hxpos = hxpos + 1/math.tan(ctheta*dt) -- using the cotangent seems to work better than the secant... or the tangent
  43. hypos = hypos + 1/math.tan(ctheta*dt) -- i think it will always go at a 45 degree angle
  44. speed = 0
  45. else
  46. hxpos = startposX + discr*math.cos(ctheta)
  47. hypos = y - discr*math.sin(ctheta)
  48. end
  49.  
  50. if startposX > 0 then
  51. startposX = 0
  52. end
  53. if rv < 12 and thrown == false then
  54. rv = rv*1.01 -- the rotational velocity is always being updated at every frame
  55. end
  56. end
  57. --[[
  58. equation of tangent line y = -x + 50*math.sqrt(2)
  59. ]]
  60.  
  61. function love.keypressed(key)
  62. if key == "space" and startposX < 0 then
  63. thrown = true
  64.  
  65. speed = 0
  66. end
  67. end
  68.  
  69. function love.draw()
  70. --love.graphics.push()
  71. love.graphics.translate(windowwidth/2, windowheight/2)
  72.  
  73.  
  74.  
  75. love.graphics.setColor(0, 1, 0)
  76. cjrcle(discr, startposX, 0, 32)
  77.  
  78. --blue circle
  79. love.graphics.setColor(0, 0, 1) -- blue paint
  80.  
  81. cjrcle(10, hxpos, hypos, 16)
  82.  
  83. love.graphics.setColor(0, 0, 0) -- black
  84. love.graphics.setLineWidth(.5)
  85. love.graphics.line(50*math.sqrt(2), 0, 0, -50*math.sqrt(2))
  86. love.graphics.setColor(1,0,0) -- red
  87. love.graphics.setLineWidth(.3)
  88. love.graphics.line(50*math.tan(math.pi/4), 0, 0, -50*math.tan(math.pi/4)) -- tan Ο€/4 = 1
  89.  
  90. love.graphics.line(0, 25*math.sqrt(3) + math.sqrt(1875)/3, 0, 25*math.sqrt(3) + math.sqrt(1875)/3)
  91.  
  92.  
  93. end
  94.  
  95.  
Advertisement
Add Comment
Please, Sign In to add comment