TGC Codebase Backup



2D character controller basics by DeadTomGC

12th Mar 2011 23:13
Summary

This is demo code for jump, left, and right control and collisions for a 2D game Character.



Description

This is demo code for jump, left, and right control and collisions for a 2D game Character.
Main uses the methods in the attached header to perform smooth sliding collisions with a another sprite. 3 sprites are used. One for the collision and another for drawing the character. The third is a static Sprite that the character will collide with.

The screen shot is old, and, oh ya, I need to make some changes to make the code more versatile, so I'll be on that soon.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    #include "methjump.h"



void DarkGDK ( void )
{
	
	dbSyncOn   ( );
	dbSyncRate ( 60 );


	dbLoadImage("sprite.bmp",1);
	dbSprite(1,0,0,1);//collision
dbSprite(2,0,0,1);//visual
dbHideSprite(1);
dbSizeSprite(1,dbSpriteWidth(2)-2,dbSpriteHeight(2)-2);//give a one pixel margin
dbSprite(3,0,200,1);//////////////////

	while ( LoopGDK ( ) )
	{
		
		jump();
		leftright();
		dbSprite(2,x-1,y-1,1);//sync the images
		if ( dbEscapeKey ( ) )
			break;

		
		dbSync ( );
	}

	
	return;
}