All pastes #517204 Raw Edit

Mario

public c v1 · immutable
#517204 ·published 2007-05-29 00:08 UTC
rendered paste body
/* Mario interpreter for the iPod * Written from scratch by Joseph Constan (Saintjimmy5294) * This is just an Early Alpha Release, but * I plan to have the Interpreter open an external text file * with level data in it and load the level from there. * I haven't done it yet (still confused a bit w/ file pointers) * But until then, It's just a simple Mario Game, demo, thingy. *//* Oh, and special thanks to * zacaj, for the idea * Mike Sweeney (ichaelmay8), for writing iBolo,  * whose level loading system I based mine off of ;) * Nintendo, for wowing the world with the invention of Mario, * Apple, for making the iPod, * And, of course, the iPodlinux team, without whom this would not be possible. *///May 17, 2007, in this program, I wrote my first 1,000 lines of code. This one's goin' in the baby book :D#include <stdio.h>#include <stdlib.h>#include <math.h>#include "pz.h"#include <errno.h>#include <string.h>#define LBLUE 0, 240, 255							//defines value for teh color Light Blue#define SHEIGHT (ttk_screen->h - ttk_screen->wy)    //sets SHEIGHT to the height of the screen#define SHWIDTH (ttk_screen->w)						//sets SWIDTH to the height of the screenstatic PzModule *module;/*images (for the ones with arrays, ie. goomba[2], the number represents the frames)*/static ttk_surface small_mario_left[2];		//small mario facing left static ttk_surface small_mario_right[2];	//small mario facing rightstatic ttk_surface mario_left[3];			//mario facing leftstatic ttk_surface mario_right[3];			//mario facing rightstatic ttk_surface flower_mario_left[3];	//flower mario facing leftstatic ttk_surface flower_mario_right[3];	//flower mario facing rightstatic ttk_surface mario_crouch_right;		//mario crouching & facing rightstatic ttk_surface mario_crouch_left;		//mario crouching & facing leftstatic ttk_surface goomba[2];			//goombastatic ttk_surface goomba_squish;		//goomba squishedstatic ttk_surface gkoopa_l[2];			//green koopa facing leftstatic ttk_surface gkoopa_r[2];			//green koopa facing rightstatic ttk_surface rkoopa_l[2];			//red koopa facing leftstatic ttk_surface rkoopa_r[2];			//red koopa facing rightstatic ttk_surface redshell[4];			//red shell spinningstatic ttk_surface greenshell[4];		//green shell spinningstatic ttk_surface ground;			//image of ground (brick)static ttk_surface block;			//coin blockstatic ttk_surface qblock[4];		//question mark (powerup) blockstatic ttk_surface coin[4];			//coin imagestatic ttk_surface mushroom;		//mushroomstatic ttk_surface 1up;				//green mushroom (extra life)static ttk_surface flower;			//power flower//static ttk_surface star[4];		//star for to give you teh invinsiblity!!!11!1!!static ttk_surface fireball[4];	//OH NOES!! T3h f1r3b4l1 0f z3h d34th!!1! run 4w4yz!/*variable declarations (brace yourself there's a lot of them)*/static int mario_x;				//x coordinate of mariostatic int mario_y;				//y coordinate of mariostatic int goomba_x[10];			//x coordinate of goombastatic int goomba_y[10];			//y coordinate of goombastatic int gkoopa_x[10];			//x coordinate of teh green koopastatic int gkoopa_y[10];			//y coordinate of teh green koopastatic int rkoopa_x[10];			//x coordinate of teh red koopastatic int rkoopa_y[10];			//y coordinate of teh red koopastatic int ground_x[100];			//x coordinate of the groundstatic int ground_y[100];			//y coordinate of the groundstatic int block_x[100];			//x coordinate of blockstatic int block_y[100];			//y coordinate of blockstatic int qblock_x[100];			//x coordinate of question mark blockstatic int qblock_y[100];			//y coordinate of question mark blockstatic int coin_x[100];				//x coordinate of coinstatic int coin_y[100];				//y coordinate of coinstatic int mushroom_x;				//I think you get the idea by now, if not, get some helpstatic int mushroom_y;static int 1up_x;static int 1up_y;static int flower_x;static int flower_y;//static int star_x;//static int star_y;static int fireball_x[2];static int fireball_y[2];static int start_x;static int start_y;static int end_x;static int view_x=0;				//left end of viewport				static int view_y=0;				//bottom of viewportstatic int view_w=SWIDTH;			//width of viewport, automatically set to the width of the iPod's screenstatic int view_h=SHEIGHT;			//height of viewport, automatically set to the height of the iPod's screenstatic int eframe=0;				//frame for the animation of koopas and goombasstatic int mframe=0;				//frame for the animation of mariostatic int mdirection;				//direction mario [0], green koopa [1] or red koopa [2] is facing, 1=left. 2=rightstatic int mwalk=0;					//if mario is moving (running or walking), 1=yes, 0=nostatic int mjump=0;					//if mario is jumping, 1=yes, 0=nostatic int mrun=0;					//if mario is running, 1=running, 0=walkingstatic int mcrouch=0;				//if mario is crouching, 1=yes, 0=nostatic int invincible=0;			//if mario is unnnnn-tuchablestatic int fallpt;					//when mario starts falling after he jumpsstatic int onground;				//if mario is on the groundstatic int buttondown[5]={0,0,0,0,0};	//if button is down, 1=yes, 2=no; [0]=select, 1=menu, 2=prev, 3=next, 4=downstatic int rkoopa_direction[10]=;static int gkoopa_direction[10];static int i=0, j=0, k=0, l=0, m=0, n=0, o=0, s=0, t=0, u=0, v=0, w=0, a=0, b=0;	//don't askstatic int goomba_state[10];		/*whether goomba is alive (1), squished (2), or dead(0)*/static int rkoopa_state[10];		/*whether red koopa is alive (1), in shell (2), or dead(0)*/static int gkoopa_state[10];		/*whether green koopa is alive (1), in shell (2), or dead(0)*/static int item_state[4]={1,1,1,1};		/*whether item is unused (item_state[]=1) or used(=0).										Array: [1] - mushroom, [2] - green mushroom, [3] - power flower, [0] - star*/static int item_direction[3]={1,1,1};	//self explanatory, 1=left, 2=right, [0] - mushroom, [2] - green mushroom, [0] - starstatic int block_state[100];		//whether block is unhit (block_state[]=1, being hit(2), or hit(=0)static int qblock_state[100];		//same as abovestatic int coin_state[100];			//same as abovestatic int mario_state=1;		//whether mario is small (1), big (2), flower (3), or, heaven forbid, dead (0)static int mxspeed=0;			//mario's horizontal speedstatic int myspeed=0;			//No, not "my speed", mario's vertical speedstatic int rkxspeed[10];			//red koopa's horizontal speedstatic int rkyspeed[10];			//red koopa's vertical speedstatic int gkxspeed[10];			//green koopa's horizontal speedstatic int gkyspeed[10];			//green koopa's vertical speedstatic int gxspeed[10];			//goomba's horizontal speedstatic int gyspeed[10];			//goomba's vertical speedstatic int lives=3;static int coins=0;static int score=0;static int lvl_width=20;static int lvl_height=14;static int lvl_tiles=lvl_width*lvl_height;static char leveldata1[lvl_tiles]={ .,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,								    .,Q,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,., 								    .,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,								    C,C,C,C,C,C,.,.,.,.,.,.,.,.,.,.,.,.,.,.,									    B,B,B,B,B,B,C,.,.,.,.,.,.,.,.,.,.,.,.,.,								    .,.,.,.,.,.,B,C,.,.,.,.,.,.,.,.,.,.,.,.,								    .,.,.,.,.,.,.,B,C,.,.,.,.,.,.,.,.,.,.,.,									    .,.,.,.,.,.,.,.,B,.,.,.,.,r,.,.,.,.,.,.,									    .,.,.,.,.,.,.,.,.,B,B,B,B,B,B,.,.,.,.,.,	//The Leveldata is the information 								    .,Q,B,.,.,.,.,.,.,.,.,.,.,.,.,.,.,B,.,.,	//used to load the level, such as								    .,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,B,B,.,.,	//locations of start and end loca-								    S,.,.,.,B,g,.,.,.,k,.,B,C,C,C,B,B,B,.,E,	//tions. It uses an array based on								    G,G,G,G,G,G,G,G,G,G,G,G,G,G,G,G,G,G,G,G,	//the size of the level, which is								    G,G,G,G,G,G,G,G,G,G,G,G,G,G,G,G,G,G,G,G};	//height * width.//Done with declarations, starting the game (sorta)static void draw_mario(PzWidget *wid, ttk_surface srf){	int i=0;	int j=0;	int k=0;	int l=0;	int m=0;	int n=0;	int o=0;	int x=0;	int y=0;	int tilex=0;	int tiley=0;	ttk_fillrect (srf, 0, 0, SWIDTH, SHEIGHT, ttk_makecol(LBLUE));	//fills the screen with the color (LBLUE = light blue) defined above	/*Level Drawing (I'm confused on this part and will probably screw up, but bear with me here) (Most of the stuff is explained in the block functiony thingy)*/		while(y<lvl_width)				{				if(leveldata1[x]==G)//ground				{				        						if(ground_x[i]>view_x && ground_x[i]<view_x+view_w && ground_y[i]>view_y && ground_y[i]<view_y+view_h) 						{							ttk_blit_image (ground, srf, ground_x[i] - view_x, ground_y[i] - view_y);							ground_y=tiley;							ground_x=tilex;						}						i++;						if(i=99)						i=0;				}              				if(leveldata1[x]==S)//start point				{						start_x=tilex;						start_y=tiley;				}				if(leveldata1[x]==E)//end point				{						end_x=tilex;						end_y=tiley;				}				if(leveldata1[x]==B && block_state[j]!=0)//regular block				{												if(block_x[j]>view_x && block_x[j]<view_x+view_w && block_y[j]>view_y && block_y[j]<view_y+view_h && block_state[j]!=0) //checks if the block is on the screen (if it only has to worry about stuff thats on the screen, it saves a lot of memory and stuff (thats how Nintendo did it ;D))						{							block_x[j]=tilex;			//sets the block's x coordinate (block_x) to the tile it is currently checking							block_y[j]=tiley;			//sets the block's y coordinate to the current tile							if(block_state[j]==1)		//if the block is not broken							ttk_blit_image (block, srf, block_x[j] - view_x, block_y[j] - view_y);	//draws the image							else if(block_state[j]==2)	//if block is being hit							{							ttk_blit_image (block, srf, block_x[j] - view_x - 4, block_y[j] - view_y - 4);	//draws the image 4 px higher than usual							}						}						j++;		//with all this code, I almost look like I know what I'm doing :-()						if(j==99)						j=0;				}				if(leveldata1[x]==Q)//[?] powerup block				{						if(qblock_x[k]>view_x && qblock_x[k]<view_x+view_w && qblock_y[k]>view_y && qblock_y[k]<view_y+view_h) 						{							qblock_x[k]=tilex;							qblock_y[k]=tiley;							if(qblock_state[k]=1)							ttk_blit_image (qblock[qframe], srf, qblock_x[k] - view_x, qblock_y[k] - view_y);							else if(qblock_state[k]==2)							{							ttk_blit_image (qblock[qframe], srf, qblock_x[k] - view_x - 5, qblock_y[k] - view_y - 5);							}							else							ttk_blit_image (usedblock, srf, qblock_x[k] - view_x, qblock_y[k] - view_y);						}						k++;						if(k==99)						k=0;				}				if(leveldata1[x]==C && coin_state[l]!=0)//coin				{						if(coin_x[l]>view_x && coin_x[l]<view_x+view_w && coin_y[l]>view_y && coin_y[l]<view_y+view_h) 						{							coin_x[l]=tilex;							coin_y[l]=tiley;							ttk_blit_image (coin[qframe], srf, coin_x[l] - view_x, coin_y[l] - view_y);							l++;						}						if(l==99)						l=0;				}				if(leveldata1[x]==g)//goomba				{				        if(goomba_x[m]>view_x && goomba_x[m]<view_x+view_w && goomba_y[m]>view_y && goomba_y[m]<view_y+view_h)						{						goomba_x[m]=tilex;						goomba_y[m]=tiley;						m++;						}						if(m==9)						m=0;				}				if(leveldata1[x]==r)//red koopa				{				        if(rkoopa_x[n]>view_x && rkoopa_x[n]<view_x+view_w && rkoopa_y[n]>view_y && rkoopa_y[n]<view_y+view_h)						{						rkoopa_x[n]=tilex;						rkoopa_y[n]=tiley;						n++;						}						if(n==9)						n=0;				}				if(leveldata1[x]==k)//green koopa				{				        if(gkoopa_x[o]>view_x && gkoopa_x[o]<view_x+view_w && gkoopa_y[o]>view_y && gkoopa_y[o]<view_y+view_h)						{						gkoopa_x[o]=tilex;						gkoopa_y[o]=tiley;						o++;						}						if(o==9)						o=0;				}				x++;				tilex=tilex+16;				if(tilex==144)				{					tilex=0;					y++;					tiley=tiley+16;				}	}draw_images();mario_x=start_x;mario_y=start_y-12;	if(t=1 && ((fireball_x[0]!>view_x && fireball_x[0]!<view_x+view_w && fireball_y[0]!>view_y && fireball_y[0]!<view_y+view_h) || (fireball_x[1]!>view_x && fireball_x[1]!<view_x+view_w && fireball_y[1]!>view_y && fireball_y[1]!<view_y+view_h)))t=0;if(mwalk==1 && mrun==0 && mdirection=2)	//mario is walking right (but not running cuz he might trip :o)mxspeed=4;if(mwalk==1 && mrun==1 && mdirection=2)	//mario is running right (but be careful now, don't go too fast ;))mxspeed=6;if(mwalk==1 && mrun==0 && mdirection=1)	//mario is walking leftmxspeed=-4;if(mwalk==1 && mrun==1 && mdirection=1)	//mario is running leftmxspeed=-6;if(mwalk==0)								//mario's a just standin der, chillinmxspeed=0;if(mjump==1 && onground==1)					//mario wants to jump and is on the ground{	fallpt=mario_y-64;	myspeed=4;}if(mario_x>=fallpt)						//the (fake and badly coded) gravity kicks in and mario starts to fallmyspeed--;if(myspeed<-4)							//caps the vertical speedmyspeed=-4;if(myspeed>4)							//caps (the other end of) the vertical speedmyspeed=4;if(mario_state!=0 && myspeed!=0) //mario is not on the groundmario_y=mario_y-myspeed;if(mario_state!=0 && mxspeed!=0)mario_x=mario_x+mxspeed;if(onground=0 && myspeed<=0 && myspeed!=-4)//there's probably a better way to do this, I'm just too lazy to figure it outmyspeed--;if(mario_state==1)		//Mario is small{	if(mario_x<ground_x[u]+16 && mario_x+16>ground_x[u] && mario_y+19<=ground_y[u]+16 && mario_y+19>=ground_y[u])	//mario is on a block of ground	onground=1;	if(mario_x<block_x[u]+16 && mario_x+16>block_x[u] && mario_y+19<=block_y[u]+16 && mario_y+19>=ground_y[u])	//mario is on a block	onground=1;	if(mario_x<qblock_x[u]+16 && mario_x+16>qblock_x[u] && mario_y+19<=qblock_y[u]+16 && mario_y+19>=ground_y[u])	//mario is on a [?] block	onground=1;	else	onground=0;	if(mario_x>=rkoopa_x[v]-16 && mario_x<=rkoopa_x[v]+8 && mario_y+19>=rkoopa_y[v] && mario_y+19<=rkoopa_y[v]+16 && myspeed<0)	{		if(rkoopa_state[v]==1)		{			if(mario_y+19>rkoopa_y[v]+8 && myspeed<0)			{				mario_state=0;			}			else			{				myspeed=4;				rkoopa_state[v]=2;			}		}		else if(rkoopa_state[v]==2)		{			if(mario_y+19>rkoopa_y[v]+8 && myspeed<0)			{				mario_state=0;			}			else			{				rkxspeed[v]=-6;				myspeed=4;			}		}	}	if(mario_x>rkoopa_x[v]+8 && mario_x<=rkoopa_x[v]+16 && mario_y+19>=rkoopa_y[v] && mario_y+19<=rkoopa_y[v]+16 && myspeed<0)	{		if(rkoopa_state[v]==1)		{			if(mario_y+19>rkoopa_y[v]+8 && myspeed<0)			{				mario_state=0;			}			else			{				myspeed=4;				rkoopa_state[v]=2;			}		}		else if(rkoopa_state[v]==2)		{			if(mario_y+19>rkoopa_y[v]+8 && myspeed<0)			{				mario_state=0;			}			else			{				rkxspeed[v]=-6;				myspeed=4;			}		}	}	if(mario_x>=gkoopa_x[v]-16 && mario_x<=gkoopa_x[v]+8 && mario_y+19>=gkoopa_y[v] && mario_y+19<=gkoopa_y[v]+16 && myspeed<0)	{		if(gkoopa_state[v]==1)		{			if(mario_y+19>gkoopa_y[v]+8 && myspeed<0)			{				mario_state=0;			}			else			{				myspeed=4;				gkoopa_state[v]=2;			}		}		else if(gkoopa_state[v]==2)		{			if(mario_y+19>gkoopa_y[v]+8 && myspeed<0)			{				mario_state=0;			}			else			{				gkxspeed[v]=-6;				myspeed=4;			}		}	}	if(mario_x>gkoopa_x[v]+8 && mario_x<=gkoopa_x[v]+16 && mario_y+19>=gkoopa_y[v] && mario_y+19<=gkoopa_y[v]+16 && myspeed<0)	{		if(gkoopa_state[v]==1)		{			if(mario_y+19>gkoopa_y[v]+8 && myspeed<0)			{				mario_state=0;			}			else			{				myspeed=4;				gkoopa_state[v]=2;			}		}		else if(gkoopa_state[v]==2)		{			if(mario_y+19>gkoopa_y[v]+8 && myspeed<0)			{				mario_state=0;			}			else			{				gkxspeed[v]=-6;				myspeed=4;			}		}	}if(mario_x>=goomba_x[v]-16 && mario_x<=goomba_x[v]+16 && mario_y+19>=goomba_y[v] && mario_y+19<=goomba_y[v]+16 && myspeed<0)	{		if(myspeed<0)		{			myspeed=4;			goomba_state[v]=2;		}		else if(myspeed!<0)		{			mario_state=0;		}	}}if(mario_state==2 || mario_state==3)	//Mario is big or flower{	if(mario_x<ground_x[u]+16 && mario_x+16>ground_x[u] && mario_y+28<=ground_y[u]+16 && mario_y+28>=ground_y[u])	//mario is on a block of ground	onground=1;	if(mario_x<block_x[u]+16 && mario_x+16>block_x[u] && mario_y+28<=block_y[u]+16 && mario_y+28>=block_y[u])	//mario is on a block	onground=1;	if(mario_x<qblock_x[u]+16 && mario_x+16>qblock_x[u] && mario_y+28<=qblock_y[u]+16 && mario_y+28>=qblock_y[u]))	//mario is on a [?] block	onground=1;	else	onground=0;	if(mario_x>=rkoopa_x[v]-16 && mario_x<=rkoopa_x[u]+8 && mario_y+28>=rkoopa_y[v] && mario_y+28<=rkoopa_y[v]+16 && myspeed<0)	//mario landed on a red koopa	{		if(rkoopa_state[v]==1)		{			if(mario_y+28>rkoopa_y[v]+8 && myspeed<0)			{				mario_state=1;			}			else			{				myspeed=4;				rkoopa_state[v]=2;			}		}		else if(rkoopa_state[v]==2)		{			if(mario_y+28>rkoopa_y[v]+8 && myspeed<0)			{				mario_state=1;			}			else			{				rkxspeed[v]=-6;				myspeed=4;			}		}	}	if(mario_x>rkoopa_x[v]+8 && mario_x<=rkoopa_x[v]+16 && mario_y+28>=rkoopa_y[v] && mario_y+28<=rkoopa_y[u]+16 && myspeed<0)	{		if(rkoopa_state[v]==1)		{			if(mario_y+28>rkoopa_y[v]+8 && myspeed<0)			{				mario_state=1;			}			else			{				myspeed=4;				rkoopa_state[v]=2;			}		}		else if(rkoopa_state[v]==2)		{			if(mario_y+28>rkoopa_y[v]+8 && myspeed<0)			{				mario_state=1;			}			else			{				rkxspeed[v]=-6;				myspeed=4;			}		}	}	if(mario_x>=gkoopa_x[v]-16 && mario_x<=gkoopa_x[v]+8 && mario_y+28>=gkoopa_y[v] && mario_y+28<=gkoopa_y[v]+16 && myspeed<0)	{		if(gkoopa_state[v]==1)		{			if(mario_y+28>gkoopa_y[v]+8 && myspeed<0)			{				mario_state=1;			}			else			{				myspeed=4;				gkoopa_state[v]=2;			}		}		else if(gkoopa_state[v]==2)		{			if(mario_y+28>gkoopa_y[v]+8 && myspeed<0)			{				mario_state=1;			}			else			{				gkxspeed[v]=-6;				myspeed=4;			}		}	}	if(mario_x>gkoopa_x[v]+8 && mario_x<=gkoopa_x[v]+16 && mario_y+28>=gkoopa_y[v] && mario_y+28<=gkoopa_y[v]+16)	//Mario is touching the l eft side of the green koopa	{		if(gkoopa_state[v]==1)		{			if(mario_y+28>gkoopa_y[v]+8 && myspeed<0)			{				mario_state=1;			}			else			{				myspeed=4;				gkoopa_state[v]=2;			}		}		else if(gkoopa_state[v]==2)		{			if(mario_y+28>gkoopa_y[v]+8 && myspeed<0)			{				mario_state=1;			}			else			{				gkxspeed[v]=-6;				myspeed=4;			)		}	}	if(mario_x>=goomba_x[v]-16 && mario_x<=goomba_x[v]+16 && mario_y+28>=goomba_y[v] && mario_y+28<=goomba_y[v]+16 && goomba_state[v]==1)	{		if(myspeed<0)		{			myspeed=4;			goomba_state[v]=2;		}		else if(myspeed!<0)		{			mario_state=1;		}	}	if(mario_x>=mushroom_x-16 && mario_x<=mushroom_x+16 && mario_y+28>=mushroom_y && mario_y+28<=mushroom_y+16)	{	 mario_state=2;	 score=score+1000;	 item_state[1]=0;	}	if(mario_x>=1up_x-16 && mario_x<=1up_x+16 && mario_y+28>=1up_y && mario_y+28<=1up_y+16)	{	 lives++;	 score=score+1000;	 item_state[3]=0;	}	 if(mario_x>=flower_x-16 && mario_x<=flower_x+16 && mario_y+28>=flower_y && mario_y+28<=flower_y+16)	{	 mario_state=3;	 score=score+1000;	 item_state[3]=0;	}	if(mario_x>=coin_x[u]-16 && mario_x<=coin_x[u]+16 && mario_y+28>=coin_y[u] && mario_y+28<=coin_y[u]+16)	 {	  coins++;	  score=score+100;	  coin_state[u]=0;	 }}if(onground==1 && myspeed<0)	//If Mario is falling and hits the groundmyspeed=0;		//break the fall (so he doesn't go through the ground of course)if(mario_x<=block_x[u]+16 && mario_x+16>=block_x[u] && mario_y<=block_y[u]+16 && mario_y>=block_y[u] && myspeed>2)	//mario hits a block (from under it){myspeed=myspeed*-1;	//reverse vertical speedblock_state[u]=2;	//tell the computer that the block was hit but hasn't paid its coin yet}/*All the stuff for the viewport system*/if(view_x+(view_w/2)<mario_x && view_x+view_h!>lvl_width*16)view_x=view_x+mxspeed;if(view_x+(view_w/2)>mario_x && view_x!<0)view_x=view_x+mxspeed;if(view_y+(view_h/2)<mario_y && view_y+view_h!>lvl_height*16)view_y=view_y+myspeed;if(view_y+(view_h/2)>mario_y && view_y!<0)view_y=view_y+myspeed;/***************************************/if(rkoopa_state[v]!=0){	if(rkoopa_y[v]<block_y[w]+16 && rkoopa_y[v]>block_y[w]-16 && rkoopa_x[v]<=block_x[w] && rkoopa_x[v]>=block_x[w]-16 && )	{	rkxspeed[v]=rkxspeed[v]*-1;	if(rkoopa_state[v]=2)		block_state[w]=2;	}	else if(rkoopa_y[v]<block_y[w]+16 && rkoopa_y[v]>block_y[w]-16 && rkoopa_x[v]>=block_x[w] && rkoopa_x[v]<=block_x[w]+16)	{	rkxspeed[v]=rkxspeed[v]*-1;		if(rkoopa_state[v]=2)		block_state[w]=2;	}	else if(rkoopa_y[v]<qblock_y[w]+16 && rkoopa_y[v]>qblock_y[w]-16 && rkoopa_x[v]<=qblock_x[w] && rkoopa_x[v]>=qblock_x[w]-16)	{	rkxspeed[v]=rkxspeed[v]*-1;		if(rkoopa_state[v]=2)		qblock_state[w]=2;	}	else if(rkoopa_y[v]<qblock_y[w]+16 && rkoopa_y[v]>qblock_y[w]-16 && rkoopa_x[v]>=qblock_x[w] && rkoopa_x[v]<=qblock_x[w]+16)	{				rkxspeed[v]=rkxspeed[v]*-1;		if(rkoopa_state[v]=2)			qblock_state[w]=2;	}	else if(rkoopa_y[v]<ground_y[w]+16 && rkoopa_y[v]>ground_y[w]-16 && rkoopa_x[v]<=ground_x[w] && rkoopa_x[v]>=ground_x[w]-16)	{	rkxspeed[v]=rkxspeed[v]*-1;		}	else if(rkoopa_y[v]<ground_y[w]+16 && rkoopa_y[v]>ground_y[w]-16 && rkoopa_x[v]>=ground_x[w] && rkoopa_x[v]<=ground_x[w]+16)	{				rkxspeed[v]=rkxspeed[v]*-1;	}	/*this is the part where a red koopa is at the edge of a platform and turns around (badly coded cuz I'm tired, but it should do)*/	else if((rkoopa_y[v]+25!>ground_y[w] && rkoopa_y[v]+39!<ground_y[w] && rkoopa_x[v]!>ground_x[w] && rkoopa_x[v]!<ground_x[w]-16) && (rkoopa_y[v]+25!>block_y[w] && rkoopa_y[v]+39!<block_y[w] && rkoopa_x[v]!>block_x[w] && rkoopa_x[v]!<block_x[w]-16) && (rkoopa_y[v]+25!>qblock_y[w] && rkoopa_y[v]+39!<qblock_y[w] && rkoopa_x[v]!>qblock_x[w] && rkoopa_x[v]!<qblock_x[w]-16)	(		if(rkoopa_sttate[v]==1)		{		rkxspeed[v]=rkxspeed[v]*-1;		}		else if(rkoopa_state[v]==20		{		rkyspeed[v]=-4;		}	}	else if(w==99)	w=0;	else	w++;}if(gkoopa_state[u]!=0){	if(gkoopa_y[v]<block_y[a]+16 && gkoopa_y[v]>block_y[a]-16 && gkoopa_x[v]<=block_x[a] && gkoopa_x[v]>=block_x[a]-16)	{			gkxspeed[v]=gkxspeed[v]*-1;		if(gkoopa_state[v]=2)			block_state[a]=2;	}	else if(gkoopa_y[v]<block_y[a]+16 && gkoopa_y[v]>block_y[a]-16 && gkoopa_x[v]>=block_x[a] && gkoopa_x[v]<=block_x[a]+16)	{			gkxspeed[v]=gkxspeed[v]*-1;		if(gkoopa_state[v]=2)			block_state[a]=2;	}	else if(gkoopa_y[v]<qblock_y[a]+16 && gkoopa_y[v]>qblock_y[a]-16 && gkoopa_x[v]<=qblock_x[a] && rkoopa_x[v]>=qblock_x[a]-16)	{			gkxspeed[v]=gkxspeed[v]*-1;		if(gkoopa_state[v]=2)			qblock_state[a]=2;	}	else if(gkoopa_y[v]<qblock_y[a]+16 && gkoopa_y[v]>qblock_y[a]-16 && gkoopa_x[v]>=qblock_x[a] && gkoopa_x[v]<=qblock_x[a]+16)	{				gkxspeed[v]=gkxspeed[v]*-1;		if(gkoopa_state[v]=2)			qblock_state[a]=2;	}	else if((gkoopa_y[v]+25!>ground_y[a] && gkoopa_y[v]+39!<ground_y[a] && gkoopa_x[v]!>ground_x[a] && gkoopa_x[v]!<ground_x[a]-16) && (gkoopa_y[v]+25!>block_y[a] && gkoopa_y[v]+39!<block_y[a] && gkoopa_x[v]!>block_x[a] && gkoopa_x[v]!<block_x[a]-16) && (gkoopa_y[v]+25!>qblock_y[a] && gkoopa_y[v]+39!<qblock_y[a] && gkoopa_x[v]!>qblock_x[a] && gkoopa_x[v]!<qblock_x[a]-16)	{	gkyspeed=-4;	}	else if(a==99)	a=0;	else	a++;}if(qblock_state[u]==2){	if(mario_state==1)	{	mushroom_y=qblock_y[u]+16;	mushroom_x=qblock_x[u];	item_direction[1]=2;	qblock_state[u]=0;	}	if(mario_state==2 || mario_state==3	{	flower_y=qblock_y[u]+16;	flower_x=qblock_x[u];	qblock_state[u]=0;	}}if(block_state[u]==2)	{	ttk_blit_image (coin[0], srf, block_x[u], block_y[u]+16));	coins++;	block_state[u]=0;	}if(item_state[1]!=0){	if(mushroom_y<block_y[u]+16 && mushroom_y>block_y[u]-16 && mushroom_x<=block_x[u] && mushroom_x>=block_x[u]-16)	//mushroom hit the left of the block	{			item_direction[1]=2;	}	else if(mushroom_y<block_y[u]+16 && mushroom_y>block_y[u]-16 && mushroom_x>=block_x[u] && mushroom_x<=block_x[u]+16)	//mushroom hit the right of the block	{			item_direction[1]=1;	}	else if(mushroom_y<qblock_y[u]+16 && mushroom_y>qblock_y[u]-16 && mushroom_x<=qblock_x[u] && mushroom_x>=qblock_x[u]-16)	//mushroom hit the left of the [?] block	{			item_direction[1]=2;	}	else if(mushroom_y<qblock_y[u]+16 && mushroom_y>qblock_y[u]-16 && mushroom_x>=qblock_x[u] && mushroom_x<=qblock_x[u]+16)	//mushroom hit the right of the [?] block	{				item_direction[1]=1;	}	else if(v==99)	v=0;	else	v++;}v++;if(v==9)	v=0;u++;if(u==99)	u=0;if(mario_y==end_y)	{	level_won=1;	if(mario_y<end_y+321)	mario_y=mario_y-4;	}else	{	ttk_blit_image (win, srf, 0, 0);	game_over();	}}static void draw_images()	{		int p=0;		int q=0;		int r=0;						if(mushroom_x>view_x && mushroom_x<view_x+view_w && mushroom_y>view_y && mushroom_y<view_y+view_h && item_state[1]==1) 				{					ttk_blit_image (mushroom, srf, mushroom_x - view_x, mushroom_y - view_y);				}		if(flower_x>view_x && flower_x<view_x+view_w && flower_y>view_y && flower_y<view_y+view_h && item_state[3]==1) 				{					ttk_blit_image (flower, srf, flower_x - view_x, flower_y - view_y);				}		if(1up_x>view_x && 1up_x<view_x+view_w && 1up_y>view_y && 1up_y<view_y+view_h && item_state[3]==1) 				{					ttk_blit_image (1up, srf, 1up_x - view_x, 1up_y - view_y);				}		if(goomba_x[p]>view_x && goomba_x[p]<view_x+view_w && goomba_y[p]>view_y && goomba_y[p]<view_y+view_h && goomba_state[p]!=0) 				{					if(goomba_state[p]==1)					ttk_blit_image (goomba[eframe], srf, goomba_x[p] - view_x, goomba_y[p] - view_y);					else if(goomba_state[p]==2)					ttk_blit_image (goomba_squished, srf, goomba_x[p] - view_x, (goomba_y[p] + 8) - view_y);					p++;					if(p==9)						p=0;				}		if(gkoopa_x[q]>view_x && gkoopa_x[q]<view_x+view_w && gkoopa_y[q]>view_y && gkoopa_y[q]<view_y+view_h && gkoopa_state[q]!=0) 				{					if(gkoopa_state[q]==1)					{						if(gkoopa_direction[q]==1)						ttk_blit_image (gkoopa_l[eframe], srf, gkoopa_x[q] - view_x, gkoopa_y[q] - view_y);						if(gkoopa_direction[q]=2)						ttk_blit_image (gkoopa_r[eframe], srf, gkoopa_x[q] - view_x, gkoopa_y[q] - view_y);					}					else if(gkoopa_state[q]==2)						ttk_blit_image (greenshell[qframe], srf, gkoopa_x[q] - view_x, (gkoopa_y[q] - 9) - view_y);					q++;					if(q==9)						q=0;				}		if(rkoopa_x[r]>view_x && rkoopa_x[r]<view_x+view_w && rkoopa_y[r]>view_y && rkoopa_y[r]<view_y+view_h && rkoopa_state[r]!=0) 				{					if(rkoopa_state[r]==1)					{						if(rkoopa_direction[r]==1)						ttk_blit_image (rkoopa_l[eframe], srf, rkoopa_x[r] - view_x, rkoopa_y[r] - view_y);						if(rkoopa_direction[r]=2)						ttk_blit_image (rkoopa_r[eframe], srf, rkoopa_x[r] - view_x, rkoopa_y[r] - view_y);					}					else if(rkoopa_state[r]==2)						ttk_blit_image (redshell[qframe], srf, rkoopa_x[r] - view_x, (rkoopa_y[r] - 9) - view_y);					r++;					if(r==9)						r=0;				}		/*if(star_x[b]>view_x && star_x[b]<view_x+view_w && star_y[b]>view_y && star_y[b]<view_y+view_h) 				{					if(item_state[0]=1)					ttk_blit_image (star[qframe], srf, star_x - view_x, star_y - view_y);				}		*/		if(mario_x>view_x && mario_x<view_x+view_w && mario_y>view_y && mario_y<view_y+view_h)	//mario is on the screen				{					if(mdirection==1 && mario_state==1 && mwalk==1 && mcrouch==0)		//if mario is small and walking left					ttk_blit_image (small_mario_left[eframe], srf, mario_x - view_x, mario_y - (view_y + 9));		//blit (draw) the corresponding image					if(mdirection==1 && mario_state==1 && mwalk==0 && mcrouch==0)		//if mario is small and standing left					ttk_blit_image (small_mario_left[0], srf, mario_x - view_x, mario_y - (view_y + 9));					if(mdirection==1 && mario_state==2 && mwalk==1 && mcrouch==0)		//if mario is big and walking left					ttk_blit_image (mario_left[mframe], srf, mario_x - view_x, mario_y - view_y);					if(mdirection==1 && mario_state==2 && mwalk==0 && mcrouch==0)		//if mario is big and standing left					ttk_blit_image (mario_left[0], srf, mario_x - view_x, mario_y - view_y);					if(mdirection==1 && mario_state==3 && mwalk==1 && mcrouch==0)		//if mario has flower powers and is walking left					ttk_blit_image (flower_mario_left[mframe], srf, mario_x - view_x, mario_y - view_y);					if(mdirection==1 && mario_state==3 && mwalk==0 && mcrouch==0)		//if mario has flower powers and is standing left					ttk_blit_image (flower_mario_left[0], srf, mario_x - view_x, mario_y - view_y);					if(mdirection==2 && mario_state==1 && mwalk==1 && mcrouch==0)		//if mario is small and walking right					ttk_blit_image (small_mario_right[eframe], srf, mario_x - view_x, mario_y - view_y);					if(mdirection==2 && mario_state==1 && mwalk==0 && mcrouch==0)		//if mario is small and standing right					ttk_blit_image (small_mario_right[0], srf, mario_x - view_x, mario_y - (view_y + 9));					if(mdirection==2 && mario_state==2 && mwalk==1 && mcrouch==0)		//if mario is big and walking right					ttk_blit_image (mario_right[mframe], srf, mario_x - view_x, mario_y - (view_y + 9));					if(mdirection==2 && mario_state==2 && mwalk==0 && mcrouch==0)		//if mario is big and standing right					ttk_blit_image (mario_right[0], srf, mario_x - view_x, mario_y - view_y);					if(mdirection==2 && mario_state==3 && mwalk==1 && mcrouch==0)		//if mario has flower powers and is walking right					ttk_blit_image (flower_mario_right[mframe], srf, mario_x - view_x, mario_y - view_y);					if(mdirection==2 && mario_state==3 && mwalk==0 && mcrouch==0)		//if mario has flower powers and is standing right					ttk_blit_image (flower_mario_right[0], srf, mario_x - view_x, mario_y - view_y);					if(mdirection==1 && mcrouch==1)										//if mario is crouching and is facing left					ttk_blit_image (flower_mario_right[mframe], srf, mario_x - view_x, mario_y - view_y);					if(mdirection==2 && mcrouch==1)										//if mario is crouching and is facing right					ttk_blit_image (flower_mario_right[0], srf, mario_x - view_x, mario_y - view_y);								else if(mario_state=0)									//mario is dead-dead					ttk_blit_image (mario_dead, srf, mario_x - view_x, mario_y - view_y);				}				mframe++;		//changes frame for mario's animation		if(mframe==2)			mframe=0;				eframe++;		//changes frame for teh enemy animations,		if(eframe==1)	//and since koopas and goombas only have			eframe=0;	//2 frames, I only need 1 variable for them all :D.		qframe++;		if(qframe==3)			qframe=0;	}	static void mario_die(){//this is most definitely not a comment}static void game_over(){//DONT FORGET TO FINISH THIS FUNCTION!!!!!//if you are reading this, apparently I forgot, please notify me immediately.}static void mario_events(PzEvent *e){e->wid->dirty = 1;    int ret = TTK_EV_CLICK;    	switch(e->type)     {     	case PZ_EVENT_BUTTON_DOWN:		switch (e->arg)         {		       case PZ_BUTTON_ACTION:			        buttondown[0]=1;				    mrun=1;					if(mario_state==3)			        {					   if(t!=2)					   {					   fireball_x[t]=mario_x+16;					   fireball_y[t]=mario_y-16;					   t++;					   }					}						break;		       case PZ_BUTTON_MENU:			        buttondown[1]=1;				    mjump=1;                    break;                       case PZ_BUTTON_NEXT:                    mwalk=1;                    mdirection=2;					buttondown[3]=1;					break;		                 case PZ_BUTTON_PREVIOUS:                    mwalk=1;                    mdirection=1;                    buttondown[2]=1;					break;               case PZ_BUTTON_PLAY:                    buttondown[4]=1;					if(onground==1 && (mario_state==2 || mario_state==3))					{					mcrouch=1;					mario_y=mario_y-12;					}					break;		}		break;	case PZ_EVENT_BUTTON_UP:		switch (e->arg)         {		       case PZ_BUTTON_ACTION:			        buttondown[0]=0;				    mrun=0;					break;		       case PZ_BUTTON_MENU:			        buttondown[1]=0;				    mjump=0;                    break;                       case PZ_BUTTON_NEXT:                    mwalk=0;					buttondown[3]=0;					break;		                 case PZ_BUTTON_PREVIOUS:                    mwalk=0;                    buttondown[2]=0;					break;               case PZ_BUTTON_PLAY:                    buttondown[4]=0;					mcrouch=0;                    break;		}		break;		default:		ret = TTK_EV_UNUSED;		break;    }	return ret;}static PzWindow *new_mario_window(){	PzWindow *ret;	ret = pz_new_window(_("Mario"), PZ_WINDOW_NORMAL);	pz_add_widget(ret, draw_mario, mario_events);	return pz_finish_window(ret);}static void init_mario(){	/*Load the images and assign them to a surface.*/        module = pz_register_module("Mario", NULL);	pz_menu_add_action("/Extras/Games/Mario", new_mario_window);    small_mario_left[0] = ttk_load_image (pz_module_get_datapath (module, "smallmarioleft.png"));        small_mario_left[1] = ttk_load_image (pz_module_get_datapath (module, "smallmarioleft2.png"));    	small_mario_right[0] = ttk_load_image (pz_module_get_datapath (module, "smallmarioright.png"));        small_mario_right[1] = ttk_load_image (pz_module_get_datapath (module, "smallmarioright2.png"));    mario_left[0] = ttk_load_image (pz_module_get_datapath (module, "marioleft.png"));        mario_left[1] = ttk_load_image (pz_module_get_datapath (module, "marioleft2.png"));   	mario_left[2] = ttk_load_image (pz_module_get_datapath (module, "marioleft3.png"));	mario_right[0] = ttk_load_image (pz_module_get_datapath (module, "marioright.png"));        mario_right[1] = ttk_load_image (pz_module_get_datapath (module, "marioright2.png"));    	mario_right[2] = ttk_load_image (pz_module_get_datapath (module, "marioright3.png"));		mario_crouch_left = ttk_load_image (pz_module_get_datapath (module, "mariocrouchright.png"));    	mario_crouch_right = ttk_load_image (pz_module_get_datapath (module, "mariocrouchleft.png"));	flower_mario_left[0] = ttk_load_image (pz_module_get_datapath (module, "flowermarioleft1.png"));        flower_mario_left[1] = ttk_load_image (pz_module_get_datapath (module, "flowermarioleft2.png"));   	flower_mario_left[2] = ttk_load_image (pz_module_get_datapath (module, "flowermarioleft3.png"));	flower_mario_right[0] = ttk_load_image (pz_module_get_datapath (module, "flowermarioright1.png"));        flower_mario_right[1] = ttk_load_image (pz_module_get_datapath (module, "flowermarioright2.png"));    	flower_mario_right[2] = ttk_load_image (pz_module_get_datapath (module, "flowermarioright3.png"));	mario_dead = ttk_load_image (pz_module_get_datapath (module, "mariodead.png"));    goomba[0] = ttk_load_image (pz_module_get_datapath (module, "goomba1.png"));        goomba[1] = ttk_load_image (pz_module_get_datapath (module, "goomba2.png"));        goomba_squish = ttk_load_image (pz_module_get_datapath (module, "goomba_squished.png"));        gkoopa_l[0] = ttk_load_image (pz_module_get_datapath (module, "greenkoopaleft.png"));        gkoopa_l[1] = ttk_load_image (pz_module_get_datapath (module, "greenkoopaleft2.png"));	gkoopa_r[0] = ttk_load_image (pz_module_get_datapath (module, "greenkooparight.png"));        gkoopa_r[1] = ttk_load_image (pz_module_get_datapath (module, "greenkooparight2.png"));    rkoopa_l[0] = ttk_load_image (pz_module_get_datapath (module, "redkoopaleft.png"));        rkoopa_l[1] = ttk_load_image (pz_module_get_datapath (module, "redkoopaleft2.png"));	rkoopa_r[0] = ttk_load_image (pz_module_get_datapath (module, "redkooparight.png"));        rkoopa_r[1] = ttk_load_image (pz_module_get_datapath (module, "redkooparight2.png"));		greenshell[0] = ttk_load_image (pz_module_get_datapath (module, "greenshell1.png"));	greenshell[1] = ttk_load_image (pz_module_get_datapath (module, "greenshell2.png"));	greenshell[2] = ttk_load_image (pz_module_get_datapath (module, "greenshell3.png"));	greenshell[3] = ttk_load_image (pz_module_get_datapath (module, "greenshell4.png"));		redshell[0] = ttk_load_image (pz_module_get_datapath (module, "redshell1.png"));	redshell[1] = ttk_load_image (pz_module_get_datapath (module, "redshell2.png"));	redshell[2] = ttk_load_image (pz_module_get_datapath (module, "redshell3.png"));	redshell[3] = ttk_load_image (pz_module_get_datapath (module, "redshell4.png"));    ground = ttk_load_image (pz_module_get_datapath (module, "brick.png"));        block = ttk_load_image (pz_module_get_datapath (module, "block.png"));        qblock[0] = ttk_load_image (pz_module_get_datapath (module, "qblock1.png"));        qblock[1] = ttk_load_image (pz_module_get_datapath (module, "qblock2.png"));        qblock[2] = ttk_load_image (pz_module_get_datapath (module, "qblock3.png"));        qblock[3] = ttk_load_image (pz_module_get_datapath (module, "qblock4.png"));    	usedblock = ttk_load_image (pz_module_get_datapath (module, "usedblock.png"));    coin[0] = ttk_load_image (pz_module_get_datapath (module, "coin.png"));        coin[1] = ttk_load_image (pz_module_get_datapath (module, "coin2.png"));        coin[2] = ttk_load_image (pz_module_get_datapath (module, "coin3.png"));        coin[3] = ttk_load_image (pz_module_get_datapath (module, "coin4.png"));        mushroom = ttk_load_image (pz_module_get_datapath (module, "mushroom.png"));        1up = ttk_load_image (pz_module_get_datapath (module, "1up.png"));        flower = ttk_load_image (pz_module_get_datapath (module, "flower.png"));        fireball[0] = ttk_load_image (pz_module_get_datapath (module, "fireball1.png"));        fireball[1] = ttk_load_image (pz_module_get_datapath (module, "fireball2.png"));        fireball[2] = ttk_load_image (pz_module_get_datapath (module, "fireball3.png"));        fireball[3] = ttk_load_image (pz_module_get_datapath (module, "fireball4.png"));        star[0] = ttk_load_image (pz_module_get_datapath (module, "star1.png"));        star[1] = ttk_load_image (pz_module_get_datapath (module, "star2.png"));    star[2] = ttk_load_image (pz_module_get_datapath (module, "star3.png"));        star[3] = ttk_load_image (pz_module_get_datapath (module, "star4.png"));	win = ttk_load_image (pz_module_get_datapath (module, "win1.png"));}PZ_MOD_INIT(init_mario)