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

Username:   Password: 
 RegisterRegister   
 A little thing I wrote bored in class sort of like Geometry wars
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
petree08




PostPosted: Wed Oct 28, 2009 7:36 pm   Post subject: A little thing I wrote bored in class sort of like Geometry wars

Yeah, I was bored during a lecture so I wrote this,

I have decided that i am going to continue working on it for a while.

if you got to this page from the link on my facebook please direct any comments you have under comments for the link, or PM me.



Peatore Space Game (2).zip
 Description:

Download
 Filename:  Peatore Space Game (2).zip
 Filesize:  273.28 KB
 Downloaded:  235 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
petree08




PostPosted: Wed Oct 28, 2009 7:54 pm   Post subject: RE:A little thing I wrote bored in class sort of like Geometry wars

here is the code,

it is kind of a jumble in terms of were things are but it isn't too bad considering the time i spent on it
code:

function Distance_Calc (X1, Y1, X2, Y2 : real4) : real4

    result sqrt ((X1 - X2) ** 2 + (Y1 - Y2) ** 2)

end Distance_Calc

procedure Frame_Rate (var LastFrameTime : int, F_P_S : int)

    if Time.Elapsed - LastFrameTime < F_P_S then
        delay (F_P_S - (Time.Elapsed - LastFrameTime))
    end if
    LastFrameTime := Time.Elapsed
end Frame_Rate


procedure Display_Timer (LastTime, NewTime, X, Y, Font1, C : int)
    var MiliTime : int
    var Minutes, Seconds : int
    var StringTime : string (10)
    StringTime := ""
    MiliTime := Time.Elapsed - LastTime

    Seconds := MiliTime div 1000
    Minutes := Seconds div 60
    if Minutes < 10 then
        StringTime := StringTime + "0"
    end if

    StringTime := StringTime + intstr (Minutes) + ":"
    MiliTime := MiliTime - (MiliTime div 60) * 1000

    loop
        if Seconds >= 60 then
            Seconds := Seconds - 60
        else
            exit
        end if
    end loop
    if Seconds < 10 then
        StringTime := StringTime + "0"
    end if

    StringTime := StringTime + intstr (Seconds)
    Font.Draw (StringTime, X, Y, Font1, C)

end Display_Timer


function Angle_Calc (X1, Y1, X2, Y2 : real4) : real4
    var Angle : real4
    if X1 - X2 = 0 then
        if Y1 > Y2 then
            Angle := 90
        else
            Angle := 270
        end if
    elsif Y1 - Y2 = 0 then
        if X1 > X2 then
            Angle := 0
        else
            Angle := 180
        end if

    else
        Angle := arctand ((sqrt ((Y1 - Y2) ** 2)) / (sqrt ((X1 - X2) ** 2)))
        if Y1 < Y2 and X1 < X2 then
            Angle := Angle + 180
        elsif Y1 < Y2 and X1 > X2 then
            Angle := 360 - Angle
        elsif Y1 > Y2 and X1 < X2 then
            Angle := 180 - Angle
        end if
    end if
    result Angle

end Angle_Calc
%%%%%%%%% Drawing Enemies

procedure Draw_Enemy_Type1 (X, Y, Angle : int)


    for Lines : 1 .. 5

        drawline (round (cosd (Lines * (360 / 5) + Angle) * 10) + X,
            round (sind (Lines * (360 / 5) + Angle) * 10) + Y,
            round (cosd ((Lines + 1) * (360 / 5) + Angle) * 10) + X,
            round (sind ((Lines + 1) * (360 / 5) + Angle) * 10) + Y
            , 10)

    end for
    drawoval (X, Y, 5, 5, 10)
    drawarc (X - round (cosd (Angle) * 15), Y - round (sind (Angle) * 15),
        15, 15, Angle - 45, Angle + 45, 10)
    drawline (X, Y, X + round (cosd (Angle) * 15), Y + round (sind (Angle) * 15), 10)
end Draw_Enemy_Type1

colorback (7)
cls
Draw_Enemy_Type1 (100, 100, 0)
procedure Spawn_Enemies (var X, Y, Angle : int, var C, Health : nat1)
    case Rand.Int (1, 4) of

        label 1 :
            randint (X, 1, maxx)
            Y := maxy + 200
            Health := 100
            C := 1
            randint (Angle, 1, 360)


        label 2 :
            randint (X, 1, maxx)
            Y := -200
            Health := 100
            C := 1
            randint (Angle, 1, 360)

        label 3 :
            randint (Y, 1, maxy)
            X := -200
            Health := 100
            C := 1
            randint (Angle, 1, 360)

        label :
            randint (Y, 1, maxy)
            X := maxx + 200
            Health := 100
            C := 1
            randint (Angle, 1, 360)


    end case
end Spawn_Enemies

%% enemy AI
procedure Enemy_AI_Type1 (XP, YP : int, var XE, YE, AngleE : int)

    AngleE := round (Angle_Calc (XP, YP, XE, YE))

    XE := round (XE + cosd (AngleE))
    YE := round (YE + sind (AngleE))


end Enemy_AI_Type1




const FIRE_DELAY := 10
const NUM_OF_PROGS := 50
const GRAV_F := 0 %.032
const MAX_FORCE := 4.5
const ENEMY_TYPES := 4
const MAX_ENIMIES := 25
const FRAME_BUFFER := 10


type ENEMY_TYPE :
    record
        X, Y, Angle : int
        Health : nat1
        EnemyC : nat1

    end record


type ENEMY_TYPE_ARRAY : array 1 .. MAX_ENIMIES of ENEMY_TYPE
type BULLET_RECORD :
    record
        XB, YB, VXB, VYB : real4
        Shot : boolean


    end record


type BULLET_TYPE : array 1 .. NUM_OF_PROGS of BULLET_RECORD



var XC : int
var YC : int
var Keys : array char of boolean
var AngleC : int
var XM, YM, Click : int
var Bullets : BULLET_TYPE
var Enemy : ENEMY_TYPE_ARRAY
var ShotNum, ShotCount : nat1
var Health : nat1
var Font1, Font2 : int
var BackGroundPic : int
var AngleE : int
var NumOfEnemies : nat1
var TimeRan : int
var TimeEndGame : int
var KillCount : nat
var TimeSinceLast : int
%procedure

setscreen ("graphics:600,600,nobuttonbar,offscreenonly")
colorback (7)
cls
for Stars : 1 .. 900
    drawdot (Rand.Int (1, maxx), Rand.Int (1, maxy), 0)


end for


BackGroundPic := Pic.New (1, 1, maxx, maxy)
loop
    KillCount := 0
    XC := 300
    YC := 300

    for I : 1 .. NUM_OF_PROGS
        Bullets (I).XB := 0
        Bullets (I).YB := 0
        Bullets (I).VXB := 0
        Bullets (I).VYB := 0
        Bullets (I).Shot := false


    end for


    Font1 := Font.New ("System:18")
    Font2 := Font.New ("monofonto:18")


    ShotNum := 1
    ShotCount := 1
    AngleC := 0
    Health := 100

    for E : 1 .. MAX_ENIMIES
        Spawn_Enemies (Enemy (E).X, Enemy (E).Y, Enemy (E).Angle,
            Enemy (E).EnemyC, Enemy (E).Health)

    end for
    colorback (7)
    cls

    Font.Draw ("Peatore presents a test run version of ...", 1, maxy - 100,
        Font2, 0)
    Font.Draw ("AWESOME FUN-TIME SPACE SHOOTER GAME!!!!!",
        0, maxy div 2 + 100, Font1, 12)
    Font.Draw ("(PEW PEW! edition)", maxx div 2 - 200, maxy div 2 + 75, Font2, 0)
    Font.Draw ("Press any key to continue", 1, 200, Font2, 12)
    View.Update
    loop
        exit when hasch
    end loop
    View.Update
    delay (2000)
    color (10)
    AngleE := 0
    TimeRan := Time.Elapsed
    %Display_Timer (LastTime, NewTime, X, Y, Font1, C : int)
    loop

        TimeSinceLast := Time.Elapsed
        Pic.Draw (BackGroundPic, 0, 0, picCopy)
        Display_Timer (TimeRan, 1, 200, maxy - 20, Font1, 12)
        Font.Draw ("(Time Survived)", 170, maxy - 30, Font2, 0)
        Font.Draw (natstr (KillCount), 10, 10, Font2, 12)
        Font.Draw ("(Kill Counter)", 10, 25, Font2, 0)
        mousewhere (XM, YM, Click)
        Input.KeyDown (Keys)
        AngleC := round (Angle_Calc (XM, YM, XC, YC))
        if Keys ('d') and XC < maxx then
            XC := XC + 2
        end if
        if Keys ('a') and XC > 1 then
            XC := XC - 2
        end if

        if Keys ('w') and YC < maxy then
            YC := YC + 2
        end if

        if Keys ('s') and YC > 1 then
            YC := YC - 2
        end if

        % drawoval (XC, YC, 20, 20, 12)
        drawoval (XC, YC, 7, 7, 12)
        drawline (round (XC + (cosd (AngleC) * 10)
            ), round (YC + (sind (AngleC) * 10)
            ), round (XC + (cosd (AngleC) * 30)
            ), round (YC + (sind (AngleC) * 30)
            ), 12)
        %    drawoval (round (XC + (cosd (AngleC) * 30)
        %       ), round (YC + (sind (AngleC) * 30)
        %      ), 10, 10, 12)

        drawarc (round (XC + (cosd (AngleC) * 10)
            ), round (YC + (sind (AngleC) * 10)
            ), 10, 10, AngleC + 50, AngleC - 50, 12)
        drawarc (round (XC + (cosd (AngleC))
            ), round (YC + (sind (AngleC))
            ), 10, 10, AngleC - 90, AngleC + 90, 12
            )
        %  drawoval (XC, YC, 40, 40, 12)

        if Click = 1 then
            ShotCount := ShotCount + 1

            if ShotCount >= FIRE_DELAY then
                ShotCount := 1

                if ShotNum < NUM_OF_PROGS then
                    ShotNum := ShotNum + 1
                else
                    ShotNum := 1
                end if

                Bullets (ShotNum).XB := round (XC + (cosd (AngleC)))
                Bullets (ShotNum).YB := round (YC + (sind (AngleC)))
                Bullets (ShotNum).Shot := true
                Bullets (ShotNum).VXB := cosd (AngleC) * MAX_FORCE
                Bullets (ShotNum).VYB := sind (AngleC) * MAX_FORCE



            end if

        end if

        for I : 1 .. NUM_OF_PROGS
            if Bullets (I).Shot then
                drawoval (round (Bullets (I).XB), round (Bullets (I).YB), 3, 3, 12)
                Bullets (I).XB := Bullets (I).XB + Bullets (I).VXB
                Bullets (I).YB := Bullets (I).YB + Bullets (I).VYB
                Bullets (I).VYB -= GRAV_F
                for E : 1 .. MAX_ENIMIES
                    if Distance_Calc (Bullets (I).XB, Bullets (I).YB, Enemy (E).X, Enemy (E).Y) < 15 then
                        if Enemy (E).Health > 0 then
                            Enemy (E).Health := Enemy (E).Health - 100
                            Bullets (I).Shot := false
                            KillCount := KillCount + 1
                        end if
                    end if
                end for

            end if


        end for
        drawoval (XM, YM, 10, 10, 0)
        drawline (XM, YM - 15, XM, YM + 15, 0)
        drawline (XM + 15, YM, XM - 15, YM, 0)
        locate (1, 1)
        %  put "Angle : ", AngleC
        % health bar
        if Keys (KEY_ENTER) then
            XC := XM
            YC := YM
        end if

        % ENEMIES
        for E : 1 .. MAX_ENIMIES
            if Enemy (E).Health > 0 then
                Enemy_AI_Type1 (XC, YC, Enemy (E).X, Enemy (E).Y, Enemy (E).Angle)
                Draw_Enemy_Type1 (Enemy (E).X, Enemy (E).Y, Enemy (E).Angle)

                if Distance_Calc (Enemy (E).X, Enemy (E).Y, XC, YC) <= 10 then
                    if Health > 0 then
                        Health := Health - 25
                    end if
                    Enemy (E).Health := 0
                end if

            else


                Spawn_Enemies (Enemy (E).X, Enemy (E).Y, Enemy (E).Angle,
                    Enemy (E).EnemyC, Enemy (E).Health)
            end if

        end for


        drawbox (8, maxy - 20, 112, maxy - 10, 0)
        drawfillbox (10, maxy - 19, 10 + Health + 1, maxy - 11, 12)
        View.Update
        exit when Health <= 0
        Frame_Rate (TimeSinceLast, FRAME_BUFFER)
    end loop


    TimeEndGame := Time.Elapsed
    for C : 1 .. maxy div 2 by 2
        cls
        drawfillbox (0, maxy, maxx, maxy - C, 12)
        Font.Draw ("YOU ARE", 1, maxy div 2 + 15, Font2, 7)
        Font.Draw ("DEAD!", 1, maxy div 2, Font2, 7)
        View.Update
    end for
    delay (1000)
    Font.Draw ("You lasted:", maxx div 2, maxy div 2 - 20, Font2, 12)
    TimeEndGame := Time.Elapsed - TimeEndGame


    Display_Timer (TimeRan + TimeEndGame, 1, 410, maxy div 2 - 20, Font1, 12)
    View.Update
    delay (100)
    Font.Draw ("Your final kill-count is... ", 10, maxy div 2 - 100, Font2, 12)
    for E : 1 .. KillCount
        drawfillbox (9, maxx div 2 - 130, maxy, maxx div 2 - 170, 7)
        Font.Draw (intstr (E), 10, maxy div 2 - 150, Font2, 12)
        delay (10)
        View.Update
    end for
    loop
        mousewhere (XM, YM, Click)
        if XM > 0 and XM < 250 and YM > 0 and YM < 20 then
            drawfillbox (0, 0, 250, 20, 12)
            if Click = 1 then
                exit
            end if
            Font.Draw ("Click here to play again", 1, 1, Font2, 7)
        else
            drawfillbox (0, 0, 250, 20, 7)
            Font.Draw ("Click here to play again", 1, 1, Font2, 12)

        end if

        View.Update
    end loop
    Input.Flush
    KillCount := 0
    cls
end loop




oh, and another thought just occured to me, it might look wierd because i used a font that is most likely not on your computer.
Tony




PostPosted: Wed Oct 28, 2009 8:11 pm   Post subject: RE:A little thing I wrote bored in class sort of like Geometry wars

I think your function Distance_Calc is build in as Math.Distance

Things like
code:

loop
        if Seconds >= 60 then
            Seconds := Seconds - 60
        else
            exit
        end if
    end loop

really just mean Seconds := Seconds % 60

Spawn Enemy repeats the same code
code:

Health := 100
C := 1
randint (Angle, 1, 360)

x4
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
petree08




PostPosted: Wed Oct 28, 2009 9:23 pm   Post subject: RE:A little thing I wrote bored in class sort of like Geometry wars

Math.Distance doesn't work with all versions of turing,

lets say the program has been running for 70 seconds

Seconds will equal 70

Seconds := Seconds - 60

Seconds now equals 10

not like Seconds := Seconds % 60 at all

the reason I had to do that was because the the display would output trippy stuff after 60 seconds, it is a really lazy way to fix it i know but it worked and i wasn't going to put anymore focus on it,

and your absolutly right about the redundant code in Spawn_Enemies. I am slightly embarrassed that i didn't catch that, but again this was written over the course of a lecture,

the lecture was about binary conversion, i felt i could skip on that and i was bored.
Tony




PostPosted: Wed Oct 28, 2009 9:45 pm   Post subject: RE:A little thing I wrote bored in class sort of like Geometry wars

oh, wait... in Turing % is the comment character... I meant mod. (70 mod 60 = 10)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
petree08




PostPosted: Wed Oct 28, 2009 9:45 pm   Post subject: RE:A little thing I wrote bored in class sort of like Geometry wars

oh, yeah that actually makes sense now, thanks
petree08




PostPosted: Wed Nov 04, 2009 2:41 pm   Post subject: Re: A little thing I wrote bored in class sort of like Geometry wars

Worked on it again for a bit,

added a new enemy type,

a screen clear button (EMP blast press spacebar)

and steven hawking voice overs (using Speakonia)



Version 2.zip
 Description:

Download
 Filename:  Version 2.zip
 Filesize:  338.36 KB
 Downloaded:  138 Time(s)

S_Grimm




PostPosted: Wed Nov 04, 2009 5:20 pm   Post subject: RE:A little thing I wrote bored in class sort of like Geometry wars

the text is sort of crowed together. other than that, good job
Sponsor
Sponsor
Sponsor
sponsor
petree08




PostPosted: Thu Nov 05, 2009 3:35 pm   Post subject: RE:A little thing I wrote bored in class sort of like Geometry wars

http://www.searchfreefonts.com/free/monofonto.htm
yeah the text is placed odd because i used a font that isn't default. the above is a link to the font
twinblade27




PostPosted: Fri Nov 06, 2009 2:24 pm   Post subject: RE:A little thing I wrote bored in class sort of like Geometry wars

well done i like it man but i had to put more enemies to change the shooting delay
Turing_Gamer




PostPosted: Fri Nov 06, 2009 4:05 pm   Post subject: Re: A little thing I wrote bored in class sort of like Geometry wars

Well done 9/10
belarussian




PostPosted: Mon Nov 16, 2009 7:21 pm   Post subject: Re: A little thing I wrote bored in class sort of like Geometry wars

ok So you can make them save their scores when you make a new file such as \
Code:

var highScoreFile : int
var highName : string
var highScore : int

%open HighScore.txt
open : highScoreFile, "HighScore.txt", get
get : highScoreFile, highName : *
get : highScoreFile, highScore
close : highScoreFile

put "Please enter your name " ..
get highName : *
highScore := numberOfTries
%Write the highscore and name to the HighScore.txt file
open : highScoreFile, "HighScore.txt", put
put : highScoreFile, highName
put : highScoreFile, highScore
close : highScoreFile

IF HIGHSCORE IS NOT BETTER THAN PREVIOUSLY SAVED SCORES

put "Sorry you did not get the highscore"
put "The current high score is ", highScore, " by ", highName
petree08




PostPosted: Mon Nov 16, 2009 7:29 pm   Post subject: RE:A little thing I wrote bored in class sort of like Geometry wars

"ok So you can make them save their scores when you make a new file"

really I had no idea...

there are a million other things that this could "do" but at this version scoring wasn't a priority and if i decide to add high score saving i will most likely use an array to save multiple entries and sort them.
BigBear




PostPosted: Mon Nov 16, 2009 10:19 pm   Post subject: RE:A little thing I wrote bored in class sort of like Geometry wars

Seems unusual that you would rather have a Narrator voice sound clip but not a high score.
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  [ 14 Posts ]
Jump to:   


Style:  
Search: