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

Username:   Password: 
 RegisterRegister   
 Sun Fighters V1.5
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Guest




PostPosted: Sat May 27, 2006 3:47 pm   Post subject: Sun Fighters V1.5

*SUN FIGHTERS V1.5*
Here is a fun gravity game named Sun Fighters. In the latest version you can pick 1P or 2P. Also added a timer effect, so it get's faster as the game progresses!

code:

%Sun Fighters! V1.5
%"Last updated ", (theDayYouReadThis - theDatelastEdited), " days ago by Drew Martell"

%VARIABLES
var var1, var2, c1, c2, sun, back, ground, face, cnt, sx, sy, line, sunx, suny, file, score1, score2, size, x : int
score1 := 0
score2 := 0
cnt := 0
var timeElapsed, scoreS1, scoreS2, speedS, msg, bestTime : string
var ch : char
var timer := Font.New ("@Terminal:10")
var rec := "Sun Fighter's Best Time.rec"
var ballx1, bally1, ballx2, bally2, vx1, vy1, vx2, vy2, gravity, speed, subSpeed : real
var keys : array char of boolean

open : file, rec, put, mod
close : file
File.Status (rec, size, x, x)
if (size = 0) then
    open : file, rec, put, mod
    put : file, "0"
    close : file
end if

procedure Reset
    open : file, rec, get
    get : file, msg
    close : file
    bestTime := msg
    cnt := 0
    c1 := yellow
    c2 := 11
    sun := brightred
    back := black
    ground := back + 1
    face := black
    line := 50
    ballx1 := line + maxx - 100
    bally1 := line
    ballx2 := line + maxx - 150
    bally2 := line
    vx1 := 5
    vy1 := 10
    vx2 := 5
    vy2 := 10
    gravity := .25
    sunx := 100
    suny := 100
    sx := 1
    sy := 1
    speed := 15
    subSpeed := .01
end Reset

procedure Pause
    View.Update
    Input.Flush
    delay (500)
    Input.Flush
    Input.Pause
end Pause

procedure Intro
    Reset
    View.Set ("title:Sun Fighters, nocursor")
    var title := Font.New ("@Terminal:40")
    drawfillbox (0, 0, maxx, maxy, blue)
    Font.Draw ("Sun Fighters!!!", 160, 280, title, brightred)
    colourback (blue)
    colour (white)
    locate (12, 14)
    put "This is a 1 or 2 player game in which you must dodge the"
    locate (13, 20)
    put "red hot sun from melting your ass. Have fun!"
    locate (16, 38)
    put "--------------"
    locate (17, 38)
    put "// CONTROLS //"
    locate (18, 38)
    put "--------------"
    locate (21, 10)
    colour (yellow)
    put "1P:   Left arrow key moves left    Right arrow key moves right"
    locate (22, 10)
    colour (11)
    put "2P:        'a' moves left               'd' moves right"
    drawbox (50, 30, maxx - 50, maxy - 30, white)
    locate (maxrow, 22)
    colour (brightgreen)
    put "Press 1 or 2 for the ammount of players"
    View.Update
    Input.Flush
    delay (500)
    Input.Flush
    ch := getchar
    if ~ ((ch = '1') or (ch = '2')) then
        Intro
    end if
end Intro

procedure Save
    bestTime := msg
    open : file, rec, get
    get : file, msg
    close : file
    if (strint (timeElapsed)) > (strint (msg)) then
        open : file, rec, put, mod
        put : file, timeElapsed
        close : file
    end if
end Save

procedure Player1
    drawfilloval (round (ballx1), round (bally1), 10, 10, c1)     %body
    drawoval (round (ballx1), round (bally1), 10, 10, face)     %body outline
    drawfilloval (round (ballx1) - 3, round (bally1) + 2, 1, 1, face)     %left eye
    drawfilloval (round (ballx1) + 3, round (bally1) + 2, 1, 1, face)     %right eye
    drawfillarc (round (ballx1), round (bally1) - 2, 2, 4, 180, 360, face)     %smile
end Player1

procedure Player2
    drawfilloval (round (ballx2), round (bally2), 10, 10, c2)     %body
    drawoval (round (ballx2), round (bally2), 10, 10, face)     %body outline
    drawfilloval (round (ballx2) - 3, round (bally2) + 2, 1, 1, face)     %left eye
    drawfilloval (round (ballx2) + 3, round (bally2) + 2, 1, 1, face)     %right eye
    drawfillarc (round (ballx2), round (bally2) - 2, 2, 4, 180, 360, face)     %smile
end Player2

procedure Sun
    drawfilloval (round (sunx), round (suny), 100, 100, sun)     %sun body
    drawfilloval (round (sunx) - 40, round (suny) + 30, 10, 10, face)     %left eye
    drawfilloval (round (sunx) + 40, round (suny) + 30, 10, 10, face)     %right eye
    drawfillarc (round (sunx), round (suny) - 2, 80, 80, 180, 360, face)     %smile
    drawoval (round (sunx), round (suny), 100, 100, face)     %sun outline
end Sun

proc Main
    View.Set ("offscreenonly")
    Reset
    loop
        scoreS1 := intstr (score1)
        scoreS2 := intstr (score2)
        timeElapsed := intstr (cnt div 50)
        speedS := realstr (speed, 0)
        cnt += 1

        %Painting
        drawfillbox (0, 0, maxx, maxy, back)     %background
        drawfillbox (0, 0, maxx, line, ground)     %floor
        Font.Draw ("Player 1: " + scoreS1, 10, 20, timer, c1)
        Font.Draw ("Player 2: " + scoreS2, 110, 20, timer, c2)
        Font.Draw ("TIME:" + timeElapsed, maxx - 170, 20, timer, sun)
        Font.Draw ("BEST:" + bestTime, maxx - 100, 20, timer, black)
        Font.Draw ("SPEED:" + speedS, (maxx div 2) - 50, 20, timer, back)
        Player1
        Player2
        Sun

        %Variables changing
        ballx1 += vx1
        bally1 += vy1
        ballx2 += vx2
        bally2 += vy2
        sunx += sx
        suny += sy
        vy1 -= gravity
        vy2 -= gravity

        %Boundaries
        if vy1 = -10 then
            vy1 := 10 - gravity
        end if
        if vy2 = -10 then
            vy2 := 10 - gravity
        end if

        if ballx1 + 15 >= maxx then
            ballx1 -= 1
            vx1 *= -1
        end if
        if ballx2 + 15 >= maxx then
            ballx2 -= 1
            vx2 *= -1
        end if

        if ballx1 <= 0 then
            ballx1 += 1
            vx1 *= -1
        end if
        if ballx2 <= 0 then
            ballx2 += 1
            vx2 *= -1
        end if

        if suny = 100 or suny = maxy - 100 then
            sy := -sy
        elsif (sunx = 100) or (sunx = maxx - 100) then
            sx := -sx
        end if

        %Controlls
        Input.KeyDown (keys)
        if keys (KEY_RIGHT_ARROW) then
            vx1 += 1
            speed -= subSpeed
        end if
        if keys (KEY_LEFT_ARROW) then
            vx1 -= 1
            speed -= subSpeed
        end if

        if (ch = '2') then
            if keys ('d') then
                vx2 += 1
                speed -= subSpeed
            end if
            if keys ('a') then
                vx2 -= 1
                speed -= subSpeed
            end if
        end if

        %Player/Player collision
        if (whatdotcolour (round (ballx1), round (bally1)) = c2) then
        end if
        if (whatdotcolour (round (ballx2), round (bally2)) = c1) then
        end if

        %Sun collision detection
        colourback (back)
        colour (white)
        locate (3, 23)
        if (ch = '2') then
            if (whatdotcolour (round (ballx2), round (bally2)) = sun) then
                put "Player 1 Wins! Press any key to continue..."
                score1 += 1
                Save
                Pause
                Intro
            end if
        end if
        if (whatdotcolour (round (ballx1), round (bally1)) = sun) then
            put "Player 2 Wins! Press any key to continue..."
            score2 += 1
            Save
            Pause
            Intro
        end if
        View.Update
        delay (round (speed))
        speed -= .0025
    end loop
end Main

Intro
Main
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Sat May 27, 2006 4:53 pm   Post subject: (No subject)

Interesting game - i bet I can dodge em longer than you. I got to 45 seconds than I got bored. That's because i cheated and ran off the map. if you press and hold right - you can squeeze your way right out of that atmosphere.

Another thing. . I've never personally been to space nor know too much about it, but do you really fly like a bat out of hell when you touch someone else? - it makes the game end real fast. If that was your intension, then loop the game and keep track of the wins for each player, rather than ending the program, that way the players can keep playing at a fast pace - restarting takes too long for a 5 second game.

Good work on it tho - and maybe get rid of the seizure land Razz.
Guest




PostPosted: Sun May 28, 2006 12:41 pm   Post subject: (No subject)

WTF???? It was working, now it isnt!!! Man I'll have to fix it... Can someone help me fix it??? I've been looking and I'm getting all confused. It worked perfectly before, and I dont remember changing anything!
MysticVegeta




PostPosted: Sun May 28, 2006 12:51 pm   Post subject: (No subject)

Quote:
Last edited by vahnx on Sun May 28, 2006 12:13 pm; edited 10 times in total

Eh, are you sure you didnt change anything?
Guest




PostPosted: Sun May 28, 2006 12:52 pm   Post subject: (No subject)

Yay I fixed the bugs =)
MysticVegeta




PostPosted: Sun May 28, 2006 1:00 pm   Post subject: (No subject)

your reset proc has the error, you are opening a file "rec" which is "Sun Fighter's Best Time.rec" without it being there, how is that possible??? It ouputs an error therefore.
NikG




PostPosted: Sun May 28, 2006 1:27 pm   Post subject: (No subject)

I changed a few things to get this to work:
First: create an empty Sun Fighter's Best Time.rec file
Second: in your Reset proc:
code:
    open : file, rec, get
    if not eof (file) then
        get : file, msg
        bestTime := msg
    else
        bestTime := "0"
    end if
    close : file

And third: something similar in your Save proc:
code:
        open : file, rec, get
        if not eof (file) then
            get : file, msg
        else
            msg := "0"
        end if
        close : file
Guest




PostPosted: Sun May 28, 2006 1:34 pm   Post subject: (No subject)

Oh I already fixed it, but thanks anyways. I must have undid something with ctrl+z by accident and saved before I posted it. The one posted works fine now.
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Sun May 28, 2006 1:49 pm   Post subject: (No subject)

It's good you fixed those things, but now what you may want to do is mix it up a little bit. The level starts the exact same way every time. Maybe have the sun start somewhere randomly, and the units randomly with a andom size map or have 5 predetermined levels built into your code and have a random variable decide which one you do each time, just a thought. .
wtd




PostPosted: Sun May 28, 2006 2:25 pm   Post subject: (No subject)

vahnx, should you continue with Turing, my suggestion would be to revise this program making use of OOP principles. Cervantes wrote a pretty decent tutorial on OOP and Turing.
Guest




PostPosted: Sun May 28, 2006 2:41 pm   Post subject: (No subject)

I finally made it past the sun, and found out you could go through that part. I updated it so you bounce off the left wall (if you make it that far).

PS Wheres Cervantes Tutorial on OOP, I searched for a few mins and couldn't find it.
Cervantes




PostPosted: Sun May 28, 2006 2:56 pm   Post subject: (No subject)

Looking for a Cervantes tutorial?

You wrote:

Hello Jeeves, I'm looking for a Cervantes tutorial on OOP in Turing.


Now, replace "Jeeves" with "the Turing Walkthrough" and what does the Turing Walkthrough say? It says: http://www.compsci.ca/v2/viewtopic.php?t=10904
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  [ 12 Posts ]
Jump to:   


Style:  
Search: