Web
Analytics
Log In  
12

Cart [#51655#] | Copy | Code | 2018-04-15 | Link
12

Sk8Border is a collaboration by Leif Halldór Ásgeirsson, Marc-André Toupin and Ben Wiley for the Anti-Fascist Game Jam.

Works in mobile browsers!

Hold Z or X to crouch, release to jump (Ollie). Do a tail or nose grind with Z or X. Rack up a nice combo to take down the wall!

More details and play instructions are at the game's official site. We recommend playing it on mobile there since we have specially tailored controls, and vibration support!

The game is "finished," but comments are always welcome.

skateboard walls mobile
P#51656 2018-04-15 21:09 ( Edited 2018-06-01 13:41)

6

Cart [#19773#] | Copy | Code | 2016-04-13 | Link
6

Cart [#19696#] | Copy | Code | 2016-04-10 | Link
6

As Scathe noted over here, there's not a proper/easy-to-use Timers API built into PICO-8. Turns out it's not too hard to build one, though, so I took up the task.

The cartridge which you can play above just counts to 10. I've reproduced all the code here:

-- start timers code

local timers = {}
local last_time = nil

function init_timers ()
  last_time = time()
end

function add_timer (name,
    length, step_fn, end_fn,
    start_paused)
  local timer = {
    length=length,
    elapsed=0,
    active=not start_paused,
    step_fn=step_fn,
    end_fn=end_fn
  }
  timers[name] = timer
  return timer
end

function update_timers ()
  local t = time()
  local dt = t - last_time
  last_time = t
  for name,timer in pairs(timers) do
    if timer.active then
      timer.elapsed += dt
      local elapsed = timer.elapsed
      local length = timer.length
      if elapsed < length then
        if timer.step_fn then
          timer.step_fn(dt,elapsed,length,timer)
        end  
      else
        if timer.end_fn then
          timer.end_fn(dt,elapsed,length,timer)
        end
        timer.active = false
      end
    end
  end
end

function pause_timer (name)
  local timer = timers[name]
  if (timer) timer.active = false
end

function resume_timer (name)
  local timer = timers[name]
  if (timer) timer.active = true
end

function restart_timer (name, start_paused)
  local timer = timers[name]
  if (not timer) return
  timer.elapsed = 0
  timer.active = not start_paused
end

-- end timers code

-- start app code

function _update ()
  update_timers()
end

function _init ()
  init_timers()

  local last_int = 0
  print(last_int)
  sfx(last_int)
  add_timer(
    "timer1",
    10,
    function (dt,elapsed,length)
      local i = flr(elapsed)
      if i > last_int then
        print(i)
        sfx(i)
        last_int = i
      end
    end,
    function ()
      print("done!")
      sfx(10)
    end
  )
end

-- end app code

The actual "Timers API" is between "-- start timers code" and "-- end timers code." It might seem a bit verbose; take what you need and leave the rest.

This should be robust enough to meet any typical needs. The main weakness right now is that you can't have multiple step or end callbacks, and you can't add callbacks after the timer is initialized.

API specification:

local timers -- CRITICAL
-- this is a table that tracks your timers by name
local last_time -- CRITICAL
-- this is the last value of time() recorded.
function init_timers() -- CRITICAL
-- run this at the start of your _init() function to make sure
-- last_time is properly in-sync.
function add_timer (name, length, step_fn, end_fn, start_paused)  -- CRITICAL
-- use this function to track a new timer.
-- PARAMS:
-- * name:
--    You can use "timers[name]" to access your timer later on, if you need to.
--    type: string
--    required? Yes.
-- * length:
--    How many seconds your timer should last.
--    type: number
--    required? Yes.
-- * step_fn:
--    A callback that gets called each time update_timers() is run.
--    Receives (dt,elapsed,length,timer) as parameters.
--    type: function
--    required? No.
-- * end_fn:
--    A callback that gets called once after the timer has expired.
--    Receives (dt,elapsed,length,timer) as parameters.
--    type: function
--    required? No.
-- * start_paused:
--    If present and truthy, makes the timer initialize as inactive.
--    type: boolean
--    required? No.
function update_timers() -- CRITICAL
-- run this as part of your _update() function.
function pause_timer(name) -- OPTIONAL
-- synactic sugar equivalent to 'timers[name].active = false.'
-- leave out if you won't use this much or at all.
-- fails silently if timer doesn't exist.
function resume_timer(name) -- OPTIONAL
-- synactic sugar equivalent to 'timers[name].active = true.'
-- leave out if you won't use this much or at all.
-- fails silently if timer doesn't exist.
function restart_timer(name, start_paused) -- OPTIONAL
-- synactic sugar equivalent to 'timers[name].elapsed = 0;timers[name].active = not start_paused.'
-- leave out if you won't use this much or at all.
-- fails silently if timer doesn't exist.
-- PARAMS:
-- * name:
--    type: string
--    required? Yes.
-- * start_paused:
--    If present and truthy, sets the timer to inactive.
--    type: boolean
--    required? No.

timer timers
P#19693 2016-04-10 18:18 ( Edited 2018-05-26 00:02)


:: More
X
About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2018-09-26 10:18 | 0.280s | 1835k | Q:35