Alright, i see afew thinks you are doing wrong.
1. At the start of the code you have:
enemy(x).x = rnd(800)
enemy(x).y = 0
you are trying to use the x variable to set all of you enemys to a random position. and x = 0 (1, there is no enemy we are using with an ID of 0 and 2. this will ONLY SET 1 ENEMYS POSITION NOT ALL OF THEM. see, you have to use a For - loop to set all of them using the variable x like so:
For x = 1 to 10 `notice the x variable, it will be incremented until 10.
enemy(x).x = rnd(800)
enemy(x).y = rnd(50) `so that arnt ALL exactly the same height.
Next x
2. Get image, this isnt a problem that you arnt using it, its very simple once you understand it. Get image - Parameters -> Image ID,x1,y1,x2,y2,Texture FLAG The Get Image Command will GRAB a SQUARE piece of your screen and save it as an image (it only is tempory, it dosent save it to the computer in a file, you use a different command to do that), its like Load Image but, you just need to put the ID you want the grabbed piece of screen to be and the position/size ect. The texture flag is if its FILTERED or not, filtering makes it LOW quality, but faster im sure (filtering = 0, nothing (good quality = 1))
Set Display Mode 800,600,32
Set Window on
`Example for Get Image
Text 0,0,"This will be turned into an image!"
`if sync is on, then sync it here to UPDATE the screen.
Get Image 1,0,0,100,20,1 `Image ID, x1,y1, x2,y2, TEXTURE FLAG
`we arnt clearing the screen so you can see that you it can paste the image around the screen.
do
Paste Image 1,RND(800),RND(600),1 `Pasting that image we grabbed above.
loop
3.(read 4 before you start editing this or your other update code)Your trying once again to paste the:
sprite 2,enemy(x).x,enemy(x).y,2
in your loop. You need to make sure this in the UPDATE LOOP so it can UPDATE ALL of the enemys.
4. You have to re-arange your update loop like so:
1. Inc y position
2. Show SPECIFIC sprite
3. check if it needs to be repositioned
4. Check Colisions
And also, with your sprites, you can ONLY paste 1 Sprite at a time which we will have to make 10 sprites, 1 for each enemy, starting at ID = 2.(if you arnt using the paste sprite command which dosent have collisions).
So since your first enemy sprite starts with the ID of 2 (since your player ball is 1) you need to paste 10 sprites + 2 so each one can have collisions:
This is in the Update Enemy Loop AT THE VERY START.
now just use the SpriteID as your sprites ID
:
Function UpdateEnemies()
For x = 1 to 10 `check through ALL 10 enemys on the screen at once, to check for the following:
SpriteID = x + 2
`now if its got here, its allready reset its position and checked for colisions, so if it hasnt ended the game (you have missed the ball) then keep moving the ball down.
Inc enemy(x).y,3 `move the enemy down at the rate of 3.
Sprite SpriteID,enemy(x).x,enemy(x).y,2
`Check if the enemy has hit the bottom of the screen (if it has then uve missed it)
If enemy(x).y >= 580
enemy(x).y = 0
enemy(x).x = RND(750) `randomly reposition the enemy.
Inc GameScore
Endif
If Sprite Collision(1,SpriteID) = 1 `1 is your ball, 2 is the specific spriteID.
Center Text Screen Width()/2,Screen height()/2,"GAME OVER!!!"
Sync
wait key
End
Endif
Next x
EndFunction
You can edit to how you need it, its just to show how it works.
That Should work. If it dosent, ill re-look over it.
This is my Code:
Set display mode 800,600,32
Set Window on
Hide mouse
type objectdata
x as integer
y as integer
endtype
Global GameScore `make this a global so the gameScore can be updated in the update enemy function.
global player as objectdata
global Dim enemy(20) as objectdata
`currently this has 20 items, just change this for how many enemys you want.
player.x = 400
player.y = 525
For x = 1 to Array Count(Enemy()) `this will return how many items there are in the enemy() array. (currently 20)
enemy(x).x = RND(580)
enemy(x).y = RND(20)
Next x
Ball() `draws the ball, so it can been grabbed and put into an image for the player to use.
Get Image 1,90,90,111,111,1 `grabs an image of the ball, since the ball is 10 in RADIUS, it will get 10 each side of 100 thus 90...110
cls
Box 0,0,10,10
Get image 2,0,0,10,10,1
cls
sync on
sync rate 60
backdrop on
color backdrop RGB(0,190,65)
do
Text 0,0,STR$(GameScore)
player.x = mousex()
draw_screen()
Sprite 1,Player.x,Player.y,1 `this will use the image of the ball, and paste it as a SPRITE at your coordinates. (sprites have collision checking.)
UpdateEnemies()
sync
loop
function draw_screen()
For x = 0 to 2
Line 0, 450 + x, 800, 450 + x `moves the line down
Next x
endfunction
function ball()
`draw ball(player)
INK RGB(0,0,255), RGB(0,0,255)
For x = 1 to 10
circle 100,100,x `this circle draws OUTWADS AROUND THE BASE COORDINATES -> eg like an explosion AROUND the barrel.
Next x
endfunction
Function UpdateEnemies()
`Array Count will output how many items there are in the -> Enemy() array just add more items at the top of your code and it will automaticly make more enemys.
For x = 1 to Array Count(Enemy()) `check through ALL 10 enemys on the screen at once, to check for the following:
SpriteID = x + 2
`now if its got here, its allready reset its position and checked for colisions, so if it hasnt ended the game (you have missed the ball) then keep moving the ball down.
Inc enemy(x).y,3 `move the enemy down at the rate of 3.
Sprite SpriteID,enemy(x).x,enemy(x).y,2
`Check if the enemy has hit the bottom of the screen (if it has then uve missed it)
If enemy(x).y >= 580
enemy(x).y = 0
enemy(x).x = RND(750) `randomly reposition the enemy.
Inc GameScore
Endif
If Sprite Collision(1,SpriteID) = 1 `1 is your ball sprite, the ENEMYSPRITE is some other sprite which you have to make for the enemy.
Center Text Screen Width()/2,Screen height()/2,"GAME OVER!!!"
Sync
wait key
End
Endif
Next x
EndFunction