Why some object don't show itself?
BlitzPlus Forums/BlitzPlus Programming/Why some object don't show itself?
| ||
I have this code;the problem is that i don't know why if i create 4 enemy,they show only one at time on-screen.....Graphics 640,480,32,1 SetBuffer BackBuffer() Global aereo=LoadImage("d:\shoot\jet1.bmp") ;a simple sprite Global terreno=LoadImage("d:\shoot\terreno.bmp") ;a simple texture of 256*256 Global missile=LoadImage("d:\shoot\bullet1.bmp") ;a simple sprite Global alien=LoadImage("d:\shoot\enemyjet1.bmp") ;a simple sprite MaskImage aereo,0,67,171 MaskImage missile,0,67,171 MaskImage alien,0,67,171 Global bit=1 MidHandle aereo MidHandle missile MidHandle alien HidePointer Global b.alieno Type missile ;an object called missile Field posx Field posy Field avanzamento Field contatore Field image End Type Type alieno Field limite_dx,limite_sx,movx,movy,movimento,energia,image,percorso,strada,sinistra,destra End Type ;MAIN Repeat Cls or_x=or_x or_y=or_y+bit ;this start the up scrolling adding "bit" to origin Origin or_x,or_y If or_y=2560 Then End ;if origin reach 2560 the program end maptiles() Origin 0,0 If or_y=200 create_enemy(150,100,alien,10,1,2) create_enemy(200,100,alien,10,1,2) create_enemy(300,100,alien,10,1,2) create_enemy(400,100,alien,10,1,2) ;move_enemy() EndIf move_enemy() If or_y=300 create_enemy(420,100,alien,5,2,2) create_enemy(320,100,alien,5,2,2) create_enemy(220,100,alien,5,2,2) create_enemy(120,100,alien,5,2,2) create_enemy(20,100,alien,5,2,2) ;move_enemy() EndIf move_enemy() DrawImage aereo,MouseX(),MouseY() If MouseHit(1)=1 ;if i hit the mouse button i create a missile create_missile() EndIf play_missile() ;this start the missil anim Flip Until KeyDown(1)=1 End ;END MAIN Function create_missile() a.missile=New missile a\image=missile a\posx=MouseX() ;the x position of missile creation is the mouse coords(the same coords of my jet of course) a\posy=a\posy+MouseY()-45 ;the missile creation start a bit up to the jet(for simulating the launch-bay hehe) a\avanzamento=4 ;the speed of the missile a\contatore=0 ;the starting value of the animation End Function Function play_missile() For a.missile=Each missile DrawImage a\image,a\posx,a\posy a\posy=a\posy-a\avanzamento ;this move the missile up a\contatore=a\contatore+a\avanzamento ;this start the counter of the missile course For b.alieno=Each alieno If ImagesCollide(a\image,a\posx,a\posy,0,b\image,b\movx,b\movy,0) ;if the alien collide with the missile the energy go down of one unit b\energia=b\energia-1 If b\energia=<0 Then Delete b Delete a ;if the missile collide with the alien the missile stop it's existance :P Exit ;exit loop if missile is dead. will cause error as they's no missile to check against the aliens EndIf Next Next End Function Function create_enemy(x,y,immagine,energia,movimento,velocita) b.alieno=New alieno b\image=immagine b\movx=x b\movy=y b\movimento=velocita b\energia=energia ;the "teoric" energy of the alien,from when reach 0 the alien explode b\percorso=y b\strada=movimento b\sinistra= - velocita b\destra= + velocita b\limite_dx=x+100 b\limite_sx=x-1 End Function Function move_enemy() For b.alieno =Each alieno DrawImage b\image,b\movx,b\movy Text b\movx,b\movy-20,b\energia If b\strada=1 movimento() Exit EndIf If b\strada=2 movimento2() Exit EndIf Next End Function Function MapTiles() tilex=0 tiley=0 For tiley=256 To -2560 Step -256 For tilex=0 To 640 Step 256 DrawBlock terreno,tilex,tiley Next Next End Function Function movimento() b\movx=b\movx+b\movimento ;start going right b\movy=b\movy+1 ;start go down If b\movx => b\limite_dx ;if reach a certain value reverse its course b\movx=b\movx-b\movimento b\movimento=b\sinistra EndIf If b\movx =< b\limite_sx ;if reach a cerain value reverse its course and so on... b\movx=b\movx+b\movimento b\movimento=b\destra EndIf If b\movy=b\percorso+400 ;continue its course until the movement down are equal to 400 Delete b EndIf End Function Function movimento2() b\movy=b\movy+(b\movimento+1) ;start go down If b\movy=b\percorso+400 Delete b EndIf End Function I don't know how to do -_-' I want some storm of enemy and not a single enemy on screen... Thanks |
| ||
Well....i think i have resolved the problem! It's the same error that i made when coding :P logical error. I have made two function "movimento() movimento2()" and inside of those function i have made en "exit" when the object is deleted....but those exit have no result because function only one time! Yes,because i call only one time those function inside my main.....so if i delete those two function and write the same code(without any change!!!)inside the main function all works pretty well,and now i have hordes of enemies hehehe |