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

Username:   Password: 
 RegisterRegister   
 Slime volley ball game code
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rhomer




PostPosted: Thu May 27, 2004 7:50 pm   Post subject: Slime volley ball game code

Here is my volley ball game...first draft....no net yet. Enjoy!!

code:

setscreen ("graphics:500;max")
setscreen ("offscreenonly")

var playerscore, computerscore : int := 0
const gravity := -0.2
const radius := 50
var chars : array char of boolean
const ballradius := 15
const xdecay := 0.995
const ydecay := 0.99


loop
    var playerx : int := 126
    var playery : int := 100
    var computerx : int := 354
    var computery : int := 100
    var ballx : int := 126
    var bally : int := 400
    var playerjump : boolean := false
    var computerjump : boolean := false
    var inplayer : boolean := false
    var dy, dx : real := 0
    var balldx, balldy : real := 0




    loop
        Input.KeyDown (chars)
        drawfilloval (playerx, playery, radius, radius, white)
        drawfilloval (computerx, computery, radius, radius, white)
        drawfilloval (ballx, bally, ballradius, ballradius, white)
        if chars (KEY_LEFT_ARROW) then
            playerx -= 2
            if chars (KEY_UP_ARROW) and playerjump = false then
                dy := 10
                playery += round (dy)
                playerjump := true
            end if
        elsif chars (KEY_RIGHT_ARROW) then
            playerx += 2
            if chars (KEY_UP_ARROW) and playerjump = false then
                dy := 10
                playery += round (dy)
                playerjump := true
            end if
        elsif chars (KEY_UP_ARROW) and playerjump = false then
            dy := 10
            playery += round (dy)
            playerjump := true
        elsif chars (KEY_SHIFT) then
            if balldx < 0.5 and balldx > -0.5 then
                balldx -= 2
            end if
        end if
        playerx += round (dx)
        playery += floor (dy)
        dx *= xdecay
        if dy > 1 or playery > 2 then
            dy += gravity
        else
            playery := 0
        end if
        dy *= ydecay
        if playery < 100 then
            playery := 100
            playerjump := false
        end if
        if playerx > 199 then
            playerx := 199
        end if

        ballx += ceil (balldx)
        bally += floor (balldy)
        balldx *= xdecay
        if balldy > 1 or bally > 2 then
            balldy += gravity
        else
            bally := 0
        end if

        if balldy > 8 then
            balldy := 8
        elsif balldy < -8 then
            balldy := -8
        end if

        if Math.Distance (ballx, bally, playerx, playery) < 75 and bally >= playery and inplayer = false then
            inplayer := true
            balldx += (ballx - playerx) / 20
            balldy += (bally - playery) / 20
        elsif Math.Distance (ballx, bally, playerx, playery) > 66 then
            inplayer := false
        end if
        if ballx > maxx - 15 then
            ballx := maxx - 15
            balldx *= -xdecay
        elsif bally > maxy - 15 then
            bally := maxy - 15
            balldy *= -ydecay
        elsif ballx < 15 then
            ballx := 15
            balldx *= -xdecay
        elsif bally < 115 and ballx > 250 then
            bally := 115
            balldy *= -ydecay
            playerscore += 1
            delay (1000)
            exit
        elsif bally < 115 and ballx <= 250 then
            bally := 115
            balldy *= -ydecay
            computerscore += 1
            delay (1000)
            exit
        end if

        if Math.Distance (ballx, bally, computerx, computery) < 70 and bally >= computery and inplayer = false then
            inplayer := true
            balldx += (ballx - computerx) / 20
            balldy += (bally - computery) / 20
        elsif Math.Distance (ballx, bally, computerx, computery) > 66 then
            inplayer := false
        end if

        if balldy > 0 and bally < playery and bally > playery - 15 and Math.Distance (ballx, bally, playerx, playery) < 66 then
            balldy *= -ydecay
        end if
        if balldy > 0 and bally < computery and bally > computery - 15 and Math.Distance (ballx, bally, computerx, computery) < 66 then
            balldy *= -ydecay
        end if
        if computerx < ballx + 15 then
            computerx += 3
        elsif computerx > ballx + 15 then
            computerx -= 3
        end if

        if computery < 100 then
            playery := 100
            computerjump := false
        end if
        if computerx < 301 then
            computerx := 301
        elsif computerx > maxx - 50 then
            computerx := maxx - 50
        end if
        Text.Locate (1, maxcol div 2 - 3)
        colorback (white)
        put playerscore, "  -  ", computerscore
        drawfilloval (playerx, playery, radius, radius, blue) % player
        drawfilloval (computerx, computery, radius, radius, brightblue) % computer
        drawfilloval (playerx + 20, playery + 20, 10, 10, white) % eye of player
        drawfilloval (computerx - 20, computery + 20, 10, 10, white) % eye of computer
        drawfilloval (playerx + 20, playery + 20, 5, 5, black) % eye ball of player
        drawfilloval (computerx - 20, computery + 20, 5, 5, black) % eye ball of computer
        drawfillbox (playerx - 50, playery - 50, playerx + 50, playery, white) % bottom half of player
        drawfillbox (computerx - 50, computery - 50, computerx + 50, computery, white) % bottom half of computer
        Draw.ThickLine (maxx div 2, 100, maxx div 2, maxy - 15, 3, brightred) % net
        drawfillbox (0, 0, maxx, 100, green) %floor
        drawfilloval (ballx, bally, ballradius, ballradius, red) % ball
        Text.Locate (maxrow - 3, 14)
        colorback (green)
        put "Press \"SHIFT\" if the ball is stuck"
        View.Update
delay(12)
    end loop


end loop
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Thu May 27, 2004 7:55 pm   Post subject: (No subject)

double posts are lame... o and dont give us that crap about it was an accident cuz the two posts were posted 2 min apart.
rhomer




PostPosted: Thu May 27, 2004 8:04 pm   Post subject: (No subject)

actually it was an accident asshole....i am sorry though.... i retracted the other post.
Paul




PostPosted: Thu May 27, 2004 8:07 pm   Post subject: (No subject)

Can you attach the .t file next time instead? I only say that cause my mouse sux. It works great, except its a littile fast, and the java version , the ball bounces higher. Great job Very Happy
Cervantes




PostPosted: Thu May 27, 2004 8:15 pm   Post subject: (No subject)

collisions and collision data are not bad, it only went through me twice after playing about 45 points.
personally, I find the screen to be too narrow, and the slimes to jump too fast. other then that, its an awesome game.
rhomer




PostPosted: Thu May 27, 2004 8:18 pm   Post subject: (No subject)

Ok i added the .t file and i slowed it down. To change the speed, change the delay at the bottom of the code (higher number = slower, lower number = faster)
guruguru




PostPosted: Thu May 27, 2004 8:19 pm   Post subject: (No subject)

Works great! Smooth animations and all! One bug though: sometimes when I jump and hit it the ball goes formard a bit and then goes through me?!?! But looks awsome!

dodge: Wtf is your problem? What a way to fend off new members...

Anyways, welcome to compsci rhomer!
rhomer




PostPosted: Thu May 27, 2004 8:20 pm   Post subject: (No subject)

Ok i added the .t file and i slowed it down. To change the speed, change the delay at the bottom of the code (higher number = slower, lower number = faster)


slime.t
 Description:

Download
 Filename:  slime.t
 Filesize:  4.78 KB
 Downloaded:  375 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
AsianSensation




PostPosted: Thu May 27, 2004 10:25 pm   Post subject: (No subject)

pretty good. Though here is another version, Homer_Simpson posted it some time ago.

http://www.compsci.ca/v2/viewtopic.php?t=2794

still, +bits for your efforts.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: