Computer Science Canada

Asteroids

Author:  upthescale [ Sun Jun 25, 2006 11:52 am ]
Post subject:  Asteroids

Yes, I have finally attempted this game. I was always scared and nervous because:

a) I never knew how to work flexible arrays
b) I never knew trig

Well now:

a) I know flexible arrays
b) I know trig

So I bring to you...

<b>Asteroids</b>

Instructions are in the game, and good luck. Ps, there are 20 levels!

*EDIT- Thank you Tony for taking my Lamer ranking off, hopefully this game will redeem me![/i]

Author:  Delos [ Sun Jun 25, 2006 3:33 pm ]
Post subject: 

On attmepting to open rar:

Error message wrote:

Error opening file.

Author:  NikG [ Sun Jun 25, 2006 6:31 pm ]
Post subject: 

I didn't have an error opening the file.

But I did die almost immediately after the game started.
Care to explain upthescale?

Also, make it so you can skip that intro screen.

Author:  upthescale [ Sun Jun 25, 2006 6:51 pm ]
Post subject: 

um u shudn't die, i never did, ddi u rerun it and try again?


the intro screen doesn't take that long!

Author:  Clayton [ Sun Jun 25, 2006 9:21 pm ]
Post subject: 

Hm, i suggest that you have some sort of execution time control, on my computer that thing runs a way too fast Sad i can barely see the thing move and i dont have any control over it barely cuz it moves so fast, oh, and you really should have some way to skip the intro, and be careful with the word wrap too Wink

Author:  upthescale [ Sun Jun 25, 2006 10:22 pm ]
Post subject: 

why u guys complaining over nothing? i can see the speed, bvut the intro? it takes two seconds

and wut wordwrap?

Author:  NikG [ Tue Jun 27, 2006 12:14 am ]
Post subject: 

upthescale wrote:
why u guys complaining over nothing? i can see the speed, bvut the intro? it takes two seconds

and wut wordwrap?
ok....
Why are you posting if you don't want to hear suggestions???
That's the point of putting stuff up here, not just to post your 100th game.
Everything that has been said was so that you could actually improve your work for once, not just forget about it and move on.

edit: and I'm sure the word wrap SuperFreak82 is referring to do is in your intro screen, how some of the words wrap to the next line

Author:  rownale [ Tue Jun 27, 2006 8:33 am ]
Post subject:  Good Job

I managed to play this game and it worked fine.
The intro is too long though (I timed it at about 15 seconds lawl)
And the words in the intro do wrap into the next line.

The main part of the game was pretty good though.
I really wish i knew how to use trig...

Good job

Author:  Clayton [ Tue Jun 27, 2006 12:57 pm ]
Post subject: 

is there something wrong with your keyboard or something? i mean there is no reason for that poor of spelling, unless you have an actual reason (such as Dan being dyslexic), and like NikG said, we are not complaining, we are trying to give you helpful hints to help you improve your game, we are not saying it is crap, but that there are ways for it to be improved, there is no such thing as a perfect program, there will always be problems, whether tolerable or not. as for the word wrap thing, that means that some of your words end up being cut off and wrapping(sp?) from line to line (eg. that has "th" on one line and "at" on the line below it)

Author:  Delos [ Tue Jun 27, 2006 1:17 pm ]
Post subject: 

upthescale has been queried about queried about his keyboard's state of integrity several times. Thus far, he is yet to give a satisfactory response. Wink

Author:  upthescale [ Tue Jun 27, 2006 4:47 pm ]
Post subject: 

When did I make a spelling Error SuperFreak and Cervcante?

Author:  Clayton [ Tue Jun 27, 2006 5:36 pm ]
Post subject: 

its not just spelling, but grammar too, if you post something like

"herez my pr0gGi, tell me Use liked"

are you honestly going to give that a proper response? also, "Cervcante"? my oh my people have trouble spelling your name Cervantes Very Happy I once remember Clevernuts but lets not go there Very Happy

Author:  upthescale [ Tue Jun 27, 2006 5:50 pm ]
Post subject: 

heres my prggi is on one of onetruegods forums:)

Author:  Clayton [ Tue Jun 27, 2006 6:02 pm ]
Post subject: 

You do realize that you have just gotten rid of your Lamer rank right? You do realize part of the reason you got it was for massive spamming right? Do you now realize that you are walking right back into that Lamer rank? The above post was not only pure spam, but utterly and completely childish.

Author:  Cervantes [ Tue Jun 27, 2006 7:31 pm ]
Post subject: 

SuperFreak82 wrote:
The above post was not only pure spam, but utterly and completely childish.

Childish? I don't even understand what it means. Laughing

As for the state of upthescale's keyboard, perhaps it's not a keyboard problem. It may be some memory problem. As evidence, I present:
upthescale wrote:
When did I make a spelling Error SuperFreak and Cervcante?

Who, me? I hadn't posted in this thread when he said that. Laughing

So the moral of the story is this. Upthescale, you need to do less spamming and communicate a bit better. It is rather difficult to understand what you're saying, quite often. And spamming is against [The Rules]. You've received a lavish amount of warnings. Think about what you're posting before you post it. If it's a one line comment that isn't directly answering a question, there's a pretty good chance it's spam.

Author:  upthescale [ Tue Jun 27, 2006 7:42 pm ]
Post subject: 

Sorry Cervantes lol i think i meatn someone else!

Author:  TokenHerbz [ Sat Aug 12, 2006 11:40 pm ]
Post subject: 

Is my astroids betteR????

TO SHOOT::: LEFT CTRL
TO MOVE:::: ARROW KEYS
TO EXIT:::: ESC

::::: Next im going to try to add upgrades, and a better detection system aswell as fixing some of my messy code in there Sad

code:

%%game window
var game_window : int
game_window := Window.Open ("Graphics: max;max, title: Basic Astroids")
View.Set ("offscreenonly, noecho, nocursor, nobuttonbar")



%%Variables
%%for the back ground stars
var xStar : array 1 .. 50 of int
var yStar : array 1 .. 50 of int
%%randomize their variables
for i : 1 .. 50
    randint (xStar (i), 0, maxx)
    randint (yStar (i), 0, maxy)
end for

%%ship points
var xPoint : array 1 .. 3 of real
var yPoint : array 1 .. 3 of real

var rotate : real := 0
var angle : real := 90
var keys : array char of boolean
var game_level : int := 0
var score : int := 0
var oldscore : int := 0
var life : int := 3
var leave_for : boolean := false

%%ship speed
var xSpeed : real := 0
var ySpeed : real := 0

%%ships bullets
type Bullets :
    record
        x : real
        y : real
        xdir : real
        ydir : real
        distance : real
    end record

var Bullet : flexible array 0 .. 0 of Bullets
var chance_to_spawn_upgrade : int := 2

%%Declare and Set Center Point
var xCenter : real
var yCenter : real

%%astroids
type astroids :
    record
        x : int
        y : int
        xs : int %%speed (it;ll be for direction too)
        ys : int
        size : int
        amount : int
    end record

var Astroid : flexible array 0 .. 0 of astroids

%%set value's
xPoint (1) := 100   %%(1) = left, 2 = top, 3 = right
yPoint (1) := 100
xPoint (2) := 105
yPoint (2) := 120
xPoint (3) := 110
yPoint (3) := 100

%%procs

%%this will rotate the ship points
proc Rotate_Ship (var x : real, var y : real, var cx : real, var cy : real, var deg : real) %%gets chords per point
    %%temperary variables
    var tempx : real
    var tempy : real
    tempx := ((x - cx) * cosd (deg) - (y - cy) * sind (deg)) + cx %Rotate x Point
    tempy := ((x - cx) * sind (deg) + (y - cy) * cosd (deg)) + cy %Rotate y Point
    %%reset the vars
    x := tempx
    y := tempy
end Rotate_Ship

%%this will draw anything needed in the game
proc Drawing
    %%the back ground screen
    Draw.FillBox (0, 0, maxx, maxy, black)
    for i : 1 .. 50
        Draw.FillOval (xStar (i), yStar (i), 1, 1, white)
    end for
    %%display (level/score/life)
    color (gray)
    colorback (black)
    locate (2, 10)
    put "Level:  ", game_level
    locate (2, 50)
    put "Lives:  ", life
    locate (2, 90)
    put "Score:  ", score
    %%the ship
    drawline (round (xPoint (1)), round (yPoint (1)), round (xPoint (2)), round (yPoint (2)), white)
    drawline (round (xPoint (2)), round (yPoint (2)), round (xPoint (3)), round (yPoint (3)), white)
    drawline (round (xPoint (3)), round (yPoint (3)), round (xPoint (1)), round (yPoint (1)), white)
    %%bullets
    for i : 1 .. upper (Bullet)
        Draw.FillOval (round (Bullet (i).x), round (Bullet (i).y), 1, 1, white)
    end for
    %%astroids
    for i : 1 .. upper (Astroid)
        Draw.Oval (Astroid (i).x, Astroid (i).y, Astroid (i).size, Astroid (i).size, white)
    end for
end Drawing

%%this will shoot the bullet
proc Shooting
    Input.KeyDown (keys)

    %%spawns you a bullet
    if keys (KEY_CTRL) then %%shoots the bullet
        if upper (Bullet) + 1 <= 3 then
            if upper (Bullet) <= 0 then
                new Bullet, upper (Bullet) + 1
                Bullet (upper (Bullet)).x := xPoint (2)
                Bullet (upper (Bullet)).y := yPoint (2)
                Bullet (upper (Bullet)).xdir := cosd (angle) * 10
                Bullet (upper (Bullet)).ydir := sind (angle) * 10
                Bullet (upper (Bullet)).distance := 350
            elsif Bullet (upper (Bullet)).distance < 300 then   %%i add this for a delay without slowing game
                new Bullet, upper (Bullet) + 1
                Bullet (upper (Bullet)).x := xPoint (2)
                Bullet (upper (Bullet)).y := yPoint (2)
                Bullet (upper (Bullet)).xdir := cosd (angle) * 10
                Bullet (upper (Bullet)).ydir := sind (angle) * 10
                Bullet (upper (Bullet)).distance := 350
            end if
        end if
    end if
    %%move bullets
    for i : 1 .. upper (Bullet)
        Bullet (i).x += Bullet (i).xdir
        Bullet (i).y += Bullet (i).ydir
        Bullet (i).distance -= 5
    end for
    %%kill bullets
    for i : 1 .. upper (Bullet)
        if Bullet (i).distance <= 0 then
            Bullet (i) := Bullet (upper (Bullet))
            new Bullet, upper (Bullet) - 1
            exit
        end if
    end for
end Shooting

proc Add_Astroids (var amount : int)
    if amount >= 12 then    %total astroids
        new Astroid, upper (Astroid) + 12
    else    %%your not that far.. (1 astroid per level)
        new Astroid, upper (Astroid) + amount
    end if
    %%to spawn them
    for i : 1 .. upper (Astroid)
        randint (Astroid (i).x, 1, 4)
        %%setting astroids off screen to stop the effect of (teleportation)
        if Astroid (i).x = 1 then   %%set off to left
            Astroid (i).x := -20
            randint (Astroid (i).y, 20, maxy - 20)
            randint (Astroid (i).ys, -5, 5)
            randint (Astroid (i).xs, 1, 5) %%make it aim to center
        elsif Astroid (i).x = 2 then    %%set it to right
            Astroid (i).x := maxx + 20
            randint (Astroid (i).y, 20, maxy - 20)
            randint (Astroid (i).ys, -5, 5)
            randint (Astroid (i).xs, -5, -1)
        elsif Astroid (i).x = 3 then    %%set at top
            Astroid (i).y := maxy + 20
            randint (Astroid (i).x, 20, maxx - 20)
            randint (Astroid (i).xs, -5, 5)
            randint (Astroid (i).ys, -5, -1)
        else    %%bottom
            Astroid (i).y := -20
            randint (Astroid (i).x, 20, maxx - 20)
            randint (Astroid (i).xs, -5, 5)
            randint (Astroid (i).ys, 1, 5)
        end if
        Astroid (i).size := 40          %%custom size
    end for
end Add_Astroids

%%this will move everything
proc Move_Obsticles
    Input.KeyDown (keys)

    %%rotates the ship
    if keys (KEY_LEFT_ARROW) then
        rotate := 6
    elsif keys (KEY_RIGHT_ARROW) then
        rotate := -6
    else
        rotate := 0
    end if
    %%reste the center variables for the ship
    xCenter := (xPoint (1) + xPoint (2) + xPoint (3)) / 3
    yCenter := (yPoint (1) + yPoint (2) + yPoint (3)) / 3
    %%rotates the 3 points
    for i : 1 .. 3
        Rotate_Ship (xPoint (i), yPoint (i), xCenter, yCenter, rotate)
    end for
    angle += rotate     %%so i know which way my ship is facing

    %%sets ships speed
    if keys (KEY_UP_ARROW) then
        xSpeed += cosd (angle) * .2
        ySpeed += sind (angle) * .2
        %%going TopRight
        if xSpeed > 10 then
            xSpeed := 10
        elsif ySpeed > 10 then
            ySpeed := 10
            %%going BottomLeft
        elsif xSpeed < -10 then
            xSpeed := -10
        elsif ySpeed < -10 then
            ySpeed := -10
        end if
    end if

    %%moves the ship
    xCenter += xSpeed
    yCenter += ySpeed
    for i : 1 .. 3
        xPoint (i) += xSpeed
        yPoint (i) += ySpeed
    end for


    %%For astroids
    %%if no astroids then...
    if upper (Astroid) <= 0 then
        game_level += 1
        Add_Astroids (game_level)   %%will spawn astroids
    end if
    %%move the astroids
    for i : 1 .. upper (Astroid)
        Astroid (i).x += Astroid (i).xs
        Astroid (i).y += Astroid (i).ys
    end for
end Move_Obsticles

%%boundries for everything
proc Boundries
    %%makes the ship warp
    if xPoint (1) < 1 and xPoint (2) < 1 and xPoint (3) < 1 then
        for i : 1 .. 3
            xPoint (i) += maxx
        end for
    elsif xPoint (1) > maxx - 1 and xPoint (2) > maxx - 1 and xPoint (3) > maxx - 1 then
        for i : 1 .. 3
            xPoint (i) -= maxx
        end for
    end if
    if yPoint (1) < 1 and yPoint (2) < 1 and yPoint (3) < 1 then
        for i : 1 .. 3
            yPoint (i) += maxy
        end for
    elsif yPoint (1) > maxy - 1 and yPoint (2) > maxy - 1 and yPoint (3) > maxy - 1 then
        for i : 1 .. 3
            yPoint (i) -= maxy
        end for
    end if

    %%make the bullets warp
    for i : 1 .. upper (Bullet)
        if Bullet (i).x >= maxx - 1 then
            Bullet (i).x -= maxx
        elsif Bullet (i).x <= 1 then
            Bullet (i).x += maxx
        end if
        if Bullet (i).y >= maxy - 1 then
            Bullet (i).y -= maxy
        elsif Bullet (i).y <= 1 then
            Bullet (i).y += maxy
        end if
    end for

    %%warp astroids
    for i : 1 .. upper (Astroid)
        if Astroid (i).x + Astroid (i).size <= 0 then
            Astroid (i).x += maxx - Astroid (i).x
        elsif Astroid (i).x >= maxx then
            Astroid (i).x -= maxx + Astroid (i).size
        end if
        if Astroid (i).y + Astroid (i).size <= 0 then
            Astroid (i).y += maxy - Astroid (i).y
        elsif Astroid (i).y >= maxy then
            Astroid (i).y -= maxy + Astroid (i).size
        end if
    end for

    %%shoot the astroid
    for i : 1 .. upper (Astroid)
        leave_for := false
        for j : 1 .. upper (Bullet)
            if Bullet (j).x <= Astroid (i).x + Astroid (i).size and Bullet (j).x >= Astroid (i).x - Astroid (i).size and
                    Bullet (j).y <= Astroid (i).y + Astroid (i).size and Bullet (j).y >= Astroid (i).y - Astroid (i).size then

                % this will make smaller astroids as you shoot them
                if Astroid (i).size > 10 then
                    if Astroid (i).size = 40 then
                        score += 20
                        oldscore += 20
                    else
                        score += 50
                        oldscore += 50
                    end if
                    new Astroid, upper (Astroid) + 1     %%add's 1 for breaking onto two
                    Astroid (upper (Astroid)) := Astroid (i)
                    Astroid (i).xs += 1
                    Astroid (upper (Astroid)).xs -= 1
                    Astroid (i).ys += 1
                    Astroid (upper (Astroid)).ys -= 1
                    Astroid (i).size -= Astroid (i).size div 2
                    Astroid (upper (Astroid)).size -= Astroid (upper (Astroid)).size div 2
                else        %%this KILLS the small ones
                    score += 100
                    oldscore += 100
                    if i = upper (Astroid) then
                        new Astroid, upper (Astroid) - 1
                    else
                        Astroid (i) := Astroid (upper (Astroid))
                        new Astroid, upper (Astroid) - 1
                    end if
                end if
                leave_for := true
                %%kill the bullet used
                Bullet (j) := Bullet (upper (Bullet))
                new Bullet, upper (Bullet) - 1
                exit        %%needed to kill the bullet correctly.
            end if
        end for
        if leave_for = true then
            exit
        end if
    end for

    %%add's a life at a certain pointage's
    if oldscore >= 1240 then     %(equivilent to 2 astroids)
        oldscore -= 1240
        life += 1
    end if

    %%ship collition (means you lose)
    for i : 1 .. upper (Astroid)
        leave_for := false
        for j : 1 .. 3     %%the ships points
            if xPoint (j) <= Astroid (i).x + Astroid (i).size and xPoint (j) >= Astroid (i).x - Astroid (i).size and
                    yPoint (j) <= Astroid (i).y + Astroid (i).size and yPoint (j) >= Astroid (i).y - Astroid (i).size then
                if xPoint (j) < 300 then
                    for h : 1 .. 3
                        xPoint (h) += 200
                    end for
                else
                    for h : 1 .. 3
                        xPoint (h) -= 200
                    end for
                end if
                if yPoint (j) < 300 then
                    for h : 1 .. 3
                        yPoint (h) += 200
                    end for
                else
                    for h : 1 .. 3
                        yPoint (h) -= 200
                    end for
                end if
                life -= 1     %%take off a life
            end if
        end for
    end for
end Boundries


%%main loop
loop
    Input.KeyDown (keys)
    cls

    Drawing         %%draws everything
    Move_Obsticles      %%moves ship/astroids
    Boundries       %%what it says
    Shooting        %%creats/moves bullets

    %%Exit the game
    if keys (KEY_ESC) then
        exit
    end if
    %%or lose
    if life <= 0 then
        exit
    end if

    View.Update
    delay (20)
end loop
Window.Close (game_window)



**If mine is better, didnt mean to show you up upthescale**

Author:  [Gandalf] [ Sun Aug 13, 2006 12:46 am ]
Post subject: 

Yes, I'd say your's is better. It could be much improved, though.

And none of that changes the fact that this is an old, dead topic. Next time if you really want to post something of yours, do that in a new topic in the [Turing Source Code] forum.

Author:  Clayton [ Sun Aug 13, 2006 11:53 am ]
Post subject: 

well seeing as hes posted here...

i noticed in your code you are using randint, i ask you : why? randint is a procedure that changes the value of your variable, why not use Rand.Int, a function? generally speaking, when you have a choice between a function or a procedure to do something, take the function

and on that note i also have to ask you why you are using drawline and randint instead of Draw.Line and Rand.Int. using the latter commands is a much better idea because it helps to introduce you to modularity, and is a much better idea in the way of organization. If i asked you, off the top of your head where the code for drawline was, could you tell me? probably not, if, on the other hand i asked you where the code was for Draw.Line was you could probably tell me in an instant, in the Draw module, so as you can see it is a big advantage to use commands such as Draw.Line and Rand.Int instead of drawline and randint respectively Very Happy


: