Use idiomatic initialization, and also more reorganizing.
This commit is contained in:
parent
2b33f88594
commit
5f00790856
11
Makefile
11
Makefile
|
@ -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
10
src/Makefile
Normal 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
|
24
src/ball.lua
24
src/ball.lua
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user