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 #20 items in Effects category by Kevin Picone

 Object Echoes - Object Motion Blur

By: Kevin Picone Added: November 14th, 2021

Category: All,Effects

Object Echoes / Object Motion Blur

  Today we'll take a look a one approach for creation echo or motion blur styled effect using nothing more than some variable addition alpha blending.

PlayBasic Code:
; PROJECT : Echo or Motion Effect
; AUTHOR  : Kev Picone - http://PlayBasic.com
; CREATED : 14/11/2021
; EDITED  : 14/11/2021
; ---------------------------------------------------------------------



	// -------------------------------------------------------
	// ---------------------- MAIN LOOP ----------------------
	// -------------------------------------------------------



	type tobject
		X#(10)
		Y#(10)
		
		SpeedX#
		SpeedY#
		Colour
	endtype	

	Dim Objects(35) as tobject

	for lp=1 to getarrayelements(Objects())
			Objects(lp)= new tobject
			x#=rnd(800)
			y#=rnd(600)
			
			
			for poslp=0 to 10
				Objects(lp).x#(poslp) = x#
				Objects(lp).y#(poslp)= y#
			next
			
			Speed#=rndrange#(10,20)
			Angle#=Rnd(360)
			Objects(lp).speedx#=cos(Angle#)*Speed#
			Objects(lp).speedy#=sin(Angle#)*Speed#
			Objects(lp).Colour =rndrgb()
	next




	Screen=Newfximage(GetScreenWidth(),GetScreenheight())
	

	// -------------------------------------------------------
	do	// -------------------- MAIN LOOP ---------------------
	// -------------------------------------------------------



				for lp=1 to getarrayelements(Objects())
					x#=Objects(lp).x#(0)
					y#=Objects(lp).y#(0)

					x#+=Objects(lp).speedx#
					y#+=Objects(lp).speedy#

					//  scroll old positions down
					for oldpos=10 to 1 step -1
						Objects(lp).x#(oldpos)=Objects(lp).x#(oldpos-1)						
						Objects(lp).y#(oldpos)=Objects(lp).y#(oldpos-1)						
					next	

					if x#<0 		then x#=0 	: Objects(lp).speedx#*= -1
					if x#>800 	then x#=800 : Objects(lp).speedx#*= -1
					if y#<0 		then y#=0 	: Objects(lp).speedy#*= -1
					if y#>600 	then y#=600 : Objects(lp).speedy#*= -1

					Objects(lp).x#(0)=x#
					Objects(lp).y#(0)=y#
					
				next

		
		
		rendertoimage Screen
		cls 0
				// render 
				lockbuffer			
				; set ink pen drawing mode to Alpha Addition / Alpha ADD	
				inkmode 1+64
				
				; step through the objects and the draw the oldest ones first
				; looping to the last down to first.
				for pass=10 to 0 step -1	
					blendlevel#=cliprange#(pass/10.0,0,1)
										
					BlendColour =255-(255*BlendLevel#)
					BlendColour=Rgb(BlendColour,BlendColour,BlendColour)


					//  Draw all the objects from this pass in one group
					for lp=1 to getarrayelements(Objects())
						x#=Objects(lp).x#(pass)
						y#=Objects(lp).y#(pass)

						//  Compute the objects colour with the fade level
						ThisRGB = rgbAlphamult (Objects(lp).Colour, BlendColour)
						
						// draw it as a circle
						circlec x#,y#,32,true,ThisRGB
					next
				next
			
				unlockbuffer				
	
				; set inkmode back to normal
				inkmode 1	
				rendertoscreen
				drawimage screen,0,0,false
				
	
		sync
		wait 10		
	loop spacekey()

 


PlayBasic LIVE - Overview of Object Echo / Motion Blur Example - (2021-11-16)

 





 Particles Using Sprites

By: Kevin Picone Added: May 6th, 2016

Category: All,Particles,Videos,Effects,Alpha Blending

Particles Demo Using Sprites

     This is an older code snippet that was originally written by Crystal Noir, it creates a type of 3D particle explosion using animated 2d sprites. I've tweaking the code and fixed some logic errors and this was the end result.

Particle Demo Video



Get Source Code




 Meta Balls - Light Blobs

By: Kevin Picone Added: April 22nd, 2016

Category: All,Demos,Videos,Effects,Alpha Blending

Meta Balls - Light Blobs

This example recreates a popular demo effect known as meta balls/blobs. The scene is calculated by working out the amount of energy that each pixel receives from the surround 'blobs' or lights. The more lights the more work each pixel has to be do.

So if you did all the work (calc the distance etc) in the inner most loops, you’d get a pretty heavy per pixel calculation. Such a loop would run slowly even in assembly/machine code. So what we need to do is come up with some ways we can simplify the inner loop to get the cost per pixel down as much as possible.

Video:



Related Links:

- Get Source Code
- A Crash Course In BASIC program Optimization





 Glow / Lightning Balls

By: Kevin Picone Added: May 1st, 2012

Category: All, Videos, Effects


     This source code is variation of the one of the older example. The main change is that this version takes on more of a 3d feel.



Download: Login to Download




 8Way Layered Star Field / Asteroids Style

By: Kevin Picone Added: December 30th, 2011

Category: All, Games, Effects, Videos

     This example creates a layered infinitely scrollable star field using shapes. The star field can move/wrap in all 8 directions, much like you'd see in Asteroids arcade style games.. Here we're using Shapes to batch render dots, rather than trying to brute force them individually


Download: Login to Download




 Rotated Column

By: Kevin Picone Added: December 29th, 2011

Category: All, Videos, Effects


     This is a little effect that renders a perspective /rotating column with camera push in/out.


Download: Login to Download




 Tree Parallax

By: Kevin Picone Added: June 19th, 2011

Category: All,Effects,Fonts,Alpha Blending


     This little demo builds old school parallax effect with a bunch of trees, the effect is not the interesting part really. It's that rather than use images/sprites the tree images are converted into a font (CRF), so the rows of trees are drawn as strings..
Download: Login to Download




 Lightning Balls

By: Kevin Picone Added: November 4th, 2010

Category: All,Effects


Lightning Ball demo displays a ring of rotating balls connected by a simple lighting/energy effect made out of lines.
Download: Login to Download




Viewing Page [1] of [3]



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]