From 8d87364afb7b033c9c070ef301c08d7be601bf30 Mon Sep 17 00:00:00 2001 From: annabunches Date: Fri, 29 Sep 2023 20:52:06 -0400 Subject: [PATCH] Initial implementation of player and bullets. --- readme.md | 8 +++-- src/Makefile | 2 +- src/bullet.lua | 33 +++++++++++++++++++ src/images/kani.png | Bin 0 -> 659 bytes src/kani.lua | 78 ++++++++++++++++++++++++++++++++++++++++++++ src/main.lua | 45 ++++++++++++++++++++++--- 6 files changed, 157 insertions(+), 9 deletions(-) create mode 100644 src/bullet.lua create mode 100644 src/images/kani.png create mode 100644 src/kani.lua diff --git a/readme.md b/readme.md index 153495a..e0fbd4a 100644 --- a/readme.md +++ b/readme.md @@ -1,12 +1,14 @@ -# +# Crankani - 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 `.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. diff --git a/src/Makefile b/src/Makefile index 708b956..ff1ad6c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ PLAYDATE_SDK_PATH := ~/playdate -GAME := Crong +GAME := Crankani all: build diff --git a/src/bullet.lua b/src/bullet.lua new file mode 100644 index 0000000..3fcd6a1 --- /dev/null +++ b/src/bullet.lua @@ -0,0 +1,33 @@ +-- Code for bullets! +import "CoreLibs/object" +import "CoreLibs/graphics" +import "CoreLibs/sprites" + +local gfx = 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 diff --git a/src/images/kani.png b/src/images/kani.png new file mode 100644 index 0000000000000000000000000000000000000000..ede83a67e45bd58583c30cf3285b8a398f9d4a84 GIT binary patch literal 659 zcmV;E0&M+>P)kdg0003aX+uL$Nkc;* zaB^>EX>4Tx04R~2kUdMoP!xurR`Cm+)DEJM!O@Opa`1}=heB;57@g82#bOdel2ZH! z{uBK%9R$I@;I828d!vJcS-fy~9}efd@4XkARvaY7{2?T1nLGU>@6x-n7T;KAhfVfq z`9YC&2OXE%^Z81{=u6vp)zAHT7Q(0qq%&0-WO)gV1F=0VGs7x2Zr%Qg_(5!iNg9fu z#Jgb<8aBKAB%TC6p5`{IQF<{jebqJ&XLRXdF=WD+n3A?MRp%6&eW^o^&pic!G$vAS zs+p1-Q6VRXW05P;ZEEtis=S_3hVmH8%Ou>9$kXIu{`Y(Bzb^k-*2m#v8$PXzVQoU6;Pqada#@T0007FOGiWi|A&vvzW@LL32;bR za{vG?BLDy{BLR4&KXw2B00(qQO+^Ri2^|&)EQ(xJfB*mh8FWQhbVF}#ZDnqB07G(R zVRU6=Aa`kWXdp*PO;A^X4i^9b0MJQ9K~zY`omEK^!!QU#O#c66_0XBdfZ6IJF(85D zK<0-cA_5!4GJTZ8<8q9-uR89Y^wo7bW(7Fuo)v(=l!&Dn3(yT`yd5~m2o!9&FQJ2$ z9o z^NkxR(Mx%@hj)EHMd(V(ZTNK=Q`b5QPh#i14G%#F|Kq}!A#QFye@eO(63d6wJt*4F t95o&tT8J4r9lMY#dCY&VSbNcBd;nvbKr>p?;xPaK002ovPDHLkV1l6I8Fc^v literal 0 HcmV?d00001 diff --git a/src/kani.lua b/src/kani.lua new file mode 100644 index 0000000..208c9fc --- /dev/null +++ b/src/kani.lua @@ -0,0 +1,78 @@ +-- Code for the player's ship. +import "CoreLibs/object" +import "CoreLibs/graphics" +import "CoreLibs/sprites" +import "bullet" + +local gfx = 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 diff --git a/src/main.lua b/src/main.lua index 5199022..4fd47ea 100644 --- a/src/main.lua +++ b/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 = 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