Initial implementation of player and bullets.
This commit is contained in:
parent
2341e8711f
commit
8d87364afb
|
@ -1,12 +1,14 @@
|
|||
# <name>
|
||||
# Crankani
|
||||
|
||||
<name> is a game for the [Playdate](https://play.date/) handheld console.
|
||||
Crankani is a game for the [Playdate](https://play.date/) handheld console. It is a shoot-em-up inspired by Galaga, Gradius, and most of all, Ikaruga.
|
||||
|
||||
In it, you control a space crab (or perhaps a crab-like spacecraft. You decide!) and must dodge bullets, fire bullets of your own, and defend yourself with a potent but limited phase shifting ability. Good luck!
|
||||
|
||||
|
||||
### Building
|
||||
|
||||
To build this code, install the [Playdate SDK](https://play.date/dev/) and run `make`. Update `PLAYDATE_SDK_PATH` in the Makefile if you have installed the SDK somewhere other than `~/playdate`.
|
||||
|
||||
`make` should produce a directory called `<Name>.pdx`. You can open this in the Playdate Simulator and sideload it onto your Playdate from there.
|
||||
`make` should produce a directory called `Crankani.pdx`. You can open this in the Playdate Simulator and sideload it onto your Playdate from there.
|
||||
|
||||
The Makefile is designed to be run under Linux and is untested on other platforms.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
PLAYDATE_SDK_PATH := ~/playdate
|
||||
GAME := Crong
|
||||
GAME := Crankani
|
||||
|
||||
all: build
|
||||
|
||||
|
|
33
src/bullet.lua
Normal file
33
src/bullet.lua
Normal file
|
@ -0,0 +1,33 @@
|
|||
-- Code for bullets!
|
||||
import "CoreLibs/object"
|
||||
import "CoreLibs/graphics"
|
||||
import "CoreLibs/sprites"
|
||||
|
||||
local gfx <const> = playdate.graphics
|
||||
|
||||
class("Bullet").extends(gfx.sprite)
|
||||
|
||||
function Bullet:init(size, friendly)
|
||||
local img = gfx.image.new(size, size)
|
||||
gfx.pushContext(img)
|
||||
gfx.drawCircleInRect(0, 0, size, size)
|
||||
gfx.popContext()
|
||||
|
||||
Bullet.super.init(self, img)
|
||||
self:setCollideRect(0, 0, self:getSize())
|
||||
|
||||
local friendly = friendly or true
|
||||
if friendly then
|
||||
self:setGroupMask(0x4)
|
||||
self:setCollidesWithGroupsMask(0x9)
|
||||
self.direction = 1
|
||||
else
|
||||
self:setGroupMask(0x10)
|
||||
self:setCollidesWithGroupsMask(0x2)
|
||||
self.direction = -1
|
||||
end
|
||||
end
|
||||
|
||||
function Bullet:update()
|
||||
self:moveWithCollisions(self.x+self.direction, self.y)
|
||||
end
|
BIN
src/images/kani.png
Normal file
BIN
src/images/kani.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 659 B |
78
src/kani.lua
Normal file
78
src/kani.lua
Normal file
|
@ -0,0 +1,78 @@
|
|||
-- Code for the player's ship.
|
||||
import "CoreLibs/object"
|
||||
import "CoreLibs/graphics"
|
||||
import "CoreLibs/sprites"
|
||||
import "bullet"
|
||||
|
||||
local gfx <const> = playdate.graphics
|
||||
|
||||
class("Kani").extends(gfx.sprite)
|
||||
|
||||
function Kani:init()
|
||||
local img = gfx.image.new("images/kani.png")
|
||||
Kani.super.init(self, img)
|
||||
print(self)
|
||||
self:setCollideRect(0, 0, self:getSize())
|
||||
self.vector = {x=0,y=0} -- movement direction
|
||||
self:setGroupMask(0x2)
|
||||
self:setCollidesWithGroupsMask(0x19)
|
||||
|
||||
self.reserveCharge = 0
|
||||
self.shotCharge = 0
|
||||
|
||||
-- input handlers
|
||||
self.inputHandlers = {
|
||||
upButtonDown = function() self.vector.y = -1 end,
|
||||
downButtonDown = function() self.vector.y = 1 end,
|
||||
leftButtonDown = function() self.vector.x = -1 end,
|
||||
rightButtonDown = function() self.vector.x = 1 end,
|
||||
upButtonUp = function() self.vector.y = 0 end,
|
||||
downButtonUp = function() self.vector.y = 0 end,
|
||||
leftButtonUp = function() self.vector.x = 0 end,
|
||||
rightButtonUp = function() self.vector.x = 0 end,
|
||||
cranked = function(change, accelChange) self:chargeReserve(change) end,
|
||||
AButtonDown = function() self:chargeShot(1) end,
|
||||
AButtonUp = function() self:fire() end,
|
||||
}
|
||||
end
|
||||
|
||||
function Kani:chargeReserve(change)
|
||||
self.reserveCharge += change / 10
|
||||
end
|
||||
|
||||
function Kani:chargeShot(amount)
|
||||
if self.reserveCharge > amount then
|
||||
self.shotCharge += amount
|
||||
self.reserveCharge -= amount
|
||||
elseif self.reserveCharge > 0 then
|
||||
self.shotCharge += self.reserveCharge
|
||||
self.reserveCharge = 0
|
||||
end
|
||||
end
|
||||
|
||||
function Kani:fire()
|
||||
if self.shotCharge <= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local bullet = Bullet(self.shotCharge)
|
||||
bullet:moveTo(self.x+16, self.y)
|
||||
bullet:add()
|
||||
self.shotCharge = 0
|
||||
end
|
||||
|
||||
function Kani:addInputHandlers()
|
||||
playdate.inputHandlers.push(self.inputHandlers)
|
||||
end
|
||||
|
||||
function Kani:removeInputHandlers()
|
||||
playdate.inputHandlers.pop()
|
||||
end
|
||||
|
||||
-- move that crab!
|
||||
function Kani:update()
|
||||
local collisions = select(3, self:moveWithCollisions(self.x + self.vector.x, self.y + self.vector.y))
|
||||
for i=0, #collisions, 1 do
|
||||
-- handle collisions
|
||||
end
|
||||
end
|
45
src/main.lua
45
src/main.lua
|
@ -1,18 +1,53 @@
|
|||
-- Collision groups:
|
||||
-- 0x1 - walls
|
||||
-- 0x2 - player
|
||||
-- 0x4 - player bullets
|
||||
-- 0x8 - enemies
|
||||
-- 0x10 - enemy bullets
|
||||
import "CoreLibs/object"
|
||||
import "CoreLibs/graphics"
|
||||
import "CoreLibs/sprite"
|
||||
import "CoreLibs/sprites"
|
||||
import "CoreLibs/timer"
|
||||
import "kani"
|
||||
|
||||
local gfx <const> = playdate.graphics
|
||||
|
||||
function setup()
|
||||
local player = nil
|
||||
|
||||
function setup()
|
||||
player = Kani()
|
||||
player:moveTo(16, 120)
|
||||
player:addInputHandlers()
|
||||
player:add()
|
||||
makeWalls()
|
||||
drawBackground()
|
||||
end
|
||||
|
||||
function makeWalls()
|
||||
makeWall(200, 0, 400, 1)
|
||||
makeWall(0, 120, 1, 240)
|
||||
makeWall(200, 0, 400, 1)
|
||||
makeWall(0, 120, 1, 240)
|
||||
end
|
||||
|
||||
function makeWall(x, y, w, h)
|
||||
local wall = gfx.sprite.new()
|
||||
wall:setSize(w, h)
|
||||
wall:setCollideRect(0, 0, wall:getSize())
|
||||
wall:setGroupMask(0x1)
|
||||
wall:add()
|
||||
end
|
||||
|
||||
function drawBackground()
|
||||
local backgroundImage = gfx.image.new(400, 240, gfx.kColorWhite)
|
||||
gfx.sprite.setBackgroundDrawingCallback(
|
||||
function(x, y, width, height)
|
||||
backgroundImage:draw(0, 0)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
function playdate.update()
|
||||
|
||||
|
||||
playdate.timer.updateTimers()
|
||||
gfx.sprite.update()
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user