Use idiomatic initialization, and also more reorganizing.

This commit is contained in:
Anna Rose 2023-09-27 15:40:02 -04:00
parent 2b33f88594
commit 5f00790856
3 changed files with 24 additions and 21 deletions

View File

@ -1,11 +1,4 @@
PLAYDATE_SDK_PATH := ~/playdate
GAME := Crong
all: build
build: clean
mkdir -p build
cd src && PLAYDATE_SDK_PATH=$(PLAYDATE_SDK_PATH) $(PLAYDATE_SDK_PATH)/bin/pdc -k main.lua ../$(GAME).pdx
clean:
rm -rf $(GAME).pdx
build:
make -C src/

10
src/Makefile Normal file
View File

@ -0,0 +1,10 @@
PLAYDATE_SDK_PATH := ~/playdate
GAME := Crong
all: build
build: clean
PLAYDATE_SDK_PATH=$(PLAYDATE_SDK_PATH) $(PLAYDATE_SDK_PATH)/bin/pdc -k main.lua ../$(GAME).pdx
clean:
rm -rf ../$(GAME).pdx

View File

@ -1,12 +1,12 @@
import "pixie"
class("Ball").extends(Pixie)
class("Ball", {
direction = {x=-1, y=1},
speed = 3,
}).extends(Pixie)
function Ball:init(width, height, color, x, y)
Ball.super.init(self, width, height, color, x, y)
self.dirX = -1
self.dirY = 1
self.speed = 3
return self
end
@ -15,23 +15,23 @@ function Ball:levelUp()
end
function Ball:move()
self:moveBy(self.dirX * self.speed,
self.dirY * self.speed)
self:moveBy(self.direction.x * self.speed,
self.direction.y * self.speed)
end
function Ball:setDirection(x, y)
x = x or self.dirX
y = y or self.dirY
self.dirX = x
self.dirY = y
x = x or self.direction.x
y = y or self.direction.y
self.direction.x = x
self.direction.y = y
end
function Ball:_normalizePosition()
local changeVector = Ball.super._normalizePosition(self)
if changeVector[1] ~= 0 then
self.dirX = changeVector[1]
self.direction.x = changeVector[1]
end
if changeVector[2] ~= 0 then
self.dirY = changeVector[2]
self.direction.y = changeVector[2]
end
end