Hello
I am currently trying to create a Tower Defense Game but whatever i try i am not able to create a working Projectile
I have a list of all the Enemys that are on the field (in order since the enemy first on the field is the first in the list and when he dies or reaches the end he will be removed and the next enemy in the list is the target)(all enemys have the same speed)
the problem with that system is that i havent found a way to get the coordinates of the enemy without having to add hundreds of blocks (with that the system wouldnt be as modular as before)
(local variable "Target" -> select item from list "x" with Index 1)
with that i know the name of the enemy but nothing else so i cant use the - Move to X/Y block and the point towards block (with speed and intervall and so) doesnt want to work in combination with the variable "Target"
If possible i want to keep the System with the list since it uses not a lot of blocks and i want to practice it (its the first time i am using the lists)
and the only other way that i can think of how it could work compares every single enemys Y to all others Y to find out whos the closest (in one of my other attempts at a Tower Defense Game i used that system and the Targeting worked but i quickly ran into memorie issues and i had over 400 blocks or so just for that and the animation or movement of the sprite wouldnt work since it was to slow/inacurate)
(if you need/want the project files i will give them to you but the game isnt ment to be public i just want to practise with all the different mechanics so the grahpics might not match up on your screen and i used
a combination of German and English words so you might not understand everything)
I dont need something that complicated (that i dont understand )
i just want a Sprite to move to the nearest enemy and collide with it
The Projectile Motion requires manual input and has a view from the side (i want a view from above)
Just as in my old attempt TowerDefense.aia (60.5 KB)
but better (without crashing with an animation and with less blocks)
Then you really probably don't 'know the basics of sprite movement'
After you have read and understand that tutorial; look for the Scott Ferguson animation samples at his (now defunct) library that might have an example similar to what you want to do. Redirecting to Google Groups . Several years ago, Scott was the expert in simple App Inventor animation.
I am not aware of any example. What you want to do seems possible. You will need to calculate the distances of all the enemy sprites from your cannon or gun first; calculate the nearest and then provide code for your projectile to 'attack' the nearest. This requires simple geometry skills, the Math Blocks, the mentioned tutorial and some patience.
Good luck. Here is an App Inventor example showing how to calculate the distance between to objects (balls, sprites) on a Canvas. The link downloads a pdf showing the technique.
i meant a list where you dont know how many sprites or what sprites are in the list
for example
List : Sprite4
Sprite 7
Sprite 2
or
List : Sprite 8
Sprite 1
Sprite 5
Sprite 9
Sprite 10
it doesnt matter matter what the name of the sprite is where it is on the canvas or how many Sprites are in the list
it will always give me the X and Y coordinates of the first Sprite in the list
i thought about something like that but for some reason it always changes the heading to 1 and not to the targetet sprite
This example works with 3 randomly placed Balls. It will 'shoot' from any of the Balls in the list at Ball 2; something similar can be used with Sprites to shoot from Ball2 to any of the Balls in the List by adjusting the code.
i never checked the enemy spawn system since it worked
at midnight or so i hastely gave the enemys health so i can test the projectile and since than i had problems with the targeting system
i accidently always set the variable that spawns the enemy to 1 (the hp) and than added the variable to the list so i would always add 1 instead of the enemys name
thats why it always was something with 1 and i thought it had something to do with the index 1
thats why it never worked