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 all: build
build: clean build:
mkdir -p build make -C src/
cd src && PLAYDATE_SDK_PATH=$(PLAYDATE_SDK_PATH) $(PLAYDATE_SDK_PATH)/bin/pdc -k main.lua ../$(GAME).pdx
clean:
rm -rf $(GAME).pdx

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" 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) function Ball:init(width, height, color, x, y)
Ball.super.init(self, 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 return self
end end
@ -15,23 +15,23 @@ function Ball:levelUp()
end end
function Ball:move() function Ball:move()
self:moveBy(self.dirX * self.speed, self:moveBy(self.direction.x * self.speed,
self.dirY * self.speed) self.direction.y * self.speed)
end end
function Ball:setDirection(x, y) function Ball:setDirection(x, y)
x = x or self.dirX x = x or self.direction.x
y = y or self.dirY y = y or self.direction.y
self.dirX = x self.direction.x = x
self.dirY = y self.direction.y = y
end end
function Ball:_normalizePosition() function Ball:_normalizePosition()
local changeVector = Ball.super._normalizePosition(self) local changeVector = Ball.super._normalizePosition(self)
if changeVector[1] ~= 0 then if changeVector[1] ~= 0 then
self.dirX = changeVector[1] self.direction.x = changeVector[1]
end end
if changeVector[2] ~= 0 then if changeVector[2] ~= 0 then
self.dirY = changeVector[2] self.direction.y = changeVector[2]
end end
end end