Check out Amazon.com!

BlitzCoder Code Archives PageMain Codes Page
Listing: 2D Games (67 Entries)
Title: Particle functions : Useful -Set- and -Update- particles functions Code Submitted By:
- rafael_the_gamecreator!
Use this piece of code to perform a special particles effect
on your game.

note: if the particle's X or Y get bigger or smaller than the screen's
size, it will be deleted .
 
Title: 2 line FPS code Code Submitted By:
- andreas_blixt

This code has now been updated to be much more accurate and it still uses 2 lines! To get the current FPS, just use CurFPS#.
 
Title: 2D Fast Fade Code Submitted By:
- waroffice

I made a file to fade out my levels in my RPG and found it could be usefull to others.

Any problems PM me
 
Title: 2D Scrolling demo Code Submitted By:
- msw
Works for Topdown and Sidescrolling games. Demo features multiple controlable players that users can switch between. Ability to turn gravity on/off. Camera automaticly follows the selected player around. Coded for BlitzPlus but I think it should work as is for Blitz3D.
 
Title: 2D Sim City roads (Auto connecting road system) Code Submitted By:
- nebula
When editing your map you can have the problem where you need to constantly select tiles and place them. This system reads the map and automatically places the correct tile.
I first noticed this system in that old game Sim City. Where you build your road and it would magically connect to other roads nearby. This example does just that.
This example can be used for multiple purposes. Lets say for Coast tiles and other tiles that need to connect to one and another.
 
Title: Alpha with optional from/to x/y parameters Code Submitted By:
- tonyg
Built from AshCroftMan's code...
http://www.blitzcoder.com/cgi-bin/code/code_showentry.pl?id=ashcroftman05202002015304&comments=no
Ignores pixels the same colour as mask value and adds from/to x/y to display portion of image in alpha.
 
Title: Alternating Tiles Code Submitted By:
- radiumgames

Changes the style of the tile designated when creating a map every time the game is loaded to change the scenery a bit. Also changes locations of trees
 
Title: Angle finder Code Submitted By:
- abraham
A function that finds the angle between two co-ordinates in 2D
 
Title: Arc functions Code Submitted By:
- thechange

Two functions to draw a single width arc - e.g. portion of outer edge of circle - using either Line or WritePixelFast, with specified position, radius, arc angle, optional offset angle and extra for ArcFrame; an optional RGB value.
 
Title: Array iteration techniques Code Submitted By:
- thechange
Demonstrating iteration/looping through a 1 and 2 dimensional array using 1 or 2 loops starting from either 0 or 1.
 
Title: Asteroids Physics Library Code Submitted By:
- darkeagle
this is an EXTREMELY nice lib for lots of things... space games, hovercraft games, etc. basically anything that you want to have asteroids type ship control in :) just remember who gave it to ya ;)
 
Title: Basic Asteroids demo code Code Submitted By:
- darkeagle
Some quick demo code which shows the physics of an Asteroids game. This code will be editited and messed around with for use in my upcoming tutorial :D
 
Title: Best of the Best, Repeated use Flat-Shaded Triangle Code Submitted By:
- guybrushniveek
The FASTEST(until proven otherwise) Flat-Shaded Triangle drawer.
(I am making a faster one as we speak, should ust about draw BIG triangles at about double the speed.)

NOTE : I am talking about lots of Triangles being drawn, and not just one or two...
I know using RECT for scanlines will draw 1 or 2 triangles faster than this, but try and run through a thousand triangles. Ah-ha.
 
Title: Coloured TEXT with OUTLINE Code Submitted By:
- da_hobo_hen
This function displays your text, in the current drawing colour, then writes it (in your current font), with a 1 pixel thick black background.

I found this code usefull, and hope you do too.

Just call txt(xpos,ypos,txt$,centeredx,centeredy)
xpos is x posisiton (pixels)
ypos is y position (pixels)
txt$ is the text
centeredx is TRUE/FALSE/1/0 - to center horrizontally
centeredy is TRUE/FALSE/1/0 - to center verticallay
 
Title: Controlled animations using the 'millisecs' command. Code Submitted By:
- grim_1_2_3
This simple piece of animation code will allow you to run you're animations at the same speed on ANY computer, No matter how fast. It is a better method than using the 'waittimer' command to control the FPS.

Note: You Must use you're own images.

Fully commented!
 
Title: Create Rotation Frames Code Submitted By:
- ghost dancer

Basically a nifty little function which you use instead of LoadImage or LoadAnimImage. Specify how much you want to rotate the image by and how many times to rotate it - it will then create a new image object with all the new rotation frames.

For example, I've used this in my Galactus game. There is only one sprite for each ship - the function creates the rotation frames for me when the game is loaded :)
 
Title: Destructable outlined terrain Code Submitted By:
- darkeagle

destroy the terrain, and it gets outlined :)

numbers 1-4 choose size of the hole to create.

*DEFINATELY* not optimised... anyone gonna help me speed it up?? :)

enjoy!
 
Title: Digital Timer Code Submitted By:
- rhyswynne
Convert any time integer into digital timer format. Requires the digitimer Global mentioned at the top of the file (the other's are simply in the demo).
 
Title: Dragging windows Code Submitted By:
- thechange

Two very simple examples of dragging a single window (or rectangles) across the screen by using the mouse.
 
Title: Draw a turnip :O Code Submitted By:
- cyanide

lol draws your very own turnip (in a bad way)
 
Title: DrawImageRotated V0.1 Code Submitted By:
- ashcroftman
Pretty fast real-time, non filtered image renderer...

Use as you would normal draw image, with the added Angle par the only differance.
 
Title: Fading system/Gamma control Code Submitted By:
- thechange
Includes an automatic screen fade in/out system as well as accurate gamma control - Utilizing Blitz' gamma control functions which only work in fullscreen.
 
Title: Fat Functions Code Submitted By:
- andy_a

Add line thickness to Lines, Rects, Ovals, Stars, & Circles.
Rects & Ovals can be rotated in near real time (depending on thickness).
All without artifacts (holes) in the thick lines. Commented and has usage examples.

Updated. Now includes fatSuperEllipse() function. Check it out!
 
Title: Final Fantasy 7 Style messasges Code Submitted By:
- nys@
Like Final Fantasy 7 you can put a message everywhere in the screen with a blue(or change it!) color, delay time between letters, mesg color, on push or on time closing of the message.
These are the requirmente for the func:
x coordinates : y coordinates : mess$="Yuour mesg here!" : delay time between letters : red : green : blue : push(it can be true or a time in msec, it means the time that the message appear on the screen, or if "true" you have to push a button to close the message)
 
Title: Finding the difference between 2 angles. Code Submitted By:
- thechange
Included are 5 different ways to find the difference between 2 angles where 0 degrees means up.
 
Title: Function scrollXY Code Submitted By:
- 86it
Scroll background using a joypad in x,y cords
 
Title: Grayscale Code Submitted By:
- pexe
Turn your graphics to Grayscale Mode.

WARNING: This script is VERY SLOW!

Enjoy.
 
Title: Heat-seaking rocket Code Submitted By:
- the-mike

When the right mouse button is pressed, this will spawn random rockets (add a "rocket.bmp", a rocket faced like this: -->) of random speed and turning rate which will track the mouse. Useful in many 2D game engines!
 
Title: How to read RPG dialogs from a text file Code Submitted By:
- dragonmood

Say you want to read characters dialogs that you want to use in a game.
You ll need :
1- a way to store it -> I propose text file in this format :
[0.0.1]
This is chapter 0,section 0,conversation 1,line 1
This is chapter 0,section 0,conversation 1,line 2
[0.0.2]
This is chapter 0,section 0,conversation 2,line 1
etc...
2 - and a function to read it from a blitz application -> my code.
Feel free touse,Any comment is welcome.

 
Title: Join and Split Banks Code Submitted By:
- poedboy
Two functions for merging two banks into a single Bank, or splitting a single bank into two seperate banks.
 
Title: Map scroll based on large tiled image Code Submitted By:
- begemoth

I included little bit comments.
Please post comments to this code.
 
Title: Movement with sin & cos Code Submitted By:
- 86it

Some old functions from the days of "AMIGA®" I dont even
know if they are very good as I just started programming
with Blitz® on PC let me know If you like them every thing will be
in a zip file for download. ENJOY!
http://64.40.92.90
"AMIGA® and Blitz® Forever"
Thanks Guys for the support for my Blitz® v1.83
 
Title: Panels have borders Code Submitted By:
- cyberseth
BlitzPlus undocumented "style" property for panels. Allows the addition of borders to panels.
 
Title: Pie functions Code Submitted By:
- thechange

Two functions for drawing either a filled pie or hollow (outline) pie - e.g. a specified section of a circle - with specified angle of pie, optional offset angle, radius, position and extras for filled pie; optional color and optional range checking parameters.
 
Title: Powerbar Example Code Submitted By:
- nacho daddy

This an example of a powerbar that I came up with for some mini-games I will be making. One example would be to let the user choose how hard they want to kick a ball. It just goes up and down, and when you click the mouse button(which can be changed to fit your programming needs), the power level is recorded and you can proceed with the game.
 
Title: Random Dirt Generator Code Submitted By:
- oracle
Here is a random dirt generator for games like Worms or Scorched Earth!
##Needs to be optimized for proper use!##
 
Title: Really fast tokens function Code Submitted By:
- kris_a
Tokenise a string in 10 lines!
 
Title: Realtime scaling Code Submitted By:
- nullmind

This is (i belive) the fastest way to draw a scaled image in realtime. It doesnt use any pixel commands.

Tested this on my 900mhz 256MB Geforce2MX (PCI). It can draw a 128x128 image resized to 640x480 in 9ms, ever loop without any pre-rendering or caching.

It does now use a scratch image created in the main game loop :) To save from creating a new image and freeing it everytime.
 
Title: Realtime screen fades Code Submitted By:
- thechange

Fade-in/out routines for Blitz2D, being variations of Snarty's fading routines, which use prebuffering and intelligent pixelwrites to squeeze that extra bit of frames out of your computer.
 
Title: Realtime transparency using dithered blending Code Submitted By:
- thechange

An alternative way to use fast transparency in 2D is to apply a mask of transparent pixels to an image.
 
Title: Replaying user input using a collection of Types Code Submitted By:
- matt_sephton
23/24 June 2002, version 0.10, tracks user controlled element
26/27 June 2002, version 0.20, tracks multiple computer controlled elements

to do: enable early quit of replay to go back to game

*** feel free to use this method as long as you give me credit

this method can be used to replay user input. this simple demo records the player control of a dot. we choose to do the correct branch of the main loop (moving or drawing) depending on if we are recording (game) or replaying (watching). this could be extended to keep track of multiple items, such as computer/AI controlled characters.

:) matt
 
Title: Res-changing code -- Can be added to any program easily Code Submitted By:
- grim_1_2_3
This piece of code basically allows you to change between resolutions easily, at any time during the program. More resolutions can be added by simply adding a few lines of code. Right now it has 3: 640 by 480, 800 by 600, and 1024 by 768. Fully commented.

Note: You must use you're own images, Since none are included with the code.

Also, Please don't be put off by all of the text in the code -- Most of it is comments, LOL -- I guess I over-did it a little :) I wanted it to be easy for everyone to understand though. Anyway -- If you delete the commented lines, You will find that the code is a LOT smaller.
 
Title: Scariest routine Code Submitted By:
- grim_1_2_3

This is just something I'm posting for fun. It is the routine which checks for a check status in a chess game I started writing a long time ago. It is 5,502 lines...!! This is one single function.
 
Title: Showing walking animations various views when directions change using the arrow keys Code Submitted By:
- grim_1_2_3
This is a sample animation program which will let you move an animated character around the screen,While the different views of the character are being animated -- Sorry, you have to use you're own animations!

Replace the backgound image with one of you're own, and replace the movanim animation with you're own to see how the program works :)

Note: I know this code is quite sloppy, And much longer than it should be, But I wrote it in a hurry just to test out some animations of my own a while back. Should still be usefull to someone :)

Fully commented!
 
Title: Simple Sin/Cos movement Code Submitted By:
- xiyo
This is just a simple "car-like" movement code. I have seen that it has been requested many times in the forums so..
 
Title: Simple shoot'em up Code Submitted By:
- thechange

Dynamic shoot'em up engine demo.
 
Title: Simple tilemap demo Code Submitted By:
- thechange

Showing the inner workings of a tilemap.
Something I found from back in Feb 2002.
 
Title: Some Image Functions Code Submitted By:
- cloudnine

Just in case you wanted to attach a handle to an image, instead of changing the image itself. If the image is not already loaded, it will load it
 
Title: Sprite Ripper - simple Code Submitted By:
- onemanband
Something i coded in 15 minutes to save time ripping placeholder gfx for my insanely megalomaniac projects.
It simply compares colors of pixels in two graphic files and creates a third gfx file where all the same colored pixels are replaced with a single color. Use it, tweak it, whatever.
 
Title: Static Code Submitted By:
- genexi2

Small piece of code used to create random static pics. and displays them.
 
Title: String Manipulation Library Code Submitted By:
- coderlaureate

I use this library in many of my Blitz programs that require intense parsing of string information.
 
Title: Super fast image rotation Code Submitted By:
- badjim

These functions work a bit like the RotateImage command, but they are fast enough for realtime use. They rotate around the image handle and do not resize the image. They clip some of the image off so you may need a transparent border around the image to prevent vital parts being chopped off.
There are two versions. A two pass version that is fast but has really bad clipping at
90 degree angles, and a three pass version that is slower (but still pretty quick) but doesn't clip too much of the image off at any angle.
 
Title: Super mario 2 tm example map collision example. Code Submitted By:
- wingsoffury
Support unlimited of blocks. and no speed slow downs !
smooth camera movemnt in 2d.
good collision rutine. that can check anny spot withing an integer.
in source map. for simple edit
use left,right,upp on keyboard.
 
Title: TGA's Code Submitted By:
- poedboy
Allows you to Create, Modify, Save, and Load tga's with alpha information. Works in blitz 2d, 3d, and plus.
 
Title: Tank (Destruct) Code Submitted By:
- thechange

Game tech demo, being a Destruct-clone (hidden minigame in Tyrian), to demonstrate destructable terrain (2D). Shows just the basics.
 
Title: Tetris (classic) Code Submitted By:
- thechange

An uncomplicated version of a classic tetris conversion.
 
Title: Text Effects Code Submitted By:
- rhyswynne
This code includes a demo of all of the text effects. They are dropped shadow, 3d, and gradient text. Relatively simple to follow, and a nice effect.
 
Title: The way of pong Code Submitted By:
- thechange

Demonstration of pong collisions without (complicated) maths.
 
Title: Types within Types Code Submitted By:
- skn3_acoders

You can do types within types with a little bit of pre work making some functions.

Check it out !
 
Title: Updating mouse coordinates when mouse leaves window Code Submitted By:
- cyberseth
With the help of a userlib, shows how to continue checking for mouse position even when mouse has gone outside of the window area. Important for windowed games!
 
Title: Vector Graphics Lib With Collisions Code Submitted By:
- darkeagle
use vector graphics easily, and check collisions. useful for if you are doing 2d in 3d and are having trouble with collisions - just set up a basic shape for each sprite you are using, then use VectorsCollide() to check for collisions! even includes scaling and rotation :)
 
Title: Vector Matrix Conversion - 2D Angle <-> Coords Code Submitted By:
- thechange

Basically 4 functions to convert from X/Y coordinates to Length/Angle and vise versa. A must for 2D space shooters and related mathematics. The major part of the code contains fun games/examples on how to use the functions, including 2D space physics.
 
Title: ai Wander source code Code Submitted By:
- alias jargon
makes crap wander.
no comments.
most likely you wont be able to modify and still work unless you are a blitz guru.
must create your own "kite.bmp" image.
if it dont work use:
Global sd=16
...or else just use that instead to be on the safe side.
 
Title: compText Code Submitted By:
- adam eavy

A Small Piece Of Code That Enables Any Text Within The Message Section To Be Printed To The Screen One Letter At A Time WIth A Small Delay Between Each Letter. Remember The Film Matrix? Its Kinda Like That!
 
Title: drawImageAlpha V1.1 (Added clipping, lut) Code Submitted By:
- ashcroftman
Mimics the original draw image command, except it now has alpha blending. Looks just about right..

V1.1 Should be alot faster now on a good cpu.
 
Title: perfect collisions!! (Best collision for stopping an object when it collides with another) *updated!!* Code Submitted By:
- grim_1_2_3

The reason I say this is the best collision code for making an object stop next to the object being collidied with, Is simply because it works regardless of how many pixels at a time you are moving the object across the screen, And it STILL detects even 1 pixel!!! Anywayz, You will need to replace the 2 images in the code with you're own to see how it works. Change the variable for 'dspeed' to however fast(number of pixels) you want the object to move across the screen when you use the keys to move it.

Note: You can now use floats for the dspeed also :)
 
Title: position 3d sprites with 2d co-ords Code Submitted By:
- darkeagle

lets you say "i want bloke A at screen co-ords 400,218. but i want alpha and real time scaling/rotating aswell!.
 
Add Your Code!
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.

Code software created by Krylar's Kreations