TIC-80 icon indicating copy to clipboard operation
TIC-80 copied to clipboard

problem with SFX in my program

Open goldorus opened this issue 4 months ago • 0 comments

I use sfx twice in my program. the first one (in input() function) works very well. but in the second (function LAVA()) the sound is not fully realized (as if it only played a fraction of a second) and runs in a loop, never stops even if I make sure that sfx does not repeat itself and even when I want to stop the sound when calling sfx -1 to stop, nothing works. I don't understand absolutely anything about it.

-- title: Mazetron -- author: Sara-Edit -- desc: commencement au jeu MAZETRON -- script: lua

local tuil={ {tu="0001",co=4},{tu="1000",co=9},{tu="0010",co=10}, {tu="1100",co=6},{tu="0000",co=14},{tu="0011",co=2}, {tu="0101",co=15},{tu="0100",co=13},{tu="1010",co=11}, {tu="1111",co=7},{tu="1001",co=17},{tu="0110",co=3}, {tu="1011",co=12},{tu="1110",co=8},{tu="0111",co=16}, {tu="1101",co=5} } girl_list={256,260,264,268,320,324,328,332,384,388,392,396,448,452,456,460} mg={} snaptuil={} au=0 cdir={} mfl=math.floor

up={x=0, y=-1} down={x=0, y=1} left={x=-1,y=0} right={x=1,y=0}

sx=210 speed=0.30 t=0 pl={ x=9, y=9, body=256} x1=1 y1=1 psy=0 turn=0

zone={ {nam="-7", x=1, y=2}, {nam="-6",x=31,y=2}, {nam="-5",x=61,y=2}, {nam="-4",x=91,y=2},{nam="-3",x=121,y=2}, {nam="-2",x=151,y=2},{nam="-1",x=181,y=2},{nam="0",x=211,y=2}, {nam="1",x=1,y=19},{nam="2",x=31,y=19},{nam="3",x=61,y=19}, {nam="4",x=91,y=19},{nam="5",x=121,y=19}, {nam="6",x=151,y=19},{nam="7",x=181,y=19} }

stars = 200 posx = {} posy = {} posz = {}

frame=0 rnd=math.random qt_porte=rnd(5,30) act=0 temps=0 text="" alt=1 joueur={} joueur.nom={} timedemo=0 timedem=0

function INTRO() poke(0x03FF8,8) if temps<900 then cls(4) tim=0 scr_tim=0 spr(258,0-timedemo,-10,9,15,0,0,2,2) spr(258,250-timedemo,-10,9,15,0,0,2,2) timedemo =timedemo+1 if timedemo>249 then timedemo=0 end

xprint("MAZETRON",120,10,{7,0},false,3,false,0) xprint("Presse la barre d'espace pour commencer",120,120, 6,false,1,false,0,false,1.3) spr(256,87,40,-1,4,0,0,2,2) else palet(2) cls(0) star() scroll_text() end if temps==2450 then palet(1) temps=0 end
if keytouch==5 then palet(1) act=1 end end

function MENUS() cls(0) rect(0,0,240,136,10) rectb(0,0,240,136,14) rect(3,3,234,130,16) rectb(3,3,234,130,15) xprint("MENU",120,11,{11,4},false,1,false,0) xprint("Nom du joueur n."..alt.." :",10,30,1,false,1,true) input(90,30) if string.byte(text,-1)==42 then text=text:sub(1,-2) joueur.nom[alt]=text text="" alt=alt+1 else xprint((text),90,30,3,false,1,true) end if alt==3 then act=2 end

end

function MAZE_MAKE() MAZE_reset() MAZE_GENa()

end

function MAZE_reset()

for a=0,239 do for b=0,135 do mset(a,b,0) end end

local c=1 d=2 for c=1,211,30 do for d=2,135,17 do for a=c,c+27 do for b=d,d+12 do mset(a,b,1) end end end end end

function MAZE_GENa()

if rnd(1,2)==1then zone[1].nam="Lava" zone[15].nam="Exit" else zone[15].nam="Exit" zone[1].nam="Lava" end

--QTwall=0 MAXwall=rnd(80,220) --exitR=rnd(0,12) qt_w=0 max_w=rnd(80,220) lim_w=rnd(5,15) sto=0 cont=0 haz=5 fois=0 qt_porte=rnd(40) repeat repeat fois=fois+1 if cont==0 then x=rnd(1,27) y=rnd(2,14) end if ALLDIR(x,y) then mset(x,y,0) qt_w=qt_w+1 else cont=0 haz=rnd(0,lim_w) end until ALLDIR(x,y)==false

if haz==1 then x=x+1 elseif haz==2 then x=x-1 elseif haz==3 then y=y+1 elseif haz==4 then y=y-1 end if haz>4 then haz=rnd(0,lim_w) else cont=1 end
if fois>1000 then break end until qt_w==max_w

-----temp- choisi endroit pour mettre sortie a droite-- a=1 local zx=zone[a].x local zy=zone[a].y

repeat exitR=rnd(0,12) until mget(zx+27,zy+exitR)~=0

mset(zx+28,zy+exitR,67) mset(zx+29,zy+exitR,66)

for d=1,28 do for e=2,14 do

local snaptuil=""

mg[1]=mget(d-1,e) mg[2]=mget(d,e-1) mg[3]=mget(d,e+1) mg[4]=mget(d+1,e)

for g=1,4 do if mg[g]>1 then mg[g]=0 end

    snaptuil=snaptuil..mg[g]

 end

for c=1,16 do

if tuil[c].tu==snaptuil and mget(d,e)==0 then mset(d,e,tuil[c].co) end

end snaptuil="" end end

for a=1,28 do for b=2,14 do if mget(a,b)==7 then mset(a,b,1) end if b==14 and mget(a,b)==5 or a==28 and mget(a,b)==8 or b==2 and mget(a,b)==12 or a==1 and mget(a,b)==16 then mset(a,b,1) end end end --- exemple mur avec typecode vert--- c=rnd(5) if c==1then b=6 for a=2,14 do mset(28,a,239) end for a=191,223,16 do mset(28,b,a) b=b+1 end elseif c==2then b=7 for a=2,14 do mset(1,a,206) end for a=222,254,16 do mset(1,b,a) b=b+1 end end

-------------the doors c=0 fois=0 repeat a=rnd(1,28) b=rnd(2,14)

ch=rnd(4) fois=fois+1 if mget(a,b)==3 and checkpath(a,b+1,a,b-1) and fget(mget(a-1,b),0) and fget(mget(a+1,b),0) and fget(mget(a-1,b),7) and fget(mget(a+1,b),7) then mset(a,b,(rnd(4)*8)+26) c=c+1 end if mget(a,b)==17 and checkpath(a-1,b,a+1,b) and fget(mget(a,b-1),0) and fget(mget(a,b+1),0) and fget(mget(a,b-1),7) and fget(mget(a,b+1),7) then mset(a,b,(rnd(4)*8)+30) c=c+1 end if fois>500 then break end until c==qt_porte

-------------the buttons local stop=0 for c=1,4 do repeat a=rnd(1,28) b=rnd(2,14) if mget(a,b)==3 then mset(a,b,(rnd(2)*4)+13+c) stop=1 elseif mget(a,b)==17 then mset(a,b,(rnd(2)*4)+21+c) stop=1 end until stop==1 stop=0 end

-------------personnages & objets e=rnd(5,22) for c=0,e do repeat a=rnd(1,28) b=rnd(2,14) d=rnd(80,189) if mget(a,b)==1 then mset(a,b,d) re=1 end until re==1 re=0 end

end

function checkpath(c,d,e,f)

local g={} for a =0,29 do g[a]={} for b =1,15 do g[a][b]=0 end end

if fget(mget(c,d-1),0) then g[c][d-1]=2 else g[c][d-1]=1 end if fget(mget(c,d+1),0) then g[c][d+1]=2 else g[c][d+1]=1 end if fget(mget(c+1,d),0) then g[c+1][d]=2 else g[c+1][d]=1 end if fget(mget(c-1,d),0) then g[c-1][d]=2 else g[c-1][d]=1 end g[c][d]=3 g[e][f]=4

repeat for a=1,28 do for b=2,14 do

if g[a][b]==1 and g[a][b+1]<3 then if fget(mget(a,b+1),0) then g[a][b+1]=2 else g[a][b+1]=1 end end

if g[a][b]==1 and g[a][b-1]<3 then if fget(mget(a,b-1),0) then g[a][b-1]=2 else g[a][b-1]=1 end end

if g[a][b]==1 and g[a+1][b]<3 then if fget(mget(a+1,b),0) then g[a+1][b]=2 else g[a+1][b]=1 end end

if g[a][b]==1 and g[a-1][b] <3 then if fget(mget(a-1,b),0) then g[a-1][b]=2 else g[a-1][b]=1 end end

if g[a][b]==1 then if g[a][b+1]==4 or g[a][b-1]==4 or g[a-1][b]==4 or g[a+1][b]==4 then return false else g[a][b]=3 end end end end

rien=1 for a=1,28 do for b=2,14 do if g[a][b]==1 then rien=0 end end end

until rien==1 return true

end

function ALLDIR(d,e)

local c=0 cdir={}

for a=(-1+d),(1+d) do for b=(-1+e),(1+e) do c=c+1 cdir[c]=mget(a,b) end end

if cdir[5]==0 or cdir[4]>29 or cdir[6]>29 then return false end

if cdir[3]==0 and cdir[2]==1 and cdir[6]==1 then return false end

if cdir[9]==0 and cdir[6]==1 and cdir[8]==1 then return false end

if cdir[7]==0 and cdir[4]==1 and cdir[8]==1 then return false end

if cdir[1]==0 and cdir[2]==1 and cdir[4]==1 then return false end if cdir[1]==0 and cdir[2]==0 and cdir[4]==0 then return false end if cdir[3]==0 and cdir[2]==0 and cdir[6]==0 then return false end

if cdir[9]==0 and cdir[6]==0 and cdir[8]==0 then return false end

if cdir[7]==0 and cdir[8]==0 and cdir[4]==0 then return false end

return true

end

function MAZE() loc=1

map((zone[loc].x)-1,zone[loc].y,31,13,0,11)

-- cls(0)

-- map(0,2,30,13,0,12) rectb(7,10,226,106,8) spr(260,2,120,-1,1,0,0,2,2) spr(262,222,120,-1,1,0,0,2,2) spr(288,20,121,-1,1,0,0,2,2) for a=30,210 do spr(290,a,121,-1,1,0,0,1,2) end spr(291,210,121,-1,1,0,0,1,2) xprint("Captain Crouch",83,118,5,false,1,true) xprint("dit:",140,118,1,false,1,true) spr(264,4,1,1) spr(265,14,1,1) spr(266,24,1,1) spr(267,34,1,1) spr(268,44,1,1) spr(280,228,1,1) spr(281,218,1,1) spr(282,208,1,1) spr(283,198,1,1) spr(284,188,1,1)

xprint("( 4)",160,2,1) xprint("(7 )",62,2,1) spr(296,162,1,1) spr(296,70,1,1) print("Te ben lette mon brun marde !",39,127,0) end

function person() MAZE()

spr(144,24,128,0,1,0,0,2,1) for a=40,213 do spr(146,a,128,0,1,0,0,2,1) end spr(148,227,128,0,1,0,0,1,1) xprint("She-ra :",43,121,6,false,1,1,true) clip(43,128,180,134) xprint("Comment je vais faire pour distribuer mes cadeaux ?" ,sx,129,0,false,1,1,true) clip()

spr(256,6,120,0,1,0,0,2,2)
sx=sx-1

if sx<-460 then sx=240 sfx(1,d5,2,0,15,0) act=2 end end

function scroll_text()

scr_tim=scr_tim+0.80

xprint([[ Malheur, les forces des tenebres

ont captures des gens et les ont

enfermes dans un labyrinth

malefique surnomme : MAZETRON

Ce labyrinth comporte des pieges

et il vous faudra du courage

pour affronter le monstre final

  situe a la salle au tresor

 et si possible, sortir de ce

  foutu trou a rat de marde !




          BONNE CHANCE !!!]],

115,140-tim*14,{15,11},false,1,false,0) tim=scr_tim/60

end

----------------------STARS-------------

function star_repos(p) posz[p]=1600 posx[p]=math.random(1,2000)-1000 posy[p]=math.random(1,1600)-800 end

function star_rndizer() local p for p=1,stars,1 do star_repos(p) posz[p]=math.random(1600) end end

function star_pts(x,y,z) if z<0 then return end local dd=(100+z)/50 local xx=x/dd local yy=y/dd pix(120+xx,65+yy,dd//4) end

star_rndizer()

sc=1 function star()

for i=1,stars,1
do
	star_pts(posx[i],posy[i],posz[i])
	posz[i]=posz[i]-16
end

sc=sc+1
if sc>stars then sc=1 end

if posz[sc]<0 then
	star_repos(sc)
end

end

function TERMINAL() poke(0x03FF8,0) map(0,0,30,17,0,0,-1,1,nil) rectb(61,25,118,49,14) xprint("INDICES:",120,15,14,false,1,true,0,true,1) xprint("gros",90,30,14,false,1,true,0) xprint("jaune",90,38,14,false,1,true,0) xprint("espace",150,30,14,false,1,true,0) xprint("planete",150,38,14,false,1,true,0) xprint("astronomie",90,46,14,false,1,true,0) xprint("lointaines",150,46,14,false,1,true,0) xprint("bizoune",90,54,14,false,1,true,0) xprint("chaleur",150,54,14,false,1,true,0) xprint("rechauffement",90,62,14,false,1,true,0) xprint("astre",150,62,14,false,1,true,0) xprint("_ _ _ _ _ _",120,83,14,false,1,false,0) xprint("S O L E I L",120,80,14,false,1,false,0) end

function PASSWORD()

map(120,0,30,17,0,0,-1,1,nil) if keyp(50,6,6) then stop=1 end if stop==0 then xprint("please insert 'password'",120,41, 14,false,1,false,0,false,1.1) else input(90,30,1) if string.byte(text,-1)==42 then text=text:sub(1,-2) end

xprint((text),121,38,14,false,2,false,0) end

end

function SHOP() poke(0x03FF8,0) cls(0) map(60,0,30,17,0,0,0)

spr(girl,94,56,0,1,0,0,4,4) spr(34,129,73,0,1,0,0,2,2) rect(56,15,128,36,13)

spr(500,71,17,-1,1,0,0,1,1) spr(501,71,29,-1,1,0,0,1,1) spr(502,71,41,-1,1,0,0,1,1) spr(503,131,17,-1,1,0,0,1,1) spr(504,131,29,-1,1,0,0,1,1) spr(505,131,41,-1,1,0,0,1,1) xprint("500",83,18,9,false,1,1) xprint("40",83,30,9,false,1,1) xprint("1020",83,42,9,false,1,1) xprint("6000",143,18,9,false,1,1) xprint("500",143,30,9,false,1,1) xprint("45",143,42,9,false,1,1) spr(24,95,16,0) spr(24,91,28,0) spr(24,99,40,0) spr(24,159,16,0) spr(24,155,28,0) spr(24,151,40,0)

end function MONSTER()

poke(0x03FF8,0) cls(0) map(0,0,30,17,0,0,-1,1,nil)

spr(256,97,9,3,1,0,0,6,4) --les personnages b=0 for a=20,226,46 do spr(224+b,a,107,3,1,0,0,2,2)

xprint("hp 143",a-2,125,1,false,1,true) b=b+2 end

xprint("Passe-Montagne donne un coup de pied au dragon",120,44,9 ,false,1,true,0)

if temps>190 then xprint("le dragon crache du feu...",120,52,9 ,false,1,true,0)end

if temps>382 then xprint("et brule les cheveux de Passe-Montagne !",120,60,9 ,false,1,true,0) end end

function LAVA() cls(2) poke(0x03FF8,0) rect(16,6,206,124,12) map(180,0,30,17,0,0,3,1) circ(119,75,48,1) circ(119,75,20,7) circb(119,75,49,8) circ(119,75,18,8) circb(119,75,20,8) if keytouch==4 and turn==0 then turn=0.01 end if turn>0 and turn<3.098 then turn=turn+0.03 rotation(120,76,1,turn,220,4,10,10,0,true) else rotation(120,75,1,turn,220,4,10,10,0,true) end

if turn>3.08 then lav_activ=true effet=1 xprint("DANGER !",120,10,7,false,1,true,0,false,1.3)

else xprint("lava lock off",120,10,14,false,1,true,0) end

if effet==1 then sfx(0,14,4,0,15) effet=0 end end

function palet(co) local pal={} pal[1]={0,0,0,145,145,145,105,56,20,125,68,214,16,64, 214,4,157,218,226,214,0,218,48,48,64,64,64,255,255,255, 230,161,125,238,64,153,145,97,36,40,105,52,48,210,48,255, 117,0} pal[2]={0,4,48,255,255,255,194,206,222,157,174,198,117,137,153, 56,76,93,36,52,76,12,32,52,4,28,52,59,93,201,65,166,246, 115,239,247,244,244,244,148,176,194,86,108,134,51,60,87} b=1 a=16320 for c=1,48 do poke(a,pal[co][c]) a=a+1 end end

function rotation(sx,sy,scale,angle,mx,my,mw,mh,key,useMap)

-- this is fixed , to make a textured quad -- X , Y , U , V local sv ={{-1,-1, 0,0}, { 1,-1, 0.999,0}, {-1,1, 0,0.999}, { 1,1, 0.999,0.999}}

local rp = {} --  rotated points storage

-- the scale is mw ( map width ) * 4 * scale -- mapwidth is * 4 because we actually want HALF width to center the image local scalex = (mw<<2) * scale local scaley = (mh<<2) * scale -- rotate the quad points for p=1,#sv do -- apply scale local _sx = sv[p][1] * scalex local _sy = sv[p][2] * scaley -- apply rotation local a = -angle local rx = _sx * math.cos(a) - _sy * math.sin(a) local ry = _sx * math.sin(a) + _sy * math.cos(a) -- apply transform sv[p][1] = rx + sx sv[p][2] = ry + sy -- scale UV's sv[p][3] = (mx<<3) + (sv[p][3] * (mw<<3)) sv[p][4] = (my<<3) + (sv[p][4] * (mh<<3)) end -- draw two triangles for the quad textri( sv[1][1],sv[1][2], sv[2][1],sv[2][2], sv[3][1],sv[3][2], sv[1][3],sv[1][4], sv[2][3],sv[2][4], sv[3][3],sv[3][4], useMap,key)

textri( sv[2][1],sv[2][2], sv[3][1],sv[3][2], sv[4][1],sv[4][2], sv[2][3],sv[2][4], sv[3][3],sv[3][4], sv[4][3],sv[4][4], useMap,key) end function xprint(txt,x,y,col,fixed,scale,smallfont,align,thin,blink)

local dirs={
	{1,0},{-1,0},{0,1},{0,-1},{1,1},
	{-1,-1},{1,-1},{-1,1}
}

if blink then
	if temps%(60*blink)//(30*blink)==1 then 
		return 
	end
end

if not x then
	x=120
	align=0
end
if not y then 
	y=63
end

if not col then 
	col={12,0} 
end
if type(col)=="number" then
	col={col}
end

if not scale then scale=1 end

local width=print(txt,0,-100,0,fixed,scale,smallfont)
local posx=x
if align==0 then
	posx=x-(width//2)
elseif align==1 then
	posx=x-width
end

if col[2] then
	local len=8
	if thin then len=4 end
	for o=1,len do
		print(txt,posx+dirs[o][1],
			y+dirs[o][2],col[2],fixed,scale,
			smallfont)
	end
end

print(txt,posx,y,col[1],fixed,scale,
	smallfont)

end

function input(x,y,cur)

local ecrit={'A','B','C','D','E','F','G','H','I','J','K', 'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y', 'Z','0','1','2','3','4','5','6','7','8','9'} for i=1,36 do if keyp(i,0,18) then sfx(0,14,4,0,15) text=text..ecrit[i] end end

if keyp(50,0,18) then text=text.."*" return text end if keyp(48,0,18) then text=text.." " end if keyp(51,0,18) and string.len(text)>1 then text=text:sub(1,-2) sfx(0,14,4,0,15) end if(time()%800<400) and cur==0 then rect((x-1)+(string.len(text)*4),y,4,5,11) end return text end

function TIC() keytouch=0

poke(0x03FF8,8) poke(16379,54)

---------------TIME-------------------

frame=frame+1 secon=math.floor(frame/60) min=math.floor(frame/3600) temps=temps+1 local b=0

---------------buttons pad------------------- for a=0,7 do if btnp(a,6,6) then keytouch=a end end

if btnp(0) and btnp(3) then keytouch=5 elseif btnp(0) and btnp(2) then keytouch=6 elseif btnp(1) and btnp(3) then keytouch=7 elseif btnp(1) and btnp(2) then keytouch=8 end

if keyp(32,6,6) then act=4
girl=girl_list[rnd(1,11)]end if keyp(33,6,6) then act=5 stop=0 end if keyp(34,6,6) then act=6 end if keyp(28,6,6) then act=3 end if keyp(29,6,6) then act=2 end if keyp(30,6,6) then temps=0 act=7 end if keyp(31,6,6) then act=8 end ----------------SCENES-----------------

if act==0 then INTRO() end if act==1 then timedem=0 MENUS() end if act==2 then MAZE_MAKE() sync(4,0,true) act=3 end if act==3 then sync(0,0) cls(0) MAZE() end if act==4 then sync(0,2) SHOP() end if act==5 then sync(0,2) PASSWORD() end if act==6 then sync(0,2) TERMINAL() end if act==7 then sync(0,1) cls(0) MONSTER() end if act==8 then sync(0,2) LAVA() end --if act==4 then person() end --if keyp(18,6,6) then act=4 end

end

goldorus avatar Feb 27 '24 21:02 goldorus