I am creating a game that will increase the number of enemies on screen! every minute ( since i am new to game making but not programming ) what i was doing is using a function x ( x being the total number of enemies) being dividing by 3 for weak enemies 4 for normal and 5 for strong. now what i want to use is a floor or ceiling function which if i get a number like 2.45643 it goes to 3 or 2
anyway i can do this??? with lua…cause thats the only way i can think of increasing the number of enemies on screen.
unless you brilliant folks have a better way
[import]uid: 215264 topic_id: 35900 reply_id: 335900[/import]
Yeah, it has exactly what you’re looking for - just check out the Documentation link at the top of the page 
math.floor(number) -- 2.45 becomes 2
math.ceil(number) -- 2.45 becomes 3
math.round(number) -- 2.45 becomes 2, 2.65 becomes 3 [import]uid: 41884 topic_id: 35900 reply_id: 142704[/import]
thank you very much my dear Sir
could you also be of help in how to load the numbers of enemies on screen cause i havnt quite figured that out yet [import]uid: 215264 topic_id: 35900 reply_id: 142705[/import]
- Put all of your enemies in a displayGroup.
[code] – make the group just once, at the beginning
local enemyGroup = display.newGroup()
– whenever you make an enemy, insert it
enemyGroup:insert(myEnemy)
– anytime you want to know how many objects are in enemyGroup:
print("# of enemies:", enemyGroup.numChildren)
– or show on screen
local enemyCount = display.newText(enemyGroup.numChildren, 0, 0, native.systemFont, 18)
– the onscreen count will never change unless you update it, though, so periodically you will want to use:
enemyCount.text = enemyGroup.numChildren[/code] [import]uid: 41884 topic_id: 35900 reply_id: 142747[/import]
Thank you would you also help me by answering another question
Let’s say I have green, red and black. And I want it to be randomized each time a new enemy comes on screen. How will I perform this? [import]uid: 215264 topic_id: 35900 reply_id: 142760[/import]
If it’s just a color, then think about what you just wrote and break it down into pieces:
colors : You have 3 colors, so make a table of them.
local colors = {}
colors[1] = { 0, 255, 0 } -- green (rGb)
colors[2] = { 255, 0, 0 } -- red (Rgb)
colors[3] = { 0, 0, 0 } -- black
random : You want to randomly pick a color. So you basically want to pick a random number between 1 and 3 (the total number of colors.) Well, #table is the total size of a table, so…
local randomColor = colors[math.random(#colors)]
The trick here is that :setFillColor doesn’t accept tables - it wants three individual numbers. So you need to “unpack” it.
myEnemy:setFillColor( unpack(randomColor) )
Breaking down what you want to do into little pieces is the very essence of coding, no matter what your programming language is. Think about those chunks and you’ll have a much easier time figuring out how to do something. [import]uid: 41884 topic_id: 35900 reply_id: 142761[/import]
Thanks but I made a mistake the green red and black are the enemy colors
What I need is a method to randomly display them coming from the top down. ( I am not using the physics engine)
I can do that part, make them come from one point and walk to another what I need to do is
From a spite sheets choose random colors to come on screen
So I got a sprite sheet with all those colors I just need a way of randomizing the colors to come on screen and also more of them as the score inceases
[import]uid: 215264 topic_id: 35900 reply_id: 142764[/import]
Yeah, it has exactly what you’re looking for - just check out the Documentation link at the top of the page 
math.floor(number) -- 2.45 becomes 2
math.ceil(number) -- 2.45 becomes 3
math.round(number) -- 2.45 becomes 2, 2.65 becomes 3 [import]uid: 41884 topic_id: 35900 reply_id: 142704[/import]
thank you very much my dear Sir
could you also be of help in how to load the numbers of enemies on screen cause i havnt quite figured that out yet [import]uid: 215264 topic_id: 35900 reply_id: 142705[/import]
- Put all of your enemies in a displayGroup.
[code] – make the group just once, at the beginning
local enemyGroup = display.newGroup()
– whenever you make an enemy, insert it
enemyGroup:insert(myEnemy)
– anytime you want to know how many objects are in enemyGroup:
print("# of enemies:", enemyGroup.numChildren)
– or show on screen
local enemyCount = display.newText(enemyGroup.numChildren, 0, 0, native.systemFont, 18)
– the onscreen count will never change unless you update it, though, so periodically you will want to use:
enemyCount.text = enemyGroup.numChildren[/code] [import]uid: 41884 topic_id: 35900 reply_id: 142747[/import]
Thank you would you also help me by answering another question
Let’s say I have green, red and black. And I want it to be randomized each time a new enemy comes on screen. How will I perform this? [import]uid: 215264 topic_id: 35900 reply_id: 142760[/import]
If it’s just a color, then think about what you just wrote and break it down into pieces:
colors : You have 3 colors, so make a table of them.
local colors = {}
colors[1] = { 0, 255, 0 } -- green (rGb)
colors[2] = { 255, 0, 0 } -- red (Rgb)
colors[3] = { 0, 0, 0 } -- black
random : You want to randomly pick a color. So you basically want to pick a random number between 1 and 3 (the total number of colors.) Well, #table is the total size of a table, so…
local randomColor = colors[math.random(#colors)]
The trick here is that :setFillColor doesn’t accept tables - it wants three individual numbers. So you need to “unpack” it.
myEnemy:setFillColor( unpack(randomColor) )
Breaking down what you want to do into little pieces is the very essence of coding, no matter what your programming language is. Think about those chunks and you’ll have a much easier time figuring out how to do something. [import]uid: 41884 topic_id: 35900 reply_id: 142761[/import]
Thanks but I made a mistake the green red and black are the enemy colors
What I need is a method to randomly display them coming from the top down. ( I am not using the physics engine)
I can do that part, make them come from one point and walk to another what I need to do is
From a spite sheets choose random colors to come on screen
So I got a sprite sheet with all those colors I just need a way of randomizing the colors to come on screen and also more of them as the score inceases
[import]uid: 215264 topic_id: 35900 reply_id: 142764[/import]
Yeah, it has exactly what you’re looking for - just check out the Documentation link at the top of the page 
math.floor(number) -- 2.45 becomes 2
math.ceil(number) -- 2.45 becomes 3
math.round(number) -- 2.45 becomes 2, 2.65 becomes 3 [import]uid: 41884 topic_id: 35900 reply_id: 142704[/import]
thank you very much my dear Sir
could you also be of help in how to load the numbers of enemies on screen cause i havnt quite figured that out yet [import]uid: 215264 topic_id: 35900 reply_id: 142705[/import]
- Put all of your enemies in a displayGroup.
[code] – make the group just once, at the beginning
local enemyGroup = display.newGroup()
– whenever you make an enemy, insert it
enemyGroup:insert(myEnemy)
– anytime you want to know how many objects are in enemyGroup:
print("# of enemies:", enemyGroup.numChildren)
– or show on screen
local enemyCount = display.newText(enemyGroup.numChildren, 0, 0, native.systemFont, 18)
– the onscreen count will never change unless you update it, though, so periodically you will want to use:
enemyCount.text = enemyGroup.numChildren[/code] [import]uid: 41884 topic_id: 35900 reply_id: 142747[/import]
Thank you would you also help me by answering another question
Let’s say I have green, red and black. And I want it to be randomized each time a new enemy comes on screen. How will I perform this? [import]uid: 215264 topic_id: 35900 reply_id: 142760[/import]
If it’s just a color, then think about what you just wrote and break it down into pieces:
colors : You have 3 colors, so make a table of them.
local colors = {}
colors[1] = { 0, 255, 0 } -- green (rGb)
colors[2] = { 255, 0, 0 } -- red (Rgb)
colors[3] = { 0, 0, 0 } -- black
random : You want to randomly pick a color. So you basically want to pick a random number between 1 and 3 (the total number of colors.) Well, #table is the total size of a table, so…
local randomColor = colors[math.random(#colors)]
The trick here is that :setFillColor doesn’t accept tables - it wants three individual numbers. So you need to “unpack” it.
myEnemy:setFillColor( unpack(randomColor) )
Breaking down what you want to do into little pieces is the very essence of coding, no matter what your programming language is. Think about those chunks and you’ll have a much easier time figuring out how to do something. [import]uid: 41884 topic_id: 35900 reply_id: 142761[/import]
Thanks but I made a mistake the green red and black are the enemy colors
What I need is a method to randomly display them coming from the top down. ( I am not using the physics engine)
I can do that part, make them come from one point and walk to another what I need to do is
From a spite sheets choose random colors to come on screen
So I got a sprite sheet with all those colors I just need a way of randomizing the colors to come on screen and also more of them as the score inceases
[import]uid: 215264 topic_id: 35900 reply_id: 142764[/import]
Yeah, it has exactly what you’re looking for - just check out the Documentation link at the top of the page 
math.floor(number) -- 2.45 becomes 2
math.ceil(number) -- 2.45 becomes 3
math.round(number) -- 2.45 becomes 2, 2.65 becomes 3 [import]uid: 41884 topic_id: 35900 reply_id: 142704[/import]