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 #130 items
Particles Using Sprites
By: Kevin Picone Added: May 6th, 2016
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.
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.
This code is a version of my flood fill path finding routine that was originally written way back in the late Amiga days, some 20 odd years ago now. The raw concept was inspired by the game Chaos Engine by the Bitmap Brothers, which featured a cooperative mode with a second AI player, even when playing in single player modes. What struck me was how well the AI player could fight and locate power ups, which seemed just like the a human player at the time. Today this kind of AI has is almost common place, but it seemed new back in the 16bit days. I don't actually know how Chaos Engine's AI algorithms work, just that it was seed for this idea. But like a lot of good ideas, this just ended up gathering dust on my legacy hard drive until now.
This example create a list of random positions then interpolates a sprite between each key frame in the set. This first version interpolates just the sprites coordinates/angle and scale, while the second version includes tint colour interpolation also.
This demo shows the core logic behind drawing radial lights in top down 2D game. The light source is made up of a group triangle fragments drawn in a circular pattern. So we just step around the edge of the circle and draw triangles from the center to the edges. This gives us an N sided polygon that represents our light in the scene, the more sides the accurate the circle will be mapped.
To make it act more light natural light, we need something to handle the occlusion/shadows. In PlayBasic we can use the ray intersection support found in the world commands. That means we define the "hard" parts of the world and by hard I mean zones where light is not allowed to go/pas through, by outlining them with lines. So when we draw our light, we run ray intersections along the triangle edges against the hard / occlusion world, if there's a collision we grab the intersection point which will clip our light map triangles for us.
This demo generates the occlusion world randomly, it's basically a cut'n'paste from the Projects/Worlds/RayIntersectWorld demo.
This example recreates a classic 3d effect that was popular on the 16bit platforms such as the Amiga / Atari ST. Those older systems support bit plane display modes, which makes such effects relatively easy. The effect works by drawing each side of the cube to different bit plane. This allows the program to alter the individual bits of the output pixel without ever accessing that memory
Modern computers use a chunky display modes though, where either a byte, 16bit word or 32bit integer are used to represent each pixel. Such displays are easy to draw dots onto, but make altering individual bits within the pixels more work. To recreate such effects in PlayBasic, we're setting up a 16bit Palette Mapped screen, then rendering the cube sides using the OR inkmode, so each side is drawn onto a separate power of 2. Creating an emulation of a bit planed display mode.
Make Occupied Map From 2 Colour image
By: Kevin Picone Added: August 23rd, 2013
This example computes map of 'occupied' rects from the 2 colour image. The Image is expected to be either black (rgb=0 ) or pure white (rgb=$ffffff). The user can draw circles with the mouse to fill the frame in. The occupied Map is drawn behind it in GREEN and RED blocks in real time.
8bit Palette Mapped Strips
By: Kevin Picone Added: August 23rd, 2013
This following example create a conceptual 256 colour screen in memory (in a PlayBasic bank). The program fills the conceptual screen with colour index byte values. These values are written to form and sinus arc (See SIN) ranging from 0 to 255, where and each row displaced by one pixel. Creating a sort of curved diagonal pattern. Each frame we colour cycle the 256 colour palette with all of the shades of the current random colour. So it appears to move, even though we never have to modify the pixel data once it's created.
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 file) from this site, without explicit written permission.