diff --git a/autobrake_test.p8 b/autobrake_test.p8 index 39dc680..a000557 100644 --- a/autobrake_test.p8 +++ b/autobrake_test.p8 @@ -43,21 +43,27 @@ end function _init() pal(1,129,1) the_ship = ship.new() - slomo = 0 + constraints:setup() + slomo = 1 sloc = 0 reroll() end function reroll() + frames=0 + sloc=0 the_ship:reroll() end function _update60() if (btnp(4)) reroll() - slomo += btnp(2) and -1 or btnp(3) and 1 or 0 - slomo = (slomo < 0) and 0 or (slomo > 60) and 60 or slomo + if (btnp(5)) constraints:cycle() + if (btnp(3)) slomo <<= 1 + if (btnp(2)) slomo >>= 1 + slomo = (slomo < 1) and 1 or (slomo > 8192) and 8192 or slomo sloc += 1 - if sloc > slomo then + if sloc >= slomo then + frames += 1 the_ship:update() sloc=0 end @@ -65,7 +71,33 @@ end function _draw() cls(1) + constraints:draw() the_ship:draw() + print("frames: " .. frames, 4, 64, 7) + print("speed: 1/" .. slomo, 8, 70, 7) + + print("thrust: ".. actual_t, 4, 80, 7) + meter(80, 80, 128, 84, actual_t/the_ship.thrust/2) + print("dx: ".. the_ship.dx, 20, 86, 7) + meter(80, 86, 128, 90, the_ship.dx/the_ship.maxspd/2) + print("x: "..the_ship.x, 24, 92, 7) + + print("xmin:"..tostr(constraints.xmin), 12, 102, 7) + print("xmax:"..tostr(constraints.xmax), 12, 108, 7) +end + +function meter(x0, y0, x1, y1, frac) + local c = 11 + if frac < 0 then + frac = -frac + c = 8 + end + local range = x1-x0 + local midpoint = x0 + (range/2) + rectfill(x0, y0-1, x0, y1+1, 13) + rectfill(midpoint, y0-1, midpoint, y1 + 1, 13) + local width = range * frac + if (width ~= 0) rectfill(x0, y0, x0 + width, y1, c) end -->8 @@ -99,7 +131,7 @@ end function ship:update() local t = btn(0) and -1 or btn(1) and 1 or 0 t *= self.thrust - t = constrain(self, t) + t = constraints:constrain(self, t) local s,lim=self.dx+t,self.maxspd local sg = sgn(s) s -= sg*self.drag @@ -109,6 +141,7 @@ function ship:update() self.x += s self.dx = s self:add_sparks(t) + actual_t = t end function ship:add_sparks(t) @@ -117,10 +150,44 @@ end -->8 -- constraints -function constrain(s, want) +constraints = { + ymin=20, + ymax=52, +} + +function constraints:constrain(s, want) return want end +function constraints:cycle() + if self.ctype=="bounds" then + self.ctype="point" + elseif self.ctype=="point" then + self.ctype="off" + else + self.ctype="bounds" + end + self:setup() +end + +function constraints:setup() + if self.ctype=="point" then + self.xmin = 64 + self.xmax = 64 + elseif self.ctype=="bounds" then + self.xmin = 32 + self.xmax = 96 + else + self.xmin = nil + self.xmax = nil + end +end + +function constraints:draw() + if (not self.xmin) return + rect(self.xmin, self.ymin, self.xmax, self.ymax, 10) +end + -->8 -- fx