Hi
The problem with your code is that using:
sc=sprite collision(pspr,0)
Will only allow you to resolve the collision for one wall during a single loop of the code. So if it detects collision with the top wall first then it won't detect the collision for the side wall at the same time. Because of this, the player can press against the top wall and force their way through the side wall.
I've modified your code slightly so the code detects and, more importantly, resolves the collision for each wall during each loop of the program.
global x1
global y1
global ex1
global ey1
global pspr
global sc
global speedx
global speedy
hijau=rgb(0,255,0)
merah=rgb(255,0,0)
biru=rgb(0,0,255)
pspr=1000
box 0,0,50,50,hijau,hijau,hijau,hijau
get image pspr,0,0,50,50
cls
box 0,0,200,100,biru,biru,biru,biru
get image 100,0,0,200,100
cls
box 0,0,100,200,biru,biru,biru,biru
get image 300,0,0,100,200
cls
sync rate 60
speedx=2
speedy=2
do
gosub player:
gosub wall: rem if the walls are not moving then this sould be placed before the do-loop as it doesn't need to be called every loop of the program
gosub kontrol:
gosub rule:
sync sleep 1
loop
player:
sprite pspr,x1,y1,pspr
return
wall:
rem create the walls using sequential id numbers
sprite 101,200,100,100
sprite 102,200,400,100
sprite 103,100,100,300
sprite 104,100,300,300
return
kontrol:
if rightkey()=1 then ex1=x1-1: x1=x1+speedx
if leftkey()=1 then ex1=x1+1 : x1=x1-speedx
if upkey()=1 then ey1=y1+1 : y1=y1-speedy
if downkey()=1 then ey1=y1-1 : y1=y1+speedy
return
rule:
remstart
now that the walls are sequentially number, you can check for collision with each wall
and position the player sprite depending on the collision with each wall in every loop
of the code
remend
for i = 101 to 104
sc=sprite collision(pspr,i)
if sc<>0
if x1>sprite x(i)-sprite width(pspr) and x1<sprite x(i)+sprite width(i)
if y1>sprite y(i)-sprite height(pspr) and y1<sprite y(i)+sprite height(i)/2
y1=ey1
endif
if y1<sprite y(i)+sprite height(i) and y1>sprite y(i)+sprite height(i)/2
y1=ey1
endif
endif
if y1>sprite y(i)-sprite height(pspr) and y1<sprite y(i)+sprite height(i)
if x1>sprite x(i)-sprite width(pspr) and x1<sprite x(i)+sprite width(i)/2
x1=ex1
endif
if x1<sprite x(i)+sprite width(i) and x1>sprite x(i)+sprite width(i)/2
x1=ex1
endif
endif
endif
next i
return
Hope this helps.