From 79d632189100a2c707b079b3ab2a2c474e6e3764 Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Thu, 29 Feb 2024 19:58:39 -0800 Subject: [PATCH] sprite renderer and parallax drifting thing renderer --- vacation.p8 | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/vacation.p8 b/vacation.p8 index 4edca8d..da9f2eb 100644 --- a/vacation.p8 +++ b/vacation.p8 @@ -1485,9 +1485,72 @@ function spark:draw() spr(48+self.f\2, self.x, self.y) end +-- other fields: level, item +-- level must provide: +-- function :pdone(item) +-- field .pdx (scrolling parallax dx) +-- item must provide: +-- drawable api +-- .x readwrite (draw coord) +-- .w (width) +parallax = { + dx=0, + z=1, +} +mknew(parallax) + +function parallax:u() + local item = self.item + if item:u() then + self.level:pdone(self) + return true + end + + item.x += self.dx + item.x += self.level.pdx * self.z + + if item.x > 256 or item.x + item.w < -128 then + self.level:pdone(self) + return true + end +end + +function parallax:draw() + self.item:draw() +end + +spritem = { + s = {0}, + sw = 1, + sh = 1, + i = 1, + xf = -1, + f = 4, + x = 0, + y = 0, +} +mknew(spritem, function(self) + self.w = (self.sw or spritem.sw) << 3 + self.h = (self.sh or spritem.sh) << 3 +end) + +function spritem:u() + self.xf += 1 + if self.xf > self.f then + self.i += 1 + if (self.i > #self.s) self.i = 1 + self.xf = 0 + end +end + +function spritem:draw() + spr(self.s[self.i], self.x, self.y, self.sw, self.sh, self.flipx, self.flipy) +end + arcade_level = { score=0, wordwait = 90, + pdx=0, } mknew(arcade_level, function(x) x.phin = toyphin.new{