# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### 2D All the way! / Reach For Stars Problem

Message
Posted: 22nd Aug 2003 04:03 Edited at: 22nd Aug 2003 04:04

Hello I am working on this puzzle game called Reach For Stars. But I have a problem with my code. It will move right to left but not left to right.

Here's My Code:
Randomize timer():Sync On:Hide Mouse:choice1=0:choice2=0
board_width=384:board_height=640:new_level=1:do:if new_level=1 then make_level
Sprite 61,MouseX(),MouseY(),6:Scale Sprite 61,50:new_level=0
Move
Sync:loop:end
Function make_level
for y=0 to 9:for x=0 to 5:board(x,y)=rnd(4)+1:next x:next y:star=1:start_x=10:start_y=90:for y=0 to 9:for x=0 to 5
if board(x,y)=1 then Sprite star,start_x,start_y,1:newstar=star+1:star=newstar
if board(x,y)=2 then sprite star,start_x,start_y,2:newstar=star+1:star=newstar
if board(x,y)=3 then sprite star,start_x,start_y,3:newstar=star+1:star=newstar
if board(x,y)=4 then sprite star,start_x,start_y,4:newstar=star+1:star=newstar
if board(x,y)=5 then sprite star,start_x,start_y,5:newstar=star+1:star=newstar
new_x=start_x+32:start_x=new_x:next x:new_y=start_y+32:start_y=new_y:start_x=10:next y
EndFunction
Function Move
hit=Sprite Collision(61,0)
if Mouseclick()=1
if hit>0
if hit>0 then x=sprite x(hit)
if hit>0 then y=sprite y(hit)
if choice1=0
choice1_x=x/32:choice1_y=(y/32)-2:choice1_star=hit:choice1=1:if hit>0 then choice1star_x=Sprite x(hit):choice1star_y=Sprite y(hit):choice1=1
else
choice2_x=x/32:choice2_y=(y/32)-2:choice2_star=hit:choice2=1:if hit>0 then choice2star_x=Sprite x(hit):choice2star_y=Sprite y(hit)
endif

Rem Check to see if they are close
x=0: y=0
if choice1=1 and choice2=1
remstart if choice1_x>choice2_x
x=choice1_x-choice2_x
else
x=choice2_x-choice1_x
endif
if choice1_y>choice2_y
y=choice1_y-choice2_y
else
y=choice2_y-choice1_y
endif

if x<=1 and y<=1
remend
temp=board(choice1_x,choice1_y)
board(choice1_x,choice1_y)=board(choice2_x,choice2_y)
board(choice2_x,choice2_y)=temp
star1=board(choice1_x,choice1_y)
star2=board(choice2_x,choice2_y)
Sprite choice1_star,choice2star_x,choice2star_y,star2
Sprite choice2_star,choice1star_x,choice1star_y,star1
choice1=0
choice2=0
endif
endif
Rem Let's Move The Sprites

endif
EndFunction
Function Match_Check
dim found(6,6)
dim star_sprite(6)
star=1
check=1
found=0
for y=0 to 9
for x=0 to 5
if board(x,y)=check then newfound=found+1:found=newfound:found(x,y)=board(x,y):star_sprite(x)=star:new_star=star+1:star=new_star
else
found=0
next x
if found>=4
for x=0 to 5
delete sprite star_sprite(x)
next x
endif
new_check=check+1
check=new_check
next y
endfunction

Posted: 24th Aug 2003 11:56
There are additional issues with it. You can swap opposite corner stars and other pairs as well. I'd assume that only adjacent stars are supposed to be swapped. The code is too complex for me to quickly debug. Finding your own bugs makes you a better and more experienced programmer.

The more you see, the more you know.
The more you know, the more you see.