News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Twitch Face

Started by kevin, February 19, 2006, 09:42:21 PM

Previous topic - Next topic

kevin

Here's the source the Twitch Face demo (link bellow). This code should work with PB1.11 or above.  But it's hard to remember now. :)


The demo includes a few tidbits worth noting.


1) Includes frame rate locking code. This forces the demo run the same speed regardless of the physical frame rate.  

  - The method employed in this demo is basically as you would achieve frame rate independence in your PB games.   That is,  providing the game logic and rendering are independent of each other.

  -  To achieve a desired frame rate the logic is updated at the required rate, over a 1 second period.  The slower the machine, means the game logic it's updated generally more than once per cycle.  The beauty of this, is that avoids interpolation.  Which can very messy and overly complex without any real noticeable improvement.  

2) Includes some functions to use the sprite render modes, as if they were image commands.  


That's about it.


Screen Shot Thread


kevin

#1
PlayBASIC LIVE - Revisiting Twitch Face Demo - (2020-07-14 )


  Here we're taking a look back a demo called Twitch Face from way back in February of 2006. The demo is various stacked blends that 'twitch' or are offset from each other.

 

   
Video:
 
 
     




   
Source Code:
 

   
PlayBASIC Code: [Select]
; PROJECT : Project1
; AUTHOR : Kevin Picone
; CREATED : 20/02/2006
; EDITED : 20/02/2006
; ---------------------------------------------------------------------


Image=loadNewImage("face.jpg")


w=getimagewidth(image)+30
h=getimageheight(image)+30

OriginalImage=ResizeFXImage(IMage,w,h,true)

PrepareFXimage OriginalImage
Scaleimage OriginalImage,200,100,1
blurimage originalimage,10

W=GetImageWidth(OriginalImage)
H=GetImageHeight(OriginalImage)

Image1=GetfreeImage()
CopyImage OriginalIMage,Image1

Image2=GetfreeImage()
CopyImage OriginalIMage,Image2





me=1
s#=2.1
max=5
for me=1 to max
CreateSprite me
positionsprite me,400,300+(me*15)
spriteimage me,Image2
centerspritehandle me
spritedrawmode me,2
scalesprite me,s#
s#=s#+1.15
spritetransparent me,true-(me=max)
next



; Calc the Number of milliseconds 1 frame Should Take
TicksPerFrame=1000/50

; Init the Time the first frame started
StartOfFrame=Timer()


; ------------------------------------------------------------------
; Start of Main Loop
; ------------------------------------------------------------------

Do

; Get the Curent Timer() value
Time=Timer()

; Calc the number of Frames past since the last STart of last update pass
FramesPast=(Time-StartOfFrame)/TicksPerFrame

; Set the Start of frame timer to the next frame
StartOfFrame=StartOFFrame+(FramesPast*TicksPerFrame)

; Set the end of this frame
NextFrame=STartOfFrame+TicksPerFrame

; Update the Logic for the number of frames that have past by
For Frames=1 to FramesPast
gosub Update_Logic
FramesPerSecond=CalcFPS()
next

; Render demo state
gosub Render_Scene


print FramesPerSecond

Sync
cls 0

; -------------------------------------------------------
; Check for a Short frame (Computer is too fast!) so wait
; -------------------------------------------------------

if Timer()<NextFrame
repeat
Wait (NewFrame-1)-timer()
until Timer()>=(NextFrame-1)
endif


loop




Render_Scene:

Create_DistortFX(OriginalIMage,image1,image2,AddColour,FadeLevel#,AlphaLEvel#,dist)
drawallsprites

y=50
DrawImage Originalimage,50,y,0
DrawImage image1,300,y,0
DrawImage image2,550,y,0

y=getscreenheight()-150
DrawImage image2,50,y,0
DrawImage image1,300,y,0
DrawImage OriginalImage,550,y,0

Return




Update_Logic:

; step rotation angle
angle#=wrapangle(angle#,1)

; values foi the dist effect
AddColour=Rgb(60+sinradius(angle#,60),20+cosradius(angle#,10),100+cosradius(angle#,100))
FadeLevel#=0.25
AlphaLEvel#=0.55-rnd#(0.5)
dist=rndrange(1,5)

; turn sprites
r#=1
for lp=1 to max
turnsprite lp,(r#/max)*lp
next

return






Function Create_DistortFX(OriginalImage,image1,image2,AddColour,FadeLevel#,AlphaLEvel#,dist)
Login required to view complete source code