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 #6 items in Graphics category by Kevin Picone
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.
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 !
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 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 fontLoadfont"Courier New",1,32,0MakeBitmapFont1,$ff0000; load the Courier New fontLoadfont"Courier New",2,64,0MakeBitmapFont2,$8f70a0setfont2; 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 formDim 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)setfps60RendertoScreenDoCls0; Update the Scroll Buffersetfont2
UpdateScroller(ScrollText(),ScrollBuffer); select What effect render Select Effect
case0; draw the scroll messagaeDrawimage ScrollBuffer,0,280,true
EffectName$="Standard Scroller"case1
Draw_XSine_Image(ScrollBuffer,0,280,32)
EffectName$="Scroller with sine X distortion"case2
Draw_YSine_Image(ScrollBuffer,0,280,270)
EffectName$="Scroller with sine Y distortion"case3rendertoimage Scrollbuffer2
Draw_XSine_Image(ScrollBuffer,0,0,24)rendertoscreen
Draw_YSine_Image(ScrollBuffer2,0,280,270)
EffectName$="Scroller with combined X&Y distortion"endselectifSpacekey()Inc Effect
If effect>3then effect=0flushkeysendifSetfont1
x=getscreenwidth()/2
y=GetScreenheight()/2+200centertext x,y,EffectName$
centertext x,y+50,"Press Space"Syncloop; ---------------------------------------------------------------------; 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)rendertoscreenEndFUnction; ---------------------------------------------------------------------; 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=0to iw-1
Y=SinRadius(Angle#,waveRadius); to reduce the number of blitsCopyRect ThisImage,x,0,x+2,ih,OutPutBuffer,Xpos,ypos+Y
inc xpos
inc xpos
Angle#=wrapangle(Angle#,0.5)next
BaseAngle#=wrapangle(BaseAngle#,2)rendertoscreenEndFUnction; ---------------------------------------------------------------------; Refresh Scroll Text/ Buffer; ---------------------------------------------------------------------Function UpdateScroller(ChrBuffer(),ScrollBuffer); use static variables to keep track of the displacementStatic 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,0Inc PixelShifts
if PixelShifts=>GetFontWidth(GetCurrentFont())
PixelShifts=0rendertoimage 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 buffertext iw-FontWidth,0,chr$(ChrBuffer(CurrentChr)); bump the current character indexinc CurrentChr
; check if the current character index is inside the buonds; of the Scroll text arrayif CurrentChr=>GetArrayElements(Chrbuffer(),1)
CurrentChr=0endifendif; restore old render surfaceRenderToImage CurrentSurface
EndFunctionFunction 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=1tolen(t$)
buffer(size+c-1)=mid(t$,c)nextendifuntil t$=""EndFUnctiondata"Hello World... Here's some old skool scroll text"Data"......................."data""; end of scroll text
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.