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
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.92 KB
 Downloaded:  132 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Dragon20942




PostPosted: Fri Mar 02, 2012 7:38 pm   Post subject: RE:How do you get multiple enemies?

Try using flexible arrays. They're arrays that can have their bounds changed. Look for em in the tutorials.
mobin12




PostPosted: Fri Mar 02, 2012 9:16 pm   Post subject: RE:How do you get multiple enemies?

it's ok i found out how to do it.
This was a double post by accident.
But thanks anyways.
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 1  [ 3 Posts ]
Jump to:   


Style:  
Search: