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

Username:   Password: 
 RegisterRegister   
 Platformer (Climber)
Index -> Programming, Turing -> Turing Submissions
Goto page Previous  1, 2, 3
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Beastinonyou




PostPosted: Wed Oct 19, 2011 9:58 pm   Post subject: Re: Platformer (Climber)

I No Longer Crash ... Which is a good thing =P

However, One thing I might remind you:

Turing:

proc free_pics % Preserves memory
    if (player.y - ground_y) >= 799 and palm_free = false then % 799 + from ground
        Pic.Free (palm_tree) % Free pic
        palm_free := true % Set boolean to true
    elsif (player.y - ground_y) <= 798 and palm_free = true then
        palm_free := false
        palm_tree := Pic.FileNew(pic_dir + "palmtree.bmp")
    end if
        %
    if (player.y - ground_y) >= 799 and sand_free = false then
        Pic.Free (sand)
        sand_free := true
    elsif (player.y - ground_y) <= 798 and sand_free = true then
        sand_free := false
        sand := Pic.FileNew(pic_dir + "sand.bmp")
    end if
        %
    if (player.y - ground_y) >= 799 and portal_free = false then
        Pic.Free (portal)
        portal_free := true
    elsif (player.y - ground_y) <= 798 and portal_free = true then
        portal_free := false
        portal := Pic.FileNew(pic_dir + "portal.bmp")
    end if
        %
    for i : 1 .. upper(sky_plat)
        if (player.y - ground_y) >= 1800 and sky_plat(i).freed = false then
            Pic.Free (sky_plat(i).plat)
            sky_plat(i).freed := true
        end if
        if (player.y - ground_y) <= 1780 and sky_plat(i).freed = true then
            sky_plat(i).plat := Pic.FileNew(pic_dir + "sky_plat_1" + ".bmp")
            sky_plat(i).freed := false
        end if
    end for
        %
    if (player.y - ground_y) >= 1800 and stary_sky_free = false then
            Pic.Free (stary_sky)
            stary_sky_free := true
    elsif (player.y - ground_y) <= 1780 and stary_sky_free = true then
            stary_sky_free := false
            stary_sky := Pic.FileNew(pic_dir + "sky1.bmp")
    end if
end free_pics
%
%
proc draw_pics
    % The if statements keep the program from drawing freed pictures
    if palm_free = false then
        Pic.Draw (palm_tree, plat(4).x + 220, plat(4).y + plat(4).h, picXor)
    end if
    if sand_free = false then
        Pic.Draw (sand, plat(4).x, plat(4).y, picXor)
    end if
    if portal_free = false then
        Pic.Draw (portal, plat(4).x, plat(4).y + plat(4).h, picXor)
    end if
    if stary_sky_free = false then
        Pic.Draw (stary_sky, plat(5).x, plat(5).y + plat(5).h, picXor)
    end if
    for i : 1 .. upper(sky_plat)
    if sky_plat(i).freed = false then
        Pic.Draw (sky_plat(i).plat, plat(i + 5).x, plat(i + 5).y, picMerge)
    end if
    end for
   
end draw_pics


With all your Picture Declarations near the top of the program, you don't need all those "freed" lines, just draw the pics. (and also no need for those other picture declarations in there.) Heck, I think you can just junk the entire "FreePics" procedure, because you've already gotten all the pictures you need, and there is no need to be freeing them repeatedly.

This is how I might edit it:

Turing:

proc draw_pics
    Pic.Draw (palm_tree, plat(4).x + 220, plat(4).y + plat(4).h, picXor)
    Pic.Draw (sand, plat(4).x, plat(4).y, picXor)
    Pic.Draw (portal, plat(4).x, plat(4).y + plat(4).h, picXor)
    Pic.Draw (stary_sky, plat(5).x, plat(5).y + plat(5).h, picXor)
    for i : 1 .. upper(sky_plat)
        Pic.Draw (sky_plat(i).plat, plat(i + 5).x, plat(i + 5).y, picMerge)
    end for
end draw_pics
Sponsor
Sponsor
Sponsor
sponsor
Aange10




PostPosted: Wed Oct 19, 2011 10:18 pm   Post subject: Re: Platformer (Climber)

Beastinonyou @ 19/10/2011, 8:58 pm wrote:
I No Longer Crash ... Which is a good thing =P
and there is no need to be freeing them repeatedly.


It's not freeing them repeatedly. I'll take it out if necessary, but isn't it good to practice freeing your pics? It's not repeatedly freeing them because it frees the bottom pictures (after u go through the portal) if you go above the purple platform. You can't go back down. (Unless you Admin cheat). Isn't this conserving space? I realize that I don't have 1000 pictures, but that shouldn't prevent me from freeing picks after a certain point? Or should it?

Tony said the same thing you did, could you please elaborate on why it's not good? (Other than the program being small.)
Beastinonyou




PostPosted: Wed Oct 19, 2011 10:34 pm   Post subject: Re: Platformer (Climber)

Freeing your pictures should be used when necessary, like in the instance that you are using many, many images.

In your situation, with a mere 15 pictures, freeing them to conserve space, is just more coding that doesn't need to be coded.

Somewhat of an Analogy - You have a gun with 1,000 bullets, and you're reloading after you fire off <15 bullets.

Not sure if it's a proper analogy, but it doesn't really make sense if you're reloading after 15 bullets, if you have 1,000, and say "Just in case I don't run out"
Aange10




PostPosted: Wed Oct 19, 2011 10:53 pm   Post subject: RE:Platformer (Climber)

Well, is it not good coding practice? I took me less than 10 minutes to code that. I want to make everything run right, and even better. 10 minutes is not much for something so appeasing. And it's easy to add new pictures. If I continued to expand, I would have a system to conserve space.

And it's more like if quick writing an essay. Yeah I don't need to think recursively to write the paper, a linear approach would be just fine. But if it was a real essay I would need to. I'm not losing anything by practicing my writing skills.
Tony




PostPosted: Wed Oct 19, 2011 11:10 pm   Post subject: RE:Platformer (Climber)

It adds complexity, which in software typically leads to bugs.

To be exact, you are manually keeping track of specific pictures, specific player locations/boundaries, and a bunch of flag/state variables. You essentially have resource, data, and logic duplication between proc free_pics and the rest of your program.

You make a good point about coding practice -- I would suggest thinking about a procedure to load/unload an abstract level. Something general enough to work for any level (current and future), so no reference to any specific resource by name.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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 3 of 3  [ 35 Posts ]
Goto page Previous  1, 2, 3
Jump to:   


Style:  
Search: