diff --git a/Makefile b/Makefile index 53df215..cf18b5c 100644 --- a/Makefile +++ b/Makefile @@ -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/ diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..708b956 --- /dev/null +++ b/src/Makefile @@ -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 diff --git a/src/ball.lua b/src/ball.lua index 95fe668..b867218 100644 --- a/src/ball.lua +++ b/src/ball.lua @@ -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