Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Q*BALL for Pico1k
- -- Submission code is this file, passed through Shrinko8, set to reducing compressed bytes:
- -- https://thisismypassport.github.io/shrinko8/
- -- Copyright (c) 2025 by Sizescape
- score = 0
- ballc = 0
- directions = {{0,1}, {0,-1}, {-1,-1}, {1,1}, {0,0}}
- -- Setup half of the cube sprite.
- for i=0,127 do y=i\8 x=i%8 if x-2*y<2 and x+2*y<32 do sset(x,y,x+2*y<14 and 3 or 2)end end
- lb=50
- wto="\^w\^t\^o"
- function _init()
- if lb < 16 then
- print(wto.."1ffgame over",28,56,7)
- print("\^o1ffscore: "..score,43,70,7)
- flip()
- _init()
- end
- lb=0
- timer = 100
- ballc += 1
- map = {}
- for y=0,9 do
- -- Offset, color, drop
- map[y] = {}
- for x=0,y+1 do
- map[y][x] = y > 0 and y < 9 and x > 0 and x<=y and {0,11,0} or {500,9,1}
- end
- end
- -- x, y, xd, yd, offset. Player is 1st, rest are qballs.
- mobs = {{2,4,0,0,0}}
- for i=1,ballc do
- y=rnd(7)\1+1
- x=rnd(y)\1+1
- add(mobs, {x,y,0,0,0})
- end
- end
- function _draw()
- cls()
- -- Update and draw map blocks based on state.
- for y=1,8 do
- for x=1,y do
- map[y][x][1] += map[y][x][3]
- if map[y][x][2] == 9 and map[y][x][3] == 0 do ox,oy=rnd(2),rnd(2) else ox,oy=0,0 end
- pal({0, 2, map[y][x][2]})
- spr(0, 48+x*16-y*8+ox, y*13+map[y][x][1]+oy,1,2,true)
- pal({0, 8, map[y][x][2]})
- spr(0, 48+x*16-y*8+8+ox, y*13+map[y][x][1]+oy,1,2,false)
- pal()
- end
- end
- function check_line(l)
- start=1
- good=1
- for i=1,#l do
- m=map[l[i][1]][l[i][2]]
- if m[2]~=11 do
- if i-start>1 do
- if map[l[start][1]][l[start][2]][3]+m[3]+good==3 do
- for j=start,i do
- map[l[j][1]][l[j][2]][2]=9
- end
- elseif m[3]==1 do
- start = i
- good = 1
- end
- end
- else
- good = 0
- end
- end
- end
- -- Look to see if player has formed a line of marked blocks.
- for i=0,9 do
- p={} for y=i,9 do add(p,{y,i+1}) end check_line(p) -- diagonal
- p={} for j=0,9-i do add(p,{i+j,j}) end check_line(p) -- anti-diagonal
- p={} for j=0,i+1 do add(p,{i,j}) end check_line(p) -- horizontal
- -- If a square is marked for dropping (color=9), and the main character has left the row/col, drop it
- for x=1,i do
- if map[i][x][2] == 9 and map[i][x][3] == 0 and not (mobs[1][1] == x and mobs[1][2] == i) do
- map[i][x][3] = 1
- score += 1
- lb+=1
- end
- end
- end
- -- Update and draw mobs based on their state.
- for b=#mobs,1,-1 do
- if mobs[b][3] == 0 and mobs[b][4] == 0 do
- d = rnd(4)\1
- -- b==1 is player character, get dir from gamepad
- if b==1 do
- d=4
- for t=0,3 do
- if btnp(t) do
- d = t
- end
- end
- end
- mobs[b][3] = directions[d+1][1]
- mobs[b][4] = directions[d+1][2]
- -- Check if movement is valid.
- if map[mobs[b][2]+mobs[b][4]][mobs[b][1] + mobs[b][3]][3] == 1 do
- mobs[b][3] = 0
- mobs[b][4] = 0
- end
- else
- -- Update offset. If we've moved 8 pixels, update position, reset direction, and color map.
- mobs[b][5] += 1
- if mobs[b][5] > 8 do
- mobs[b] = {mobs[b][1]+mobs[b][3], mobs[b][2]+mobs[b][4], 0, 0, 0}
- map[mobs[b][2]][mobs[b][1]][2] = b==1 and 10 or 11
- end
- end
- -- Draw player and balls.
- bx = 52+mobs[b][1]*16-mobs[b][2]*8+(2*mobs[b][3]-mobs[b][4])*mobs[b][5]+4
- by = mobs[b][2]*13+mobs[b][4]*mobs[b][5]+mobs[b][5]*(mobs[b][5]-9)/2
- if b==1 then -- Player
- print(wto.."181웃",bx-7,by-6,14)
- print('"',bx-2,by-4,1)
- else -- Balls
- circfill(bx, by, 5, 1)
- circfill(bx-1, by-1, 4, 12)
- end
- end
- -- dfs to find if a mob can be reached from a block. If not, set it to drop to let them decay.
- visited={}
- function search(x,y)
- for m in all(mobs) do if m[1]==x and m[2]==y do return true end end
- if visited[y*10+x] or map[y][x][3] == 1 do return end
- visited[y*10+x] = true
- for d in all(directions) do if search(x+d[1],y+d[2]) do return true end end
- end
- y = rnd(9)\1
- x = rnd(y+1)\1
- if not search(x,y) do
- map[y][x][2] = 9
- end
- -- Draw timer
- line(0, 120, 0, 20+100-timer, 11)
- -- Draw score
- print(score, 0, 0, 7)
- line(127, 0, 127, lb*6, lb < 16 and 8 or 11)
- -- Check for level complete. Speed up the timer if player holds X since I'm impatient.
- timer -= btn(5) and 1 or .1
- if timer <= 0 do
- _init()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment