Skip to content

Instantly share code, notes, and snippets.

@Xzer0X
Created September 29, 2019 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xzer0X/9958a85eb3bb3429e38f689c1fd5592e to your computer and use it in GitHub Desktop.
Save Xzer0X/9958a85eb3bb3429e38f689c1fd5592e to your computer and use it in GitHub Desktop.
Code for the UW GI Game Jam Fall 2019.
Tab 0:
--unknown ocean
--markus
--init
tile=0
found=0
fb=0
v=0
pos=0
mode=0
state=0
r=0
blueprint=0
p = {
x=16,
y=16,
celx=16/8,
cely=16/8
}
slct={
n=0,
x=8
}
mouse={
x=0,
y=0,
b=0
}
pattern = {}
Tab 1:
--update
music(0)
function _update()
p.celx = p.x/8
p.cely = p.y/8
if r==0 then
if state==0 then
update_menu()
elseif state==1 then
update_blueprnt()
elseif state==2 then
update_game()
end
end
if state==3 then
update_win()
end
mouse_coord()
if r==1 then end_update() end
end
function update_menu()
if btnp(1) or mouse.b==1then
random()
state=1
music(1)
end
end
function update_game()
end_check()
if btnp(4) then
if mode!= 2 then
mode+=1
else mode=0 end
end
if mode==0 then update_move()
elseif mode==1 then update_build()
else update_place() end
--move hotbar
slct.x = slct.n*8
end
function update_build()
if btnp(1) then
if slct.n!=4 then
slct.n+=1
else slct.n=0 end
elseif btnp(0) then
if slct.n!=0 then
slct.n-=1
else slct.n=4 end
end
end
function update_move()
if btnp(5) then
r=1
find_pattern()
if found==1 then
found=0
state = 3
end
end
if btnp(0) and fget(mget(p.celx-1,p.cely),0)==false then
p.x-=8
sfx(4)
elseif btnp(1) and fget(mget(p.celx+1,p.cely),0)==false then
p.x+=8
sfx(4)
elseif btnp(2) and fget(mget(p.celx,p.cely-1),0)==false then
p.y-=8
sfx(4)
elseif btnp(3) and fget(mget(p.celx,p.cely+1),0)==false then
p.y+=8
sfx(4)
end
end
function update_place()
if btnp(0) then pos=0
elseif btnp(1) then pos=1
elseif btnp(2) then pos=2
elseif btnp(3) then pos=3 end
if btnp(5) or mouse.b==1 then
fb=3
if pos==0 then
mset(p.celx-1,p.cely,slct.n+3)
sfx(3)
elseif pos==1 then
mset(p.celx+1,p.cely,slct.n+3)
sfx(3)
elseif pos==2 then
mset(p.celx,p.cely-1,slct.n+3)
sfx(3)
elseif pos==3 then
mset(p.celx,p.cely+1,slct.n+3)
sfx(3)
end
end
end
function mouse_coord()
poke(0x5f2d, 1)
mouse.x = stat(32)
mouse.y = stat(33)
mouse.b = stat(34)
end
function end_check()
if fget(mget(p.celx-1,p.cely),0)and
fget(mget(p.celx+1,p.cely),0)and
fget(mget(p.celx,p.cely-1),0)and
fget(mget(p.celx,p.cely+1),0)then
r=1
end
end
function end_update()
if btnp(1) then
for i=0,4 do
for j=0,5 do
mset(i,j,2)
end
end
for i=0,16 do
mset(i,15,18)
end
p.x=16
p.y=16
mode=0
pos=0
r=0
slct.n=0
slct.x=8
mset(0,0,21)
mset(1,0,22)
mset(2,0,19)
mset(3,0,20)
mset(4,0,35)
end
end
function random()
pattern={}
for j=17,19 do
for i=17,19 do
tile=(flr(rnd(6))+3)
if tile == 8 then
tile=2
end
mset(i,j,tile)
add(pattern,mget(i,j))
end
end
end
function update_blueprnt()
if btnp(1) then state=2 end
end
function update_win()
if v==1 then
if btnp(1) then
state = 0
v=0
end
end
end
function find_pattern()
for y=1,4 do
for x=0,3 do
if mget(x,y)==pattern[1] then
if mget(x+1,y)==pattern[2] then
if mget(x+2,y)==pattern[3] then
if mget(x,y+1)==pattern[4] then
if mget(x+1,y+1)==pattern[5] then
if mget(x+2,y+1)==pattern[6] then
if mget(x,y+2)==pattern[7] then
if mget(x+1,y+2)==pattern[8] then
if mget(x+2,y+2)==pattern[9] then
found=1
end
end
end
end
end
end
end
end
end
end
end
end
Tab 2:
--draw
function _draw()
if state==0 then
draw_menu()
elseif state==1 then
draw_blueprnt()
elseif state==2 then
draw_game()
elseif state==3 then
draw_game()
end
spr(9,mouse.x,mouse.y)
end
function draw_menu()
cls()
rectfill(0,0,128,128,1)
print("unknown ocean",40,20,0)
print("press ➡️ or left click to start",3,70)
end
function draw_game()
cls()
if fb==1 then
feedback()
end
if fb !=0 then
fb-=1
end
map(0,0,0,0,5,6)
spr(17,slct.x,0)
spr(1,p.x,p.y)
if r==0 then
draw_dark()
if mode==0 then
print("move",105,4,7)
elseif mode==1 then
print("select",105,4,7)
else print("build",105,4,7) end
end
--place block
if mode==2 then
if r==0 then
if pos==0 then
spr(17,p.x-8,p.y)
elseif pos==1 then
spr(17,p.x+8,p.y)
elseif pos==2 then
spr(17,p.x,p.y-8)
elseif pos==3 then
spr(17,p.x,p.y+8)
end
end
end
if state==3 and btnp(1)then
v=1
end
if v==1 then draw_win() end
end
function draw_dark()
rectfill(0,8,39,47,5)
end
function draw_blueprnt()
cls()
rectfill(0,0,128,128,1)
rectfill(46,46,77,77,2)
map(17,17,50,50,3,3)
end
function draw_win()
rectfill(0,0,128,128,1)
print("you win!",50,40,0)
end
function feedback()
rectfill(0,0,42,50,7)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment