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

Username:   Password: 
 RegisterRegister   
 collision (whatdorcolor?)...
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Charger




PostPosted: Mon May 09, 2005 1:17 pm   Post subject: collision (whatdorcolor?)...

Hi
Im new here,I just found out about this site,
anyways I need help with this game that im making, could someone tell me how to make the gray blocks the boundries, so that the players dont go past them.

code:
setscreen ("offscreenonly,graphics:700;500")
mousehide
var keyboard : array char of boolean
var playerx, playery : int := 200
var player2x, player2y : int := 222
var player3x, player3y : int := 375
var player4x, player4y : int := 400
var ballx, bally : int := 288
var x : int := 100
var mousex, mousey, mb : int

Input.KeyDown (keyboard)

%intro
cls
setscreen ("offscreenonly,nobuttonbar,position:truemiddle,centre,graphics:700;500")
colorback (black)
cls

var song : int
var N, y, b : int := 10
var keyb : array char of boolean
var clr : int := 218 % The color to assign to
var text1 : int := Font.New ("Times New Roman:38:Bold") % First Font

for i : 0 .. 39
    RGB.SetColor (clr, 0, 0, i / 39)
    Font.Draw ("THUNDER PUCK 2K5", (maxx div 2) - (Font.Width ("THUNDER PUCK 2K5", text1) div 2), (maxy div 2) - 9, text1, clr)
    View.Update
    drawfillbox ((maxx div 2) - Font.Width ("THUNDER PUCK 2K5", text1) - 5, (maxy div 2) - 13, ((maxx div 2) + Font.Width ("THUNDER PUCK 2K5", text1) + 5), (maxy div 2) + 13, 7)
    delay (50)
end for
delay (1000)
for decreasing i : 39 .. 0
    RGB.SetColor (clr, 0, 0, i / 39)
    Font.Draw ("THUNDER PUCK 2K5", (maxx div 2) - (Font.Width ("THUNDER PUCK 2K5", text1) div 2), (maxy div 2) - 9, text1, clr)
    View.Update
    drawfillbox ((maxx div 2) - Font.Width ("THUNDER PUCK 2K5", text1) - 5, (maxy div 2) - 13, ((maxx div 2) + Font.Width ("THUNDER PUCK 2K5", text1) + 5), (maxy div 2) + 13, 7)
    delay (50)
end for
%intro

colourback (brightred)

loop
    View.Update
    cls
    Input.KeyDown (keyboard)

    %===================1st player=============
    if keyboard (KEY_UP_ARROW) then
        playery += 2
        if sqrt ((playerx - player3x) ** 2 + (playery - player3y) ** 2) < 29 or sqrt ((playerx - player4x) ** 2 + (playery - player4y) ** 2) < 29 then
            playery -= 2
        end if
    elsif keyboard (KEY_DOWN_ARROW) then
        playery -= 2
        if sqrt ((playerx - player3x) ** 2 + (playery - player3y) ** 2) < 29 or sqrt ((playerx - player4x) ** 2 + (playery - player4y) ** 2) < 29 then
            playery += 2
        end if
    end if

    if keyboard (KEY_RIGHT_ARROW) then
        playerx += 2
        if sqrt ((playerx - player3x) ** 2 + (playery - player3y) ** 2) < 29 or sqrt ((playerx - player4x) ** 2 + (playery - player4y) ** 2) < 29 then
            playerx -= 2
        end if

    elsif keyboard (KEY_LEFT_ARROW) then
        playerx -= 2
        if sqrt ((playerx - player3x) ** 2 + (playery - player3y) ** 2) < 29 or sqrt ((playerx - player4x) ** 2 + (playery - player4y) ** 2) < 29 then
            playerx += 2
        end if
    end if

    %===================player 2=============
    if keyboard ('5') then
        player2y += 2
        if sqrt ((player2x - player3x) ** 2 + (player2y - player3y) ** 2) < 29 or sqrt ((player2x - player4x) ** 2 + (player2y - player4y) ** 2) < 29 then
            player2y -= 2
        end if
    elsif keyboard ('2') then
        player2y -= 2
        if sqrt ((player2x - player3x) ** 2 + (player2y - player3y) ** 2) < 29 or sqrt ((player2x - player4x) ** 2 + (player2y - player4y) ** 2) < 29 then
            player2y += 2
        end if
    end if

    if keyboard ('3') then
        player2x += 2
        if sqrt ((player2x - player3x) ** 2 + (player2y - player3y) ** 2) < 29 or sqrt ((player2x - player4x) ** 2 + (player2y - player4y) ** 2) < 29 then
            player2x -= 2
        end if

    elsif keyboard ('1') then
        player2x -= 2
        if sqrt ((player2x - player3x) ** 2 + (player2y - player3y) ** 2) < 29 or sqrt ((player2x - player4x) ** 2 + (player2y - player4y) ** 2) < 29 then
            player2x += 2
        end if
    end if

    %===================player 3=============
    if keyboard ('i') then
        player3y += 2
        if sqrt ((player3x - playerx) ** 2 + (player3y - playery) ** 2) < 29 or sqrt ((player3x - player2x) ** 2 + (player3y - player2y) ** 2) < 29 then
            player3y -= 2
        end if
    elsif keyboard ('k') then
        player3y -= 2
        if sqrt ((player3x - playerx) ** 2 + (player3y - playery) ** 2) < 29 or sqrt ((player3x - player2x) ** 2 + (player3y - player2y) ** 2) < 29 then
            player3y += 2
        end if
    end if

    if keyboard ('l') then
        player3x += 2
        if sqrt ((player3x - playerx) ** 2 + (player3y - playery) ** 2) < 29 or sqrt ((player3x - player2x) ** 2 + (player3y - player2y) ** 2) < 29 then
            player3x -= 2
        end if

    elsif keyboard ('j') then
        player3x -= 2
        if sqrt ((player3x - playerx) ** 2 + (player3y - playery) ** 2) < 29 or sqrt ((player3x - player2x) ** 2 + (player3y - player2y) ** 2) < 29 then
            player3x += 2
        end if
    end if

    %===================player 4 =============
    if keyboard ('w') then
        player4y += 2
        if sqrt ((player4x - playerx) ** 2 + (player4y - playery) ** 2) < 29 or sqrt ((player4x - player2x) ** 2 + (player4y - player2y) ** 2) < 29 then
            player4y -= 2
        end if
    elsif keyboard ('s') then
        player4y -= 2
        if sqrt ((player4x - playerx) ** 2 + (player4y - playery) ** 2) < 29 or sqrt ((player4x - player2x) ** 2 + (player4y - player2y) ** 2) < 29 then
            player4y += 2
        end if
    end if

    if keyboard ('d') then
        player4x += 2
        if sqrt ((player4x - playerx) ** 2 + (player4y - playery) ** 2) < 29 or sqrt ((player4x - player2x) ** 2 + (player4y - player2y) ** 2) < 29 then
            player4x -= 2
        end if

    elsif keyboard ('a') then
        player4x -= 2
        if sqrt ((player4x - playerx) ** 2 + (player4y - playery) ** 2) < 29 or sqrt ((player4x - player2x) ** 2 + (player4y - player2y) ** 2) < 29 then
            player4x += 2
        end if
    end if

    %===================Background=============
    drawfillbox (0, 0, 700, 485, black)
    %===================player 1=============
    drawoval (playerx, playery, 15, 15, gray)
    drawfilloval (playerx, playery, 10, 10, brightblue)
    %===================player 2=============
    drawoval (player2x, player2y, 15, 15, gray)
    drawfilloval (player2x, player2y, 10, 10, brightblue)
    %===================player 3=============
    drawoval (player3x, player3y, 15, 15, gray)
    drawfilloval (player3x, player3y, 10, 10, brightred)
    %===================player 4=============
    drawoval (player4x, player4y, 15, 15, gray)
    drawfilloval (player4x, player4y, 10, 10, brightred)
    %===================Ball=============
    drawfilloval (ballx, bally, 7, 7, gray)
    %===================Arena=============
    %Center
    drawfilloval (353, 257, 50, 50, gray)
    drawfilloval (353, 257, 40, 40, brightred)
    %Goal Line Left
    drawfillbox (39, 230, 37, 286, 0)
    %Goal Line Right
    drawfillbox (661, 230, 659, 287, 0)
    %Left
    drawfillbox (29, 344, 39, 298, gray)
    drawfillbox (1, 287, 39, 298, gray)
    drawfillbox (1, 286, 10, 231, gray)
    drawfillbox (1, 230, 39, 220, gray)
    drawfillbox (30, 219, 39, 171, gray)
    %Top
    drawfillbox (29, 344, 237, 355, gray)
    drawfillbox (248, 344, 238, 483, gray)
    drawfillbox (249, 475, 461, 483, gray)
    drawfillbox (451, 475, 461, 344, gray)
    drawfillbox (462, 344, 669, 354, gray)
    %Bottom
    drawfillbox (30, 162, 250, 171, gray)
    drawfillbox (250, 162, 241, 14, gray)
    drawfillbox (241, 6, 452, 14, gray)
    drawfillbox (461, 6, 452, 172, gray)
    drawfillbox (461, 163, 660, 172, gray)
    %Right
    drawfillbox (659, 343, 669, 297, gray)
    drawfillbox (659, 288, 699, 298, gray)
    drawfillbox (690, 288, 699, 221, gray)
    drawfillbox (659, 221, 689, 231, gray)
    drawfillbox (659, 220, 669, 163, gray)
    %===================ScoreBoard=============
    put " BlueScore:                                                              Red Score:  "
    %===================MouseCord...=============
    locate (1, 1)
    Mouse.Where (mousex, mousey, mb)
    colour (0)
    %put mousex, ", ", mousey

    if playerx > 39 and playerx < 251 and (playery > 17 and playery < 175 or playery > 344 and playery < 473) then
        put "here"
    end if
end loop


thanks
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Mon May 09, 2005 1:46 pm   Post subject: (No subject)

What you can do is use whatdotcolor. But in order to do that, change the color of the puck to 20 or something (check the colors for grey). And all you do is check if the tips of the circles are equal to grey. You'll have to check this before you draw the actual player. It would be smething like this
code:

drawfill_background(somewhere) %This is your arena
%now since your players aren't in an array, you'll have to do it individually
if whatdotcolor (playerx - (radius of player), playery) not = gray then
     % move left, and repeat that for moving right only - to +
elsif whatdotcolor (playerx, playery + (radius of player)) not= gray then
     %move up, and repeat for down only + to -
end if
drawfillplayer1
%Now repreat this for all 4 players

if your players were in an array you could simply do this
code:

drawfill_background(somewhere)
for i: 1 .. 4
 %This is your arena
%now since your players aren't in an array, you'll have to do it individually
if whatdotcolor (playerx(i) - (radius of player), playery(i)) not = gray then
     % move left, and repeat that for moving right only - to +
elsif whatdotcolor (playerx(i), playery(i) + (radius of player(i))) not= gray then
     %move up, and repeat for down only + to -
end if
drawfillplayer(i)

But I don't have much time to go too deep into detail, but you seem like you know enough to figure it out Razz
Good Luck.
Martin




PostPosted: Mon May 09, 2005 2:03 pm   Post subject: (No subject)

There's a post in this form with a title something like 'Announcement: ---> READ THIS FIRST <---'

I suggest you read it.
Charger




PostPosted: Tue May 10, 2005 8:40 am   Post subject: (No subject)

Martin wrote:
There's a post in this form with a title something like 'Announcement: ---> READ THIS FIRST <---'

I suggest you read it.


ohh sorry about that, I was in a hurry and i posted as soon as I registered. I know better now Smile
and thanks for the help jamonathin
Charger




PostPosted: Mon May 16, 2005 12:40 pm   Post subject: (No subject)

im still haveing problems with it, you think you could explain it more?
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  [ 5 Posts ]
Jump to:   


Style:  
Search: