A89: C Question


[Prev][Next][Index][Thread]

A89: C Question



attached is a demo i wrote using a huge mat for a map and it draws the 
background and saves it etc, but i was wondering why doesn't my scrolling 
work, it should when you get to a edge, disp the new map and move the char 
to the opsite side, so why doesn't it?
Thanks for any help.
#define SAVE_SCREEN
#include <nostub.h>
#include <all.h>

int _ti89;

static int map1[32][40]=
{
	{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,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1,1,1,1,1,1,1,1,1,1,1},
	{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
};
ICON chari=
{
	{
		0x3C0,
		0x420,
		0xA50,
		0x420,
		0x240,
		0x180,
		0x180,
		0x3FFC,
		0x43C2,
		0x43C2,
		0x3C0,
		0x420,
		0x810,
		0x1008,
		0x1008,
		0x1008
	}
};
ICON grou[2]=
{
	{
		0x8888,
		0x1111,
		0x2222,
		0x4444,
		0x8888,
		0x1111,
		0x2222,
		0x4444,
		0x8888,
		0x1111,
		0x2222,
		0x4444,
		0x8888,
		0x1111,
		0x2222,
		0x4444
	},
	{
		0x0000,
		0x0000,
		0x0000,
		0x0000,
		0x0000,
		0x0000,
		0x0000,
		0x0000,
		0x0000,
		0x0000,
		0x0000,
		0x0000,
		0x0000,
		0x0000,
		0x0000,
		0x0000
	}
};
ICON* picon=NULL;
int X = 32;
int Y = 32;
int i = 0;
int key = 0;
int XX = 0;
int YY = 0;
int pageud = 0;
int pagelr = 1;
LCD_BUFFER bg={0};

void drawbg(void)
{
	ICON* gicon;
	for(XX=0+(pageud*6);XX<10+(pageud*6);XX+=1)
	{
		for(YY=0+(pagelr*10);YY<6+(pagelr*10);YY+=1)
		{
			gicon = &grou[map1[YY][XX]-1];     // -1 because arrays in C are zero based
			DrawIcon(XX*16,YY*16,gicon,A_NORMAL);
		}
	}
	LCD_save(bg);
	return;
}

void _main(void)
{
void *kbq = kbd_queue ( );
	ClrScr();
	drawbg();
	picon = 0;
	picon = &chari;
	DrawIcon(X,Y,picon,A_NORMAL);
	while(key!=264)
	{
		if (!OSdequeue (&key, kbq))
		{
			key=tolower(ngetchx());
			if(key==337)//Up
			{
				LCD_restore(bg);
				Y-=16;
				DrawIcon(X,Y,picon,A_NORMAL);
			}
			if(key==340)//Down
			{
				LCD_restore(bg);
				Y+=16;
				DrawIcon(X,Y,picon,A_NORMAL);
			}
			if(key==338)//Left
			{
				LCD_restore(bg);
				X-=16;
				DrawIcon(X,Y,picon,A_NORMAL);
			}
			if(key==344)//Right
			{
				LCD_restore(bg);
				X+=16;
				DrawIcon(X,Y,picon,A_NORMAL);
			}
//Stops working
			if(X>=160&&pagelr<=4)//Page Right			Doesn't	
			{
				pagelr+=1;
				drawbg();
				X=0;
				DrawIcon(0,Y,picon,A_NORMAL);
			}
			if(X<=0&&pagelr>=0)//Page Left					Doesn't
			{
				pagelr-=1;
				drawbg();
				X=160;
				DrawIcon(160,Y,picon,A_NORMAL);
			}
			if(Y>=96&&pageud<=5)//Page Down				Doesn't
			{
				pageud+=1;
				drawbg();
				Y=0;
				DrawIcon(X,0,picon,A_NORMAL);
			}
			if(Y<=0&&pageud>=0)//Page Up						Works
			{
				pageud-=1;
				drawbg();
				Y=96;
				DrawIcon(X,96,picon,A_NORMAL);
			}
		}
	}
	return 0;
}
Rob Smith
----
Stupidity got us into this mess - why can't it get us out?
Proud member of:
<a href="http://pa.ticalc.org">Programmers Anonymous</a>
<a href="http://www.tigalaxy.com">TIGALAXY</a>
<a href="http://c489.tigalaxy.com">C-4-89</a>
<a href="aim:addbuddy?screenname=Billvortex">Add Me To Your AIM Buddy List</a>

References: