Computer Science Canada

HELP! Editing code for Dodgeball game.

Author:  penny2199 [ Mon Jan 05, 2015 9:56 am ]
Post subject:  HELP! Editing code for Dodgeball game.

What is it you are trying to achieve?
-make the player a circle
-Get collision detection to work


What is the problem you are having?
I've tried editing the code to get the game to work. I don't know what I'm doing wrong when I edit. My player becomes a stretchable box/circle and the dodgeballs keep going through the player.

Can someone give me an edited code for me to play?



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


%Dodgeball Game Project

View.Set ("graphics,nobuttonbar")
var playerpos, points, playerxpos, playerypos : int
var ballspeed, ballposition, ballradius : int
var gameover : int
var chars : array char of boolean
var anykey : string (1)

points := 0
playerxpos := 585
playerypos := 175
gameover := 0

%Home Screen
locate (11, 1)
put "" : 28, "Welcome to Alien Showdown"
put "" : 29, "Press any key to play!"
put ""
put "" : 34, "How to play:"
put "" : 18, "Use the arrow keys to move. Avoid the flying orbs!"
loop
    if hasch then
        getch (anykey)
        exit
    else
    end if
end loop
cls

put "Story:"

put "Square Town is under Attack by the Aliens! Weirdly shaped beings are"
put "destroying your town! Avoid the orbs the Aliens shoot."
put ""
put "Can you survive?"
put "Enter any key to start."
loop
    if hasch then
        getch (anykey)
        exit
    else
    end if
end loop
cls

loop

    %Draws original dodgeballs and determines position and size
    randint (ballradius, 20, 40)
    randint (ballposition, 1, 315)
    ballspeed := 0
    drawfilloval (maxx + 50, maxy - 50 - ballposition, ballradius, ballradius, 45)

    %Begins loop
    loop
        cls

        %Character commands
        Input.KeyDown (chars)

        %Moves character down
        if chars (KEY_DOWN_ARROW) then
            if playerypos > 0 then
                playerypos -= 2
            end if
        end if

        %Moves character up
        if chars (KEY_UP_ARROW) then
            if playerypos < maxy - 66 then
                playerypos += 2
            end if
        end if

        %Moves character up
        if chars (KEY_LEFT_ARROW) then
            if playerxpos > 0 then
                playerxpos -= 2
            end if
        end if

        %Moves character up
        if chars (KEY_RIGHT_ARROW) then
            if playerxpos < maxx - 50 then
                playerxpos += 2
            end if
        end if

        %Draws "character"
        drawfillbox (playerxpos, playerypos, playerxpos + 50, playerypos + 50, 21)

        %Draws dodgeballs
        drawfilloval (ballspeed, maxy - 50 - ballposition, ballradius, ballradius, 45)
        ballspeed := ballspeed + 5
        delay (7)
        exit when ballspeed = 700

        %Determines if a dodgeball hits the player
        if ballspeed = playerxpos and ballspeed <= playerxpos + 50 and ballposition >= playerypos and ballposition <= playerypos + 50 then
            gameover += 1
            exit
        end if

    end loop

    %Adds up points
    points := points + 1

    %Exits to Game Over screen when hit by a dodgeball
    if gameover > 0
            then
        exit
    end if

end loop
cls

put "Score: ", points, " "





Please specify what version of Turing you are using
<Answer Here>


: