Hello folks,
I'm working on a space shooter; and here's my problem.
I am basically throwing some alien ships on the screen at random X and Y locations. Now, we all know that this method can cause some of the images to overlap. However, I am trying to write a small routine that checks each alien against one another and if they are within 50 pixels of each other on the Y plane, then one of them gets moved.
I wrote the function which *should* work. In fact, when I execute it and use some "print" statements to check my variables to make sure the math and comparisons are working properly, all is well. The code works as I intended.
HOWEVER.....
When I transfer the code into my Space Game engine, overlap does occur. Can someone explain to me why it works fine when I use "print" to display the co-ordinates but it misbehaves when I'm blitting to the screen?
Here is the code:
;----------
Function Initialize_Aliens ()
Alien_Count = 0
SeedRnd MilliSecs()
For Alien_Index = 1 To NUM_ALIENS
Aliens(Alien_Index)=New Alien
Aliens(Alien_Index)\Alien_X=800+(Rnd(0,500))
Aliens(Alien_Index)\Alien_Y=100+(Rnd(0,500))
Aliens(Alien_Index)\Alive=1
Alien_Count = Alien_Count+1
Next
;Below is the routine that is giving me the problems!!;
For Alien_Index = 1 To NUM_ALIENS
For Alien_Work_Counter= 1 To NUM_ALIENS
Alien_Math=Aliens(Alien_Index)\Alien_Y-Aliens (Alien_Work_Counter)\Alien_Y
(NOTE: That line above is all on one line in my program. This website won't let me post it as one line...)
Alien_Math=Abs(Alien_Math)
If Alien_Math <= 50 And Alien_Index <> Alien_Work_Counter Then Aliens(Alien_Index)\Alien_Y=Aliens(Alien_Index)\Alien_Y+50
(Please note that the above line beginning with "If Alien_Math <= 50" is also all on one line in my editor.)
Next
Next
End Function
;--------
As you can see, I am subtracting one Y position from another and then using the ABS command to turn it positive. If that number is less than or equal to 50, I increase the value of the Y position of the Alien Craft by 50.
Again, it works using "print" to check the variables. It does not work correctly when I blit my bitmaps to the screen.
So....
What am I doing wrong?
Thanks to all in advance.
-Spo-
PS: I do have all my variables defined as global, so I can access them throughout the program. (Yes, I know this is sloppy..... )
I'm working on a space shooter; and here's my problem.
I am basically throwing some alien ships on the screen at random X and Y locations. Now, we all know that this method can cause some of the images to overlap. However, I am trying to write a small routine that checks each alien against one another and if they are within 50 pixels of each other on the Y plane, then one of them gets moved.
I wrote the function which *should* work. In fact, when I execute it and use some "print" statements to check my variables to make sure the math and comparisons are working properly, all is well. The code works as I intended.
HOWEVER.....
When I transfer the code into my Space Game engine, overlap does occur. Can someone explain to me why it works fine when I use "print" to display the co-ordinates but it misbehaves when I'm blitting to the screen?
Here is the code:
;----------
Function Initialize_Aliens ()
Alien_Count = 0
SeedRnd MilliSecs()
For Alien_Index = 1 To NUM_ALIENS
Aliens(Alien_Index)=New Alien
Aliens(Alien_Index)\Alien_X=800+(Rnd(0,500))
Aliens(Alien_Index)\Alien_Y=100+(Rnd(0,500))
Aliens(Alien_Index)\Alive=1
Alien_Count = Alien_Count+1
Next
;Below is the routine that is giving me the problems!!;
For Alien_Index = 1 To NUM_ALIENS
For Alien_Work_Counter= 1 To NUM_ALIENS
Alien_Math=Aliens(Alien_Index)\Alien_Y-Aliens (Alien_Work_Counter)\Alien_Y
(NOTE: That line above is all on one line in my program. This website won't let me post it as one line...)
Alien_Math=Abs(Alien_Math)
If Alien_Math <= 50 And Alien_Index <> Alien_Work_Counter Then Aliens(Alien_Index)\Alien_Y=Aliens(Alien_Index)\Alien_Y+50
(Please note that the above line beginning with "If Alien_Math <= 50" is also all on one line in my editor.)
Next
Next
End Function
;--------
As you can see, I am subtracting one Y position from another and then using the ABS command to turn it positive. If that number is less than or equal to 50, I increase the value of the Y position of the Alien Craft by 50.
Again, it works using "print" to check the variables. It does not work correctly when I blit my bitmaps to the screen.
So....
What am I doing wrong?
Thanks to all in advance.
-Spo-
PS: I do have all my variables defined as global, so I can access them throughout the program. (Yes, I know this is sloppy..... )