UnderwareDesign
May 24, 2013, 06:03:31 AM *
News: Code Conversion - Convert Amos To PlayBASIC  (2nd,April,2013)
   Home    
Pages: 1 2 [3]
 
Author Topic: Asteroids  (Read 4570 times)
Member


WWW
« Reply #30 on: December 21, 2010, 12:54:45 PM »


weird............after compiling it is now running wayyyyyy too fast on my machine.!!!???!?!?!

gonna rip my Proprietary timer code out and run on setfps().

it is strange this has just started to happen,seemingly all of a sudden.

PB 1-64M
Editor119b3.exe
Logged
Member
Development Team


WWW
« Reply #31 on: December 21, 2010, 06:09:46 PM »

Code:
; PROJECT : ast frag2
; AUTHOR  : Microsoft
; CREATED : 16/01/2010
; EDITED  : 21/12/2010
; ---------------------------------------------------------------------
ScreenVsync on
gametimer2=timer()

gameloop()
end

Constant gamespeed=20 ;fps


function gameloop()
   local x
    Repeat
      Cls 0
;
      If timer()>=gametimer2
;        gametimer2=(Timer()+(1000/gamespeed));gamespeed)
      gametimer2=(Timer()+20);gamespeed)
        circle x,100,5,1
        x=x+1
        sync
    EndIf
    ; sync
  Until   false
endFunction


   The logic of the loop is broken, rather than redraw completely at 20 MS intervals it's drawing the circle + syncing, but clearing the graphics buffer every iteration.  

Code:

ScreenVsync on

Constant gamespeed=50 ;fps

gameloop()

end



function gameloop()
   local x
gametimer2=timer()

   Repeat
;
CurrentTime=Timer()
      If CurrentTime>=gametimer2
     gametimer2=(CurrentTime+(1000/GameSpeed))

; redraw frame only when at least 20 milliseconds have pasted
RenderGame()    

   EndIf
   ; sync
   Until spacekey()
endFunction



Psub RenderGame()

     Cls
         circle x,100,5,1
         x=mod(x+1,800)
         sync

EndPsub



   This approach is basically what SetFPS does anyway, with one exception, setting fps means that when syncing on computers that can run the loop faster than required (Less than 20, when that's the target), than it gives the free time given back to windows.   This is not he case in this loop however, as this loop is a hogging all the cpu since it's constantly waiting for the next frame to occur.
  

  This can be dropped in a bit like this,

Code:

ScreenVsync on
Constant gamespeed=50 ;fps

gameloop()

end



function gameloop()
   local x
gametimer2=timer()

   Repeat

;
CurrentTime=Timer()

TimeToNextFrame=gametimer2-CurrentTime

      If TimeToNextFrame<1

       gametimer2=(CurrentTime+(1000/GameSpeed))

; redraw frame only when at least 20 milliseconds have pasted
RenderGame()    

else

; CHeck if there's a more then 5 milliseonds to go
if TimeToNextFrame>=5
wait 4
endif

   EndIf
   ; sync
   Until spacekey()
endFunction



Psub RenderGame()

     Cls
         circle x,100,5,1
         x=mod(x+1,800)
         sync

EndPsub



Logged

Member


WWW
« Reply #32 on: December 22, 2010, 01:53:38 PM »

oh yeah thanks yet again kevin.

p.s. i am love with PB again after empty sorted the IDE. woohoo.

Cheers.
Logged
Member


WWW
« Reply #33 on: April 29, 2012, 02:31:27 PM »

I have been meaning to post the source for asteroids for a while,it is fairly long in the tooth and has a few bugs,but i wont spend any more time on it.

Asteroids FINAL.rar (977.09 KB - downloaded 11 times.)
Logged
Member

WWW
« Reply #34 on: April 29, 2012, 02:58:28 PM »

monkeybot, Great Work!!!  Wink
Logged
Member


WWW
« Reply #35 on: May 03, 2012, 12:58:50 PM »

Thanks Atlus.
Logged
Member

« Reply #36 on: May 03, 2012, 02:07:36 PM »

Hello monkeybot!

I have tried to start your Asteroids, but an error massage appeared:

Error String: Variable 'inputlibrary_version' is Not defined in Scope declaration.

I use PlayBasic Vers. 1.64N

Can you tell me, what I have to do?

Greetings by

Sigtrygg
Logged
Member


WWW
« Reply #37 on: May 04, 2012, 02:10:19 PM »

i assume the source?

um...did you decompress the archive properly?
do you have the input lib in PB installed correctly?
Logged
Member
Development Team


WWW
« Reply #38 on: May 04, 2012, 02:19:59 PM »


  I had a look at this the other day (thanks for posting btw), and had much the same issue, it seemed that one of the sources wasn't included in the project file so I had to add it again.  After that it was fine. 
Logged

Member


WWW
« Reply #39 on: May 04, 2012, 02:27:17 PM »

oops
i better sort that out.
Logged
Pages: 1 2 [3]
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2009, Simple Machines LLC | Privacy Policy Valid XHTML 1.0! Valid CSS!