EXAMPLE SOURCE CODES


     This is a small collection of mostly game example source codes. These source codes are made available to help PlayBasic programmers kick start their game programming journey. Looking for more source code / tutorials & media, then remember to visit the PlayBasic Resource board on our forums.

Found #7 items in Graphics category

 Mirrored Floor

By: Kevin Picone Added: September 10th, 2009

Category: All, Graphics, Effects


This example creates the illusion that a perspectively zooming image (in this case a Pb logo) is casting a reflection upon a tiled floor.
Download: Login to Download




 Pyramid

By: ATLUS Added: March 20th, 2008

Category: All,Graphics

For beginers
Download: Login to Download




 Rotating Scroller

By: Kevin Picone Added: May 4th, 2007

Category: All,Graphics


This example creates a rotating scroll text with perspective echoes of itself. Use the Up/Down Arrows to change the number of echoes...

Written in PB1.62


Download: Login to Download




 Torch Flames

By: Kevin Picone Added: February 12th, 2007

Category: All,Graphics


This example creates series of 45 flaming torches. The flame effect is created procedurally using a simple variation of classic 'fire' effect. This means that each frame we're dynamically updating/drawing each flame in this demo. In game though, you'd only need to update a handful, then mirroring the, create the same illusion. But anyway, you get idea.


Download: Login to Download




 Textured Twister

By: Kevin Picone Added: January 31st, 2007

Category: All,Graphics


This example creates an old school 'twisting vine' styled effect as seen in many demos.


Download: Login to Download




 Screen Styles

By: Kevin Picone Added: January 30th, 2007

Category: All,Screen,Graphics

This codes gives you a way to change the default PlayBasic screen style. (Windowed mode only). You need to be careful when changing the style though, as some settings will make your program none operational! - But ya get that !

Download: Login to Download




 Sin Scroller X and Y axis

By: Kevin Picone Added: June 18th, 2006

Category: All,Scroller,Sine,Graphics


     This code is rendering text to the screen in a sine wave pattern. The text will fade in and out, and the vertical position of the text will wobble. The text will also have a gradient color effect, with the color changing from blue to purple. The text is displayed in the center of the screen, and will continue to animate until the space key or escape key is pressed.

PlayBasic Code:
; PROJECT : Xand Y sine wave text renering test
; AUTHOR  : Kev Picone - http://PlayBasic.com
; CREATED : 30/12/2021
; EDITED  : 30/12/2021
; ---------------------------------------------------------------------


         if GetFontStatus(50)=false
            LoadFont   "Agency FB",50,148,1,8
            FontDrawmode 50,1
         endif
         
            
setfps 20
      screen=newfximage(getscreenwidth(),getscreenheight())
      
      Message$="Sine Wave X&Y Axis"
      FadeLevel#=1
   Do
      ;cls 
      rendertoimage screen
      cls $112233
         setfont 50
      ShadedText(Screen,100,Message$, FadeLevel#)
   rendertoscreen
   
      fadeangle#=wrapangle(fadeangle#,0.5)
   FadeLevel#= 0.5+sin(fadeangle#)   
      drawimage screen,0,0,false

      sync
   loop spacekey()=true or esckey()=true

   
   end




Function ShadedText(Screen,Ypos,Message$, FadeLevel#)
   oldSurface   =getSurface()

  Static WobbleAngle#
  Static WobbleAngle2#


    Static VertialWobbleAngle#
 
      rendertoimage screen
      
      
      //FadeLevel#=cliprange(FadeLevel#,0,1)
      
      screenwidth   =GetSurfaceWidth()
      screenHeight=GetSurfaceHeight()
      
      
      imageviewport Screen,0,0,screenWidth,ScreenHeight

      TW=GetTextWidth(Message$)

      Xpos=(ScreenWidth/2)-(TW/2)

      ThisRGB=rgb(50,50,50)


      
      Level = Cliprange( ($90*FadeLevel#) , 0,255)
      if level>0
         for lp =0 to 2      
            ink rgbfade(ThisRgB,50) or Argb(Level,0,0,0)
            text Xpos,Ypos,Message$
            Level+=$16
            Xpos+=2
            Ypos+=1
         next
      endif   
      Rgb1=rgb(20,70,170)
      Rgb2=rgb(220,230,250)

      Rows=GetTextHeight("|")   
      
      Alpha = Cliprange( ($ff*FadeLevel#) , 0,255)
      
      if Alpha>0
      TextWidthInPixels = GetTextWidth(Message$)
      VerticalWaveChunkSize = 4   
      
      VerticalRows=Rows+16
      For lp =0 to VerticalRows   ;Rows+16
         scaler#=float(lp)/VerticalRows
         
         scaler#*= cos(WobbleAngle#)+0.5
         
         ThisRGB=RgbAlphaBlend(Rgb1,RGB2,Scaler#*100) and $00ffffff
         ink lsl32(Alpha,24) or ThisRGB
         
         
         Ypos2=Ypos+lp
         
         OffsetX   =Cos(WobbleAngle#+(lp*1))*5
         OffsetX   +=Sin(WobbleAngle2#-(lp/5))*3
         
         
         //  draw this strip with 
         
      for xwave=0 to TextWidthInPixels step VerticalWaveChunkSize
         
         
            VerticalOffset =sin(VertialWobbleAngle#+(Xwave*0.5))*20
         ;   VerticalOffset+=cos(VertialWobbleAngle#+(Xwave*0.3))*4
            
            ;cosradius(WobbleAngle#,12)

            ScreenX1 = xwave+xpos+OffsetX               
            ScreenX2 = ScreenX1+VerticalWaveChunkSize
            FinalYpos =Ypos2+VerticalOffset   
            imageviewport Screen,ScreenX1,ypos2,ScreenX2,Ypos2+1

            text Xpos+OFFSETX,ypos+VerticalOffset,Message$
         next   
   next
   
   endif   

      imageviewport Screen,0,0,screenWidth,ScreenHeight
      
      WobbleAngle#=wrapangle(WobbleAngle#,2.5)
      WobbleAngle2#=wrapangle(WobbleAngle2#,1.5)
      
      
      VertialWobbleAngle#= wrapangle(VertialWobbleAngle#,0.5)
      
   rendertoimage oldSurface

   
endFunction





PlayBasic -   Code Snippet  - Sine Wave Scroller - 18th June  2006

This is classic source code example from way back in 2006.  The demo shows a simple right to left scrolling message with sine wave distortions applied.   First we start with the basic scroller, next we add sine distortion on the X axis, then the Y axis finishing off by combining them..

  VIDEO:



music by: https://BenSound.com

  Code:

PlayBasic Code:
; PROJECT : Sine_Scrollers
; AUTHOR  : Kevin Picone
; CREATED : 18/06/2006
; EDITED  : 18/06/2006
; ---------------------------------------------------------------------

 ; load the Courier New font
	Loadfont  "Courier New",1,32,0
	MakeBitmapFont 1,$ff0000

 ; load the Courier New font
	Loadfont  "Courier New",2,64,0
	MakeBitmapFont 2,$8f70a0
	setfont 2

	; Make a type to hold the various bits of info ab

	SineWaveWidth=32
	ScrollHeight=GetTextHeight("Y")


	; CReate an array to hold the Scroll text in charater form
	Dim ScrollText(0)
   Read_Text_To_Scroller_Array(ScrollText())
	 

	; Original Scroll buffer
	ScrollBuffer=NewImage(800+(SineWaveWidth*2)+GetFontWidth(2),ScrollHeight)

	ScrollBuffer2=NewImage(800+(SineWaveWidth*2)+GetFontWidth(2),ScrollHeight)
	

setfps 60
	RendertoScreen
	Do
		Cls 0		
		
			; Update the Scroll Buffer
			setfont 2
			UpdateScroller(ScrollText(),ScrollBuffer)


			; select What effect render 
			Select Effect
				case 0
						; draw the scroll messagae
						Drawimage ScrollBuffer,0,280,true
						EffectName$="Standard Scroller"

				case 1
 						Draw_XSine_Image(ScrollBuffer,0,280,32)
						EffectName$="Scroller with sine X distortion"

				case 2
						Draw_YSine_Image(ScrollBuffer,0,280,270)
						EffectName$="Scroller with sine Y distortion"

				case 3	
						rendertoimage Scrollbuffer2
						Draw_XSine_Image(ScrollBuffer,0,0,24)
						rendertoscreen
						Draw_YSine_Image(ScrollBuffer2,0,280,270)
						EffectName$="Scroller with combined X&Y distortion"
			endselect




			if Spacekey() 
				Inc Effect
				If effect>3 then effect=0
				flushkeys
			endif

			Setfont 1
			x=getscreenwidth()/2
			y=GetScreenheight()/2+200
			centertext x,y,EffectName$ 
			centertext x,y+50,"Press Space"


		Sync	
	loop


; ---------------------------------------------------------------------
; Copy an Image width a X sine wave applied
; ---------------------------------------------------------------------

Function Draw_XSine_Image(ThisImage,Xpos,Ypos,XwaveRAdius)
	Static BaseAngle# 

	OutputBuffer=getsurface()

	IW=GetImageWidth(ThisImage)
	IH=GetImageheight(ThisImage)

	For Angle#=BaseAngle# to Baseangle#+IH
		X=SinRadius(Angle#,XwaveRadius)					
		CopyStripH ThisImage,y,0,iw,OutPutBuffer,Xpos-XwaveRAdius+X,ypos 
		inc Y		
		inc Ypos
	next
	
	BaseAngle#=wrapangle(BaseAngle#,0.5)
	rendertoscreen
EndFUnction




; ---------------------------------------------------------------------
; Copy an Image with a Y sine wave applied
; ---------------------------------------------------------------------

Function Draw_YSine_Image(ThisImage,Xpos,Ypos,WaveRAdius)
	Static BaseAngle# 

	OutputBuffer=getsurface()

	IW=GetImageWidth(ThisImage)
	IH=GetImageheight(ThisImage)

	Angle#=baseangle#
	if iw>GetImageWidth(Outputbuffer) then iw=GetImageWidth(Outputbuffer)
	For x=0 to iw-1
		Y=SinRadius(Angle#,waveRadius)					
		; to reduce the number of blits
		CopyRect ThisImage,x,0,x+2,ih,OutPutBuffer,Xpos,ypos+Y 
		inc xpos
		inc xpos
		Angle#=wrapangle(Angle#,0.5)
	next
	
	BaseAngle#=wrapangle(BaseAngle#,2)
	rendertoscreen
EndFUnction







; ---------------------------------------------------------------------
; Refresh Scroll Text/ Buffer
; ---------------------------------------------------------------------

Function UpdateScroller(ChrBuffer(),ScrollBuffer)
	; use static variables to keep track of the displacement
	Static PixelShifts,CurrentChr
	CurrentSurface=getSurface()

	; get the current fonts + width & height
	ThisFont=GetCurrentFOnt()
	FontWidth=GetFontWidth(ThisFont)
	FontHeight=GetFontHeight(ThisFont)
		
	; Get the Scroll Buffers Width and Height
	IW=GetImagewidth(ScrollBuffer)
	IH=GetImageHeight(ScrollBuffer)


	; Move the Scroll buffer 1 pixel to the left 
	 CopyRect  ScrollBuffer,1,0,IW,IH,ScrollBuffer,0,0

	 Inc PixelShifts
	 if PixelShifts=>GetFontWidth(GetCurrentFont())
	 	PixelShifts=0
		
		 rendertoimage scrollbuffer
		; clear any left over pixels 
			boxc iw-fontwidth,0,iw,ih,true,0
		; draw a new character on the end of the scroll image buffer
		  text iw-FontWidth,0,chr$(ChrBuffer(CurrentChr))

		; bump the current character index
		inc CurrentChr
		; check if the current character index is inside the buonds
		; of the Scroll text array
		if CurrentChr=>GetArrayElements(Chrbuffer(),1)
				CurrentChr=0
		endif
	 endif

	; restore old render surface
	RenderToImage 	CurrentSurface
	
EndFunction



Function Read_Text_To_Scroller_Array(Buffer())
	Dim buffer(0)	
	repeat
		Size=GetArrayElements(Buffer(),1)
		t$=readdata$()
		if t$<>""
			redim Buffer(Size+Len(t$))
			For c=1 to len(t$)
					buffer(size+c-1)=mid(t$,c)
			next								
		endif
	until t$=""	
EndFUnction


 data "Hello World... Here's some old skool scroll text" 
 Data "......................."
 data ""  ; end of scroll text










Viewing Page [1] of [1]



Want More Source Codes?:



Release Type: The source code & tutorials found on this site are released as license ware for PlayBasic Users. No Person or Company may redistribute any file (tutorial / source code or media files) from this site, without explicit written permission.

 

 
     
 
       

(c) Copyright 2002 / 2024 Kevin Picone , UnderwareDesign.com  - Privacy Policy   Site: V0.99a [Alpha]