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

Username:   Password: 
 RegisterRegister   
 picture fuzing
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TrAnCeIn4LiFe




PostPosted: Tue Jun 08, 2004 4:13 pm   Post subject: picture fuzing

alrite i finaly got around to put the enemy on the screen and some life bars with special abillity, but now i have a rpoblem when i put enemy to go down it fuzes and removes my actually plane form the game... so here is the code and there is also attachment to see wha tis actualyl happening

code:
/***************************************************************
 *                          Images                             *
 ***************************************************************/
var xx : array 1 .. 4 of int := init (0, 0, 0, 0) % plain array
var xxb : array 1 .. 1 of int := init (0)
var sprite : array 1 .. 4 of int % your ship
sprite (1) := Pic.FileNew ("redplane1.bmp")
sprite (2) := Pic.FileNew ("redplane2.bmp")
sprite (3) := Pic.FileNew ("redplane3.bmp")
sprite (4) := Pic.FileNew ("redplane4.bmp")

var sprite1 : array 1 .. 6 of int % life bar
sprite1 (1) := Pic.FileNew ("life1.bmp")
sprite1 (2) := Pic.FileNew ("life2.bmp")
sprite1 (3) := Pic.FileNew ("life3.bmp")
sprite1 (4) := Pic.FileNew ("life4.bmp")
sprite1 (5) := Pic.FileNew ("life5.bmp")
sprite1 (6) := Pic.FileNew ("life6.bmp")

var sprite2 : array 1 .. 2 of int % special ability bar
sprite2 (1) := Pic.FileNew ("mana1.bmp")
sprite2 (2) := Pic.FileNew ("mana2.bmp")

var sprite3 : array 1 .. 4 of int % enemy planes
sprite3 (1) := Pic.FileNew ("enemy1.bmp")
sprite3 (2) := Pic.FileNew ("enemy2.bmp")
sprite3 (3) := Pic.FileNew ("enemy3.bmp")
sprite3 (4) := Pic.FileNew ("enemy4.bmp")

var missle : int := Pic.FileNew ("upgrade2.bmp")

var background : int := Pic.FileNew ("back.bmp") % background
/***************************************************************
 *                      Scoring System                         *
 ***************************************************************/
var e_plane : array 1 .. 5 of int % enemy plain score keep
var plane_count : int := 0 % plains destroyed
var z : int % data file
/***************************************************************
 *                         Movement                            *
 ***************************************************************/
var chars : array char of boolean
var key : string (1) % for shotting missles
var byt, byb : int := 0 % bullet up y,bottom y,
var bxr, bxl : int := 0 % bullet right x,left x
var yt, yb : int := 0 % plane up y,bottom y,
var xr, xl : int := 0 % plane right x,left x
var exr, exl, eyt, eyb : int := 0
/***************************************************************
 *                         Other                               *
 ***************************************************************/
var i : int % information data file
var counter : int := 10 % position of y
var counter2 : int := 0 % how many characters
var counter3 : int := 0 % x counter for information data
var charpool : array 1 .. 2000 of string % data file letters for introduction
var font : int := Font.New ("Times New Roman:10") % font for menu section
var planelife : int := 5 % plane life
var planespecial : int := 1 % plane special ability
var num : int := 4
var ebullet : int := 0
/***************************************************************
 *                      Introduction                           *
 ***************************************************************/

procedure info

    setscreen ("noecho,nocursor")
    colorback (black)
    cls

    open : i, "info.t", get
    assert i > 0

    loop
        get : i, skip
        exit when eof (i)
        counter2 += 1
        get : i, charpool (counter2) : *
    end loop

    for a : 1 .. counter2
        for x : 1 .. length (charpool (a))
            locate (1 + counter3, counter)
            colour (white)
            put charpool (a) (x) ..
            delay (40)
            counter += 1
        end for
        counter := 10
        counter3 += 1
    end for

    Input.Pause

    cls
    close : i

end info

/***************************************************************
 *                      Game Code                              *
 ***************************************************************/

%/%%%%%%%%%%%%%%%
%  Score Sytem  %
%%%%%%%%%%%%%%%\%

open : z, "score system.t", get

assert z > 0

for x : 1 .. 5

    get : z, skip
    get : z, e_plane (x)

end for

close : z

procedure boundries (x, y : int)

    %/%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %  Set Boundries For Plane    %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%\%

    for z : 1 .. 4
    end for
    if sprite (z) >= bxr - 1 then
        sprite (z) := xl + 1
    end if
end boundries

procedure bars

    %/%%%%%%%%%%%%%%%%%%
    %  Life Counter    %
    %%%%%%%%%%%%%%%%%%\%

    for z : 1 .. 1
        Pic.Draw (sprite (xx (z)), bxr, byt, picMerge)
    end for

    if ebullet = sprite (z) - 25 then
        planelife := planelife - 1
    end if

    %/%%%%%%%%%%%%%%%%%%%%
    %  Draw Life Bars    %
    %%%%%%%%%%%%%%%%%%%%\%

    for x : 1 .. 6

        if planelife = 5 then
            Pic.Draw (sprite1 (1), 0, 225, picMerge)
        elsif planelife = 4 then
            Pic.Draw (sprite1 (2), 0, 225, picMerge)
        elsif planelife = 3 then
            Pic.Draw (sprite1 (3), 0, 225, picMerge)
        elsif planelife = 2 then
            Pic.Draw (sprite1 (4), 0, 225, picMerge)
        elsif planelife = 1 then
            Pic.Draw (sprite1 (5), 0, 225, picMerge)
        else
            Pic.Draw (sprite1 (6), 0, 225, picMerge)
        end if
    end for
    View.Update

    %/%%%%%%%%%%%%%%%%%%%
    %  Plain Special    %
    %%%%%%%%%%%%%%%%%%%\%

    if chars ('x') then
        planespecial := planespecial - 1
    end if
    for y : 1 .. 2
        if planespecial = 1 then
            Pic.Draw (sprite2 (1), 0, 125, picMerge)
        else
            Pic.Draw (sprite2 (2), 0, 125, picMerge)
        end if
    end for

end bars

process enemy

    %/%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %  Randomize Enemy's and Location    %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\%

    loop
        randint (byt, 0, maxx)
        for decreasing x : maxy .. 1
            exr += +exr + exl
            eyt += +eyt + eyb
            randomize
            randint (num, 1, 4)
            View.Update
            Pic.Draw (sprite3 (num), eyt + x - x, exr + x, picMerge)
        end for
    end loop
end enemy

process shoot

    %/%%%%%%%%%%%%%%%%%%
    %  Special Attack  %
    %%%%%%%%%%%%%%%%%%\%

    if chars ('x') then
        if xx (1) > 0 then
            for bullet : 1 .. maxy - (byt)
                for x : 1 .. 1
                    bxr += +xl + xr
                    byt += +yb + yt
                    View.Update
                    Pic.Draw (background, 0, 0, picCopy)
                    Pic.Draw (sprite (xx (x)), bxr, byt, picMerge)
                    View.Update
                    Pic.Draw (missle, bxr + 25, byt + bullet, picMerge)
                    View.Update
                    Pic.Draw (missle, bxr + 0, byt + bullet, picMerge)
                    View.Update
                    Pic.Draw (missle, bxr + 50, byt + bullet, picMerge)
                    bars
                end for
            end for
        end if
    end if

    %/%%%%%%%%%%%%%%%%
    %  Normal Shoot  %
    %%%%%%%%%%%%%%%%\%

    if chars ('z') then
        if xx (1) > 0 then
            for bullet : 1 .. maxy - (byt)
                for x : 1 .. 1
                    bxr += +xl + xr
                    byt += +yb + yt
                    View.Update
                    Pic.Draw (background, 0, 0, picCopy)
                    Pic.Draw (sprite (xx (x)), bxr, byt, picMerge)
                    Pic.Draw (missle, bxr + 25, byt + bullet, picMerge)
                    bars
                end for
            end for
        end if
    end if
end shoot

procedure fly

    View.Set ("offscreenonly,nobuttonbar")
    setscreen ("graphics:maxx;maxy,noecho,nocursor")
    View.Update

    %/%%%%%%%%%%%%%%%%%%%%%%%%%%
    %  Input Keys For Plane    %
    %%%%%%%%%%%%%%%%%%%%%%%%%%\%

    loop
        Input.KeyDown (chars)
        if chars (KEY_UP_ARROW) then
            for x : 1 .. 1
                xx (x) := x
                yt := 4
            end for
        elsif chars (KEY_RIGHT_ARROW) then
            for x : 1 .. 1
                xx (x) := 2
                xr := 4
            end for
        elsif chars (KEY_DOWN_ARROW) then
            for x : 1 .. 1
                xx (x) := x
                yb := yb - 4
            end for
        elsif chars (KEY_LEFT_ARROW) then
            for x : 1 .. 1
                xx (x) := x + 2
                xl := xl - 4
            end for
        end if

        fork shoot

        %/%%%%%%%%%%%%%%%%%%%
        %  Move Airplane    %
        %%%%%%%%%%%%%%%%%%%\%

        if xx (1) > 0 then
            for x : 1 .. 1
                bxr += +xl + xr
                byt += +yb + yt
                View.Update
                Pic.Draw (background, 0, 0, picCopy)
                Pic.Draw (sprite (xx (x)), bxr, byt, picMerge)
                bars
            end for
            View.Update
        end if

        %/%%%%%%%%%%%%%%%%%
        %  Clear Modes    %
        %%%%%%%%%%%%%%%%%\%

        xl := 0
        xr := 0
        yt := 0
        yb := 0

    end loop

end fly

/***************************************************************
 *                      Game Run Code                          *
 ***************************************************************/

loop
    fork enemy
    fly
end loop


any ideas on how i could fix this and also the special bar flickers like crazy...



Year End.zip
 Description:

Download
 Filename:  Year End.zip
 Filesize:  181.46 KB
 Downloaded:  91 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Tue Jun 08, 2004 4:41 pm   Post subject: (No subject)

Interesting...

1) If you're going to attatch the zip file, why bother posting the code? A tad redundant...

2) You main problems lie in:
a) using processes. These are a bane when it comes to games. Instead, in your main loop (I like that everything is neatly procedurized), use a for loop or something to check the status of everything that needs to be checked, then apply appplicable fucntions - move it, blow it up, enlarge, etc etc.

b) You're using 'offscreenonly', but REALLY badly...example:
code:

         View.Update
         Pic.Draw (background, 0, 0, picCopy)
         Pic.Draw (sprite (xx (x)), bxr, byt, picMerge)
         View.Update
         Pic.Draw (missle, bxr + 25, byt + bullet, picMerge)
         View.Update
         Pic.Draw (missle, bxr + 0, byt + bullet, picMerge)
         View.Update
         Pic.Draw (missle, bxr + 50, byt + bullet, picMerge)

No!!!!
code:

         Pic.Draw (background, 0, 0, picCopy)
         Pic.Draw (sprite (xx (x)), bxr, byt, picMerge)
         Pic.Draw (missle, bxr + 25, byt + bullet, picMerge)
         Pic.Draw (missle, bxr + 0, byt + bullet, picMerge)
         Pic.Draw (missle, bxr + 50, byt + bullet, picMerge)
         View.Update

Yes...

Input.Keydown == good.

You'll have to shuffle your code around a bit, possibly move your input detection to your main loop...
TrAnCeIn4LiFe




PostPosted: Tue Jun 08, 2004 7:53 pm   Post subject: (No subject)

u been host helpful that like solved all my problems thx Smile, and i learn a thing or to really good help Smile
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: