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

Username:   Password: 
 RegisterRegister   
 Making a cricle follow the x and y of another
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2, 3, 4
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mobin12




PostPosted: Wed Jan 11, 2012 8:53 pm   Post subject: Re: Making a cricle follow the x and y of another

Alright guys, thank you very much with all your help
So here's my way of thanking you guys (MY CODE):
code:

%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 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 := ""

%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
        if enemy (3) = 1 then
            drawfilloval (enemy (1), enemy (2), 7, 7, 41)
        elsif enemy (3) = 0 then
            enemy (1) := 15
            enemy (2) := 15
            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

        %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

also it would be very great if anyone could help me with: make a lot more enemies appear in different spots of the ENEMY BAY. Rather then one enemy in the same spot.
Thanks a lot guys. Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Wed Jan 11, 2012 9:34 pm   Post subject: Re: Making a cricle follow the x and y of another

Nice game.

If you want to have enemies spawn in different locations try using Rand.Int (min, max). You can also check if the random spawn location satisfies certain conditions, (for instance, not too close to the player).

If you want multiple enemies, you should create an array of enemies (enemy data I mean). Then you cycle through each one when checking for collision.
mobin12




PostPosted: Thu Jan 12, 2012 10:22 am   Post subject: RE:Making a cricle follow the x and y of another

but if i do randint the enemy will appear outside the 'ENEMY BAY'.
Dreadnought




PostPosted: Thu Jan 12, 2012 3:59 pm   Post subject: Re: Making a cricle follow the x and y of another

Like I said you might have to check if the new position is allowed. Alternately, it seems your "enemy bay" is just a frame around the playing area (I think but I don't have the background pictures), that's 4 rectangles. All you have to do is randomly select one of the four rectangle and then randomly select a position within the chosen rectangle.
Alex C.




PostPosted: Thu Jan 12, 2012 4:05 pm   Post subject: RE:Making a cricle follow the x and y of another

um try this tutorial: http://compsci.ca/v3/viewtopic.php?t=8808
this has alot of links to basic programming
mobin12




PostPosted: Tue Jan 17, 2012 4:17 pm   Post subject: RE:Making a cricle follow the x and y of another

@Alex C.
this does not help at all
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 4 of 4  [ 51 Posts ]
Goto page Previous  1, 2, 3, 4
Jump to:   


Style:  
Search: