It looks like you're new here. If you want to get involved, click one of these buttons!
Hi guys,
I'm attempting to make a little game where you have a character, which is a sprite, and by using the accelerometer you tilt the iPad to collect little stars that appear, which will also be sprites. Once you've touched the star it disappears.
There are 5 different coloured stars that I want to appear in random places, when you collect them you get points and more start appearing.
I think I need to use a table to hold the different stars and have them appear on the screen, but I can't find any really easy to understand tutorials or examples on how to use tables in this way.
Could any of you link me to a really good tutorial, or quickly write up an example table that does this?
Please say if you need any more information, I'd post all my current code but I don't know if it would really be relevant.
Thanks
Comments
@joshlong93 This help.
EDIT: Code modified from the original.
@joshlong93 See this ling to a game I made. It sounds similar to what you're doing. Maybe it will help.
Thanks @dave1707 , I think I get most of that.
What do the z, a and b stand for? Also, how would I make each of the 5 stars a different sprite?
Thanks, for the quick answer!
@joshlong93 The z,a,b are just variables that I use. z is a variable in the "for" loop that goes from 1 to 5. The a and b are variables in another "for" loop. The "a" is a counter that goes from 1 to the number of entries in the table "tab". "b" is the values in the table. Since I created the entries with a vec2, that means there are 2 values per entry. The way to access them is with b.x and b.y . You could put the different sprites in a table and use the "a" variable to access that table. I'll give you an example soon.
@joshlong93 I modified the original code to show 5 different sprites.
that's been really helpful thank you @dave1707! If I could just ask one more question, how would I randomly make more than one of a particular star show up?
@joshlong93 I'm not sure if this is what you're after. I show 4 sprites and the 5th one will be a duplicate of one of the 4.
This code allows for didpfferent types of stars with different colors, values and sizes etc.
@Coder
can be compacted to
(which could also be merged into the for loop)
@SkyTheCoder yeah that makes the code shorter