Loading ...
Sorry, an error occurred while loading the content.

help with graphics

Expand Messages
  • Marc
    Good Morning, I wrote a simple game that I like but it runs too slow. I know I must learn the graphics routines like GetDc (sorry) I don t know much about
    Message 1 of 10 , Sep 28, 2010
    • 0 Attachment
      Good Morning,
      I wrote a simple game that I like but it runs too slow. I know I must learn the graphics routines like GetDc (sorry) I don't know much about them.
      I studied a few programs and I don't understand how the graphics are 'printed' without a print #, statement.
      Can anyone direct me in how to use these routines. My program runs very slow and I feel I need to learn these.
      Thanks,
      Marc Rossi
    • Bill Lopez
      It might be a good idea if you showed some code as an example, Marc. Off hand, perhaps your image is too large? The larger an image is, the more pixels must
      Message 2 of 10 , Sep 28, 2010
      • 0 Attachment
        It might be a good idea if you showed some code as an example, Marc. Off hand, perhaps your image is too large? The larger an image is, the more pixels must be painted. For most purposes, 640 x 480 is sufficient, and allows for adequate animation at the same time.

        Full screen images always take awhile to paint, not to mention creating monstrous files. Just because an image can be drawn full screen, doesn't mean that it should be drawn full screen. If an image 320 x 240 suits the purpose, why make a government project out of it? Remember the definition of an elephant: a mouse drawn to government specifications, usually with red ink!



        [Non-text portions of this message have been removed]
      • Rod
        I wrote a blitter .lsn file which might get you started. http://basic.wikispaces.com/file/view/Blit.zip
        Message 3 of 10 , Sep 28, 2010
        • 0 Attachment
          I wrote a blitter .lsn file which might get you started. http://basic.wikispaces.com/file/view/Blit.zip

          --- In libertybasic@yahoogroups.com, "Marc" <mrossi8888@...> wrote:
          >
          > Good Morning,
          > I wrote a simple game that I like but it runs too slow. I know I must learn the graphics routines like GetDc (sorry) I don't know much about them.
          > I studied a few programs and I don't understand how the graphics are 'printed' without a print #, statement.
          > Can anyone direct me in how to use these routines. My program runs very slow and I feel I need to learn these.
          > Thanks,
          > Marc Rossi
          >
        • Stefan Pendl
          ... I don t think you need to delve into API programming for a simple game. If you can upload or post the code, we will better be able to help you. ... Stefan
          Message 4 of 10 , Sep 28, 2010
          • 0 Attachment
            >
            > Good Morning,
            > I wrote a simple game that I like but it runs too slow. I
            > know I must learn the graphics routines like GetDc (sorry) I
            > don't know much about them.
            > I studied a few programs and I don't understand how the
            > graphics are 'printed' without a print #, statement.
            > Can anyone direct me in how to use these routines. My
            > program runs very slow and I feel I need to learn these.
            > Thanks,
            > Marc Rossi
            >

            I don't think you need to delve into API programming for a simple game.

            If you can upload or post the code, we will better be able to help you.

            ---
            Stefan Pendl
            http://stefanpendl.runbasichosting.com/

            Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
            Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

            Liberty BASIC Bug Tracker ... http://libertybasicbugs.wikispaces.com/

            Books at http://www.lulu.com/ and http://www.amazon.com/
            Alyce Watson ... APIs for Liberty BASIC
            Carl Gundel .... Beginning Programming with Liberty BASIC

            Windows 7 Home Premium 64-bit RTM
            AMD Turion X2 RM-70 2GHz, 4GB RAM
          • Marc Rossi
            Hi Stefan, The problem is that when the spaceship shoots, it takes about 5 seconds before I can shoot another one.  If I add sound, it takes about 15
            Message 5 of 10 , Sep 29, 2010
            • 0 Attachment
              Hi Stefan,
              The problem is that when the spaceship shoots, it takes about 5 seconds before I can shoot another one.  If I add sound, it takes about 15 seconds.  When I want the enemy ships to fire, I locate the position of them with spritexy? and the I use a for loop to have them shoot and when this is going on, the background won't scroll and the whole game freezes until the enemies are done firing.  I will show you the code.
              Thanks,
              Marc RossiNOMAINWIN
              Menu #runner,"&Program", "&About", [whatabout]
              Menu #runner, "&Exit", "&Quit", [quit]
              dim alienboong(3,3)  ' alien ships are made in this array
              WindowHeight = 700
              WindowWidth = 500
              UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
              UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
              open "Space Destroyer" for graphics_nf_nsb  as #runner
              print #runner, "trapclose [quit]"
              global deadboong1
              global deadboong2

              shpx = 185
              shpy = 400
              bx = 0
              by = 0

              midx = 170
              midy = 300
              LOADBMP, "big", "big.bmp"     ' load bmps     big is the background
              LOADBMP, "ship1", "ship1.bmp"
              LOADBMP, "fireball", "fireball.bmp"
              LOADBMP, "fireball2", "fireball3.bmp"
              LOADBMP, "boong", "boong.bmp"
              'LOADBMP, "fire1", "fire1.bmp"
              'LOADBMP, "fire2", "fire2.bmp"
              print #runner, "backgroundxy ";bx; " ";by    ' coordinates for background
              print #runner, "background big"                   ' load background
              #runner, "addsprite ship1 ship1";
              #runner, "addsprite fireball fireball";
              #runner, "addsprite fireball2 fireball2";
              #runner, "addsprite fireball3 fireball2";
              #runner, "addsprite boong1 boong";
              #runner, "addsprite boong2 boong";
              print #runner, "spritescale boong1 20";
              print #runner, "spritescale boong2 20";
              print #runner, "spritescale fireball 25";
              print #runner, "spritescale fireball2 20";
              print #runner, "spritescale fireball3 20";
              print #runner, "spritevisible ship1 on";
              print #runner, "spritexy ship1 ";shpx; " ";shpy
              print #runner, "DRAWSPRITES"

              call alienships
              call alienshoot    lx1,    lx2,   ly1,  ly2
              [j]   ' from the pause about menu
              timer 100,  [movement]
              print #runner, "setfocus;when characterInput  [moveship]"   ' get user input from keyboard (event driven input)
                   ' sub to move alien sprites
              'wait
              [movement]
              call movebackground bx, by      ' sub call to move background
              call checkshipcol shpx, shpy ,  lx1,    lx2,   ly1,  ly2
               'call alienshoot    lx1,    lx2,   ly1,  ly2
              wait
              [moveship] ' move spaceship
              k$ = Inkey$
              if asc(right$(k$, 1)) = _VK_RIGHT then
              call goright shpx, shpy
              end if
              if asc(right$(k$, 1)) = _VK_LEFT then
              call goleft, shpx, shpy
              end if
              if asc(right$(k$, 1)) = _VK_UP then
              call goup shpx, shpy
              end if
              if asc(right$(k$, 1)) = _VK_DOWN then
              call godown shpx, shpy
              end if
              if k$ = " " then  ' spacebar shoots weapon from spaceship
              call firegun  bulletx, bullety, shpx, shpy
              end if
              wait
              sub goright byref varx, byref vary
              varx = varx + 4
              print #runner,  "spritexy ship1 ";varx; " ";vary
              print #runner, "spritexy? ship1 varx vary"
              if varx > 390 then varx = 390
              end sub
              sub goleft byref varx, byref vary
              varx = varx - 4
              print #runner,  "spritexy ship1 ";varx; " ";vary
              print #runner, "spritexy? ship1 varx vary"
              if varx < 1 then varx  =  1
              end sub
              sub goup byref varx, byref vary
              vary = vary - 7
              print #runner,  "spritexy ship1 ";varx; " ";vary
              print #runner, "spritexy? ship1 varx vary"
              if vary < 100  then vary = 100
              end sub
              sub godown byref varx, byref vary
              vary = vary + 7
              print #runner,  "spritexy ship1 ";varx; " ";vary
              print #runner, "spritexy? ship1 varx vary"
              if vary > 500  then vary = 500
              end sub
              sub firegun byref gx1, byref  gy1, byref varx, byref vary   ' sub to shoot gun
              print #runner, "spritexy? ship1 varx vary"
              print #runner, "spritexy fireball "; varx; " ";vary
              gx1 = varx + 40
              gy1 = vary
              print #runner, "spritevisible fireball on";
               ' playwave "phasers1_x"
              for bulletgun = 1 to 55
                gy1 = gy1 - 8
                call checkforcollisions   ' sub call to check for collisions in the incremental for loop i use to show the bullet
                print #runner, "spritexy fireball ";gx1; " ";gy1
                print #runner, "DRAWSPRITES"     ' the drawsprites command is giving me trouble with the background graphics from the for loop
                next bulletgun
                print #runner, "spritevisible fireball off";
              end sub
              sub movebackground byref bx, byref  by                  ' moves the background
                  by = by - 10
                  print #runner, "backgroundxy ";bx;" ";by
                  print #runner, "drawsprites";
              end sub
               
              sub checkforcollisions                                      ' check for collisions from main ship hitting boongs
               
                      print #runner, "spritexy? boong1"
                      input #runner,  cx, cy                  ' x and y of boong
                      print #runner, "spritexy? fireball"
                      input #runner, firex, firey              ' x and y of bullet
                       ' boong1 dead
                       if firex >= cx - 20   and firex <= cx + 50   and firey <= cy + 20 and firey >= cy - 20 then    ' position of bullet hitting boon
                        print #runner, "spritevisible boong1 off";
                        print #runner, "spritexy boong1 ";700; " ";1
                        playwave "explosion_x"
                        deadboong1 = 1
                      end if

                       print #runner, "spritexy? boong2"
                       input #runner,  cx2, cy2                  ' x and y of boong
                       print #runner, "spritexy? fireball"
                       input #runner, firex2, firey2              ' x and y of bullet
                        ' boong2 dead
                       if firex2 >= cx2 - 20   and firex2 <= cx2 + 50   and firey2 <= cy2 + 20 and firey2 >= cy2 - 20 then    ' position of bullet hitting boon
                        print #runner, "spritevisible boong2 off";
                        print #runner, "spritexy boong2 ";800; " ";1
                        playwave "explosion_x"
                        deadboong2 = 1
                       end if
                       if deadboong1 = 1 and deadboong2 = 1 then
                        call alienships
                        call alienshoot  lx1,lx2,ly1,ly2
                       end if
              end sub
              sub checkshipcol byref sx, byref sy , byref  lx1,  byref   lx2,  byref  ly1, byref  ly2                ' ship colliding with alien ships and bullets from alienships
               print #runner, "spritecollides ship1 list$";            ' ship and alien ship collision
                 if  list$ = "boong1" then
                     print #runner, "spritevisible boong1 off";
                     print #runner, "spritexy ship1 "; 700; " ";1
                     print #runner, "spritexy boong1 ";800; " ";1
                     print #runner, "spritevisible ship1 off";
                     playwave "explosion_x"
                     for a = 1 to 2000
                     next a
                     print #runner, "spritexy ship1 "; sx; " ";sy
                     print #runner, "spritevisible ship1 on";
                     deadboong1 =  1
                 end if
                   if  list$ = "boong2" then
                     print #runner, "spritexy ship1 "; 700; " ";1
                     print #runner, "spritexy boong2 ";800; " ";1
                     print #runner, "spritevisible boong2 off";
                     print #runner, "spritevisible ship1 off";
                     playwave "explosion_x"
                     for a = 1 to 2000
                     next a
                     print #runner, "spritexy ship1 "; sx; " ";sy
                     print #runner, "spritevisible ship1 on";
                     deadboong2 = 1
                     end if
                     if deadboong1 = 1 and deadboong2 = 1 then
                     call alienships
                     call alienshoot    lx1,    lx2,   ly1,  ly2
                     end if
                     if  list$ = "fireball2"  then
                     print #runner, "spritexy ship1 "; 700; " ";700
                     print #runner, "spritevisible ship1 off";
                     print #runner, "spritexy fireball2 "; 900; " ";4
                     print #runner, "spritevisible fireball2 off";
                    ' playwave "explosion_x"
                     for a = 1 to 20000
                     next a
                     print #runner, "spritexy ship1 "; sx; " ";sy
                     print #runner, "spritevisible ship1 on";
                   end if
                    if  list$ = "fireball3"  then
                      print #runner, "spritexy ship1 "; 700; " ";700
                      print #runner, "spritexy fireball3 "; 900; " ";5
                     print #runner, "spritevisible fireball3 off";
                      print #runner, "spritevisible ship1 off";
                   '   playwave "explosion_x"
                      for a = 1 to 20000
                      next a
                      print #runner, "spritexy ship1 "; sx; " ";sy
                      print #runner, "spritevisible ship1 on";
                  end if
               end sub
              sub alienships                    ' position 2 ships ready for battle
              for a = 1 to 2
                for b = 1 to 2
                alienboong(a,b) = int(rnd(b) * 250) + 1       ' make random spaced alien ships
              next b
              next a
              print #runner, "spritevisible boong1 on"
              print #runner, "spritevisible boong2 on"
              print #runner, "spritexy boong1 ";alienboong(1,1) + 20; " ";alienboong(1,2) + 15   ' x and y
              print #runner, "spritexy boong2 ";alienboong(2,1) + 30; " ";alienboong(2,2) + 30   ' x and y
              print #runner, "drawsprites";
               deadboong1 = 0   ' set the reinitialize flags back to zero
               deadboong2 = 0
              end sub
               

              sub alienshoot    lx1,   lx2,   ly1,  ly2

              print #runner, "spritexy? boong1"
              input #runner,  lx1, ly1                  ' x and y of boong
              print #runner, "spritexy? boong2"
              input #runner, lx2, ly2
                locx1 = lx1
                locx2 = lx2
                locy1 = ly1
                locy2 = ly2
              for h = 1 to 75
               locx1 = locx1 + 2
               locx2 = locx2 - 2
               locy1 = locy1 + 5
               locy2 = locy2 + 5
                 print #runner, "spritexy fireball2 ";locx1; " ";locy1
                  print #runner, "spritexy fireball3 ";locx2; " ";locy2
                print #runner, "spritexy? fireball3"
                input #runner,  px1, py1                  ' x and y of bullets
                print #runner, "spritexy? fireball2"
                input #runner, px2,py2
                print #runner, "DRAWSPRITES";
              next h
              end sub

              wait
              [whatabout]
              timer 0
              se = 2
              notice "Space Destroyer" + chr$(13) + "Written in  Basic" + chr$(13); "     By m f r   2010"
              goto [j]
              wait
               
              wait
              [quit]
              close #runner
              end  ' end program
               
               
               


              --- On Tue, 9/28/10, Stefan Pendl <pendl2megabit@...> wrote:


              From: Stefan Pendl <pendl2megabit@...>
              Subject: RE: [libertybasic] help with graphics
              To: libertybasic@yahoogroups.com
              Date: Tuesday, September 28, 2010, 2:31 PM


               



              >
              > Good Morning,
              > I wrote a simple game that I like but it runs too slow. I
              > know I must learn the graphics routines like GetDc (sorry) I
              > don't know much about them.
              > I studied a few programs and I don't understand how the
              > graphics are 'printed' without a print #, statement.
              > Can anyone direct me in how to use these routines. My
              > program runs very slow and I feel I need to learn these.
              > Thanks,
              > Marc Rossi
              >

              I don't think you need to delve into API programming for a simple game.

              If you can upload or post the code, we will better be able to help you.

              ---
              Stefan Pendl
              http://stefanpendl.runbasichosting.com/

              Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
              Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

              Liberty BASIC Bug Tracker ... http://libertybasicbugs.wikispaces.com/

              Books at http://www.lulu.com/ and http://www.amazon.com/
              Alyce Watson ... APIs for Liberty BASIC
              Carl Gundel .... Beginning Programming with Liberty BASIC

              Windows 7 Home Premium 64-bit RTM
              AMD Turion X2 RM-70 2GHz, 4GB RAM











              [Non-text portions of this message have been removed]
            • Stefan Pendl
              ... SPRITEMOVEXY or SPRITETRAVELXY will get rid of the FOR-loop, since they update with each DRAWSPRITES issued. Shouting is automatic and independent, so
              Message 6 of 10 , Sep 29, 2010
              • 0 Attachment
                >
                > Hi Stefan,
                > The problem is that when the spaceship shoots, it takes about
                > 5 seconds before I can shoot another one.  If I add sound, it
                > takes about 15 seconds.  When I want the enemy ships to fire,
                > I locate the position of them with spritexy? and the I use a
                > for loop to have them shoot and when this is going on, the
                > background won't scroll and the whole game freezes until the
                > enemies are done firing.  I will show you the code.
                > Thanks,
                > Marc Rossi

                SPRITEMOVEXY or SPRITETRAVELXY will get rid of the FOR-loop, since they update with each DRAWSPRITES issued.
                Shouting is automatic and independent, so there is no need to control it.

                There are several tutorials about game development:

                http://www.coolprog.com/ENGLISH/index.html

                http://basic.wikispaces.com/Are+There+Any+Tutorials#Tutorials-Online%20Resources

                http://lbpe.wikispaces.com/graphics#Graphics%20and%20Game%20Programming-Sprite%20Byte%20Tutorials

                Several places for game source code:

                http://alycesrestaurant.com/Games.htm

                http://www.lbdownloads.com/games.php

                http://www.foundrysearch.com/index.php (browse down to Category: Games)

                ---
                Stefan Pendl
                http://stefanpendl.runbasichosting.com/

                Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
                Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

                Liberty BASIC Bug Tracker ... http://libertybasicbugs.wikispaces.com/

                Books at http://www.lulu.com/ and http://www.amazon.com/
                Alyce Watson ... APIs for Liberty BASIC
                Carl Gundel .... Beginning Programming with Liberty BASIC

                Windows 7 Home Premium 64-bit RTM
                AMD Turion X2 RM-70 2GHz, 4GB RAM
              • Rod
                The problem is that when the spaceship shoots, it takes about 5 seconds before I can shoot another one. If I add sound, it takes about 15 seconds
                Message 7 of 10 , Sep 29, 2010
                • 0 Attachment
                  "The problem is that when the spaceship shoots, it takes about 5 seconds before I can shoot another one. If I add sound, it takes about 15 seconds"

                  :) You do need to browse the sprite demos and forget about the blitter for now. Playwave async will sort out the sound, and a few more bullet sprites will allow faster shooting. Liberty is plenty fast enough for a shootemup game.
                • JanetTerra
                  In addition to the advice given by Stefan, you might also look at the playwave command. There are 2 ways to play a wave fine, synchronously and
                  Message 8 of 10 , Sep 29, 2010
                  • 0 Attachment
                    In addition to the advice given by Stefan, you might also look at the playwave command. There are 2 ways to play a wave fine, synchronously and asynchronously. Sync (the default) means 'stop all code action until the wav file finishes.' Async (if specified) means 'continue on with code action while wav file is playing.'

                    playwave "mySound.wav"
                    because it's default, is the same as
                    playwave "mySound.wav", sync

                    If you change to
                    playwave "mySound.wav", async

                    you won't have that delay. Check out playwave in the help file.


                    --- In libertybasic@yahoogroups.com, Marc Rossi <mrossi8888@...> wrote:
                    >
                    > Hi Stefan,
                    > The problem is that when the spaceship shoots, it takes about 5 seconds before I can shoot another one. If I add sound, it takes about 15 seconds [snip]
                    >
                  • Stefan Pendl
                    ... The basic layout for a game is similar to the following: 1) event handler for keyboard events (when characterInput ...) a) update positional variables or
                    Message 9 of 10 , Sep 29, 2010
                    • 0 Attachment
                      >
                      > "The problem is that when the spaceship shoots, it takes
                      > about 5 seconds before I can shoot another one. If I add
                      > sound, it takes about 15 seconds"
                      >
                      > :) You do need to browse the sprite demos and forget about
                      > the blitter for now. Playwave async will sort out the sound,
                      > and a few more bullet sprites will allow faster shooting.
                      > Liberty is plenty fast enough for a shootemup game.
                      >

                      The basic layout for a game is similar to the following:

                      1) event handler for keyboard events (when characterInput ...)
                      a) update positional variables or change the value of a delta move variable
                      b) set action flags for shooting, etc.

                      2) TIMER to handle the rest of the game (50 ~ 100ms)
                      a) turn off timer, if processing takes longer than the timer interval (TIMER 0)
                      b) update positional variables of the character
                      c) check collisions
                      d) check action flags
                      e) anything left to check, for instance win or loose
                      f) initialize shooting
                      g) update enemy positions
                      h) check the joystick
                      ...
                      y) turn timer on, if it was turned off initially
                      z) DRAWSPRITES

                      Start small and add to it.

                      Keep in mind, that there is no need for loops, the TIMER handles all things.

                      ---
                      Stefan Pendl
                      http://stefanpendl.runbasichosting.com/

                      Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
                      Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

                      Liberty BASIC Bug Tracker ... http://libertybasicbugs.wikispaces.com/

                      Books at http://www.lulu.com/ and http://www.amazon.com/
                      Alyce Watson ... APIs for Liberty BASIC
                      Carl Gundel .... Beginning Programming with Liberty BASIC

                      Windows 7 Home Premium 64-bit RTM
                      AMD Turion X2 RM-70 2GHz, 4GB RAM
                    • Stefan Pendl
                      ... Anyone, no. The only one is Carl, so you might send him an enhancement request. ... Stefan Pendl http://stefanpendl.runbasichosting.com/ Liberty BASIC 4.04
                      Message 10 of 10 , Oct 3, 2010
                      • 0 Attachment
                        >
                        > The 'blitter.lsn' file is a personal version of LB's Tutorial.
                        >
                        > It is very useful because we see instantly the output of a
                        > program, and can learn what a command (or a set of commands) does.
                        >
                        > I had a similar one called "My Code Bank". I had to abandon it.
                        >
                        > What is sorely lacking is GLOBAL search. Can anyone modify
                        > the LB Tutorial's source code to make the Search global?
                        >

                        Anyone, no.

                        The only one is Carl, so you might send him an enhancement request.

                        ---
                        Stefan Pendl
                        http://stefanpendl.runbasichosting.com/

                        Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
                        Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

                        Liberty BASIC Bug Tracker ... http://libertybasicbugs.wikispaces.com/

                        Books at http://www.lulu.com/ and http://www.amazon.com/
                        Alyce Watson ... APIs for Liberty BASIC
                        Carl Gundel .... Beginning Programming with Liberty BASIC

                        Windows 7 Home Premium 64-bit RTM
                        AMD Turion X2 RM-70 2GHz, 4GB RAM
                      Your message has been successfully submitted and would be delivered to recipients shortly.