Bomb Defuser (Assets)

Retourner au jeu

Vous pouvez utiliser ces fichiers mais pensez à me créditer :p

La cartouche
Les sprites

Code

Programme principal


--virtual computer (fc jam)
--by bigaston

cartdata("bigaston_vc")
poke(0x5f2d, 1) -- initiate mouse listener

function _init()
	mouse={x=0,y=0,press=0}
	
	if dget(2)==1 then dset(1,1) end
	
	game_over=false
	tic=30
	ctic=0
	s=60
	
	start=false
	
	count=0
	
	level=1
	
	f_t={alive=true,x=108,y=107,grab=false,mx=0,my=0}
	
	f_l={alive=true,x=1,y=1,grab=false,mx=0,my=0}
	
	f_c={alive=false,x=25,y=23,grab=false,mx=0,my=0,content=false}
	
	f_m={alive=false,x=25,y=23,grab=false,mx=0,my=0}
	
	f_h={alive=false,x=25,y=80,grab=false,mx=0,my=0,size=74}
	
	f={}
	f.alive=true
	f.x=31
	f.y=27
	f.grab=false
	f.mx=0
	f.my=0
	f.size=74 --66
	
	password_1=""
	
	password_3=""
	notif_3=false
	
	grid_4={}
	grid_true_4={}
	
	for i=1,16 do
		add(grid_4,"0")
		add(grid_true_4,"0")
	end
	hexa_4=""
	init_4()
	
end

function _update()
	h()
	
	f_level()
	
	if game_over and btnp(5) then reset() end
	
	if level!=5 then minutage() end
	test_fenetre()
	
	mouse.x=stat(32)
	mouse.y=stat(33)
	mouse.press=stat(34)
	
	update_corbeille()
	update_hint()
	start_menu()
	
	move_fenetre()
end

function _draw()
	cls()
	
	pc()
	
	fenetre()
	
	spr(1,mouse.x,mouse.y)
end

function pc()
	rectfill(0,0,127,127,12)
	draw_hint()
	draw_start()
	rectfill(0,121,127,127,3)
	rectfill(28,121,127,127,6)
	spr(2,1,122)
	print("start",8,122)
	print(heure..":"..minute,107,122,5)
	draw_corbeille()
end

function h()
	heure=stat(93)
	minute=stat(94)
	
	if (heure<10) then
		heure="0"..heure
	end
	
	if (minute<10) then
		minute="0"..minute
	end
end

function minutage()
	tic-=1
	
	if (tic==0) then
		tic=30
		s-=1
	end
	
	if s==0 then
		game_over=true
	end
end

function test_fenetre()
	if (mouse.press==1) then
		if (mouse.x>=f_l.x+14) and (mouse.x<=f_l.x+18) then
			if (mouse.y>=f_l.y) and (mouse.y<=f_l.y+4) then
				f_l.alive=false
			end
		end
		
		if (mouse.x>=f_t.x+14) and (mouse.x<=f_t.x+18) then
			if (mouse.y>=f_t.y) and (mouse.y<=f_t.y+4) then
				f_t.alive=false
			end
		end
		
		if (mouse.x>=f.x+(f.size-4)) and (mouse.x<=f.x+f.size) then
			if (mouse.y>=f.y) and (mouse.y<=f.y+4) then
				f.alive=false
			end
		end
		
		if (mouse.x>=f_c.x+63) and (mouse.x<=f_c.x+67) then
			if (mouse.y>=f_c.y) and (mouse.y<=f_c.y+4) then
				f_c.alive=false
			end
		end
		
		if (mouse.x>=f_m.x+20) and (mouse.x<=f_m.x+24) then
			if (mouse.y>=f_m.y) and (mouse.y<=f_m.y+4) then
				f_m.alive=false
			end
		end
		
		if (mouse.x>=f_h.x+f_h.size-4) and (mouse.x<=f_h.x+f_h.size) then
			if (mouse.y>=f_h.y) and (mouse.y<=f_h.y+4) then
				f_h.alive=false
			end
		end
		
		if (mouse.x>=f_t.x) and (mouse.x<=f_t.x+13) then
			if (mouse.y>=f_t.y) and (mouse.y<=f_t.y+4) then
				f_t.grab=true
				f_t.mx=mouse.x-f_t.x
				f_t.my=mouse.y-f_t.y
			end
		end
		
		if (mouse.x>=f_l.x) and (mouse.x<=f_l.x+13) then
			if (mouse.y>=f_l.y) and (mouse.y<=f_l.y+4) then
				f_l.grab=true
				f_l.mx=mouse.x-f_l.x
				f_l.my=mouse.y-f_l.y
			end
		end
		
		if (mouse.x>=f_c.x) and (mouse.x<=f_c.x+62) then
			if (mouse.y>=f_c.y) and (mouse.y<=f_c.y+4) then
				f_c.grab=true
				f_c.mx=mouse.x-f_c.x
				f_c.my=mouse.y-f_c.y
			end
		end
		
		if (mouse.x>=f_m.x) and (mouse.x<=f_m.x+19) then
			if (mouse.y>=f_m.y) and (mouse.y<=f_m.y+4) then
				f_m.grab=true
				f_m.mx=mouse.x-f_m.x
				f_m.my=mouse.y-f_m.y
			end
		end
		
		if (mouse.x>=f_h.x) and (mouse.x<=f_h.x+f_h.size-5) then
			if (mouse.y>=f_h.y) and (mouse.y<=f_h.y+4) then
				f_h.grab=true
				f_h.mx=mouse.x-f_h.x
				f_h.my=mouse.y-f_h.y
			end
		end
		
		if (mouse.x>=f.x) and (mouse.x<=f.x+(f.size-5)) then
			if (mouse.y>=f.y) and (mouse.y<=f.y+4) then
				f.grab=true
				f.mx=mouse.x-f.x
				f.my=mouse.y-f.y
			end
		end
	end
end

function move_fenetre()
	if (mouse.press==2) then
		f_t.grab=false
		f_l.grab=false
		f_c.grab=false
		f_m.grab=false
		f_h.grab=false
		f.grab=false
	end
	
	if f_t.grab then
		f_t.x=mouse.x-f_t.mx
		f_t.y=mouse.y-f_t.my
	end
	
	if f_l.grab then
		f_l.x=mouse.x-f_l.mx
		f_l.y=mouse.y-f_l.my
	end
	
	if f_c.grab then
		f_c.x=mouse.x-f_c.mx
		f_c.y=mouse.y-f_c.my
	end
	
	if f_m.grab then
		f_m.x=mouse.x-f_m.mx
		f_m.y=mouse.y-f_m.my
	end
	
	if f_h.grab then
		f_h.x=mouse.x-f_h.mx
		f_h.y=mouse.y-f_h.my
	end
	
	if f.grab then
		f.x=mouse.x-f.mx
		f.y=mouse.y-f.my
	end
end

function init_4()
	local assos="0123456789abcdef"
	local hexa="0000000100100011010001010110011110001001101010111100110111101111"
	local random=-1
	
	for i=0, 3 do
		random=flr(rnd(16))+1
		hexa_4=hexa_4..sub(assos,random,random)
		
		for l=0,3 do
			grid_true_4[1+(i*4)+l]=sub(hexa,1+(random-1)*4+l,1+(random-1)*4+l)
		end
	end
end

function start_menu()
	if ctic!=0 then ctic-=1 end
	if mouse.press==1 and ctic==0 then
		if mouse.x>=0 and mouse.x<=27 then
			if mouse.y>=121 and mouse.y<=127 then
				if (start==true) then
					start=false 
					ctic=15
				elseif not start then
				 start=true ctic=15
					ctic=15
				end
			end
		end
	end
	
	if start and mouse.press==1 and ctic==0 then
		if mouse.x>=0 and mouse.x<=40 then
			if mouse.y>=113 and mouse.y<=119 then
				off()
			end
		end
	end
end

function draw_start()
	if start then
		rectfill(-1,60,40,121,5)
		rectfill(0,60,40,68,3)
		spr(6,1,61)
		print("allan",9,62,6)
		spr(7,1,113)
		print("shutdown",9,114,6)
	end
end

function off(reset)
	if level==2 then
		dset(1,1)
	end
	
	cls()
	print("shutdown the computer",22,59,5)
	stop("please restart",36,65,5)
end

function reset()
	dset(1,0)
	dset(2,0)
	_init()
end

menuitem(1,"!erase data",reset)
            

Affichage des fenêtres


--fenetres

function fenetre()
	if not game_over then
		if f_t.alive then	fenetre_timing(f_t.x,f_t.y) end
		if f_l.alive then fenetre_level(f_l.x,f_l.y) end
		if f_h.alive then fenetre_hint(f_h.x,f_h.y) end
	
		if (level==1) then
			if f.alive then	fenetre_1(f.x,f.y) end
		end
	
		if (level==2) then
			if f.alive then	fenetre_2(f.x,f.y) end
		end
	
		if (level==3) then
			if f.alive then	fenetre_3(f.x,f.y) end
		end
	
		if (level==4) then
			if f.alive then	fenetre_4(f.x,f.y) end
		end
	
		if (level==5) then
			if f.alive then	fenetre_5(f.x,f.y) end
		end
	
		if f_c.alive then fenetre_corbeille(f_c.x,f_c.y) end
		if f_m.alive then fenetre_morse(f_m.x,f_m.y) end
	end
	
	if game_over then fenetre_over() end
end

function fenetre_timing(x,y)
	rectfill(x,y,x+18,y+12,5)
	rectfill(x+1,y+5,x+17,y+11,6)
	spr(3,x+14,y)
	if (s<10) then print("⧗0"..s,x+2,y+6,0) 
	else print("⧗"..s,x+2,y+6,0) end
end

function fenetre_level(x,y)
	rectfill(x,y,x+18,y+12,5)
	rectfill(x+1,y+5,x+17,y+11,6)
	spr(3,x+14,y)
	if (level<10) then
		l="0"..level
	end
	
	print("★"..l,x+2,y+6,0)
end

function fenetre_corbeille(x,y)
	rectfill(x,y,x+67,y+32,5)
	rectfill(x+1,y+5,x+66,y+31,6)
	spr(3,x+63,y)
	
	if f_c.content then
		spr(8,x+2,y+6)
		print("password_3.txt",x+11,y+8,5)
	end
end

function fenetre_morse(x,y)
	rectfill(x,y,x+24,y+33,5)
	rectfill(x+1,y+5,x+23,y+32,7)
	spr(3,x+20,y)
	print("..../",x+2,y+6,5)
	print("..---",x+2,y+13,5)
	print("/--./",x+2,y+20,5)
	print("..---",x+2,y+27,5)
end

function fenetre_1(x,y)
	rectfill(x,y,x+66,y+32,5)
	rectfill(x+1,y+5,x+65,y+31,6)
	spr(3,x+62,y)
	print("enter password",x+6,y+7,3)
	rect(x+12,y+14,x+54,y+22,5)
	print(password_1,x+14,y+16,3)
	rectfill(x+28,y+24,x+36,y+30,5)
	print("ok",x+29,y+25,7)
end

function fenetre_2(x,y)
	rectfill(x,y,x+74,y+24,5)
	rectfill(x+1,y+5,x+73,y+23,6)
	spr(3,x+70,y)
	
	if dget(1)==0 then
		print("an update is ready",x+2,y+6,12)
		print("please restart",x+11,y+12,12)
		print("the machine",x+17,y+18,12)
	else
		print("machine is updated",x+2,y+6,12)
		rectfill(x+33,y+16,x+41,y+22,5)
		print("ok",x+34,y+17,7)
	end
end

function fenetre_3(x,y)
	rectfill(x,y,x+66,y+32,5)
	rectfill(x+1,y+5,x+65,y+31,6)
	spr(3,x+62,y)
	print("enter password",x+6,y+7,3)
	rect(x+12,y+14,x+54,y+22,5)
	print(password_3,x+14,y+16,3)
	rectfill(x+28,y+24,x+36,y+30,5)
	print("ok",x+29,y+25,7)
end

function fenetre_4(x,y)
	rectfill(x,y,x+22,y+40,5)
	rectfill(x+1,y+5,x+21,y+39,6)
	spr(3,x+18,y)
	rectfill(x+7,y+32,x+15,y+38,5)
	print("ok",x+8,y+33,7)
	print(hexa_4,x+4,y+6,5)
	
	for i=0,3 do
		for l=0,3 do
			if grid_4[l*4+i+1]=="0" then
				spr(5,(x+2)+5*i,(y+12)+5*l)
			else
				spr(4,(x+2)+5*i,(y+12)+5*l)
			end
		end
	end 
end

function fenetre_5(x,y)
	rectfill(x,y,x+58,y+18,5)
	rectfill(x+1,y+5,x+57,y+17,6)
	spr(3,x+54,y)
	print("gg! you finish",x+2,y+6,5)
	print("the game!",x+13,y+12,5)
end

function fenetre_hint(x,y)
	if level==1 then
		rectfill(x,y,x+74,y+12,5)
		rectfill(x+1,y+5,x+73,y+11,7)
		spr(3,x+70,y)
		print("all is in the name",x+2,y+6,5)
		f_h.size=74
	elseif level==2 then
		rectfill(x,y,x+34,y+12,5)
		rectfill(x+1,y+5,x+33,y+11,7)
		spr(3,x+30,y)
		print("shutdown",x+2,y+6,5)
		f_h.size=34
	elseif level==3 then
		rectfill(x,y,x+46,y+12,5)
		rectfill(x+1,y+5,x+45,y+11,7)
		spr(3,x+42,y)
		print("delete file",x+2,y+6,5)
		f_h.size=46
	elseif level==4 then
		rectfill(x,y,x+26,y+102,5)
		rectfill(x+1,y+5,x+25,y+101,7)
		spr(3,x+22,y)
		print("0 0000",x+2,y+6,5)
		print("1 0001",x+2,y+12,5)
		print("2 0010",x+2,y+18,5)
		print("3 0011",x+2,y+24,5)
		print("4 0100",x+2,y+30,5)
		print("5 0101",x+2,y+36,5)
		print("6 0110",x+2,y+42,5)
		print("7 0111",x+2,y+48,5)
		print("8 1000",x+2,y+54,5)
		print("9 1001",x+2,y+60,5)
		print("a 1010",x+2,y+66,5)
		print("b 1011",x+2,y+72,5)
		print("c 1100",x+2,y+78,5)
		print("d 1101",x+2,y+84,5)
		print("e 1110",x+2,y+90,5)
		print("f 1111",x+2,y+96,5)
		f_h.size=26
	end
end

function fenetre_over()
	rectfill(24,52,102,78,0)
	rect(24,52,102,78,8)
	
	print("time is over!",38,54,8)
	print("you have been eject",26,60,8)
	print("by the firewall",34,66,8)
	print("press ❎ for retry",30,72,8)
end
            

Gestion des niveaux


--level code

function f_level()
	if not game_over then
		if level==1 then level_1() end
		if level==2 then level_2() end
		if level==3 then level_3() end
		if level==4 then level_4() end
	end
end

function level_1()
	keyboard=stat(31)
	if keyboard==" " then keyboard="" end
	
	if #password_1<10 then
		password_1=password_1..keyboard
	end
	
	if btnp(0) then
		password_1=sub(password_1,0,#password_1-1)
	end

	if (mouse.x>=f.x+28) and (mouse.x<=f.x+36) then
		if (mouse.y>=f.y+24) and (mouse.y<=f.y+30) then
			if (mouse.press==1) then
				if password_1=="password" then
					level+=1
					s=60
					f.size=74
					f_h.alive=false
					dset(2,1)
				end
			end
		end
	end
end

function level_2()
	if dget(1)==1 then
		if mouse.press==1 then
			if mouse.x>=f.x+33 and mouse.x<=f.x+41 then
				if mouse.y>=f.y+16 and mouse.y<=f.y+22 then
					level+=1
					s=60
					f.size=66
					notif_3=true
					f_h.alive=false
					f_c.content=true
				end
			end
		end
	end
end

function level_3()
	keyboard=stat(31)
	if keyboard==" " then keyboard="" end
	
	if #password_3<10 then
		password_3=password_3..keyboard
	end
	
	if btnp(0) then
		password_3=sub(password_3,0,#password_3-1)
	end
	
	if (mouse.x>=f.x+28) and (mouse.x<=f.x+36) then
		if (mouse.y>=f.y+24) and (mouse.y<=f.y+30) then
			if (mouse.press==1) then
				if password_3=="h2g2" then
					level+=1
					f_h.alive=false
					s=60
					f.size=22
					notif_3=false
				end
			end
		end
	end
end

function level_4()
	if count!=0 then count-=1 end
	
	for i=0,3 do
		for l=0,3 do
			if mouse.press==1 and count==0 then
				if mouse.x>=f.x+7 and mouse.x<=f.x+15 then
					if mouse.y>=f.y+32 and mouse.y<=f.y+38 then
						local test=false
						for i=1,16 do
							if grid_4[i]!=grid_true_4[i] then
								test=true
							end
						end
						
						if not test then
							level=5
							f_h.alive=false
							f_t.alive=false
							f_l.alive=false
							f.size=58
						end
					end
				end
				
				if mouse.x>=f.x+2+5*i and mouse.x<=f.x+5+5*i then
					if mouse.y>=f.y+12+5*l and mouse.y<=f.y+15+5*l then
						if grid_4[l*4+i+1]=="0" then 
							grid_4[l*4+i+1]="1" 
							count=15
						elseif grid_4[l*4+i+1]=="1" then 
							grid_4[l*4+i+1]="0" 
							count=15 
						end
					end
				end
			end
		end
	end
end
            

Gestion de la corbeille et des indices


--dossier

function draw_corbeille()
	sspr(80,0,8,8,110,2,16,16)
	print("trash",108,18)
	
	if notif_3 then	spr(11,120,12) end
end

function update_corbeille()
 if mouse.press==1 then
 	if mouse.x>=108 and mouse.x<=126 then
 		if mouse.y>=2 and mouse.y<=22 then
 			f_c.alive=true
 			notif_3=false
 		end
 	end
 	
 	if f_c.alive and f_c.content then
 		if mouse.x>=f_c.x+2 and mouse.x<=f_c.x+65 then
 			if mouse.y>=f_c.y+6 and mouse.y<=f_c.y+13 then
 				f_m.alive=true
 			end
 		end
 	end
 end
end

function draw_hint()
	sspr(72,0,8,5,2,104,17,10)
	print("hints",1,115,5)
end

function update_hint()
	if mouse.press==1 and start==false then
 	if mouse.x>=1 and mouse.x<=19 then
 		if mouse.y>=104 and mouse.y<=119 then
 			f_h.alive=true
 		end
 	end
 end
end