Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function love.load()
- --Object = require "classic"
- require "cjrcle"
- windowwidth = 1000
- windowheight = 1000
- love.graphics.setBackgroundColor(1, 1, 1)
- sucess = love.window.setMode(windowwidth, windowheight) -- what does this line do? ... will work but the circle is offset
- ctheta = math.pi/2
- x = 0
- y = 0
- startposX = -500
- discr = 50
- hr = 10
- speed = 1
- thrown = false -- a variable to check if the hammer has been let go
- -- hammer position
- hxpos = startposX + discr*math.cos(math.pi/2)
- hypos = y - discr*math.sin(math.pi/2)
- rv = 1 -- rotational velocity
- end
- function love.update(dt)
- ctheta = ctheta - rv*math.pi*dt
- if speed < 10 then
- startposX = startposX + speed
- end
- hxpos = startposX + discr*math.cos(ctheta) -- this snippet of code calculates the hammer position for the next frame
- hypos = y - discr*math.sin(ctheta)
- -- 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
- if thrown == true then
- hxpos = hxpos + 1/math.tan(ctheta*dt) -- using the cotangent seems to work better than the secant... or the tangent
- hypos = hypos + 1/math.tan(ctheta*dt) -- i think it will always go at a 45 degree angle
- speed = 0
- else
- hxpos = startposX + discr*math.cos(ctheta)
- hypos = y - discr*math.sin(ctheta)
- end
- if startposX > 0 then
- startposX = 0
- end
- if rv < 12 and thrown == false then
- rv = rv*1.01 -- the rotational velocity is always being updated at every frame
- end
- end
- --[[
- equation of tangent line y = -x + 50*math.sqrt(2)
- ]]
- function love.keypressed(key)
- if key == "space" and startposX < 0 then
- thrown = true
- speed = 0
- end
- end
- function love.draw()
- --love.graphics.push()
- love.graphics.translate(windowwidth/2, windowheight/2)
- love.graphics.setColor(0, 1, 0)
- cjrcle(discr, startposX, 0, 32)
- --blue circle
- love.graphics.setColor(0, 0, 1) -- blue paint
- cjrcle(10, hxpos, hypos, 16)
- love.graphics.setColor(0, 0, 0) -- black
- love.graphics.setLineWidth(.5)
- love.graphics.line(50*math.sqrt(2), 0, 0, -50*math.sqrt(2))
- love.graphics.setColor(1,0,0) -- red
- love.graphics.setLineWidth(.3)
- love.graphics.line(50*math.tan(math.pi/4), 0, 0, -50*math.tan(math.pi/4)) -- tan Ο/4 = 1
- love.graphics.line(0, 25*math.sqrt(3) + math.sqrt(1875)/3, 0, 25*math.sqrt(3) + math.sqrt(1875)/3)
- end
Advertisement
Add Comment
Please, Sign In to add comment