Compare commits
30 Commits
5d2dafa64c
...
hud-update
Author | SHA1 | Date | |
---|---|---|---|
5870c129eb
|
|||
68863280f3
|
|||
3f7c4f59c0
|
|||
804eb62ae7
|
|||
303148876d
|
|||
b379e47dbf
|
|||
4ca3913637
|
|||
f9ba59d992
|
|||
dd143060ac
|
|||
60b685d94b
|
|||
cc1e7ea5b7
|
|||
6b8efe3438
|
|||
c2668cefea
|
|||
eebd84544b
|
|||
965fc0d688
|
|||
cc3ed20f76
|
|||
fa0cff1ffc
|
|||
4f8b861cdb
|
|||
5dc259c094
|
|||
51629376f2
|
|||
c5e49740c4
|
|||
59738d0376
|
|||
f736f50870
|
|||
ccb897af24
|
|||
c130f4cf52
|
|||
cf48497432
|
|||
9dc36a95ee
|
|||
d33d7ad6d1
|
|||
00678f97fd
|
|||
8fa98e3132
|
@ -81,9 +81,10 @@ function _draw()
|
|||||||
print("dx: ".. the_ship.dx, 20, 86, 7)
|
print("dx: ".. the_ship.dx, 20, 86, 7)
|
||||||
meter(80, 86, 128, 90, the_ship.dx/the_ship.maxspd/2)
|
meter(80, 86, 128, 90, the_ship.dx/the_ship.maxspd/2)
|
||||||
print("x: "..the_ship.x, 24, 92, 7)
|
print("x: "..the_ship.x, 24, 92, 7)
|
||||||
|
print("bx: "..gbx, 20, 98, 7)
|
||||||
|
|
||||||
print("xmin:"..tostr(constraints.xmin), 12, 102, 7)
|
print("xmin:"..tostr(constraints.xmin), 12, 108, 7)
|
||||||
print("xmax:"..tostr(constraints.xmax), 12, 108, 7)
|
print("xmax:"..tostr(constraints.xmax), 12, 114, 7)
|
||||||
end
|
end
|
||||||
|
|
||||||
function meter(x0, y0, x1, y1, frac)
|
function meter(x0, y0, x1, y1, frac)
|
||||||
@ -127,26 +128,24 @@ function ship:draw()
|
|||||||
spr(1,self.x,self.y)
|
spr(1,self.x,self.y)
|
||||||
end
|
end
|
||||||
|
|
||||||
if (self.dx == 0) return
|
--if (self.dx == 0) return
|
||||||
local bd, f = brake_dist(self.dx, self.thrust + self.drag)
|
local bd, f = brake_dist(self.dx, self.thrust + self.drag)
|
||||||
local bdx = self.x+bd-2
|
gbx = self.x+bd
|
||||||
spr(3, bdx,self.y-2)
|
spr(3, gbx-2,self.y-2)
|
||||||
print(tostr(f), bdx, self.y - 8, 14)
|
print(tostr(f), gbx-2, self.y - 8, 14)
|
||||||
end
|
end
|
||||||
|
|
||||||
function calc_velocity(v0, t, vmax, drag)
|
function calc_velocity(v0, t, vmax, drag)
|
||||||
local v1 = v0 + t
|
v0 = mid(v0 + t, vmax, -vmax)
|
||||||
local sg = sgn(v1)
|
return v0 - mid(drag, -drag, v0)
|
||||||
v1 -= sg*drag
|
|
||||||
if (sgn(v1) != sg) return 0
|
|
||||||
if (abs(v1) > vmax) return sg*vmax
|
|
||||||
return v1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ship:update()
|
function ship:update()
|
||||||
local t = btn(0) and -1 or btn(1) and 1 or 0
|
local t = btn(0) and -1 or btn(1) and 1 or 0
|
||||||
t *= self.thrust
|
t *= self.thrust
|
||||||
t = constraints:constrain(self, t)
|
t = constraints:constrain(self, t)
|
||||||
|
-- t = constraints:constrain(self, t)
|
||||||
|
-- t = constraints:constrain(self, t)
|
||||||
local s = calc_velocity(self.dx, t, self.maxspd, self.drag)
|
local s = calc_velocity(self.dx, t, self.maxspd, self.drag)
|
||||||
|
|
||||||
self.x += s
|
self.x += s
|
||||||
@ -165,10 +164,31 @@ constraints = {
|
|||||||
|
|
||||||
function constraints:constrain(s, want)
|
function constraints:constrain(s, want)
|
||||||
self.color=10
|
self.color=10
|
||||||
|
if (not self.xmin) return want
|
||||||
|
|
||||||
local v1 = calc_velocity(s.dx, want, s.maxspd, s.drag)
|
-- bmx: brake max
|
||||||
local bd, bf = brake_dist(v1, s.thrust + s.drag)
|
local v1, bmx = calc_velocity(s.dx, want, s.maxspd, s.drag), s.thrust + s.drag
|
||||||
|
local bd, bf = brake_dist(v1, bmx)
|
||||||
|
local bx, txm = s.x + bd + v1, self.xmax
|
||||||
|
if bx < self.xmin then
|
||||||
|
-- predicted brake point left
|
||||||
|
-- of xmin; apply max reverse
|
||||||
|
-- thrust, treat xmin as our
|
||||||
|
-- max target, and handle
|
||||||
|
-- overbraking by coalescing
|
||||||
|
-- with past +xmax case
|
||||||
|
self.color = 9
|
||||||
|
want = s.thrust
|
||||||
|
txm = self.xmin
|
||||||
|
v1 = calc_velocity(s.dx, want, s.maxspd, s.drag)
|
||||||
|
bd, bf = brake_dist(v1, bmx)
|
||||||
|
bx = bd + s.x + v1
|
||||||
|
end
|
||||||
|
if (bx <= txm) return want
|
||||||
|
self.color = 8
|
||||||
|
local overage = bx - txm
|
||||||
|
want -= overage/max(bf,1)
|
||||||
|
if (want < -s.thrust) want = -s.thrust
|
||||||
return want
|
return want
|
||||||
end
|
end
|
||||||
|
|
||||||
|
2162
last_tyrianlike.p8
Normal file
2162
last_tyrianlike.p8
Normal file
File diff suppressed because it is too large
Load Diff
705
vacuum_gambit.p8
705
vacuum_gambit.p8
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user