1. Re: fonts - Reply

>>Colin also dislikes my frequent use of global variables - he obviously
>>thinks they are an equivalent of a 'goto' on the scale of mortal sins.
>>What do you think? Personally, I believe, a well placed label and a
>>'goto' can saved you a lot of headaches, and it can actually make your
>>code more readable than convoluted attempts to avoid it! Jiri

Right... I've had Qbasic code be less readable trying to avoid a goto....
but sometimes the effort *DOES* make it more readable.. it just depends.

>I agree with your opinion. I also like to use global variables to make
>my codes more readable, compact and easy to use. Upto now, Using
>global variable is the most comfortable & handy way to me to avoid
>complicacy, and i found no problem in using them yet.

Yup... In my Asteroids clone, I'm using this structure for the program:

-- Includes

-- Variables and constants

-- Procedures

procedure play_game()
    -- Init all variables (They weren't inited before)

    update_player()  --Get input and update players position
    update_rocks()   --Move rocks and kill dead ones
    update_sats()    --Move satilites and kill dead ones
    update_shots()   --Move shots and kill dead ones
    update_particles() --move explosions and, guess what? kill dead ones
    delay(1)
    -- Display info on screen if needed, goto next level if needed, etc.
    if play_again then play_game() end if
end procedure

play_game()

Because there is nothing to pass, it is easy to add new stuff. For
collision detection, update_rocks test for collisions with the player and
rocks, and update_shots tests for collision with the rocks, satillites
and player.
This makes it VERY easy to add something else. I just pop in a new item,
say, update_enemy_ships(), use the structure for them
(enemy_ship[ENERGY][1]), and pop them in before update_rocks. Anything
they fire is handled in update_shots(), their collision with rocks is
tested in update_rocks(), etc. (I just add enough code for the extra
collision detection, piece 'o cake :)
Also, to avoid heavy flicker (I don't have any fast drawing routines,
just the standard draw_polygon() and pixel()), they are erased and drawn
inside their own functions. And since everything is global, I don't need
to pass new params to update_rocks for more collision detection.

See? Globals are our friends.... :)

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu