hive.saysi.org

 

HIVE PICO-8 Tutorial

§6

6a: map, sprites & palette swapping

cloudly.p8

function _draw()
  --bg
  cls(1)
  circfill(84,20,5,10)
  rectfill(0,90,127,127,0)
  --map
  palt(0, false)
  palt(1, true)
  pal(13,0)
  map(0,0,0,0,16,16)
  palt()
  pal()
  --cloud
  spr(0,50,0,4,4)
end

function _update()

end



Merit Badge Challenge 6a ★★★

LANDSCAPE! Draw a landscape scene using the map and tiled sprites. Consider the time of day, weather, principles of composition. Use palette shenanigans to print black.





6b: simple timers & palette cycling

cloudly.p8


cloudx=128
cloud=0
flash=false
flashdown=100

function _draw()
  --bg
  cls(flash and 3 or 1)
  circfill(84,20,5,10)
  rectfill(0,90,127,127,flash and 14 or 0)
  --map
  palt(0, false)
  palt(1, true)
  if not flash then
    pal(13,0)
  end
  map(0,0,0,0,16,16)
  palt()
  pal()
  --cloud
  if flash then
    pal(6,7)
    pal(13,7)
  end
  pal()
  spr(cloud,cloudx,0,4,4)
  flash=false
end

function _update()
  --cloudcode
  cloudx-=.3333
  if cloudx < -32 then
    cloudx=128+RND(20)
    cloud=flr(rnd(3))*4
  end

  --flash counter
  flashdown-=1
  if flashdown <= 0 then
    flash=true
    flashdown=rnd()<.4 and rnd(100) or rnd(20)
  end
end



Merit Badge Challenge 6b ★★★

KINETIC LANDSCAPE using timers and palette cycling breathe life into your landscape.





6c: custom functions & powers of recursion

cloudly.p8


cloudx=128
cloud=0
flash=false
flashdown=100

function _draw()
  --bg
  cls(flash and 3 or 1)
  circfill(84,20,5,10)
  rectfill(0,90,127,127,flash and 14 or 0)
  --map
  palt(0, false)
  palt(1, true)
  if not flash then
    pal(13,0)
  end
  map(0,0,0,0,16,16)
  if flash and rnd()<.2 then
    spr(218,rnd(120)+4,72+rnd(44),1,3)
  end
  palt()
  pal()
  --cloud
  if flash then
    pal(6,7)
    pal(13,7)
    lightning(cloudx+16,20)
  end
  pal()
  spr(cloud,cloudx,0,4,4)
  flash=false
end

function _update()
  --cloudcode
  cloudx-=.3333
  if cloudx < -32 then
    cloudx=128+RND(20)
    cloud=flr(rnd(3))*4
  end

  --flash counter
  flashdown-=1
  if flashdown <= 0 then
    flash=true
    flashdown=rnd()<.4 and rnd(100) or rnd(20)
  end
end

function lightning(x,y)
  local newx=x+(rnd(2)-1)*16
  local newy=y+(rnd(2)-.3)*10
  line(x,y,newx,newy,rnd(7)+8)
  if newy<110 then
    lightning(newx,newy)
    if rnd()<.1 then
      lightning(newx,newy)
    end
  end
end



Merit Badge Challenge 6c ★★★

ENCAPSULATED BEHAVIORS WORKSHOP Describe your custom functions to the HIVELORDS (see 6c+)



Merit Badge Challenge 6c+ ★★★★

ENCAPSULATED BEHAVIORS Create some custom functions that allow you to repeat some bit of code or behavior efficiently again under varied circumstances, that is to say with different parameter inputs. Can you create a stable recursion (ie one that doesn't crash the program)?