From f550f3032706482f162759f1cffeb1ed16375569 Mon Sep 17 00:00:00 2001 From: James Turk Date: Tue, 4 Apr 2023 23:52:00 -0500 Subject: [PATCH] pick up and drop --- toomgis.p8 | 81 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/toomgis.p8 b/toomgis.p8 index 853ee0e..ad6f4b3 100644 --- a/toomgis.p8 +++ b/toomgis.p8 @@ -99,6 +99,17 @@ function add2body(n) end end +function hitbody() + to_remove = max(rnd(pieces * 0.5), 1) + for i=0,to_remove do + if pieces == 1 then + break + end + pieces -= 1 + deli(tbody) + end +end + function full() for i=2, 14 do add2body(i) @@ -131,16 +142,20 @@ end -- level levels = { - {name="store aisle", - sky=7, - gnd=5, - mapy=2 + { + name="store aisle", + sky=7, + gnd=5, + mapy=2, + bad_item_ratio=0.1, }, - {name="city nights", + { + name="city nights", sky=2, gnd=5, - mapy=5 - } + mapy=5, + bad_item_ratio=0.2, + }, } lvl = levels[1] horizon = 64 @@ -148,13 +163,10 @@ items = { {x=0, y=0, n=0}, {x=0, y=0, n=0}, {x=0, y=0, n=0}, - -- {x=0, y=0, n=0}, - -- {x=0, y=0, n=0}, - -- {x=0, y=0, n=0}, - -- {x=0, y=0, n=0}, - -- {x=0, y=0, n=0}, - -- {x=0, y=0, n=0}, - -- {x=0, y=0, n=0}, + {x=0, y=0, n=0}, + {x=0, y=0, n=0}, + {x=0, y=0, n=0}, + {x=0, y=0, n=0}, } @@ -181,7 +193,7 @@ function level_draw() if item.n != 0 then spr(item.n, item.x-px, item.y) -- collider - circ(item.x-px+4, item.y+4, 4, 8) + -- circ(item.x-px+4, item.y+4, 4, 8) end end @@ -195,6 +207,9 @@ function level_upd() if btn(⬅️) then vx -= 0.05 end + -- if btn(⬆️) then + -- pieces += 1 + -- end if vx < 0 then vx = 0 elseif vx > 3 then @@ -203,14 +218,14 @@ function level_upd() if btnp(❎) and py == 0 then yacc = 6 elseif py > 0 then - yacc = -3 + yacc = -1 elseif py == 0 and yacc < 0 then -- on ground yacc = 0 vy = 0 end - -- check for falling off back of screen and player collide + -- check for falling off back of screen and player collision for item in all(items) do if item.x < px then item.n = 0 @@ -219,19 +234,27 @@ function level_upd() local d = dist(20+8, 96-py+8, item.x+4-px, item.y+4) --printh(item.n.." "..(item.x+4-px)..","..(item.y+4).." d="..d) if d < toomgis_radius() and item.n != 0 then + -- item collision + if item.n > 16 then + hitbody() + else + add2body(item.n) + end item.n = 0 end end -- add item if inactive (chance increases as more slots inactive) to_check = rnd(items) if to_check.n == 0 then - to_check.n = flr(rnd(14)+2) + -- good items 2-14, bad items 18-30 + if rnd() < lvl.bad_item_ratio then + to_check.n = flr(rnd(12)+18) + else + to_check.n = flr(rnd(12)+2) + end to_check.x = px + 128 + rnd(100) to_check.y = rnd(100) end - - -- make toomgis bigger as he rolls - --add2body(flr(rnd(14)+2)) end -->8 @@ -260,14 +283,14 @@ __gfx__ 022247440000000044e444e4009ea9000aaaaaa000787800008ff8000555550000aa880000ffff00bbb88abbc1fff11c0644466000899880f4ffffff00997799 0222244400000000044eee40009ae9000aaaaaa0008787000088880004545400000aa000000ff00099998999cc1111cc06644600008989800ff4f4f000977779 022224770000000000444400000ee00000aaaa000088880000088000045454000008a000000ff000099999900cccccc0006666000008880000ffff0009977079 -02202944000000000000000000333300000033000000000000033000000330000003300000000000000000000033330000000000000000000000000009997799 -202029990000000000000000030330300000033000330300023333300099990003333330000000300000000003ffff3000000000000000000000000009999999 -20202099000000000000000030300303000999330000300022233320099a9a90033bb33000000b300000000003ffff3000000000000000000000000009999999 -202024090000000000000000030330300099990300888800023202229999999933bbbb330000b33000000000033333300000000000000000000000000a990000 -2020404f00000000000000000330033000999900088888800322232099999a9933bbbb33000b330000000000033333300000000000000000000000000a999000 -0020040f00000000000000000003300009999000088888800202020099999999333bb33300b3300000000000033333300000000000000000000000000aaa9999 -00000000000000000000000000033000999000000888888022202220099999900333333003330000000000000333333000000000000000000000000000aa9999 -00000000000000000000000000033000990000000088880002000200009999000030030000000000000000000033330000000000000000000000000000aaaaaa +02202944000000000006000000333300000033000000000000033000000330000003300000000000000000000033330000000330000030000033330009997799 +202029990000000000666660030330300000033000330300023333300099990003333330000000300333333003ffff300030330000023300033ee33009999999 +20202099000000000063336030300303000999330000300022233320099a9a90033bb33000000b300377773003ffff30000330000002220033eeee3309999999 +202024090000000000633360030330300099990300888800023202229999999933bbbb330000b330037997300333333000030000002222003edeede30a990000 +2020404f00000000006333600330033000999900088888800322232099999a9933bbbb33000b3300037997300333333000222000002222003eeeeee30a999000 +0020040f00000000006333600003300009999000088888800202020099999999333bb33300b330000377773003333330022222000022220033edee330aaa9999 +0000000000000000006333600003300099900000088888802220222009999990033333300333000003333330033333300022200000222200033ee33000aa9999 +00000000000000000006660000033000990000000088880002000200009999000030030000000000000000000033330000020000000220000033330000aaaaaa 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000aaaaaa 00000000000000000000000000000000000006440000000000000000099999099099099000000000000000000000000000000011000000000000000000a0aaaa 0700077700000000000000000000000000006444000000000000000099909909999999900000000000000000000000000000011100000000000000000000aaaa