diff --git a/src/images/game/player.png b/src/images/game/player.png new file mode 100644 index 0000000..3bc242c Binary files /dev/null and b/src/images/game/player.png differ diff --git a/src/main.lua b/src/main.lua index d36d1a1..6cd6b2b 100644 --- a/src/main.lua +++ b/src/main.lua @@ -9,6 +9,7 @@ playdate.display.setRefreshRate(50) gfx.setBackgroundColor(gfx.kColorWhite) local grassBackground = gfx.image.new("images/game/grass.png") +local playerImage = gfx.image.new("images/game/player.png") local pitchFlyTimeMs = 2500 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 centerX, centerY = screenW / 2, screenH / 2 -local batBaseX, batBaseY = centerX - 34, 220 +local batBaseX, batBaseY = centerX - 34, 215 local batLength = 45 @@ -34,6 +35,11 @@ local batTipX = 0 local batTipY = 0 local hit = false +local MODES = { + batting = 0, + running = 1 +} +local currentMode = MODES.batting local hitAnimatorY local hitAnimatorX @@ -49,18 +55,37 @@ local basePositions = { home = { x = screenW * 0.474, y = screenH * 0.79 } } -local fielders -function resetFielders() - fielders = { - first = { x = screenW - 65, y = screenH * 0.48 }, - second = { x = screenW * 0.70, y = screenH * 0.30 }, - shortstop = { x = screenW * 0.30, y = screenH * 0.30 }, - third = { x = screenW * 0.1, y = screenH * 0.48 }, - pitcher = { x = screenW * 0.48, y = screenH * 0.40 } - } -end -resetFielders() +local fielders = { + first = {}, + second = {}, + shortstop = {}, + third = {}, + pitcher = {} +} +function resetFielderPositions() + fielders.first.x = screenW - 65 + fielders.first.y = screenH * 0.48 + 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) ballSizeAnimator:reset(ballSizeMs) @@ -77,7 +102,7 @@ end function pitch() pitchAnimator:reset() - resetFielders() + resetFielderPositions() ballVelX = 0 ballVelY = 0 ballX = 200 @@ -232,6 +257,7 @@ function playdate.update() updateGameState() grassBackground:draw(0, 0) + playerImage:draw(player.x, player.y) gfx.setColor(gfx.kColorBlack) gfx.setLineWidth(2)