Identify an enemy in Bucle + Type (code provided)
Blitz3D Forums/Blitz3D Programming/Identify an enemy in Bucle + Type (code provided)
| ||
i have the following code to create my enemies: For cant=1 to 5 Enemy.Enemy=New Enemy enemy\ex#=Rand(0,640) ; posicion X del enemigo enemy\ey#=Rand(0,480) ; posicion Y del enemigo enemy\espd#=.5 ; velocidad del enemigo enemy\roamx=Rand(0,640) ; posicion 'x' para vagar (aleatoria entre 0 y 640) enemy\roamy=Rand(0,480) ; posicion 'y' para vagar (aleatoria entre 0 y 480) enemy\elife#=100 ; ahora el enemigo tiene vida, jojojo, estamos mas parejos enemy\ebarX#=enemy\ex# enemy\ebarY#=enemy\ey# Next i want to give a right click over an enemy and the enemy lose .5 points of life (whole life is 100). now, i cannt identify wich of the 5 enemies i am attacking :( is posible to identify the enemy in the screen? any ideas? |
| ||
i can detect the mouse position but how to identify every enemy? |
| ||
Wouldn't you compare the mouse position to the current position of each enemy, and take the energy from the one that 'matches'? |
| ||
yes, i though that but if you point another enemy how will the program remember the last enemy life or before the first enemy hit? suppose you have 5 enemies and all enemies have 100 points of life, every hit you land is 10 point less: you hit enemy1, 2 times so this enemy have 80 points you hit enemy2, 9 times so this enemy has 10 points to die you hit enemy3, 1 time so this enemy has 90 points now if you atack the first enemy how will the system remeber the remaining life of the enemy? |
| ||
Because you're storing the remaining/current life of the enemy in a field in your type, so everytime you check the mouse position against the current position of each enemy, you take off some 'life' from the enemy that matches. Or have I missed something obvious? :o) |
| ||
maybe there is something ovbios i can understand. recap: with this bucle i create 5 enemies. my problem is how to identify wich is the enemy number 1, number 2, number 3, number 4, number 5. |
| ||
Matt, You don't really need to know which enemy is which. When checking to see which one you've clicked on you'll need to go through them all anyway for your distance checking. Make sense? Stevie |