Skip to content

Commit

Permalink
using 0.2.2 mouse btn alias+api
Browse files Browse the repository at this point in the history
reworked x/o control mapping
  • Loading branch information
freds72 committed Dec 8, 2020
1 parent 7fadffb commit 7d75689
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 76 deletions.
29 changes: 18 additions & 11 deletions carts/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,8 @@ function attach_plyr(thing,actor)
-- slow mode: pico calls _update 2 times
-- 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,} do
if(_slow==0) _wp_hud=not btn(6)
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 @@ -990,18 +990,19 @@ function attach_plyr(thing,actor)
-- cursor: fwd+rotate
-- cursor+x: weapon switch+rotate
-- wasd: fwd+strafe
-- o: fire
-- x: fire
-- direct mouse input?
if peek(0x5f80)==1 then
da+=(128-peek(0x5f81))/8
if stat(38)!=0 then
da+=stat(38)/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
if 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
end

if(_btns[_btnup]) dz=1
Expand Down Expand Up @@ -1264,6 +1265,7 @@ function play_state()
print(cpu,2,3,3)
print(cpu,2,2,15)
]]
-- printb(stat(0),2,2,15)
end
end

Expand Down Expand Up @@ -1311,6 +1313,10 @@ end
function _init()
-- force gc
stat(0)
-- mouse
-- enable lock+button alias
poke(0x5f2d,7)

cartdata(mod_name)

-- exit menu entry
Expand Down Expand Up @@ -1361,6 +1367,7 @@ function _update()
_update_state()
-- capture video!
if(peek(0x5f83)==1) poke(0x5f83,0) extcmd("video")

_slow+=1
end

Expand Down
26 changes: 13 additions & 13 deletions carts/title.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local snd="36530600324c000000000000000000000000000000000000000000000000000000000
-- supports player 1 or player 2 input
local _btnp=btnp
function btnp(b)
return _btnp(b,0) or _btnp(b,1)
return _btnp(b,0) or _btnp(b,1)
end

-- copy image text to spritesheet/memory
Expand Down Expand Up @@ -47,7 +47,7 @@ end

-- intro screen
function start_state()
local ttl=300
local ttl=300
-- reset saved state
dset(0,-1)

Expand Down Expand Up @@ -101,19 +101,16 @@ function menu_state()
return
function()
-- mouse?
if peek(0x5f80)==1 then
if stat(38)!=0 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)
mouse_x=mid(mouse_x+stat(38)/2,0,126)
mouse_y=mid(mouse_y+stat(39)/2,0,126)
end
if mouse_ttl>0 then
mouse_ttl-=1
-- reset control scheme if using mouse
switch_scheme(0)
end
poke(0x5f80,0)

anm_ttl=(anm_ttl+1)%48
if menu_i>0 then
Expand Down Expand Up @@ -141,10 +138,10 @@ function menu_state()
menus[menu_i].sel=active_sel
end

if btnp() then
if btnp(🅾️) then
if(menu_i>1)sfx(0)
menu_i=max(1,menu_i-1)
elseif btnp(🅾️) then
elseif btnp() then
if(menu_i>0)sfx(1)
menu_i+=1
if menu_i>#menus then
Expand Down Expand Up @@ -336,7 +333,7 @@ function credits_state()
end
print(sp,64-#sp*2,80,15)

if(ttl>0 and time()%4<2) print("🅾️/❎\23MENU",44,122,15)
if(ttl>0 and time()%4<2) print("FIRE/USE\23MENU",38,122,15)

pal(endgame_gfx.pal,1)
end,
Expand Down Expand Up @@ -382,7 +379,7 @@ end
local _scheme=0
function switch_scheme(scheme)
local scheme_help={
{caption="keyboard mode 1",btnfire=🅾️,btnuse=,btndown=⬇️,btnup=⬆️,space=0x20},
{caption="keyboard mode 1",btnfire=,btnuse=🅾️,btndown=⬇️,btnup=⬆️,space=0x20},
{caption="keyboard mode 2",btnfire=⬆️,btnuse=⬇️,btndown=7,btnup=7,space=0x8}
}
_scheme=scheme or ((_scheme+1)%2)
Expand All @@ -400,6 +397,9 @@ function switch_scheme(scheme)
end

function _init()
-- mouse suport
poke(0x5f2d, 7)

cartdata(mod_name)

-- control scheme
Expand All @@ -416,7 +416,7 @@ function _init()

-- special case for end game state
if(state==2 and mapid+1>#_maps_group) state=4

local states={
-- default
[0]={start_state},
Expand Down
56 changes: 4 additions & 52 deletions plates/fps.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,46 +216,18 @@
}
if (abs(dy) > abs(dx) * 0.6) // vertical
{
// o button
if (dy < -deadzone) b |= 0x10;
// x button
if (dy > deadzone) b |= 0x20;
if (dy < -deadzone) b |= 0x20;
// o button
if (dy > deadzone) b |= 0x10;
}

pico8_buttons[0] |= b;
}
}
}
}

function track_mouse(e) {
// enable mouse reading
pico8_gpio[0] = 1;
// clamp value to -127/127
pico8_gpio[1] = 128 - Math.min(Math.max(-127,Math.round(e.movementX)),127);
pico8_gpio[2] = 128 - Math.min(Math.max(-127,Math.round(e.movementY)),127);
}

function track_click(e, step) {
if (!p8_is_running) return;

// clear fire button
pico8_buttons[0] = 0;

// left (fire/ok)
if(e.buttons & 0x1) {
pico8_buttons[0] |= 0x10;
}
// right (open/cancel)
if(e.buttons & (0x2|0x8)) {
pico8_buttons[0] |= 0x20;
}
// middle
if(e.buttons & 0x4) {
pico8_buttons[0] |= 0x40;
}
}


// p8_update_layout_hash is used to decide when to update layout (expensive especially when part of a heavy page)
var p8_update_layout_hash = -1;
var last_windowed_container_height = 512;
Expand Down Expand Up @@ -564,26 +536,6 @@
// need to watch: https://www.chromestatus.com/feature/5723553087356928
canvas.requestPointerLock();
});

// pointer lock event listeners
function lockChangeAlert() {
if (document.pointerLockElement === canvas ||
document.mozPointerLockElement === canvas) {
canvas.addEventListener("mousemove", track_mouse, false);
canvas.addEventListener("mousedown", function(event){ track_click(event, 0); });
canvas.addEventListener("mouseup", function(event){ track_click(event, 1); });
} else {
// reset mouse values
pico8_gpio[0]=0
pico8_gpio[1]=0
canvas.removeEventListener("mousemove", track_mouse, false);
// document.removeEventListener("click", function(event){ track_click(event, 0); }, false);
}
}

// Hook pointer lock state change events for different browsers
document.addEventListener('pointerlockchange', lockChangeAlert, false);
document.addEventListener('mozpointerlockchange', lockChangeAlert, false);
}

// load and run script
Expand Down
Binary file modified plates/img/right_paddle.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 removed tools/wad_reader-3.7.tar.gz
Binary file not shown.
Binary file added tools/wad_reader-3.8.tar.gz
Binary file not shown.

0 comments on commit 7d75689

Please sign in to comment.