Bomb Defuser (Assets)

Retourner au jeu

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

La cartouche
Les sprites

Code


--bomb defuser (1hgj)
--by bigaston

poke(0x5f2d, 1) -- initiate mouse listener

function _init()
    mouse={}
	rnd_math()
	
	entre1=0
	entre2=0
	finish=false
	game_over=false
	
	dellay=0
	aff="?"
	temps=10
	tic=30
end

function _update()
	mouse.x=stat(32)
	mouse.y=stat(33)
	mouse.press=stat(34)
	
	test()
	test_mouse()
	
	if (temps!=0) and (finish!=true) and (game_over!=true) then
		tic-=1
		
		if (tic==0) then
			tic=30
			temps-=1
			
            if (temps==0) then
				game_over=true
			end
		end
	end
	
	if ((finis) or (game_over)) then
		if btnp(5) then
			_init()
		end
	end
end

function _draw()
	cls(7)
	palt(0,false)
	palt(7,true)
	map(0,0,0,0,16,16)
	
	print(n1.." "..s.." "..n2.." = "..aff,46,33,8)
	
	rectfill(0,121,128,128,5)
	print("create in 1h for the 146th 1hgj",3,122,7)	
	if (finish) then
		print("gg! you defuse the bomb",18,1,5)
		print("press ❎ to restart",30,7,5)
	end
	
	if (game_over) then
		print("oh non! the bomb explode!",14,1,5)
		print("press ❎ to restart",30,7,5)
	end
	
	print(temps,60,49,5)
	
	spr(10,mouse.x,mouse.y)
end

function math(enter)
	if (#soluce==2) then
		if (entre1==0) then
			entre1=enter
			aff=""..enter
		elseif (entre2==0) then
			entre2=enter
			aff=aff..enter
		end
	else
		aff=""..enter
		entre1=enter
		entre2=enter
	end
end

function test()
	if ((entre1!=0) and (entre2!=0)) then		
		if (aff==soluce) then
			finish=true
		else
			game_over=true
		end
	end
end

function rnd_math()
	n1=flr(rnd(9))+1
	n2=flr(rnd(9))+1
	sr=flr(rnd(2))
	
	if (sr==0) then
		s="+"
		soluce=""..(n1+n2)
	elseif (sr==1) then
		s="x"
		soluce=""..(n1*n2)
	end
end

function test_mouse()
	if (dellay!=0) then
		dellay-=1
	end
	
	if ((mouse.press==1) and (dellay==0)) then
		
		if ((mouse.x>=32) and (mouse.x<=51)) then
			if ((mouse.y>=56) and (mouse.y<=75)) then
				math(1)
				dellay=15
			elseif ((mouse.y>=78) and (mouse.y<=97)) then
				math(4)
				dellay=15		
			elseif ((mouse.y>=100) and (mouse.y<=119)) then
				math(7)
				dellay=15			
			end
			
		elseif ((mouse.x>=54) and (mouse.x<=73)) then
			if ((mouse.y>=56) and (mouse.y<=75)) then
				math(2)
				dellay=15
			elseif ((mouse.y>=78) and (mouse.y<=97)) then
				math(5)
				dellay=15		
			elseif ((mouse.y>=100) and (mouse.y<=119)) then
				math(8)
				dellay=15			
			end
		
		elseif ((mouse.x>=76) and (mouse.x<=95)) then
			if ((mouse.y>=56) and (mouse.y<=75)) then
				math(3)
				dellay=15
			elseif ((mouse.y>=78) and (mouse.y<=97)) then
				math(6)
				dellay=15		
			elseif ((mouse.y>=100) and (mouse.y<=119)) then
				math(9)
				dellay=15			
			end
		end
	end
end