Home Page Downloads Order Community Support
 

 

 
 

 

 

 

 
 

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 #124 items

Title Glenz Vector Cube
Author By: Kevin Picone Added: August 23rd, 2013
Category All,Palette Mapping
Description      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.

Download




Title Make Occupied Map From 2 Colour image
Author By: Kevin Picone Added: August 23rd, 2013
Category All,Maps
Description 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.

Download




Title 8bit Palette Mapped Strips
Author By: Kevin Picone Added: August 23rd, 2013
Category All,Palette Mapping
Description 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.
Download




Title 16bit Palette Mapped Strips
Author By: Kevin Picone Added: August 23rd, 2013
Category All,Palette Mapping
Description Here's a 16bit example that's using 4096 colour palette. The screen colour indexes are set up so that each pixel on screen is the distance from the screen center. The palette created each frame from 16 banks of 256 colours. Each block of 256 colours is shaded via sinus and offset in the palette table, creating the illusion of motion.
Download




Title C64 Screen Emulation
Author By: Kevin Picone Added: April 1st, 2013
Category All,Palette Mapping
Description This source code example recreates the hires screen (character map) mode from the classic 8bit home computer the commodore 64. The code uses the new palette mapping commands to convert the bits in each character to groups of eight 32bit pixels.

Requires PlayBasic V1.64O (2013)

Download




Title Sliding Collision Around A Track
Author By: Kevin Picone Added: June 5th, 2012
Category All,Sprites ,Collision
Description     This example lets the player move a sprite character around an oval shaped track. The player has full sliding collision with the track and fences. The demo uses the built in sprites sliding world collision mode to handle the positioning of the sprite. All we do is move it, the collision engine will work out the new position for us. Obviously if the collision is world based, we need to create world, which is done randomly here in code. In a real game you'd knock up a little tool for such things.

    To create the track shape, we draw two ovals to a world buffer, an outer and inner edge. These two edges form the track. Sliding collision is single sided so the line segments in the outter oval and inner oval need to be connected in opposite directions. Together these form the area that will keep the moving sprite within.

    The track also includes some randomly sized rectangles splodged around it. These also drawn as line segment outlines. Where each segment is pointing outwards. So when a sprite pushes against the segment, the collision engine pushes/slides the character into new safe position.

    Anyway, most of this example is really in setting the collision world. The actual movement code in the main loop is trivial, nothing more than MoveSprite. In a real game we'd obviously use our own game editor to built the collision world to suit the game visual environment.

Download




Title Vertical Sprite Depth Ordering
Author By: Kevin Picone Added: June 3rd, 2012
Category All, Sprites ,Videos
Description      This example breaks away from the concept that depth is straight into the screen. In fact, Sprite Depth/ Scene Depth are just a sort order keys for the object. We can set the depth key to anything we like (0 to $ffff). Here i'm creating a scene where the sprites drawn vertically sorted upon their Y values.

     To do this, we're using the sprites screen position on the Y axis, and inverting it for our depth value. We need to invert the value as the sorting engine draws things in highest to lowest. So smaller z values are drawn after higher ones.

     What this means is that characters further down the screen (represented as some coloured ellipses) are drawn after characters above them. So foreground characters can appear to walk in front of other characters.



Download




Title Selective Tile Map Refreshing II
Author By: Kevin Picone Added: May 20th, 2012
Category All,Maps
Description     This is a more updated version of the previous example. The only real difference is that, this one uses built maps where is the original one demonstrates the hands on method. Apart from that they're pretty much the same, with just some tweaks for newer editions of PlayBasic V1.64M and above.

    This is another short PlayBasic source code example, this one's demonstrating a selective redrawing method using PlayBasic Maps. The program attempts to reduce the cost per refresh by not redrawing the entire backdrop picture every frame. It does this by tagging the overdrawn zones that need to be restored using a Map. So basically the backdrop picture is first cut up into an Map representation. In this example the block size is 32x by 32y pixels, giving us a level size of (800/32 by 600/32). The demo uses two versions of the level tile map data. One is the original and the second is a version we're going to draw from. We need two since the redraw version gets cleared and altered each frame.

     When drawing character objects (in this demo those are the circular blobs), we move the object then convert it's 2d space coordinates back into map coordinates. Then copy from this tile/block area from Original Level to the Refresh Level. We repeat this process for all on screen objects. So after processing our characters, the refresh map contains the parts of the backdrop that need to refreshed (reset) back to it's original state before drawing the next frame. So rather than redraw the entire backdrop picture every time, we can selectively refresh the backdrop. This type of method works really well in 2D games, as it allows the program to lower the cost per-pixel, ironing out the performance for older systems. By older, I mean systems beyond 5 years, closer to 10 years old really
Download




Viewing Page [1] of [16]

Back - Next

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 file) from this site, without explicit written permission.

 

 
     
 
       

 

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