alrite im sick of fiddlin with this thing. it works for the most part, but there are a few glitches. this is one way to control the barriers, altho seeing how much work that was and how it still doesnt work im thinking there must be a better way
click on the top 2/3 of ech barrier 4 times to destroy that section....i have no idea why the bottom sections wont work, but im sick of messing with it. if u have any questions just call em out
sync on : sync rate 60 : set display mode 640,480,32
rem make a simple image for the barrier
ink rgb(255,255,255),0
box 0,0,120,30
get image 1,0,0,120,30
rem make a small image for mouse collision detection
get image 2,0,0,5,5
rem clear screen
cls
rem make a small bmp to hold all of our barriers
create bitmap 1,630,30
rem paste the barrier image into 4 spots on the bitmap
for x = 0 to 511 step 120
paste image 1,x,0
inc x,50
next x
rem set the current bmp to the screen (bmp 0)
set current bitmap 0
rem create an array to hold all the data for the barriers
barrier=4
section=9 : rem i used 9 to make it easier to subdivide the barrier
dim SectionHealth(barrier, section)
rem initialize all section's HP to 4
for b = 1 to 4
for s = 1 to 9
SectionHealth(b,s) = 4
next s
next b
rem make an array for storing locations of each section
barrier=4
section=10
XorY=2
dim SectionLoc(barrier, section, XorY)
rem fill array with data about each section
SectionCounter=1
for b=0 to 3 : rem each barrier
for Y=0 to 29 step 10 : rem Y value of each section's top-left corner
for X = (b*170) to (b*170)+ 119 step 40 : rem This formula calculates the X coordinate of each section's top-left corner
SectionLoc(b+1,SectionCounter,1)=X
SectionLoc(b+1,SectionCounter,2)=Y
inc SectionCounter : rem increase the section number
next x
next Y
SectionCounter=1 : rem reset the Section Number for the new barrier
next b
rem main loop
do
rem go to the barrier bmp and get the image of the current barrier setup
set current bitmap 1
get image 3,0,0,629,29
set current bitmap 0
rem make sprites for the current barrier setup andone for the mouse location
sprite 1,0,0,3
sprite 2,Mousex(),MouseY(),2
rem print text explaining what to do
text 0,200,"Click on a spot on the barriers to damage that section"
rem check for mouseclick
if mouseclick()=1
if mouseflag=0 : rem this flag stops continuous damag
if sprite collision(1,2) : rem check if you clicked on the barrier using sprite collision
BarrierHit(Mousex(),MouseY() ): rem i prefer to use functions for this so that mouse coordinates cant change during checking
mouseflag=1 : rem turn on the flag
endif
endif
else
rem if mouse ISNT clicked then reset the flag
mouseflag=0
endif
rem refresht the screen
sync
cls
loop
function BarrierHit(MouseX1, MouseY1)
rem find which barrier was hit based on the X value
if MouseX1 < 145 : rem Barrier 1 hit
B=1
else
if MouseX1 < 315 : rem Barrier 2 hit
B=2
else
if MouseX1 < 485 : rem Barrier 3 hit
B=3
else
B=4 : rem Only other option is Barrier 4
endif
endif
endif
rem now that we have established which barrier was hit we can find which section was hit
for s = 1 to 9
X=SectionLoc(B,s,1) : rem set x = the X value of the top left corner of the section
if X <= MouseX1 AND MouseX1 <= X+40
rem then we know the mouse click location was between the left and right sides of the section
Y=SectionLoc(B,s,2) : rem repeat process for Y
if y <= MouseY1 AND MouseY1 <= Y+10
rem we kow this section was hit
rem set FinalS to the hit section and exit this loop
FinalS = s
goto exit1
endif
endif
next s
rem exit from above loop
exit1:
Rem lower the health of the hit Section
if SectionHealth(B,FinalS)>0 then SectionHealth(B,FinalS)=SectionHealth(B,FinalS)-1
rem check for destroyed section and react accordingly (by covering the section with a black box)
if SectionHealth(B,FinalS)=0
set current bitmap 1
ink 0,0
X=SectionLoc(B,FinalS,1)
Y=SectionLoc(B,FinalS,2)
box X,Y,X+40,Y+10
endif
set current bitmap 0
endfunction