Init commit.
Very basic swing and hit physics. Pitches every 5 seconds. Not much else!
This commit is contained in:
commit
be3223b28d
|
@ -0,0 +1,100 @@
|
||||||
|
import 'CoreLibs/graphics.lua'
|
||||||
|
import 'CoreLibs/animator.lua'
|
||||||
|
import 'CoreLibs/easing.lua'
|
||||||
|
|
||||||
|
local gfx = playdate.graphics
|
||||||
|
playdate.display.setRefreshRate(50)
|
||||||
|
|
||||||
|
gfx.setBackgroundColor(gfx.kColorWhite)
|
||||||
|
|
||||||
|
lastPosition = playdate.getCrankPosition()
|
||||||
|
|
||||||
|
-- text = "Oop"
|
||||||
|
|
||||||
|
timeSinceLastSwing = 999999
|
||||||
|
|
||||||
|
local ball = gfx.image.new(10, 10, gfx.kColorBlack)
|
||||||
|
local animationDuration = 2000
|
||||||
|
local ballStartY, endY = -20, 250
|
||||||
|
local easingFunction = playdate.easingFunctions.outQuint
|
||||||
|
local ballAnimator = gfx.animator.new(animationDuration, ballStartY, endY, easingFunction)
|
||||||
|
|
||||||
|
local screenW, screenH = 400, 240
|
||||||
|
local centerX, centerY = screenW / 2, screenH / 2
|
||||||
|
local batBaseX, batBaseY = centerX - 34, 200
|
||||||
|
|
||||||
|
local circleR = 45
|
||||||
|
|
||||||
|
local ballY = ballStartY
|
||||||
|
local lastBallY = ballY
|
||||||
|
local ballX = 200
|
||||||
|
local ballVelX, ballVelY = 0, 0
|
||||||
|
|
||||||
|
local batTipX = 0
|
||||||
|
local batTipY = 0
|
||||||
|
|
||||||
|
local hit = false
|
||||||
|
|
||||||
|
function pitch()
|
||||||
|
ballAnimator:reset()
|
||||||
|
ballVelX = 0
|
||||||
|
ballVelY = 0
|
||||||
|
ballX = 200
|
||||||
|
hit = false
|
||||||
|
end
|
||||||
|
|
||||||
|
function playdate.AButtonDown()
|
||||||
|
pitch()
|
||||||
|
end
|
||||||
|
|
||||||
|
local pitchClockSec = 5
|
||||||
|
local elapsedTime = 0
|
||||||
|
|
||||||
|
function playdate.update()
|
||||||
|
local deltaTime = playdate.getElapsedTime()
|
||||||
|
playdate.resetElapsedTime()
|
||||||
|
elapsedTime = elapsedTime + deltaTime
|
||||||
|
|
||||||
|
if elapsedTime > pitchClockSec then
|
||||||
|
elapsedTime = 0
|
||||||
|
pitch()
|
||||||
|
end
|
||||||
|
|
||||||
|
gfx.clear()
|
||||||
|
crankChange, acceleratedChange = playdate.getCrankChange()
|
||||||
|
|
||||||
|
if hit then
|
||||||
|
ballX = ballX + ballVelX
|
||||||
|
ballY = ballY + ballVelY
|
||||||
|
else
|
||||||
|
ballY = ballAnimator:currentValue()
|
||||||
|
end
|
||||||
|
|
||||||
|
batAngle = math.rad(playdate.getCrankPosition() + 180)
|
||||||
|
batTipX = batBaseX + (circleR * math.sin(batAngle))
|
||||||
|
batTipY = batBaseY + (circleR * math.cos(batAngle))
|
||||||
|
|
||||||
|
if hit == false and
|
||||||
|
--(lastBallY - 2) < batTipY and ballY >= batTipY and batTipX > ballX then
|
||||||
|
math.abs(ballY - batTipY) < 10 and batTipX > ballX then -- math.abs(batTipX - ballX) < 10 then
|
||||||
|
ballAngle = batAngle + math.rad(90)
|
||||||
|
mult = math.abs(acceleratedChange / 15)
|
||||||
|
ballVelX = mult * -15 * math.sin(ballAngle)
|
||||||
|
ballVelY = mult * 5 * math.cos(ballAngle)
|
||||||
|
if ballVelY > 0 then
|
||||||
|
ballVelX = ballVelX * -1
|
||||||
|
ballVelY = ballVelY * -1
|
||||||
|
end
|
||||||
|
hit = true
|
||||||
|
end
|
||||||
|
lastBallY = ballY
|
||||||
|
|
||||||
|
gfx.setColor(gfx.kColorBlack)
|
||||||
|
-- ball:draw(ballX, ballY)
|
||||||
|
gfx.setLineWidth(2)
|
||||||
|
gfx.drawCircleAtPoint(ballX, ballY, 8)
|
||||||
|
|
||||||
|
gfx.setLineWidth(5)
|
||||||
|
gfx.drawLine(batBaseX, batBaseY, batTipX, batTipY)
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue