This is my second post since you posted last, Dave. So, make sure you read the one that is above this one too. I went over your code changes, but because you are using your own media, I couldn't actually run it. I would need to use my own media for that, and I didn't feel like fooling with it at the moment. I just kind of proof read it.
Looking at the code, my suspicions look to be correct about the check image problem. I didn't see any real problems with the collision other than that. I made some of my own mods to show you what might be done. I tried to comment on certain things that were important right in the code. Hopefully, you can understand it.
After Tuesday, I won't be able to help you. I will be out of town until next Sunday. So, you got me until after Tuesday night. I would like to see how this game comes out for ya!
Just keep at it, you'll get it!
D Ogre
<edited post>
Below is your orginal code with my comments and a few changes in place.
Don't know if it runs because I don't have the media.
REMSTART
*****************************
* My First Game Attempt *
* Space Invader Type Game *
* with help from D Ogre *
*****************************
REMEND
REM *** initialize screen ***
HIDE MOUSE
SYNC ON
SYNC RATE 60
REM *** load graphics ***
REM invaders
LOAD BITMAP "D:bmpinvaders.bmp",1
GET IMAGE 1,0,0,29,29
GET IMAGE 2,30,0,59,29
GET IMAGE 3,60,0,89,29
REM ship
LOAD BITMAP "D:bmpship.bmp",2
GET IMAGE 100,0,0,29,29
REM laser
LOAD BITMAP "D:bmplaser.bmp",3
GET IMAGE 101,0,0,5,5
REM explosion
LOAD BITMAP "D:bmpexplode.bmp",4
GET IMAGE 110,0,0,29,29
GET IMAGE 111,30,0,59,29
GET IMAGE 112,60,0,89,29
GET IMAGE 113,90,0,119,29
REM blank image after explosion
INK RGB(0,0,0),0
BOX 0,0,29,29
GET IMAGE 114,0,0,29,29
REM delete garbage
DELETE BITMAP 1
DELETE BITMAP 2
DELETE BITMAP 3
DELETE BITMAP 4
SET CURRENT BITMAP 0
REM *** setup sprites ***
REM BACKSAVE STATE=OFF, TRANSPARENCY=ON
REM NEED THIS ONLY ONCE!!! OUT OF THE GAME LOOP.
REM invaders
FOR i=1 TO 18:SET SPRITE i,0,1:NEXT i
REM ship and laser
FOR i=100 TO 101:SET SPRITE i,0,1:NEXT i
REM explosion
FOR i=110 TO 114:SET SPRITE i,0,1:NEXT i
REM grab screen size
screenx=SCREEN WIDTH()
screeny=SCREEN HEIGHT()
REM *** arrays ***
DIM ship(18)
REM *** starting of game variables ***
new_game:
level=0
score=0
lives=3
REM *** each new level variables ***
new_level:
offsetx=30
offsety=50
movex=3
destroyed=0
explode=0
fire=0
entity=0
REM create invader rows for levels (1 level right now)
REM could use READ/DATA/RESTORE for each level here!
FOR pic=1 TO 3
FOR ship= 1 TO 6
inc entity
ship(entity)=pic
NEXT ship
NEXT pic
Rem set text size for LIVES, TITLE, and SCORE
set text size 20
Rem position the ship
Rem The subroutines will take care of the rest concerning
Rem the image assignment and locations of the sprites.
Rem There is no need to do anymore positioning and set up.
POSITION MOUSE 320,450
Rem *** game action loop ***
REPEAT
CLS
GOSUB title
GOSUB background
GOSUB invaders
GOSUB ship_controls
GOSUB laser_collision
SYNC
UNTIL destroyed=18 or lives=0
Rem Find out game status
SET TEXT SIZE 40
IF lives>0
INC level
FOR l=1 TO 30
INK RGB(RND(128)+127,RND(128)+127,RND(128)+127),0
CENTER TEXT screenx/2,screeny/2,"LEVEL "+STR$(level)+" COMPLETED !!!"
WAIT 10:SYNC
NEXT l
ELSE
CENTER TEXT screenx/2,screeny/2,"GAME OVER"
SET TEXT SIZE 10
CENTER TEXT screenx/2,screeny-40/2,"To Quit Press the ESC key"
SYNC
REPEAT:UNTIL ESCAPEKEY()=1
END
ENDIF
REM Here you could check to see what level it is.
REM IF it is the end game level you could display a
REM Congratulations! for winning and then display high score.
REM Maybe go back to the main title screen.
goto new_level
REM *** gosubs ***
REM score
REM you dont need the double quotes at then end +"" of the text.
REM I also wouldn't use SET TEXT SIZE in a loop, DB dosen't
REM like it very well. VERY SLOW and unpredictable! Set it
REM before any loops. Remember the sub. is part of the loop.
title:
rem SET TEXT SIZE 20
INK RGB(255,255,255),0
CENTER TEXT screenx/2,5,"INVADER CLONE"
TEXT 50,5,"SCORE: "+str$(score)
TEXT 500,5,"LIVES: "+str$(lives)
RETURN
REM create background
background:
INK RGB(0, 0, 255), 0
DrawRect(0, 0, 639, 479)
INK RGB(255, 255, 255), 0
FOR d = 1 TO 10
DOT RND(639), RND(479)
NEXT d
RETURN
REM space invaders movement
invaders:
invader = 0
FOR y = 0 TO 2
FOR x = 0 TO 5
INC invader
invadx = offsetx + ((SPRITE WIDTH(invader)*x)*1.5)
invady = offsety + ((SPRITE HEIGHT(invader)*y)*1.5)
SPRITE invader, invadx, invady, ship(invader)
NEXT x
NEXT y
offsetx = offsetx + movex
IF SPRITE X(1) < 30 THEN movex = 3
IF SPRITE X(6) > 570 THEN movex = -3
RETURN
REM ship movement
ship_controls:
my = MOUSEY()
mx = MOUSEX()
IF my < 300 THEN my = 300
IF my > 450 THEN my = 450
IF mx > 610 THEN mx = 610
SPRITE 100, mx, my, 100
IF MOUSECLICK() = 1 AND FIRE = 0 AND explode = 0
lsrx = mx + 12
lsry = my
fire = 1
ENDIF
IF fire=1
SPRITE 101,lsrx,lsry,101
DEC lsry,30
IF lsry<0
SPRITE 101,0,0-SPRITE HEIGHT(101),101
FIRE=0
ENDIF
ENDIF
RETURN
REM check for collision and then explode
REM technically you could combine this with the ship subroutine.
REM you could put it inside the IF FIRE=1/ENDIF statement.
REM This way the program isn't constantly checking for the collision
REM when not firing. Only when you've fired the laser it make this check.
laser_collision:
hit=checkcollision()
IF hit>0
lsry=0
reckage=hit
frame=110
explode=1
delay=TIMER()+60
score=score+10
ENDIF
Rem This part of the code could go into the beginning of the invader subroutine.
IF explode=1
ship(reckage)=frame
IF TIMER()>delay
INC frame
IF frame>114 THEN INC destroyed : explode=0
delay=TIMER()+60
ENDIF
ENDIF
RETURN
REM *** Functions ***
REM draw screen border
FUNCTION DrawRect(left,top,right,bottom)
LINE left,top,right,top
LINE right,top,right,bottom
LINE right,bottom,left,bottom
LINE left,bottom,left,top
ENDFUNCTION
REM check for collision
REM The SPRITE IMAGE check is only going to be used for the
REM invaders only!!! If you are using images 1-3 then the check
REM indicates anything less than 4. (MAX INVADER IMAGES + 1)
REM Don't include ship, laser, and explosion in the count.
REM If you use 99 invader images, then max would be less than (<) 100.
FUNCTION checkcollision()
FOR enemies=1 TO 18
IF SPRITE HIT(101,enemies)>0 AND SPRITE IMAGE(enemies)<4
EXITFUNCTION enemies
ENDIF
NEXT enemies
ENDFUNCTION 0
This next snippet is an update. It is a VERY, very, very rough draft of a somewhat complete project. You can run this one right now. There is no media required. It makes its own graphics. I did this because I don't know if I will have any more time to help you work it out methodically in stages this week. Play around with it and try to figure it out on your own for now. I will pick up where we left off next week.
` Dave's Invader Clone Project
`
` This is a very rough draft, but working project.
` It needs some mods and polishing to complete it.
` Sorry about the messy coding. I hope it's not confusing!
` Enjoy...
REM *** initialize screen ***
HIDE MOUSE
SYNC ON
SYNC RATE 60
REM I did this so I could test the code.
REM You can use your own bitmaps below.
REM build media
CREATE BITMAP 1,30,30
SET CURRENT BITMAP 1
REM 1 row
INK RGB (255,0,0),0
BOX 0,0,29,29
GET IMAGE 1, 0, 0, 29, 29
REM 2 row
INK RGB(0,255,0),0
BOX 0,0,29,29
GET IMAGE 2, 0, 0, 29, 29
REM 3 row
INK RGB(0,0,255),0
BOX 0,0,29,29
GET IMAGE 3, 0, 0, 29, 29
REM make random explosion
REM use frames 4-7
cls
ink rgb(255,255,255),0
for i= 4 to 7
if i=4 then p=5:po=12
if i=5 then p=8:po=10
if i=6 then p=14:po=8
if i=7 then p=29:po=0
particle=rnd(100)+1
for x=1 to particle
dot rnd(p)+po,rnd(p)+po
next x
get image i,0,0,29,29
next i
REM frame #8 (Blank)
INK RGB(0,0,0),0
BOX 0,0,29,29
GET IMAGE 8,0,0,29,29
REM ship
INK RGB(255,255,255),0
BOX 0,0,29,29
GET IMAGE 100, 0, 0, 29, 29
REM laser
INK RGB(255,255,0),0
BOX 0,0,5,5
GET IMAGE 101, 0, 0, 5, 5
REM delete garbage
DELETE BITMAP 1
SET CURRENT BITMAP 0
FOR i=1 to 36:SET SPRITE i,0,1:NEXT i
SET SPRITE 100,0,1:SET SPRITE 101,0,1
REM dimension invader arrays
DIM ship(18)
DIM bomber(18)
DIM bombx(18)
DIM bomby(18)
REM grab screen size
screenx = SCREEN WIDTH()
screeny = SCREEN HEIGHT()
new_game:
level=1
score=0
lives=3
REM *** variables ***
start_game_level:
destroyed=0
explode=0
fire=0
offsetx=30
offsety=50
movex=3
fire=0
vessel=0
FOR pic=1 TO 3
FOR enemy=1 to 6
INC vessel
Ship(vessel)=pic
NEXT enemy
NEXT pic
set text size 20
REM position ship
POSITION MOUSE 320, 450
Rem *** game action loop ***
repeat
CLS
GOSUB screen
GOSUB invaders
GOSUB ship
SYNC
until destroyed=18 or lives=0
IF lives>0
INC level
FOR l=1 TO 200
INK RGB(RND(128)+127,RND(128)+127,RND(128)+127),0
CENTER TEXT screenx/2,screeny/2,"LEVEL "+STR$(level)+" COMPLETED !!!"
WAIT 10:SYNC
NEXT l
ELSE
set text size 40
CENTER TEXT screenx/2,screeny/2,"GAME OVER"
SET TEXT SIZE 10
CENTER TEXT screenx/2,screeny-40/2,"To Quit Press the ESC key"
SYNC
REPEAT:UNTIL ESCAPEKEY()=1
END
ENDIF
goto start_game_level
REM *** gosubs ***
REM create background
screen:
INK RGB(0, 0, 255), 0
DrawRect(0, 0, 639, 479)
INK RGB(255, 255, 255), 0
FOR d = 1 TO 30
DOT RND(639), RND(479)
NEXT d
CENTER TEXT screenx/2,5,"INVADER CLONE"
TEXT 50,5,"SCORE: "+str$(score)
TEXT 500,5,"LIVES: "+str$(lives)
RETURN
REM space invaders
invaders:
IF EXPLODE=1
ship(INVADER_HIT)=FRAME
IF TIMER()>DELAY
INC FRAME
IF FRAME>8 THEN INC DESTROYED:EXPLODE=0
DELAY=TIMER()+60
ENDIF
ENDIF
invader=0
FOR y=0 TO 2
FOR x=0 TO 5
INC invader
rem this part controls invader bombing (multiple bombers!!!)
IF RND(150)=75 and bomber(invader)=0 and sprite image(invader)<4
rem play sound here for bomb dropping
bomber(invader)=1
bombx(invader)=sprite x(invader)+12
bomby(invader)=sprite y(invader)+sprite height(invader)
ENDIF
IF bomber(invader)=1
sprite invader+18,bombx(invader),bomby(invader),101
inc bomby(invader),5
if sprite hit(invader+18,100)>0 and sprite image(100)=100
sprite invader+18,bombx(invader),screeny+1,101
rem sound here for ship explosion
bomber(invader)=0
status=4
killed=1
delay2=timer()+60
else
if bomby(invader)>screeny
sprite invader+18,bombx(invader),screeny+1,101
bomber(invader)=0
endif
endif
ENDIF
invadx=offsetx+(SPRITE WIDTH(invader)*x)*1.5
invady=offsety+(SPRITE HEIGHT(invader)*y)*1.5
SPRITE invader,invadx,invady,ship(invader)
NEXT x
NEXT y
IF SPRITE X(1)<30 THEN movex=3
IF SPRITE X(6)>570 THEN movex=-3
offsetx=offsetx+movex
RETURN
REM ship movement
ship:
if killed=0
status=100
my=MOUSEY()
mx=MOUSEX()
IF my<300 THEN my=300
IF my>450 THEN my=450
IF mx>610 THEN mx=610
IF MOUSECLICK()=1 AND FIRE=0 AND EXPLODE=0
lsrx=mx+12
lsry=my
rem play sound here for ship laser
FIRE=1
ENDIF
IF FIRE=1
SPRITE 101,lsrx,lsry,101
DEC lsry,10
INVADER_HIT=CHECK_ENEMY_COLLISION()
IF INVADER_HIT>0
SPRITE 101,lsrx,0-SPRITE HEIGHT(101),101
rem play sound here for invader explosion
inc score,10
FRAME=4
EXPLODE=1
FIRE=0
DELAY=TIMER()+60
ELSE
IF lsry<0
SPRITE 101,lsrx,0-SPRITE HEIGHT(101),101
FIRE=0
ENDIF
ENDIF
ENDIF
ELSE
if timer()>delay2
inc status
delay2=timer()+60
if status>8
dec lives
killed=0
if lives>0
set text size 40
ink rgb(255,255,255),0
center text screenx/2,screeny/2,"GET READY."
sync
set text size 20
wait 3000
endif
endif
endif
ENDIF
SPRITE 100,mx,my,status
RETURN
REM *** Functions ***
REM draw screen border
FUNCTION DrawRect(left, top, right, bottom)
LINE left, top, right, top
LINE right, top, right, bottom
LINE right, bottom, left, bottom
LINE left, bottom, left, top
ENDFUNCTION
Rem Game Collision
FUNCTION CHECK_ENEMY_COLLISION()
FOR enemies=1 to 18
IF SPRITE HIT(101,enemies)>0 and sprite image(enemies)<4
EXITFUNCTION enemies
ENDIF
NEXT enemies
ENDFUNCTION 0
See ya later...