What I see a lot of new people doing is using the commands LOAD BITMAP when they are intending to load images. This may not answer your question Jamesb187, but I thought it's worth mentioning to avoid a common mistake and misconception.
One has to change their thinking a bit to understand what DB means by BITMAP. A Bitmap is the screen on which pictures (images if you will)are drawn. Do not confuse this with the picture file format for a DIB that usually ends with the extension .bmp . When you use a command such as
load bitmap "alien1.bmp", Alien1 you are creating a hidden drawing area (an extra screen) sized to your file alien1.bmp . Since you are immediately grabbing the image wuth the GET IMAGE command, I am assuming your original intention was to create an image from the file. To do this, use LOAD IMAGE instead of LOAD BITMAP.
This is important because they are two different things and they both take up resources and memory. If you are not deleting the bitmaps after using LOAD BITMAP, they stay around in the background waiting to be drawn to. You'll then have a duplicate of your picture when you are using GET IMAGE. So, to minimize resource usage in this case, use LOAD IMAGE directly.
Also, you are only allowed to use 32 bitmaps (screens) 0 to 31. 0 is the main display screen where everything is displayed. The others are hidden in memory. There can be 65535 images on the other hand. So, to state it flat - BITMAPS are drawing areas, IMAGES are the textures and pictures you will use in your games.
Now don't get me wrong. Often, one will have a page of multiple images. Like a sprite sheet that may have a series of images laid out that represent a simple animation. In this case, one may use LOAD BITMAP to load the entire sheet. Then use get image to select the specific areas from the sheet.
As far as the size of your images,
Quote: "they are all 20x20 bmps"
When you are capturing an area using GET IMAGE, the x2 y2 size always captures 1 pixel less than their values. So logically it seems GET IMAGE alien1,0,0,19,19 would capture 20 pixels (0 - 19), but it only captures 19. You would have to use
GET IMAGE Alien1,0,0,20,20
to capture the full 20 pixels.
One other thing, you can improve performance by capturing your images directly to video memory if you want. Add a ,1 at the end of the GET IMAGE or LOAD IMAGE commands:
GET IMAGE Alien1,0,0,20,20,1
or
LOAD IMAGE "Alien1.bmp",Alien1,1
DBC automatically copies from SYSTEM memory to VIDEO memory if you don't load your images directly to video memory, but if there are a lot of images, it can hamper performance; especially if they are large images.
Now in answer to your question, it probably has to do with the color of the bullet. There's some sprite collision glitch that can cause problems if the color isn't just right. Each of the color components are compared (red blue green) in the collision. If transparency is on, sometimes a 0 in one of the compnents will be read as transparent and no collision will be detected. Try making the bullet white and see if that makes a difference. Or try making sure all of the images have some measure of red green and blue in them (more than 10 units).
Here. I changed the bullet to a green block with some red and green in it (15 units of each) and it works with all of the aliens:
rem space invaders clone
rem initialise the screen and timers
randomize timer()
sync on
StartTime = timer()
rem array to hold alien sprite numbers
dim AlienArray(50)
for n = 1 to 50
AlienArray(n) = n
next n
rem declare variables and constants
rem playing area constants
LeftEdge = 120
TopEdge = 100
RightEdge = 550
BottomEdge = 400
rem leftmost alien starting positions
rem alien1 is the top row, alien 5 is the bottom row
Alien1Top = 100
Alien2Top = 120
Alien3Top = 140
Alien4Top = 160
Alien5Top = 180
AlienLeft = 150
rem player base starting position
BaseLeft = 300
BaseTop = 340
rem constants to hold image and sprite names
Alien1 = 1
Alien2 = 2
Alien3 = 3
Base = 4
Explosion = 5
AlienBullet = 6
BaseBullet = 7
Shield = 8
rem movement constants
AlienMove = 2
BaseMove = 4
BulletMove = 4
rem others
AlienBulletCounter1 = 1
AlienBulletCounter2 = 1
AlienBulletCounter3 = 1
BulletShot = 0
SpaceBarPressed = 1
FireBase = 0
BulletFired = 1
rem load images
load bitmap "alien1.bmp", Alien1
get image Alien1, 0, 0, 19, 19
load bitmap "alien2.bmp", Alien2
get image Alien2, 0, 0, 19, 19
load bitmap "alien3.bmp", Alien3
get image Alien3, 0, 0, 19, 19
load bitmap "base.bmp", Base
get image Base, 0, 0, 19, 19
load bitmap "explosion.bmp", Explosion
get image Explosion, 0, 0, 19, 19
load bitmap "alienbullet.bmp", AlienBullet
get image AlienBullet, 0, 0, 9, 9
load bitmap "basebullet.bmp", BaseBullet
cls rgb(15,255,15)
get image BaseBullet, 0, 0, 9, 9
load bitmap "shield.bmp", Shield
get image Shield, 0, 0, 4, 8
rem game loop
do
rem draw the aliens
for n = 1 to 50
if n < 21
AlienImage = Alien1
else
if n > 20 and n < 31
AlienImage = Alien2
else
if n > 30 and n < 51
AlienImage = Alien3
endif
endif
endif
if n < 11
AlienTop = Alien1Top
Offset = 0
else
if n > 10 and n < 21
AlienTop = Alien2Top
Offset = 10
else
if n > 20 and n < 31
AlienTop = Alien3Top
Offset = 20
else
if n > 30 and n < 41
AlienTop = Alien4Top
Offset = 30
else
if n > 40 and n < 51
AlienTop = Alien5Top
Offset = 40
endif
endif
endif
endif
endif
if AlienArray(n) > 0
sprite AlienArray(n), AlienLeft + ((n-Offset) * 30) - 30, AlienTop, AlienImage
else
delete sprite n
endif
next n
rem move the aliens
if timer() > AlienDelay
AlienLeft = AlienLeft + AlienMove
if AlienLeft => (RightEdge - 300) or AlienLeft <= Leftedge
Alien1Top = Alien1Top + 20
Alien2Top = Alien2Top + 20
Alien3Top = Alien3Top + 20
Alien4Top = Alien4Top + 20
Alien5Top = Alien5Top + 20
AlienMove = AlienMove * -1
endif
AlienDelay = timer() + 1000
endif
rem move the base
if leftkey() and BaseLeft > LeftEdge
BaseLeft = BaseLeft - BaseMove
else
if rightkey() and BaseLeft < RightEdge
BaseLeft = BaseLeft + BaseMove
endif
endif
rem draw the base - sprite 80
sprite 80, BaseLeft, BaseTop, Base
rem fire bullets from the base - sprite 54 - and handle collision
if spacekey() and BulletFired = 1
SpaceBarPressed = 1
FireBase = 1
endif
if SpaceBarPressed = 1
FiringBasePosX = sprite x(80)
FiringBasePosY = sprite y(80)
SpaceBarPressed = 0
endif
if FireBase = 1 and FiringBasePosY > -15
sprite 54, FiringBasePosX, FiringBasePosY, BaseBullet
for n = 1 to 50
if sprite hit(54, n)
AlienArray(n) = 0
FireBase = 0
delete sprite 54
endif
next n
FiringBasePosY = FiringBasePosY - BulletMove
BulletFired = 0
else
BulletFired = 1
endif
sync
loop
Enjoy your day.