parent
42a537dae0
commit
5fc72c46fe
Binary file not shown.
After Width: | Height: | Size: 720 B |
52
src/main.lua
52
src/main.lua
|
@ -9,6 +9,7 @@ playdate.display.setRefreshRate(50)
|
||||||
gfx.setBackgroundColor(gfx.kColorWhite)
|
gfx.setBackgroundColor(gfx.kColorWhite)
|
||||||
|
|
||||||
local grassBackground = gfx.image.new("images/game/grass.png")
|
local grassBackground = gfx.image.new("images/game/grass.png")
|
||||||
|
local playerImage = gfx.image.new("images/game/player.png")
|
||||||
|
|
||||||
local pitchFlyTimeMs = 2500
|
local pitchFlyTimeMs = 2500
|
||||||
local ballStartY, endY = 90, 250
|
local ballStartY, endY = 90, 250
|
||||||
|
@ -20,7 +21,7 @@ local ballSizeAnimator = gfx.animator.new(ballSizeMs, 9, 6, playdate.easingFunct
|
||||||
|
|
||||||
local screenW, screenH = 400, 240
|
local screenW, screenH = 400, 240
|
||||||
local centerX, centerY = screenW / 2, screenH / 2
|
local centerX, centerY = screenW / 2, screenH / 2
|
||||||
local batBaseX, batBaseY = centerX - 34, 220
|
local batBaseX, batBaseY = centerX - 34, 215
|
||||||
|
|
||||||
local batLength = 45
|
local batLength = 45
|
||||||
|
|
||||||
|
@ -34,6 +35,11 @@ local batTipX = 0
|
||||||
local batTipY = 0
|
local batTipY = 0
|
||||||
|
|
||||||
local hit = false
|
local hit = false
|
||||||
|
local MODES = {
|
||||||
|
batting = 0,
|
||||||
|
running = 1
|
||||||
|
}
|
||||||
|
local currentMode = MODES.batting
|
||||||
|
|
||||||
local hitAnimatorY
|
local hitAnimatorY
|
||||||
local hitAnimatorX
|
local hitAnimatorX
|
||||||
|
@ -49,18 +55,37 @@ local basePositions = {
|
||||||
home = { x = screenW * 0.474, y = screenH * 0.79 }
|
home = { x = screenW * 0.474, y = screenH * 0.79 }
|
||||||
}
|
}
|
||||||
|
|
||||||
local fielders
|
local fielders = {
|
||||||
function resetFielders()
|
first = {},
|
||||||
fielders = {
|
second = {},
|
||||||
first = { x = screenW - 65, y = screenH * 0.48 },
|
shortstop = {},
|
||||||
second = { x = screenW * 0.70, y = screenH * 0.30 },
|
third = {},
|
||||||
shortstop = { x = screenW * 0.30, y = screenH * 0.30 },
|
pitcher = {}
|
||||||
third = { x = screenW * 0.1, y = screenH * 0.48 },
|
}
|
||||||
pitcher = { x = screenW * 0.48, y = screenH * 0.40 }
|
function resetFielderPositions()
|
||||||
}
|
fielders.first.x = screenW - 65
|
||||||
end
|
fielders.first.y = screenH * 0.48
|
||||||
resetFielders()
|
|
||||||
|
|
||||||
|
fielders.second.x = screenW * 0.70
|
||||||
|
fielders.second.y = screenH * 0.30
|
||||||
|
|
||||||
|
fielders.shortstop.x = screenW * 0.30
|
||||||
|
fielders.shortstop.y = screenH * 0.30
|
||||||
|
|
||||||
|
fielders.third.x = screenW * 0.1
|
||||||
|
fielders.third.y = screenH * 0.48
|
||||||
|
|
||||||
|
fielders.pitcher.x = screenW * 0.48
|
||||||
|
fielders.pitcher.y = screenH * 0.40
|
||||||
|
end
|
||||||
|
resetFielderPositions()
|
||||||
|
|
||||||
|
local player = {
|
||||||
|
x = basePositions.home.x - 40,
|
||||||
|
y = basePositions.home.y - 3,
|
||||||
|
nextBase = nil,
|
||||||
|
prevBase = nil,
|
||||||
|
}
|
||||||
|
|
||||||
function hitBall(destX, destY, hitFlyTime)
|
function hitBall(destX, destY, hitFlyTime)
|
||||||
ballSizeAnimator:reset(ballSizeMs)
|
ballSizeAnimator:reset(ballSizeMs)
|
||||||
|
@ -77,7 +102,7 @@ end
|
||||||
|
|
||||||
function pitch()
|
function pitch()
|
||||||
pitchAnimator:reset()
|
pitchAnimator:reset()
|
||||||
resetFielders()
|
resetFielderPositions()
|
||||||
ballVelX = 0
|
ballVelX = 0
|
||||||
ballVelY = 0
|
ballVelY = 0
|
||||||
ballX = 200
|
ballX = 200
|
||||||
|
@ -232,6 +257,7 @@ function playdate.update()
|
||||||
updateGameState()
|
updateGameState()
|
||||||
|
|
||||||
grassBackground:draw(0, 0)
|
grassBackground:draw(0, 0)
|
||||||
|
playerImage:draw(player.x, player.y)
|
||||||
|
|
||||||
gfx.setColor(gfx.kColorBlack)
|
gfx.setColor(gfx.kColorBlack)
|
||||||
gfx.setLineWidth(2)
|
gfx.setLineWidth(2)
|
||||||
|
|
Loading…
Reference in New Issue