Computer Science Canada How do you get multiple enemies? |
Author: | mobin12 [ Thu Feb 09, 2012 7:19 pm ] | ||
Post subject: | How do you get multiple enemies? | ||
What is it you are trying to achieve? I want to have multiple enemies when the score reaches 250 (So it's kind of like a difficulty)
Please specify what version of Turing you are using Turing 1.4.1 The code is also in the 'zip' file |
Author: | Raknarg [ Thu Feb 09, 2012 7:28 pm ] | ||
Post subject: | RE:How do you get multiple enemies? | ||
You would use flexible arrays I believe. Or just a regular array, but you keep track of the amount of enemies you have. One thing I would change for sure is how you have youyr variables set up. The player, for instance, you have as player (1) = x and player (2) = y. Thats bad format; if someone was trying to figure out your code, it would be diffivult for someone to understand, especially if it becomes longer. If the reason you have this is to have less random variables, I would suggest looking into records:
|
Author: | Aange10 [ Fri Feb 10, 2012 11:39 am ] |
Post subject: | RE:How do you get multiple enemies? |
Also, what is it you are having difficulty with? |
Author: | mobin12 [ Fri Feb 10, 2012 4:16 pm ] |
Post subject: | RE:How do you get multiple enemies? |
i dont know how to make a lot of enemies spawn at a certain point. I have never tried something like this before, it's very new for me. |
Author: | Raknarg [ Fri Feb 10, 2012 6:01 pm ] |
Post subject: | RE:How do you get multiple enemies? |
You can use an arrays to keep track of individual enemies. For instance: var enemyX, enemyY : array 1 .. 5 of int var enemyLive : array 1 .. 5 of boolean This is assuming there are 5 enemies. Enemy 1 would get the first element of all those arrays, enemy 2 would get element 2, etc. You use the x and y to keep track of enemies. When you want to spawn an enemy, you set the x and y and set the Live variable to true. When they die, set that variable to false. Only draw them when they're live. Thats the basic idea. |
Author: | mobin12 [ Fri Feb 10, 2012 6:12 pm ] |
Post subject: | RE:How do you get multiple enemies? |
thanks very much i will try that |
Author: | mobin12 [ Sat Feb 11, 2012 2:51 pm ] |
Post subject: | Re: How do you get multiple enemies? |
Alright i have tried that, but i ended up with a huge error: For the code of collision of the enemy with the shockwave, player, and bullet. Does it have to be repeated for every single enemy. Because if that's true then would i just copy and paste and change the numbers? |
Author: | Raknarg [ Sat Feb 11, 2012 4:20 pm ] | ||
Post subject: | RE:How do you get multiple enemies? | ||
What I would do is include a for loop for every object that needs to check for certain collisions. For instance, when you calculate bullet conditions such as movement, you can calculate collisions as well. Lets say you had five bullets total and ten enemies:
same thing goes for the shockwave. You would calulate everything for the shockwave, then you would check for collisions in the same loop. If I got your question totally wrong, you should reword it. |
Author: | mobin12 [ Mon Feb 13, 2012 5:27 pm ] | ||
Post subject: | Re: How do you get multiple enemies? | ||
I found another way of doing it but i'm not sure if it is something one of you would do so... Oh and it's actually pretty fun to play in my opinion.
|
Author: | mirhagk [ Mon Feb 13, 2012 6:23 pm ] | ||
Post subject: | RE:How do you get multiple enemies? | ||
See this:
Don't do that. For loops and arrays would turn this into like 4 lines. |
Author: | Raknarg [ Mon Feb 13, 2012 6:40 pm ] |
Post subject: | RE:How do you get multiple enemies? |
See, the problem is that you're using separate arrays for each enemy. At least if you are going to do that, you should save your time by putting them all in one array: var enemy1 : array 1 .. 3 of int var enemy2 : array 1 .. 3 of int var enemy3 : array 1 .. 3 of int can be shortened into var enemy : arrat 1 .. 3, 1.. 3 of int |
Author: | mobin12 [ Wed Feb 15, 2012 5:47 pm ] |
Post subject: | RE:How do you get multiple enemies? |
is anyone familiar with 'realstr'? |
Author: | Raknarg [ Thu Feb 16, 2012 11:33 am ] |
Post subject: | RE:How do you get multiple enemies? |
lol I tried figuring it out a while ago, but gave up. |
Author: | mobin12 [ Thu Feb 16, 2012 3:52 pm ] |
Post subject: | RE:How do you get multiple enemies? |
what i dont understand is what you have to put after the comma. in the help section it says something about width?... |
Author: | Dreadnought [ Thu Feb 16, 2012 4:16 pm ] | ||
Post subject: | Re: How do you get multiple enemies? | ||
realstr basically converts a real number to a string with at least the length (width) specified (the length is increased if the number is larger). You should perhaps know that real numbers (sometimes called floating point numbers) hold 16 digits along with an exponent (in scientific notation form [digits]e[exponent] where e is 10 to the power of exponent). The largest value for the exponent seems to be 309 (from my tests). Note that around 1e308 you might get infinity (yes Turing can sometimes return infinity). It should be noted that realstr will round to 6 digits after the decimal point. If you want more you'll have to use frealstr or erealstr. as an example:
Basically, the width controls the minimum length of the string that is created (it will be increased if the number contains more digits). If you really want more control over the conversion I suggest looking into erealstr and frealstr. Hope this helps. |
Author: | mobin12 [ Fri Feb 17, 2012 9:29 am ] |
Post subject: | RE:How do you get multiple enemies? |
what would the length be if i only wanted the digits before the decimal example: realstr (38.567549, '?') |
Author: | Zren [ Fri Feb 17, 2012 12:41 pm ] |
Post subject: | RE:How do you get multiple enemies? |
If your only interest is the whole digits. Floor the number. It will round down to the nearest integer. intstr(floor(38.234)) |
Author: | Dreadnought [ Fri Feb 17, 2012 1:00 pm ] | ||||||
Post subject: | Re: How do you get multiple enemies? | ||||||
In this case, realstr cannot help you. You must turn to other options erealstr and frealstr. In the special case you mentioned where you want the whole part you can use 'round(num)' to round or 'num div 1' to avoid rounding (I use div in case of negative numbers). frealstr can be used in this case since it deals with the fractional part. To avoid leading spaces in the string we choose a width of zero and the function will increase it to the correct value. For the fraction width we choose 0, this width will not be increased, so we effectively remove the decimal part of the number. Note that frealstr will still produce a decimal point in the string, but will round to the nearest integer. Example :
You can also use erealstr, but then it will display in scientific notation and make things more complicated.
So if all you want is the integer part, I sugget using instr (round( )) or intstr ( () div 1), and if you want some form of fraction, you can use frealstr. However, you can also multiply but some power of 10, round to an integer, divide by the same power of 10 and then take the realstr of that. Example:
Hope this helps. |
Author: | mobin12 [ Fri Feb 17, 2012 4:34 pm ] | ||
Post subject: | RE:How do you get multiple enemies? | ||
ok so i want to use a variable that gets percentage out of 100 and it is a real. But i want to use realstr to change it to a string so i can use it in a Font.Draw. Something i have tried is: (This is part of my game to show how much health you have.)
|
Author: | Raknarg [ Fri Feb 17, 2012 4:50 pm ] |
Post subject: | RE:How do you get multiple enemies? |
ok, so do you only want to show the integer portion or two decimal points after or something? |
Author: | mobin12 [ Fri Feb 17, 2012 5:53 pm ] |
Post subject: | RE:How do you get multiple enemies? |
only the integer and no decimal points and also no decimal (if possible) |
Author: | Dreadnought [ Sat Feb 18, 2012 3:34 am ] | ||
Post subject: | Re: How do you get multiple enemies? | ||
So basically, what you want (I think) is to display only the whole value of a percentage. The easiest way in my opinion is to simply multiply the decimal value by 100, round then convert the integer to a string.
Alternately, you can use frealstr(realNumber, 0, 2) and remove the first two digits using (3..*). |
Author: | mobin12 [ Sat Feb 18, 2012 7:28 pm ] |
Post subject: | Re: How do you get multiple enemies? |
yes thank you very much This fixed my problem |