Skip to content

Commit

Permalink
reworked controls
Browse files Browse the repository at this point in the history
  • Loading branch information
freds72 committed Nov 22, 2020
1 parent 483f2ff commit 2e066f7
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 59 deletions.
74 changes: 36 additions & 38 deletions carts/main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- globals
local _slow,_ambientlight,_ammo_factor,_intersectid,_onoff_textures,_transparent_textures,_bsp,_cam,_plyr,_things,_sprite_cache,_actors,_btns,_wp_hud,_msg=0,0,1,0,{[0]=0},{}
local _slow,_ambientlight,_ammo_factor,_intersectid,_onoff_textures,_transparent_textures,_things,_btns,_bsp,_cam,_plyr,_sprite_cache,_actors,_wp_hud,_msg=0,0,1,0,{[0]=0},{},{},{}

--local k_far,k_near=0,2
--local k_right,k_left=4,8
Expand Down Expand Up @@ -371,8 +371,8 @@ function draw_flats(v_cache,segs)
if #verts>2 then
local sector,pal0=segs.sector
local floor,ceil,light,things=sector.floor,sector.ceil,max(sector.lightlevel,_ambientlight),{}
-- not visible?
if(floor+m8<0) polyfill(verts,sector.tx or 0,floor,sector.floortex,light)
-- not visible or no texture?
if(sector.floortex!=0 and floor+m8<0) polyfill(verts,sector.tx or 0,floor,sector.floortex,light)
if(ceil+m8>0) polyfill(verts,0,ceil,sector.ceiltex,light)

-- draw walls
Expand Down Expand Up @@ -789,7 +789,7 @@ function with_physic(thing)
-- alive floating actor? : track target height
if not self.dead and actor.floating then
dz+=rnd(1.6)-0.9
if(self.target) dz+=mid((self.target[3]-self[3])>>8,-2,2)
if(self.target) dz+=mid(self.target[3]-self[3],-512,512)>>8
-- avoid woobling
dz*=friction
end
Expand Down Expand Up @@ -883,7 +883,7 @@ function with_physic(thing)
-- buttons
if ldef.trigger and ldef.playeruse then
-- use special?
if btnp(🅾️) then
if btnp(_btnuse) then
ldef.trigger(self)
end
-- trigger/message only closest hit
Expand Down Expand Up @@ -962,7 +962,7 @@ function with_health(thing)
self.health=max(self.health-hp)\1
if self.health==0 then
-- register kill
if(instigator==_plyr and self.actor.countkill) _kills+=1
if(self.actor.countkill) _kills+=1

die(self,dmg)
end
Expand Down Expand Up @@ -991,8 +991,7 @@ function with_health(thing)
end

function attach_plyr(thing,actor,skill)
local dmg_factor=({0.5,1,1,2})[skill]
local bobx,boby,speed,da,wp,wp_slot,wp_yoffset,wp_y,hit_ttl,wp_switching=0,0,actor.speed,0,thing.weapons,thing.active_slot,0,0,0
local bobx,boby,speed,da,wp,wp_slot,wp_yoffset,wp_y,hit_ttl,dmg_factor,wp_switching=0,0,actor.speed,0,thing.weapons,thing.active_slot,0,0,0,pack(0.5,1,1,2)[skill]

local function wp_switch(slot)
if(wp_switching) return
Expand Down Expand Up @@ -1020,7 +1019,7 @@ function attach_plyr(thing,actor,skill)
-- but button state is updated only on first frame
-- skip button state check in this case (e.g. keep hud open)
if(_slow==0) _wp_hud=not (btn(6) or btn(6,1))
for i,k in pairs{0,3,1,2,4} do
for i,k in pairs{0,3,1,2,} do
if btnp(k) or btnp(k,1) then
-- only switch if we have the weapon and it's not the current weapon
_wp_hud,_btns=(wp_slot!=i and wp[i]) and wp_switch(i),{}
Expand All @@ -1031,21 +1030,21 @@ function attach_plyr(thing,actor,skill)
-- cursor+x: weapon switch+rotate
-- wasd: fwd+strafe
-- o: fire
if btn(🅾️) then
if(_btns[0]) dx=1
if(_btns[1]) dx=-1
-- direct mouse input?
elseif peek(0x5f80)==1 then
if peek(0x5f80)==1 then
da+=(128-peek(0x5f81))/8
daf=0.2
poke(0x5f80,0)
elseif btn(❎) then
if(_btns[0]) dx=1
if(_btns[1]) dx=-1
else
if(_btns[0]) da-=0.75
if(_btns[1]) da+=0.75
end

if(_btns[2]) dz=1
if(_btns[3]) dz=-1
if(_btns[_btnup]) dz=1
if(_btns[_btndown]) dz=-1

_wp_hud=btn(6)
poke(0x5f30,1)
Expand Down Expand Up @@ -1208,8 +1207,6 @@ end
--_max_cpu,_max_cpu_ttl=0,0

function play_state()
_things,_btns,_wp_hud={},{}

-- stop music (eg. restart game)
music(-1)

Expand Down Expand Up @@ -1262,7 +1259,7 @@ function play_state()
draw_bsp()
_plyr:hud()

if(_msg) print(_msg,64-#_msg*2,120,15)
if(_msg) printb(_msg,64-#_msg*2,50,15)

-- spr(0,0,64,16,8)
-- debug messages
Expand Down Expand Up @@ -1301,10 +1298,10 @@ function gameover_state(pos,angle,target,h)
idle_ttl-=1
-- avoid immediate button hit
if idle_ttl<0 then
if btnp(🅾️) then
if btnp(_btnuse) then
-- 1: gameover
load(mod_name.."_0.p8",nil,_skill..",".._map_id..",1")
elseif btnp() then
elseif btnp(_btnfire) then
-- 3: retry
load(mod_name.."_0.p8",nil,_skill..",".._map_id..",3")
end
Expand All @@ -1314,7 +1311,7 @@ function gameover_state(pos,angle,target,h)
function()
draw_bsp()

if(time()%4<2) printb("you died - ❎ restart/🅾️ menu",8,120,12)
if(time()%4<2) printb(" you died\n\nFIRE\23RESTART USE\23MENU",22,108,12)

-- set screen palette
-- pal({140,1,139,3,4,132,133,7,6,134,5,8,2,9,10},1)
Expand All @@ -1336,8 +1333,8 @@ function _init()
-- launch params
local p=split(stat(6))
_skill,_map_id=tonum(p[1]) or 2,tonum(p[2]) or 1
-- sky texture
_sky_height,_sky_offset=_maps_sky[_map_id*2-1],_maps_sky[_map_id*2]
-- sky texture + load keyboard control mapping
_sky_height,_sky_offset,_btnfire,_btnuse,_btndown,_btnup=_maps_sky[_map_id*2-1],_maps_sky[_map_id*2],dget(35),dget(36),dget(37),dget(38)
-- skybox fill pattern
fillp(0xaaaa)

Expand All @@ -1352,19 +1349,17 @@ function _update()
end

-- any futures?
local tmp={}
for k,async_handle in pairs(_futures) do
for i=#_futures,1,-1 do
-- get actual coroutine
local f=async_handle.co
local f=_futures[i].co
-- still active?
if f and costatus(f)=="suspended" then
-- todo: remove assert for release
assert(coresume(f))
add(tmp,async_handle)
coresume(f)
else
deli(_futures,i)
end
end
_futures=tmp


-- decay flash light
_ambientlight*=0.8
-- keep world running
Expand Down Expand Up @@ -1506,12 +1501,16 @@ function unpack_special(sectors,actors)
end
elseif special==243 then
-- exit level
local delay=unpack_variant()
return function()
-- save player's state
_plyr:save()

-- record level completion time + send stats
load(mod_name.."_0.p8",nil,_skill..",".._map_id..",2,"..(time()-_start_time)..",".._kills..",".._monsters..",".._secrets)
local t=time()-_start_time
do_async(function()
wait_async(delay)
-- record level completion time + send stats
load(mod_name.."_0.p8",nil,_skill..",".._map_id..",2,"..t..",".._kills..",".._monsters..",".._secrets)
end)
end
end
end
Expand Down Expand Up @@ -1578,7 +1577,7 @@ function unpack_actors()
-- A_WeaponReady
function(item)
return function(owner,weapon)
if not _wp_hud and btn() then
if not _wp_hud and btn(_btnfire) then
local inventory,ammotype,newqty=owner.inventory,item.ammotype,0
-- handle "fist" (eg weapon without ammotype)
if(ammotype) newqty=inventory[ammotype]-item.ammouse
Expand Down Expand Up @@ -1821,7 +1820,7 @@ function unpack_actors()
end
end

local pickup_factory={
item.pickup=pack(
-- default inventory item (ex: lock)
function(thing,target)
pickup(thing,target.inventory)
Expand All @@ -1844,8 +1843,7 @@ function unpack_actors()
function(thing,target)
pickup(thing,target,"armor")
end
}
item.pickup=pickup_factory[kind+1]
)[kind+1]

-- actor states
unpack_array(function()
Expand Down
108 changes: 90 additions & 18 deletions carts/title.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ function start_state()
end

function menu_state()
local mouse_ttl,mouse_x,mouse_y=0,0,0
local help_keyboard,help_mouse,help_i,help_ttl,help={
"",
"🅾️/(c)\23SELECT",
"❎/(x)\23BACK",
"(p)AUSE\23CONTROL OPTIONS"
},
{
"",
"LEFT MOUSE\23SELECT",
"RIGHT MOUSE\23BACK"
},0,90
local menus,menu_i,anm_ttl={
{"wHICH ePISODE?",_maps_label,sel=1,max=1},
{"sELECT sKILL lEVEL",
Expand All @@ -85,24 +97,61 @@ function menu_state()

return
function()
help=help_keyboard
if help_ttl>0 then
help_ttl-=1
else
help_ttl=30
help_i+=1
end
-- mouse?
if peek(0x5f80)==1 then
mouse_ttl=30
mouse_x+=(128-peek(0x5f81))/2
mouse_y+=(128-peek(0x5f82))/2
mouse_x=mid(mouse_x,0,126)
mouse_y=mid(mouse_y,0,126)
end
if mouse_ttl>0 then
mouse_ttl-=1
help=help_mouse
-- reset control scheme if using mouse
switch_scheme(0)
end
poke(0x5f80,0)

help_i=help_i%#help

anm_ttl=(anm_ttl+1)%48
if menu_i>0 then
local active_sel=menus[menu_i].sel
if btnp(2) then
active_sel-=1
sfx(0)
end
if btnp(3) then
active_sel+=1
sfx(0)
if mouse_ttl>0 then
local prev_sel=active_sel
for i=1,#menus[menu_i][2] do
if i<=menus[menu_i].max and mouse_y>69+i*8 and mouse_y<=75+i*8 then
active_sel=i
end
end
if(prev_sel!=active_sel) sfx(0)
else
if btnp(2) then
active_sel-=1
sfx(0)
end
if btnp(3) then
active_sel+=1
sfx(0)
end
-- unlocked?
active_sel=mid(active_sel,1,menus[menu_i].max)
end
-- unlocked?
menus[menu_i].sel=mid(active_sel,1,menus[menu_i].max)
menus[menu_i].sel=active_sel
end
if btnp(5) then

if btnp(❎) then
if(menu_i>1)sfx(0)
menu_i=max(1,menu_i-1)
elseif btnp(4) then
elseif btnp(🅾️) then
if(menu_i>0)sfx(1)
menu_i+=1
if menu_i>#menus then
Expand All @@ -117,35 +166,39 @@ function menu_state()
cls()
memcpy(0x6000,0x4e00,64*13)
spr(0,0,13,16,15)
printb("@fsouchu",2,121,vcol(4))
printb("@gamecactus",83,121,vcol(4))
printb("@FSOUCHU",2,0,vcol(2))
printb("@GAMECACTUS",83,0,vcol(2))

-- dark menu background
-- todo: fix
for i=0,15 do
pal(vcol(i),sget(112+i,129-13))
--pset(i,0,i)
end
sspr(12,51,104,19+#menus[menu_i][2]*9,12,64)
sspr(12,51,104,15+#menus[menu_i][2]*8,12,64)
pal()

-- title
printb(menus[menu_i][1],63-#menus[menu_i][1]*2,69,vcol(14))
printb(menus[menu_i][1],63-#menus[menu_i][1]*2,67,vcol(14))

-- selection marker
rectfill(18,70+menus[menu_i].sel*9,113,79+menus[menu_i].sel*9,vcol(2))
rectfill(18,68+menus[menu_i].sel*8,113,75+menus[menu_i].sel*8,vcol(2))
palt(vcol(0),false)
palt(vcol(4),true)
sspr(anm_ttl\12*10,115,11,12,14,68+menus[menu_i].sel*9)
sspr(anm_ttl\12*10,115,11,12,14,65+menus[menu_i].sel*8)
palt()

-- menu items
for i=1,#menus[menu_i][2] do
local s=menus[menu_i][2][i]
if(i>menus[menu_i].max) s=masked(s)
printb(s,28,72+i*9,i<=menus[menu_i].max and vcol(4) or vcol(3))
printb(s,28,69+i*8,i<=menus[menu_i].max and vcol(4) or vcol(3))
end

if(mouse_ttl>0) palt(vcol(4),true) sspr(41,115,10,10,mouse_x,mouse_y) palt()

local s=help[help_i+1]
printb(s,64-#s*2,121,vcol(3),vcol(2))
pal(title_gfx.pal,1)
end,
-- init
Expand Down Expand Up @@ -319,10 +372,29 @@ function slicefade_state(...)
memcpy(0x0,0x6000,8192)
end
end
local _scheme=0
function switch_scheme(scheme)
local scheme_help={
{caption="keyboard mode 1",btnfire=🅾️,btnuse=❎,btndown=⬇️,btnup=⬆️},
{caption="keyboard mode 2",btnfire=⬆️,btnuse=⬇️,btndown=7,btnup=7}
}
_scheme=scheme or ((_scheme+1)%2)
local s=scheme_help[_scheme+1]
menuitem(1,s.caption,switch_scheme)
-- save scheme
dset(34,_scheme)
dset(35,s.btnfire)
dset(36,s.btnuse)
dset(37,s.btndown)
dset(38,s.btnup)
end

function _init()
cartdata(mod_name)

-- control scheme
switch_scheme(dget(34))

-- sound effects
local addr=0x3200
for i=0,#snd\4-1 do
Expand Down
Binary file modified graphics/G_END.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/G_TITLE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2e066f7

Please sign in to comment.