7 Replies Latest reply: Apr 29, 2012 8:25 PM by Owen Buddenbaum RSS

    Need some help making a game

    GKelly642

      Hello, i'm creating a game with Director using Lingo. Basically its a game which has targets moving down the screen at random horizontal positions. Currently i have 5 target sprites with the script below attached to each of them. I want to make the same thing but only use 1 target sprite however i'm not sure how to go about this. I want targets randomly being created at a random intial vertical location then for them to go down the screen. You'll see what i mean in the link to the game below. Thanks any help is appreciated even some pseudocode on how i would go about solving this problem would be useful.

      Thanks Graham.

       

      Game link: http://www.andkon.com/arcade/adventureaction/targetmania/

       

      Lingo script currently attached to 5 target sprites:

      property pSprite, pVInitLoc, pHInitLoc, pEndLoc, pSpeed

       

      on beginSprite me

        pSprite=sprite(me.spritenum)

        pVInitLoc=-50

        pEndLoc=650

        pSpeed=random(1,4)

        pSprite.locV=pVInitLoc

        pSprite.locH=(random(10)*50)-25

      end

       

      on exitFrame me

        pSprite.locv=pSprite.locv+pSpeed 

        if pSprite.locV>pEndLoc then

            pHInitLoc=(random(10)*50)-25

            pSpeed=random(1,4)

            pSprite.locV=pVInitLoc

            pSprite.locH=pHInitLoc

          end if

      end

        • 1. Re: Need some help making a game
          komtol Community Member

          why only one sprite

          • 2. Re: Need some help making a game
            GKelly642 Community Member

            Code has to be efficient to get a decent mark, if i use 5 sprites it isn't efficient but if i use 1 sprite it is efficient. Any ideas how i'd go about doing the above with 1 target sorite?

            • 3. Re: Need some help making a game
              James Newton, ACP CommunityMVP

              Coding and sprites are two different things. The game you link to uses way more than 5 sprites. Using many instances of a single script is efficient. It means you can make one change in one place, and it will affect all the targets.

               

              Writing code that will simulate multiple sprites in a single sprite is not efficient. It's re-inventing the wheel.

               

              Perhaps you could talk to your tutor about what s/he means by "efficient code", and revise your approach accordingly.

              • 4. Re: Need some help making a game
                GKelly642 Community Member

                Ok will do. I have another question (I HATE LINGO lol). Is there any way to randomly make the sprites appear on the screen at different times rather than using the speed of the sprite to make it look like they are moving in randomly? I'm not to good at wording this stuff should be a wa i can show you lol. Thanks yet again.

                • 5. Re: Need some help making a game
                  Owen Buddenbaum Community Member

                  you shouldn't use sprite behaviors for a game

                   

                  sprite behaviors are similar to flash components, it's a tool for application design

                   

                  more, 99% of simple games are totally procedural, no object class are requiered

                   

                  so you'd better use an entry point in a global script ("movie"), then from it, call your engine hart in a static class ("parent")

                   

                   

                  another error: do not use exitFrame/prepareFrame/stepFrame events for a game routine.

                  use enterFrame instead, this event is called when cpu is free, between 2 render steps

                  • 6. Re: Need some help making a game
                    James Newton, ACP CommunityMVP

                    Owen, I can agree with you about using enterFrame... in most cases. (It is perfectly fine to use stepFrame if no changes are made to sprite display or positions within the stepFrame event).

                     

                    However, I cannot agree with your statements:

                     

                         you shouldn't use sprite behaviors for a game

                     

                    and

                     

                         more, 99% of simple games are totally procedural, no object class are requiered

                     

                    These statements make me think that you have not explored behaviors or object-oriented programming sufficiently, and that you do not understand the benefits of using these techniques. Perhaps you would like to elaborate on your opinion?

                    • 7. Re: Need some help making a game
                      Owen Buddenbaum Community Member

                      Sorry i made an error,

                       

                      the correct sentence is:

                       

                      "99% of procedural games are totally procedural, no object INSTANCES are required"

                       

                      for procedural programming, use static classes. no movie scripts because of a garbage collector issue, excepted as en entry point