
-----------------------------------
mobin12
Thu Feb 09, 2012 7:19 pm

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)




%Set the screen size
setscreen ("graphics:900;550,nobuttonbar,offscreenonly")

var chars : array char of boolean
var enemy, player : array 1 .. 3 of int
enemy (1) := 15
enemy (2) := 15
enemy (3) := 1
player (1) := 450
player (2) := 275
player (3) := 1
var mx, my, b : int
var shockwave : array 1 .. 4 of int
shockwave (3) := 1
shockwave (4) := 0
var space : int := 0
var count : int := 3
var health : int := 215
var Intro : int := Pic.FileNew ("Game-Intro.jpg")
var Instructions : int := Pic.FileNew ("Game-Instructions.jpg")
var Background : int := Pic.FileNew ("Game-Background.jpg")
var Pause : int := Pic.FileNew ("Game-Pause.jpg")
var End : int := Pic.FileNew ("Game-End.jpg")
var font : int := Font.New ("DigifaceWide:46")
var font1 : int := Font.New ("Ethnocentric:13")
var score : int := 0
var s : string := ""
var rectangle : int

%THE INTRO
loop
    Pic.Draw (Intro, 0, 0, picMerge)
    mousewhere (mx, my, b)
    exit when mx > 288 and mx < 634 and my > 185 and my < 234 and b = 1
    View.Update
end loop

%THE INSTRUCTIONS
loop
    Pic.Draw (Instructions, 0, 0, picMerge)
    mousewhere (mx, my, b)
    exit when mx > 242 and mx < 694 and my > 104 and my < 170 and b = 1
    View.Update
    cls
end loop

%THE GAME
loop
    loop
        %Draw the Background for the game
        Pic.Draw (Background, 0, 0, picMerge)
        
        s:=intstr(score)
        Font.Draw ("score: ", 0, 507, font1, black)
        Font.Draw (s, 94, 507, font1, black)
        
        %Draw the player
        if player (3) = 1 then
            drawfilloval (player (1), player (2), 10, 10, 54)
            drawfilloval (player (1), player (2), 8, 8, 55)
        end if
        
        %Draw the enemy
        if enemy (3) = 1 then
            drawfilloval (enemy (1), enemy (2), 7, 7, 41)
        end if

        %Randomly place the enemy in the 'ENEMY BAY'
        randint (rectangle,1,4)
        if enemy (3) = 0 and rectangle = 1 then
            randint (enemy (1),7,893)
            randint (enemy (2),7,30)
            drawfilloval (enemy (1), enemy (2), 7, 7, 41)
            enemy (3) := 1
        elsif enemy (3) = 0 and rectangle = 2 then
            randint (enemy (1),7,29)
            randint (enemy (2),38,513)
            drawfilloval (enemy (1), enemy (2), 7, 7, 41)
            enemy (3) := 1
        elsif enemy (3) = 0 and rectangle = 3 then
            randint (enemy (1),37,893)
            randint (enemy (2),491,513)
            drawfilloval (enemy (1), enemy (2), 7, 7, 41)
            enemy (3) := 1
        elsif enemy (3) = 0 and rectangle = 4 then
            randint (enemy (1),870,893)
            randint (enemy (2),38,483)
            drawfilloval (enemy (1), enemy (2), 7, 7, 41)
            enemy (3) := 1
        end if

        Input.KeyDown (chars)
        %Player controls
        if chars ('a') and player (1) > 48 then
            player (1) := player (1) - 2
        end if
        if chars ('d') and player (1) < 851 then
            player (1) := player (1) + 2
        end if
        if chars ('w') and player (2) < 472 then
            player (2) := player (2) + 2
        end if
        if chars ('s') and player (2) > 49 then
            player (2) := player (2) - 2
        end if

        % Attempt on enemy follow
        if player (1) > enemy (1) then
            enemy (1) := enemy (1) + 1
        end if
        if player (1) < enemy (1) then
            enemy (1) := enemy (1) - 1
        end if
        if player (2) > enemy (2) then
            enemy (2) := enemy (2) + 1
        end if
        if player (2) < enemy (2) then
            enemy (2) := enemy (2) - 1
        end if

        %Shockwave
        if chars (' ') and count > 0 and space = 0 then
            shockwave (1) := player (1)
            shockwave (2) := player (2)
            shockwave (3) := 1
            shockwave (4) := 1
            count := count - 1
            space := 1
        end if
        if not chars (' ') then
            space := 0
        end if

        if chars ('e') then
            Pic.Draw (Pause, 0, 0, picMerge)
            Input.Pause
        end if
        
        %Display amount of shockwaves that are left
        if count = 3 then
            drawoval (198, 538, 7, 7, 39)
            drawoval (198, 538, 8, 8, 39)
            drawoval (222, 538, 7, 7, 39)
            drawoval (222, 538, 8, 8, 39)
            drawoval (245, 538, 7, 7, 39)
            drawoval (245, 538, 8, 8, 39)
        end if
        if count = 2 then
            drawoval (198, 538, 7, 7, 39)
            drawoval (198, 538, 8, 8, 39)
            drawoval (222, 538, 7, 7, 39)
            drawoval (222, 538, 8, 8, 39)
        end if
        if count = 1 then
            drawoval (198, 538, 7, 7, 39)
            drawoval (198, 538, 8, 8, 39)
        end if
        if count = 0 then
        end if

        %Firing the bullets
        mousewhere (mx, my, b)
        if b = 1 then
            drawline (player (1), player (2), mx, my, 40)
        end if

        %Enemy collision with shockwave
        if round (sqrt (((player (1) - enemy (1)) ** 2) + (player (2) - enemy (2)) ** 2))  216 and mx < 389 and my > 183 and my < 271 and b = 1 then
            %Set the variables
            enemy (1) := 15
            enemy (2) := 15
            enemy (3) := 1
            player (1) := 450
            player (2) := 275
            player (3) := 1
            count := 3
            health := 215
            score := 0
            exit
        end if
        
        %Close the game if 'EXIT' is clicked
        if mx > 522 and mx < 692 and my > 200 and my < 257 and b = 1 then
            Window.Close (defWinID)
        end if
    end loop
end loop



Please specify what version of Turing you are using
Turing 1.4.1

The code is also in the 'zip' file

-----------------------------------
Raknarg
Thu Feb 09, 2012 7:28 pm

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:


type shipSpecs : 
     record
          x, y : int
     end record

var player : shipSpecs

player.x := 50
player.y := 100


-----------------------------------
Aange10
Fri Feb 10, 2012 11:39 am

RE:How do you get multiple enemies?
-----------------------------------
Also, what is it you are having difficulty with?

-----------------------------------
mobin12
Fri Feb 10, 2012 4:16 pm

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.

-----------------------------------
Raknarg
Fri Feb 10, 2012 6:01 pm

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.

-----------------------------------
mobin12
Fri Feb 10, 2012 6:12 pm

RE:How do you get multiple enemies?
-----------------------------------
thanks very much i will try that

-----------------------------------
mobin12
Sat Feb 11, 2012 2:51 pm

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?

-----------------------------------
Raknarg
Sat Feb 11, 2012 4:20 pm

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:


for i : 1 .. 5
     calculate_bullet_stuff ()
     for j : 1 .. 10
          if bullet (i) and enemy (j) collide then
               kill enemy (j)
               kill bullet (i)
          end if
     end for
end for

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.

-----------------------------------
mobin12
Mon Feb 13, 2012 5:27 pm

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.


%Set the screen size
setscreen ("graphics:900;550,nobuttonbar,offscreenonly")

var chars : array char of boolean
var player : array 1 .. 3 of int
player (1) := 450
player (2) := 275
player (3) := 1
var enemy1, enemy2, enemy3 : array 1 .. 3 of int
enemy1 (1) := 15
enemy1 (2) := 15
enemy1 (3) := 1
enemy2 (1) := 15
enemy2 (2) := 15
enemy2 (3) := 1
enemy3 (1) := 15
enemy3 (2) := 15
enemy3 (3) := 1
var mx, my, b : int
var shockwave : array 1 .. 4 of int
shockwave (3) := 1
shockwave (4) := 0
var space : int := 0
var count : int := 3
var health : int := 215
var Intro : int := Pic.FileNew ("Game-Intro.jpg")
var Instructions : int := Pic.FileNew ("Game-Instructions.jpg")
var Background : int := Pic.FileNew ("Game-Background.jpg")
var Pause : int := Pic.FileNew ("Game-Pause.jpg")
var End : int := Pic.FileNew ("Game-End.jpg")
var font : int := Font.New ("DigifaceWide:46")
var font1 : int := Font.New ("Ethnocentric:13")
var score : int := 0
var s : string := ""
var rectangle : int

%THE INTRO
loop
    Pic.Draw (Intro, 0, 0, picMerge)
    mousewhere (mx, my, b)
    exit when mx > 288 and mx < 634 and my > 185 and my < 234 and b = 1
    View.Update
end loop

%THE INSTRUCTIONS
loop
    Pic.Draw (Instructions, 0, 0, picMerge)
    mousewhere (mx, my, b)
    exit when mx > 242 and mx < 694 and my > 104 and my < 170 and b = 1
    View.Update
    cls
end loop

%THE GAME
loop
    loop
        %Draw the Background for the game
        Pic.Draw (Background, 0, 0, picMerge)
        
        s:=intstr(score)
        Font.Draw ("score: ", 0, 507, font1, black)
        Font.Draw (s, 94, 507, font1, black)
        
        %Draw the player
        if player (3) = 1 then
            drawfilloval (player (1), player (2), 10, 10, 54)
            drawfilloval (player (1), player (2), 8, 8, 55)
        end if
        
        %Draw the enemy
        if enemy1 (3) = 1 then
            drawfilloval (enemy1 (1), enemy1 (2), 7, 7, 41)
        end if
        if enemy2 (3) = 1 then
            drawfilloval (enemy2 (1), enemy2 (2), 7, 7, 41)
        end if
        if enemy3 (3) = 1 then
            drawfilloval (enemy3 (1), enemy3 (2), 7, 7, 41)
        end if

        %Randomly spawn the enemy in the 'ENEMY BAY'
        %Enemy 1
        randint (rectangle,1,4)
        if enemy1 (3) = 0 and rectangle = 1 then
            randint (enemy1 (1),7,893)
            randint (enemy1 (2),7,30)
            drawfilloval (enemy1 (1), enemy1 (2), 7, 7, 41)
            enemy1 (3) := 1
        elsif enemy1 (3) = 0 and rectangle = 2 then
            randint (enemy1 (1),7,29)
            randint (enemy1 (2),38,513)
            drawfilloval (enemy1 (1), enemy1 (2), 7, 7, 41)
            enemy1 (3) := 1
        elsif enemy1 (3) = 0 and rectangle = 3 then
            randint (enemy1 (1),37,893)
            randint (enemy1 (2),491,513)
            drawfilloval (enemy1 (1), enemy1 (2), 7, 7, 41)
            enemy1 (3) := 1
        elsif enemy1 (3) = 0 and rectangle = 4 then
            randint (enemy1 (1),870,893)
            randint (enemy1 (2),38,483)
            drawfilloval (enemy1 (1), enemy1 (2), 7, 7, 41)
            enemy1 (3) := 1
        end if
        %Enemy 2
        if enemy2 (3) = 0 and rectangle = 1 then
            randint (enemy2 (1),7,893)
            randint (enemy2 (2),7,30)
            drawfilloval (enemy2 (1), enemy2 (2), 7, 7, 41)
            enemy2 (3) := 1
        elsif enemy2 (3) = 0 and rectangle = 2 then
            randint (enemy2 (1),7,29)
            randint (enemy2 (2),38,513)
            drawfilloval (enemy2 (1), enemy2 (2), 7, 7, 41)
            enemy2 (3) := 1
        elsif enemy2 (3) = 0 and rectangle = 3 then
            randint (enemy2 (1),37,893)
            randint (enemy2 (2),491,513)
            drawfilloval (enemy2 (1), enemy2 (2), 7, 7, 41)
            enemy2 (3) := 1
        elsif enemy2 (3) = 0 and rectangle = 4 then
            randint (enemy2 (1),870,893)
            randint (enemy2 (2),38,483)
            drawfilloval (enemy2 (1), enemy2 (2), 7, 7, 41)
            enemy2 (3) := 1
        end if
        %Enemy 3
        if enemy3 (3) = 0 and rectangle = 1 then
            randint (enemy3 (1),7,893)
            randint (enemy3 (2),7,30)
            drawfilloval (enemy3 (1), enemy3 (2), 7, 7, 41)
            enemy3 (3) := 1
        elsif enemy3 (3) = 0 and rectangle = 2 then
            randint (enemy3 (1),7,29)
            randint (enemy3 (2),38,513)
            drawfilloval (enemy3 (1), enemy3 (2), 7, 7, 41)
            enemy3 (3) := 1
        elsif enemy3 (3) = 0 and rectangle = 3 then
            randint (enemy3 (1),37,893)
            randint (enemy3 (2),491,513)
            drawfilloval (enemy3 (1), enemy3 (2), 7, 7, 41)
            enemy3 (3) := 1
        elsif enemy3 (3) = 0 and rectangle = 4 then
            randint (enemy3 (1),870,893)
            randint (enemy3 (2),38,483)
            drawfilloval (enemy3 (1), enemy3 (2), 7, 7, 41)
            enemy3 (3) := 1
        end if

        Input.KeyDown (chars)
        %Player controls
        if chars ('a') and player (1) > 48 then
            player (1) := player (1) - 2
        end if
        if chars ('d') and player (1) < 851 then
            player (1) := player (1) + 2
        end if
        if chars ('w') and player (2) < 472 then
            player (2) := player (2) + 2
        end if
        if chars ('s') and player (2) > 49 then
            player (2) := player (2) - 2
        end if

        %Make the enemy follow the player's position
        %Enemy 1
        if player (1) > enemy1 (1) then
            enemy1 (1) := enemy1 (1) + 1
        end if
        if player (1) < enemy1 (1) then
            enemy1 (1) := enemy1 (1) - 1
        end if
        if player (2) > enemy1 (2) then
            enemy1 (2) := enemy1 (2) + 1
        end if
        if player (2) < enemy1 (2) then
            enemy1 (2) := enemy1 (2) - 1
        end if
        %Enemy 2
        if player (1) > enemy2 (1) then
            enemy2 (1) := enemy2 (1) + 1
        end if
        if player (1) < enemy2 (1) then
            enemy2 (1) := enemy2 (1) - 1
        end if
        if player (2) > enemy2 (2) then
            enemy2 (2) := enemy2 (2) + 1
        end if
        if player (2) < enemy2 (2) then
            enemy2 (2) := enemy2 (2) - 1
        end if
        %Enemy 3
        if player (1) > enemy3 (1) then
            enemy3 (1) := enemy3 (1) + 1
        end if
        if player (1) < enemy3 (1) then
            enemy3 (1) := enemy3 (1) - 1
        end if
        if player (2) > enemy3 (2) then
            enemy3 (2) := enemy3 (2) + 1
        end if
        if player (2) < enemy3 (2) then
            enemy3 (2) := enemy3 (2) - 1
        end if

        %Shockwave
        if chars (' ') and count > 0 and space = 0 then
            shockwave (1) := player (1)
            shockwave (2) := player (2)
            shockwave (3) := 1
            shockwave (4) := 1
            count := count - 1
            space := 1
        end if
        if not chars (' ') then
            space := 0
        end if

        if chars ('e') then
            Pic.Draw (Pause, 0, 0, picMerge)
            Input.Pause
        end if
        
        %Display amount of shockwaves that are left
        if count = 3 then
            drawoval (198, 538, 7, 7, 39)
            drawoval (198, 538, 8, 8, 39)
            drawoval (222, 538, 7, 7, 39)
            drawoval (222, 538, 8, 8, 39)
            drawoval (245, 538, 7, 7, 39)
            drawoval (245, 538, 8, 8, 39)
        end if
        if count = 2 then
            drawoval (198, 538, 7, 7, 39)
            drawoval (198, 538, 8, 8, 39)
            drawoval (222, 538, 7, 7, 39)
            drawoval (222, 538, 8, 8, 39)
        end if
        if count = 1 then
            drawoval (198, 538, 7, 7, 39)
            drawoval (198, 538, 8, 8, 39)
        end if
        if count = 0 then
        end if

        %Firing the bullets
        mousewhere (mx, my, b)
        if b = 1 then
            drawline (player (1), player (2), mx, my, 40)
        end if

        %Enemy collision with shockwave
        %Enemy 1
        if round (sqrt (((player (1) - enemy1 (1)) ** 2) + (player (2) - enemy1 (2)) ** 2))  216 and mx < 389 and my > 183 and my < 271 and b = 1 then
            %Set the variables
            %Enemy 1
            enemy1 (1) := 15
            enemy1 (2) := 15
            enemy1 (3) := 1
            %Enemy 2
            enemy2 (1) := 15
            enemy2 (2) := 15
            enemy2 (3) := 1
            %Enemy 3
            enemy3 (1) := 15
            enemy3 (2) := 15
            enemy3 (3) := 1
            %Player
            player (1) := 450
            player (2) := 275
            player (3) := 1
            %Shocwave count
            count := 3
            %Score
            score := 0
            %Health
            health := 215
            exit
        end if
        
        %Close the game if 'EXIT' is clicked
        if mx > 522 and mx < 692 and my > 200 and my < 257 and b = 1 then
            Window.Close (defWinID)
        end if
    end loop
end loop


-----------------------------------
mirhagk
Mon Feb 13, 2012 6:23 pm

RE:How do you get multiple enemies?
-----------------------------------
See this:

  %Make the enemy follow the player's position
        %Enemy 1
        if player (1) > enemy1 (1) then
            enemy1 (1) := enemy1 (1) + 1
        end if
        if player (1) < enemy1 (1) then
            enemy1 (1) := enemy1 (1) - 1
        end if
        if player (2) > enemy1 (2) then
            enemy1 (2) := enemy1 (2) + 1
        end if
        if player (2) < enemy1 (2) then
            enemy1 (2) := enemy1 (2) - 1
        end if
        %Enemy 2
        if player (1) > enemy2 (1) then
            enemy2 (1) := enemy2 (1) + 1
        end if
        if player (1) < enemy2 (1) then
            enemy2 (1) := enemy2 (1) - 1
        end if
        if player (2) > enemy2 (2) then
            enemy2 (2) := enemy2 (2) + 1
        end if
        if player (2) < enemy2 (2) then
            enemy2 (2) := enemy2 (2) - 1
        end if
        %Enemy 3
        if player (1) > enemy3 (1) then
            enemy3 (1) := enemy3 (1) + 1
        end if
        if player (1) < enemy3 (1) then
            enemy3 (1) := enemy3 (1) - 1
        end if
        if player (2) > enemy3 (2) then
            enemy3 (2) := enemy3 (2) + 1
        end if
        if player (2) < enemy3 (2) then
            enemy3 (2) := enemy3 (2) - 1
        end if 

Don't do that. For loops and arrays would turn this into like 4 lines.

-----------------------------------
Raknarg
Mon Feb 13, 2012 6:40 pm

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

-----------------------------------
mobin12
Wed Feb 15, 2012 5:47 pm

RE:How do you get multiple enemies?
-----------------------------------
is anyone familiar with 'realstr'?

-----------------------------------
Raknarg
Thu Feb 16, 2012 11:33 am

RE:How do you get multiple enemies?
-----------------------------------
lol I tried figuring it out a while ago, but gave up.

-----------------------------------
mobin12
Thu Feb 16, 2012 3:52 pm

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?...

-----------------------------------
Dreadnought
Thu Feb 16, 2012 4:16 pm

Re: How do you get multiple enemies?
-----------------------------------
put realstr(3.141593, 2) %-> "3.141593" (width was increased to 8)
put realstr(3.141593, 8) %-> "3.141593" (width of 8)
put realstr(3.14159265358, 12) %-> "    3.141593" (padded with 4 spaces to get a width of 12)

% With exponents we get a slightly longer string
put realstr (6.626069e-34, 2) % -> "6.626069e-34" (width was increased to 11)
put realstr (6.626069e-34, 11) % -> "6.626069e-34" (width of 11)
put realstr (6.62606957e-34, 12) % -> " 6.626069e-34"  (padded with 1 space to get a width of 12)

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 [tdoc]erealstr[/tdoc] and [tdoc]frealstr[/tdoc].

Hope this helps.

-----------------------------------
mobin12
Fri Feb 17, 2012 9:29 am

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, '?')

-----------------------------------
Zren
Fri Feb 17, 2012 12:41 pm

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))

-----------------------------------
Dreadnought
Fri Feb 17, 2012 1:00 pm

Re: How do you get multiple enemies?
-----------------------------------
In this case, realstr cannot help you. You must turn to other options var pi1000 :string := frealstr(3141.59265359,0,0)
put pi1000 % prints "3142."
put pi1000(1..length(pi1000)-1) % removing the last character (the decimal point) we obtain "3142"

% If now you want to keep two digits after the decimal point, we ask for a fractional width of 2.
put frealstr (3141.59653589,0,2) % will print "3141.59" rounding to two digits after the decimal point.

% Note that in the special case that you want to round to an integer
put intstr(round(3141.59653589)) % I don't need intstr for put, but this way I am still getting a string
% Or if you don't want any rounding at all 
put intstr(3141.59653589 div 1) % Since div rounds toward zero


You can also use erealstr, but then it will display in scientific notation and make things more complicated.
put erealstr (3141.59265359,0,0,0) % prints 3e+3 which is not what you want.
put erealstr (3141.59265359,0,3,0) % "3.142e+3" is still in scientific notation, which you don't want (I assume)


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: % If I want two digits after the decimal point
put realstr (round(3141.592653589 * 100) / 100,0)
% Is equivalent to 
put frealstr (3141.592653589,0,2)

Hope this helps.

-----------------------------------
mobin12
Fri Feb 17, 2012 4:34 pm

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.)

var h : string := ""
var healthpercentage : real
healthpercentage := (health/215) * 100
h:=realstr(healthpercentage,0)
Font.Draw (h, 481, 530, font2, white)
Font.Draw ("%", 518, 527, font1, white)


-----------------------------------
Raknarg
Fri Feb 17, 2012 4:50 pm

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?

-----------------------------------
mobin12
Fri Feb 17, 2012 5:53 pm

RE:How do you get multiple enemies?
-----------------------------------
only the integer and no decimal points and also no
decimal (if possible)

-----------------------------------
Dreadnought
Sat Feb 18, 2012 3:34 am

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.

Font.Draw(intstr(round(0.7852*100)) + "%", 200, 200, defFontId, black)
% This will draw "79%"

Alternately, you can use frealstr(realNumber, 0, 2) and remove the first two digits using (3..*).

-----------------------------------
mobin12
Sat Feb 18, 2012 7:28 pm

Re: How do you get multiple enemies?
-----------------------------------
yes thank you very much
This fixed my problem
