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

Username:   Password: 
 RegisterRegister   
 space game
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
fehrge




PostPosted: Wed May 18, 2005 10:53 am   Post subject: space game

This is a simple game that I am making in my spare time. It is not finished and I am still working on it.

code:

%George Fehr

View.Set ("graphics:800;600,position:0;0,title:Space Invasion")
%***********
%*variables******************************************************************
%***********
%mouse variables
var mx : int := 0
var my : int := 0
var mb : int := 0
var exitFinal : boolean := false

%paddle variables
var x1 : int
var x2 : int
var y1 : int := 5
var y2 : int := 15
%starting position
x1 := 220
x2 := x1 + 100

%enemy
var ex : int := 400
var ey : int := 600
var eSpeed : int
var newEnemy : boolean := false
var hit1 : boolean := false

%bullet variables
var b1X : int
var b1Y : int
var endbullet : boolean := false

var b2X : int
var b2Y : int

var count1 : int
var count2 : int

%colour
var color1 : int := 0
var color2 : int := 1
var color3 : int
var bgcolor : int := 7

%score numbers
var score : int := 0
var hits : int := 0
var lives : int := 10
var ammo : int := 0

%score string values
var scoreS : string := ""
var hitsS : string := ""
var livesS : string := ""
var ammoS : string := ""

var playerName : string

%font variables
var font1 := Font.New ("arial:50")
var font2 := Font.New ("arial:30")
var font3 := Font.New ("arial:20")

%************
%*procedures*************************************************************
%************

procedure intro
    Font.Draw ("By:", 300, 300, font1, 1)
    Font.Draw ("George", 300, 250, font1, 1)
    Font.Draw ("Space Invasion", 200, 400, font1, 1)
    delay (500)
    Font.Draw ("Get Ready", 200, 150, font1, 1)
    delay (1000)
    cls
end intro

procedure background
    Draw.FillBox (0, 0, 200, 600, 1)
    Draw.FillBox (195, 0, 200, 600, 0)
    Font.Draw ("Restart", 20, 100, font3, 0)
    Font.Draw ("Quit", 20, 60, font3, 0)
    Font.Draw ("High Scores", 20, 20, font3, 0)
end background

procedure scoring
    Font.Draw ("Score:", 10, 520, font3, 0)
    Font.Draw ("Hits:", 10, 450, font3, 0)
    Font.Draw ("Lives:", 10, 380, font3, 0)
    Font.Draw ("Ammo:", 10, 310, font3, 0)
    scoreS := intstr (score)
    livesS := intstr (lives)
    hitsS := intstr (hits)
    ammoS := intstr (ammo)
    Draw.FillBox (100, 520, 190, 560, 1)
    Font.Draw (scoreS, 100, 520, font3, 0)
    Draw.FillBox (75, 450, 190, 500, 1)
    Font.Draw (hitsS, 75, 450, font3, 0)
    Draw.FillBox (90, 380, 190, 430, 1)
    Font.Draw (livesS, 90, 380, font3, 0)
    Draw.FillBox (110, 310, 190, 360, 1)
    Font.Draw (ammoS, 110, 310, font3, 0)
end scoring

procedure highScore
    Font.Draw ("High Scores", 100, 520, font1, 0)
    Font.Draw (playerName, 100, 420, font2, 0)

    Font.Draw ("Score:", 10, 320, font2, 0)
    Font.Draw ("Hits:", 10, 280, font2, 0)
    Font.Draw ("Lives:", 10, 240, font2, 0)
    Font.Draw ("Ammo:", 10, 200, font2, 0)
    Font.Draw (scoreS, 125, 320, font2, 0)
    Font.Draw (hitsS, 100, 280, font2, 0)
    Font.Draw (livesS, 115, 240, font2, 0)
    Font.Draw (ammoS, 140, 200, font2, 0)
end highScore

process fireBullet
    endbullet := true
    %bullet variables
    b1X := x1 + 5
    b1Y := 20
    count1 := 1
    %bullet variables
    b2X := x2 - 5
    b2Y := 20
    count2 := 1

    loop
        b1Y := count1
        b2Y := count2
        count1 += 10
        count2 += 10

        Draw.FillBox (b1X, b1Y, b1X + 5, b1Y + 10, 0)
        Draw.FillBox (b2X, b2Y, b2X + 5, b2Y + 10, 0)
        delay (15)
        Draw.FillBox (b1X, b1Y, b1X + 5, b1Y + 10, 7)
        Draw.FillBox (b2X, b2Y, b2X + 5, b2Y + 10, 7)
        if whatdotcolor (b1X + 2, b1Y + 11) = 1 or whatdotcolor (b2X + 2,
                b2Y + 11) = 1 then
            hit1 := true
            exit
        end if
        exit when b2Y >= 580
    end loop
    if hit1 = true then
        score += 100
        hits += 1
        newEnemy := true
        hit1 := false
    end if
    ammo += 2
    endbullet := false
end fireBullet

procedure levelUp
    Font.Draw ("LEVEL UP", 400, 200, font1, 1)
    delay (500)
    Font.Draw ("LEVEL UP", 400, 200, font1, 7)
    score += 200
    eSpeed += 1
end levelUp

procedure MouseDown
    fork fireBullet
end MouseDown

%******
%*main*******************************************************************
%******
put "Enter you name: " ..
get playerName : *

setscreen ("nocursor")

loop
    %change background
    colorback (bgcolor)
    cls

    score := 0
    hits := 0
    lives := 10
    ammo := 0
    eSpeed := 2
    intro

    %draw the background
    background
    delay (500)

    %main loop

    loop

        Draw.FillBox (x1, y1, x2, y2 + 40, bgcolor)
        Draw.FillBox (ex, ey, ex + 50, ey + 50, bgcolor) %enemy
        Mouse.Where (mx, my, mb)
        if mx > 20 and mx < 180 and my > 20 and my < 50 and mb = 1 then
            cls
            highScore
            delay (10000)
            exit
        elsif mx > 20 and mx < 100 and my > 60 and my < 90 and mb = 1 then
            cls
            exitFinal := true
            exit
        elsif mx > 20 and mx < 160 and my > 100 and my < 130 and mb = 1 then
            cls
            delay (1000)
            exit
        end if
        if mx > 250 then
            x1 := mx - 50
            x2 := mx + 50
        end if
        if mx > 250 and mx < 750 and mb = 1 and endbullet = false then
            MouseDown
        end if
        if newEnemy = true then % enemy
            ex := Rand.Int (200, 750)
            ey := 600
            newEnemy := false
        end if
        ey := ey - eSpeed %enmey

        %paddle
        Draw.FillBox (x1, y1, x2, y2, color1)
        Draw.FillBox (x1 + 5, y1, x1 + 15, y1 + 40, color1)
        Draw.FillBox (x2 - 5, y1, x2 - 15, y1 + 40, color1)
        Draw.FillBox (ex, ey, ex + 50, ey + 50, 1) %enemy

        if ey <= 50 then %enemy
            lives -= 1
            newEnemy := true
        end if

        scoring

        if lives <= 0 then
            cls
            exitFinal := true
            exit
        end if
       
        if score = 500 then
            levelUp %4
        elsif score = 1500 then
            levelUp %6
        elsif score = 3000 then
            levelUp %8
        elsif score = 5000 then
            levelUp %10
        elsif score = 7500 then
            levelUp %12
        elsif score = 10000 then
            levelUp %14
        elsif score = 12500 then
            levelUp %16
        elsif score = 15000 then
            levelUp %18
        end if
        delay (20)
    end loop
    exit when exitFinal = true
end loop

highScore
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Wed May 18, 2005 12:56 pm   Post subject: (No subject)

Quite nice.

1)
Learn how to use View.Update().

2)
Learn to position your window correctly. There are ways of dynamically centering windows...hmm...that gives me an idea.

3)
Please don't use processes. They're evil. They seem to work reasonably well in your programme, but don't get into the habit of using them. Their level of complexity and lack of functionality will bite you later on. See if you can take what you have and instead of running seperate processes, incorporate all movement into one happy main loop.

4)
"nobuttonbar" is useful.

5)
Your colours! Oh your colours! Brighter, more jovial colours would make the proggie quite some better...

6)
Instructions would have been nice...it took me quite some time to realize that I wasn't supposed to *catch* those blocks, despite the odd container-shaped thing at the bottom having almost a perfect fit for them!
And what was the point of having 2 bullets?
Also, your 'ammo' counter is a little odd. Is it telling us how much we have left (as the name implies) or how much we have used (as the name most defintely does not imply).

Good job, but fix it to make it even better.
+ bits.
jamonathin




PostPosted: Wed May 18, 2005 1:04 pm   Post subject: (No subject)

I didn't play very much of it, I got to level 2. I couldn't take it any more, that game's just dull and boring. If this game was something unique I wouldn't be saying this, but there are so many of these games that if you're gonna post one, make it good. I thought there'd be a lot more than was was playing with all of that code.

At first I tough you were just supposed to catch the boxes because of that wierd shape, then I realized you shoot them down.

Dont take any of this personally, I just didn't want to fall asleep.

Things to learn next:

- Multiple Falling Items at different speeds
- Graphics (background, see coutsos credits above)
- Reading the Game suggestion topic, to find out what other gaems besides that
- Offscreenonly/View.Update
- Keyboard (array char of boolean/Input.KeyDown)
- The all mighty comma ' , ' <- Use that when var'ing more than one variable where they are all equal to the same thing.
- cls : Don't draw overtop of everything else with black

EDIT: I was typing this up while delos was posting, I like how we both tried to catch the boxes lol.
Lazarus




PostPosted: Wed May 18, 2005 1:40 pm   Post subject: (No subject)

The ammo was going up every time I shot, even when I missed "porpusly" (spelling?), shouldn't it go down?

Also you should have added bonus's so some object are worth more points, you get extra ammo, extra lives etc, only from Random objects though.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: