![]() |
|
#1
|
|||
|
|||
|
I have one enemy in the game at the moment, it's properties are all tied up into a function enemy() How can I multiply this function several times? so if this is the functions code: Code:
function gameenemy() if enemy.y>playerbullet.y and playerbullet.x<enemy.x+enemy.image:width() and playerbullet.x>enemy.x then enemy.x=math.random(20,460) enemy.y=math.random(10,150) end end What would I need to add to achieve this? --- function gameenemy() for i=0,5 do if enemy[i].y>playerbullet.y and playerbullet.x<enemy[i].x+enemy[i].image:width() and playerbullet.x>enemy[i].x then enemy[i].x=math.random(20,460) enemy[i].y=math.random(10,150) end end --- -This is what I want to do, loop the function's code multiple times, and each enemy acts independantly of the other. Without having to create a function per enemy. |
|
#2
|
|||
|
|||
|
*Bump*
|
|
#3
|
||||
|
||||
|
hey,
i cant really understand you but i think you want that set up as a function so you dont have to constantly retype those lines. am i right? you could try: Code:
function gameenemy(object) if object.y>playerbullet.y and playerbullet.x<object.x+object.image:width() and playerbullet.x>object.x then object.x=math.random(20,460) object.y=math.random(10,150) end while true do gameenemy(enemy) end
__________________
The PSP Programming and Development Mega Thread -Rock Station- PSN: Xsjado7 Quote:
|
|
#4
|
|||
|
|||
|
Using the above example, you could put a for loop inside the while loop, and have the enemies in an array. So something like..
while true do for(i=5, i<5, i++) gameenemy(enemy[i]) end end I don't remember the lua for loop though, I know that ones wrong, just an example. Back to hitting on that hot chick over there ....
__________________
Member number: 3 Meat lover? Watch: http://www.chooseveg.com/animal-cruelty.asp |
|
#5
|
||||
|
||||
|
yeah that would work well LordCthulu. so try:
Code:
function gameenemy(object) if object.y>playerbullet.y and playerbullet.x<object.x+object.image:width() and playerbullet.x>object.x then object.x=math.random(20,460) object.y=math.random(10,150) end while true do for(i=5, i<5, i++) gameenemy(enemy[i]) end end
__________________
The PSP Programming and Development Mega Thread -Rock Station- PSN: Xsjado7 Quote:
|
|
#6
|
|||
|
|||
|
I sincerely apologise for the late reply :|
Just busy atm with exams :( Thanks though, I'll try it out afterwards, many thanks, originalfragster |
![]() |
|
|
|||
|
|||
|
|
| Thread Tools | |
| Display Modes | |
|
|