Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How do you get multiple enemies?
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mobin12




PostPosted: 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)


Turing:


%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)) <= shockwave (3) and shockwave (4) = 1 and enemy (3) = 1 and round (sqrt (((enemy (1) - player (1)) ** 2) + (enemy (2) - player (2)) ** 2)) <= shockwave (3) and shockwave (4) = 1 and enemy (3) = 1 and score <= 99999 then
            enemy (3) := 0
            score := score + 5
        end if
       
        %Enemy collision with bullet
        if mx <= (enemy (1) + 7) and mx >= (enemy (1) - 7) and b = 1 and my <= (enemy (2) + 7) and my >= (enemy (2) - 7) and b = 1 and score <= 99999 then
            enemy (3) := 0
            score := score + 10
        end if
       
        %Enemy collision with player and player health
        drawfillbox (395, 528, 394 + health, 542, 46)
        if enemy (3) = 1 and enemy (1) - 7 <= (player (1) + 12) and enemy (1) + 7 >= (player (1) - 12) and enemy (2) - 7 <= (player (2) + 12) and enemy (2) + 7 >= (player (2) - 12) and health >= 1 then
            health := health - 1
            score := score - 2
        end if
        if health = 0 then
            player (3) := 0
        end if

        %Draw the shockwaves
        if shockwave (4) = 1 then
            drawoval (shockwave (1), shockwave (2), shockwave (3), shockwave (3), 41)
            shockwave (3) := shockwave (3) + 3
            drawoval (shockwave (1), shockwave (2), shockwave (3), shockwave (3), 40)
            shockwave (3) := shockwave (3) + 3
            drawoval (shockwave (1), shockwave (2), shockwave (3), shockwave (3), 39)
            shockwave (3) := shockwave (3) + 3
            if shockwave (3) >= 1000 + 5 then
                shockwave (4) := 0
            end if
        end if
       
        %Anti-flicker command
        View.Update
       
        %Slow program down
        Time.Delay (8)
       
        %Clear screen for the next loop
        cls
        exit when player (3) = 0
    end loop
   
    %THE END
    loop
        s:=intstr(score)
        Pic.Draw (End, 0, 0, picMerge)
        Font.Draw (s, 481, 355, font, white)
        View.Update
        mousewhere (mx, my, b)
       
        %Restart the game if 'TRY AGAIN' is clicked
        if mx > 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



2D-SHOOTER.zip
 Description:

Download
 Filename:  2D-SHOOTER.zip
 Filesize:  909.45 KB
 Downloaded:  143 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: 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:

Turing:

type shipSpecs :
     record
          x, y : int
     end record

var player : shipSpecs

player.x := 50
player.y := 100
Aange10




PostPosted: 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?
mobin12




PostPosted: 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.
Raknarg




PostPosted: 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.
mobin12




PostPosted: Fri Feb 10, 2012 6:12 pm   Post subject: RE:How do you get multiple enemies?

thanks very much i will try that
mobin12




PostPosted: 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?
Raknarg




PostPosted: 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:

Turing:

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.
Sponsor
Sponsor
Sponsor
sponsor
mobin12




PostPosted: 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.
Turing:


%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)) <= shockwave (3) and shockwave (4) = 1 and enemy1 (3) = 1 and round (sqrt (((enemy1 (1) - player (1)) ** 2) + (enemy1 (2) - player (2)) ** 2)) <= shockwave (3) and shockwave (4) = 1 and enemy1 (3) = 1 and score <= 99999 then
            enemy1 (3) := 0
            score := score + 5
        end if
        %Enemy 2
        if round (sqrt (((player (1) - enemy2 (1)) ** 2) + (player (2) - enemy2 (2)) ** 2)) <= shockwave (3) and shockwave (4) = 1 and enemy2 (3) = 1 and round (sqrt (((enemy2 (1) - player (1)) ** 2) + (enemy2 (2) - player (2)) ** 2)) <= shockwave (3) and shockwave (4) = 1 and enemy2 (3) = 1 and score <= 99999 then
            enemy2 (3) := 0
            score := score + 5
        end if
        %Enemy 3
        if round (sqrt (((player (1) - enemy3 (1)) ** 2) + (player (2) - enemy3 (2)) ** 2)) <= shockwave (3) and shockwave (4) = 1 and enemy3 (3) = 1 and round (sqrt (((enemy3 (1) - player (1)) ** 2) + (enemy3 (2) - player (2)) ** 2)) <= shockwave (3) and shockwave (4) = 1 and enemy3 (3) = 1 and score <= 99999 then
            enemy3 (3) := 0
            score := score + 5
        end if
       
        %Enemy collision with bullet
        %Enemy 1
        if mx <= (enemy1 (1) + 7) and mx >= (enemy1 (1) - 7) and b = 1 and my <= (enemy1 (2) + 7) and my >= (enemy1 (2) - 7) and b = 1 and score <= 99999 then
            enemy1 (3) := 0
            score := score + 10
        end if
        %Enemy 2
        if mx <= (enemy2 (1) + 7) and mx >= (enemy2 (1) - 7) and b = 1 and my <= (enemy2 (2) + 7) and my >= (enemy2 (2) - 7) and b = 1 and score <= 99999 then
            enemy2 (3) := 0
            score := score + 10
        end if
        %Enemy 3
        if mx <= (enemy3 (1) + 7) and mx >= (enemy3 (1) - 7) and b = 1 and my <= (enemy3 (2) + 7) and my >= (enemy3 (2) - 7) and b = 1 and score <= 99999 then
            enemy3 (3) := 0
            score := score + 10
        end if
       
        %Enemy collision with player and player health
        %Enemy 1
        drawfillbox (395, 528, 394 + health, 542, 46)
        if enemy1 (3) = 1 and enemy1 (1) - 7 <= (player (1) + 12) and enemy1 (1) + 7 >= (player (1) - 12) and enemy1 (2) - 7 <= (player (2) + 12) and enemy1 (2) + 7 >= (player (2) - 12) and health >= 1 then
            health := health - 1
            score := score - 2
        end if
        %Enemy 2
        if enemy2 (3) = 1 and enemy2 (1) - 7 <= (player (1) + 12) and enemy2 (1) + 7 >= (player (1) - 12) and enemy2 (2) - 7 <= (player (2) + 12) and enemy2 (2) + 7 >= (player (2) - 12) and health >= 1 then
            health := health - 1
            score := score - 2
        end if
        %Enemy 3
        if enemy3 (3) = 1 and enemy3 (1) - 7 <= (player (1) + 12) and enemy3 (1) + 7 >= (player (1) - 12) and enemy3 (2) - 7 <= (player (2) + 12) and enemy3 (2) + 7 >= (player (2) - 12) and health >= 1 then
            health := health - 1
            score := score - 2
        end if
        if health = 0 then
            player (3) := 0
        end if

        %Draw the shockwaves
        if shockwave (4) = 1 then
            drawoval (shockwave (1), shockwave (2), shockwave (3), shockwave (3), 41)
            shockwave (3) := shockwave (3) + 3
            drawoval (shockwave (1), shockwave (2), shockwave (3), shockwave (3), 40)
            shockwave (3) := shockwave (3) + 3
            drawoval (shockwave (1), shockwave (2), shockwave (3), shockwave (3), 39)
            shockwave (3) := shockwave (3) + 3
            if shockwave (3) >= 1000 + 5 then
                shockwave (4) := 0
            end if
        end if
       
        %Anti-flicker command
        View.Update
       
        %Slow program down
        Time.Delay (8)
       
        %Clear screen for the next loop
        cls
        exit when player (3) = 0
    end loop
   
    %THE END
    loop
        s:=intstr(score)
        Pic.Draw (End, 0, 0, picMerge)
        Font.Draw (s, 481, 355, font, white)
        View.Update
        mousewhere (mx, my, b)
       
        %Restart the game if 'TRY AGAIN' is clicked
        if mx > 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




PostPosted: Mon Feb 13, 2012 6:23 pm   Post subject: RE:How do you get multiple enemies?

See this:
Turing:

  %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




PostPosted: 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
mobin12




PostPosted: Wed Feb 15, 2012 5:47 pm   Post subject: RE:How do you get multiple enemies?

is anyone familiar with 'realstr'?
Raknarg




PostPosted: 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.
mobin12




PostPosted: 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?...
Dreadnought




PostPosted: 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:
Turing:
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 erealstr and frealstr.

Hope this helps.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 23 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: