Example #1
0
void game_print(char *string, int x, int y)
{
	GsSprite print_char;
	char q;
	
	print_char.x = x;
	print_char.y = y;
	print_char.w = 8;
	print_char.h = 8;
	print_char.r = NORMAL_LUMINOSITY;
	print_char.g = NORMAL_LUMINOSITY;
	print_char.b = NORMAL_LUMINOSITY;
	print_char.cx = 640;
	print_char.cy = 24;
	print_char.tpage = 10;
	print_char.attribute = COLORMODE(COLORMODE_4BPP);

	while(*string)
	{
		if(*string >= 0x20 && *string <= 0x7F)
		{
			q = *string;
			q -= 0x20;
			
			print_char.u = (q&0x1f)<<3;
			print_char.v = (q/0x20)<<3;
			GsSortSimpleSprite(&print_char);
		}
		print_char.x+=8;
		string++;
	}
}
Example #2
0
int main()
{
	GsDispEnv my_dispenv;
	GsDrawEnv my_drawenv;
	GsLine my_line;
	GsSprite my_sprite;
	GsRectangle colorbox;
	GsDot my_dot;
	unsigned short pad1;
	unsigned int WasL2=0, WasR2=0, WasL1=0, WasR1=0, WasSelect = 0;
	int x, y;

	PSX_InitEx(PSX_INIT_NOBIOS);
	GsInit();
	GsClearMem();
	SetVBlankHandler(my_vblank_handler);

	// This has to be interlaced	
	GsSetVideoModeEx(640, 480, EXAMPLES_VMODE, 0, 1, 0);
	
	my_dispenv.x = 0;
	my_dispenv.y = 0;
	
	GsSetDispEnv(&my_dispenv);
	
	my_drawenv.dither = 0;
	my_drawenv.draw_on_display = 1;
	my_drawenv.x = 0;
	my_drawenv.y = 0;
	my_drawenv.w = 640;
	my_drawenv.h = 512;
	my_drawenv.ignore_mask = 0;
	my_drawenv.set_mask = 0;
	
	GsSetDrawEnv(&my_drawenv);
	
	GsSetList(primitive_list);
	
	load_ui_graphics();
	while(GsIsDrawing());
	
	colorbox.x = 0;
	colorbox.y = 0;
	colorbox.w = 640;
	colorbox.h = 511;
	colorbox.r = 255;
	colorbox.g = 255;
	colorbox.b = 255;
	colorbox.attribute = 0;
	
	GsSortRectangle(&colorbox);
	
	sort_color_boxes();
	
	
	my_sprite.x = 0;
	my_sprite.y = 0;
	my_sprite.tpage = 10;
	my_sprite.u = 0;
	my_sprite.v = 0;
	my_sprite.attribute = 0;
	my_sprite.cx = 640;
	my_sprite.cy = 480;
	my_sprite.r = my_sprite.g = my_sprite.b = NORMAL_LUMINOSITY;
	my_sprite.scalex = my_sprite.scaley = 0;
	my_sprite.w = 16;
	my_sprite.h = 24;
		
	GsDrawList();	
	while(GsIsDrawing());
	
	// Backup 32x32 area
	MoveImage(cursor_x, cursor_y, 992, 0, 32, 32);
	
	my_dot.attribute = 0;
	
	while(1)
	{	
		while(speed_counter)
		{
			old_cursor_x = cursor_x;
			old_cursor_y = cursor_y;
	
			// Restore 32x32 area
			MoveImage(992, 0, old_cursor_x, old_cursor_y, 32, 32);
			while(GsIsDrawing());
			
			PSX_ReadPad(&pad1, NULL);
		
			if(pad1 & PAD_LEFT)
				cursor_x-=cursor_speed;
			
			if(pad1 & PAD_RIGHT)
				cursor_x+=cursor_speed;
			
			if(pad1 & PAD_UP)
				cursor_y-=cursor_speed;
		
			if(pad1 & PAD_DOWN)
				cursor_y+=cursor_speed;
			
			if(cursor_x <= 0)
				cursor_x = 0;
			
			if(pad1 & PAD_CROSS)
			{
				if(cursor_y >= 384)
				{
					y = (cursor_y - 384) >> 4;
					x = cursor_x >> 6;
					
					current_color[0] = paint_colors[(y * 10)+x][0];
					current_color[1] = paint_colors[(y * 10)+x][1];
					current_color[2] = paint_colors[(y * 10)+x][2];
				}
				else
				{
				
				switch(brush_type)
				{
					case 0:
						if(cursor_y >= 384)
						{
							break;
						}
					
						my_dot.r = current_color[0];
						my_dot.g = current_color[1];
						my_dot.b = current_color[2];
						my_dot.x = cursor_x;
						my_dot.y = cursor_y;
				
						GsSortDot(&my_dot);
					break;
					case 1:
						if(cursor_y >= 380)
						{
							break;
						}
					
						my_dot.r = current_color[0];
						my_dot.g = current_color[1];
						my_dot.b = current_color[2];
						my_dot.x = cursor_x + 1;
						my_dot.y = cursor_y;
				
						GsSortDot(&my_dot);
						
						my_dot.x++;
						
						GsSortDot(&my_dot);
						
						my_dot.y++;
						my_dot.x-=2;
						
						GsSortDot(&my_dot);
						
						my_dot.x++;
						
						GsSortDot(&my_dot);
						
						my_dot.x++;
						
						GsSortDot(&my_dot);
						
						my_dot.x++;
						
						GsSortDot(&my_dot);
						
						my_dot.y++;
						my_dot.x-=2;
						
						GsSortDot(&my_dot);
						
						my_dot.x++;
						
						GsSortDot(&my_dot);
					break;
				}
				
				}
				
				GsDrawList();
				while(GsIsDrawing());
			}
				
			if((pad1 & PAD_R2) && !WasR2)
			{
				cursor_speed++;
				WasR2 = 1;
			}
				
			if((pad1 & PAD_L2) && !WasL2)
			{
				cursor_speed--;
				WasL2 = 1;
			}
			
			if(!(pad1 & PAD_R2))
				WasR2 = 0;
				
			if(!(pad1 & PAD_L2))
				WasL2 = 0;
			
			if((pad1 & PAD_R1) && !WasR1)
			{
				brush_type++;
				WasR1 = 1;
			}
			
			if((pad1 & PAD_L1) && !WasL1)
			{
				brush_type--;
				WasL1 = 1;
			}
			
			if((pad1 & PAD_SELECT) && !WasSelect)
			{
				my_sprite.attribute ^= (ENABLE_TRANS | TRANS_MODE(0));
				my_dot.attribute ^= (ENABLE_TRANS | TRANS_MODE(0));
				WasSelect = 1;
			}
			
			if(!(pad1 & PAD_SELECT))
				WasSelect = 0;
			
			if(!(pad1 & PAD_R1))
				WasR1 = 0;
				
			if(!(pad1 & PAD_L1))
				WasL1 = 0;
				
			if(cursor_speed <= 0)
				cursor_speed = 1;
				
			if(cursor_speed >= 8)
				cursor_speed = 7;
				
			if(brush_type <= 0)
				brush_type = 0;
				
			if(brush_type > 1)
				brush_type = 1;	
	
			// Backup 32x32 area
				MoveImage(cursor_x, cursor_y, 992, 0, 32, 32);
				while(GsIsDrawing());
			
		//	if(cursor_x != old_cursor_x || cursor_y != old_cursor_y)
		//	{
			//	printf("cx = %d, cy = %d, cursor_speed = %d, brush_type = %d\n",
			//	cursor_x, cursor_y, cursor_speed, brush_type);
		

			

		
				my_sprite.x = cursor_x;
				my_sprite.y = cursor_y;
				GsSortSimpleSprite(&my_sprite);
		
				GsDrawList();
				while(GsIsDrawing());
		//	}
			
			speed_counter--;
		}
Example #3
0
void game_run()
{
	int x, y, a, b, c;

	unsigned short padbuf;

	while(speed_counter > 0)
	{
		scc++;
		
		if(vibration_cntdown > 0)
		{
			printf("vibration = %d\n", vibration_cntdown);
			pad_enable_vibration(0);
			pad_set_vibration(0, 0xFF, 0x80);
			vibration_cntdown--;
			
			if(vibration_cntdown == 0)
				pad_set_vibration(0, 0, 0);
		}	
		
		PSX_ReadPad(&padbuf, NULL);
		
		if(scc == 5 && !game_over)
		{
			if(snake_dir <= SNAKE_DIR_RIGHT)
			{
				if(padbuf & PAD_UP)
					snake_dir = SNAKE_DIR_UP;
							
				if(padbuf & PAD_DOWN)
					snake_dir = SNAKE_DIR_DOWN;
			}
			else
			{	
				if(padbuf & PAD_LEFT)	
					snake_dir = SNAKE_DIR_LEFT;
							
				if(padbuf & PAD_RIGHT)
					snake_dir = SNAKE_DIR_RIGHT;
			}
			
			for(y = 0; y < 29; y++)
				for(x = 0; x < 40; x++)
				{
					if(snake_array[y][x] == snake_size)
					{
						switch(snake_dir)
						{
							case SNAKE_DIR_LEFT:
								b = y;
								a = x-1;
							break;
							case SNAKE_DIR_RIGHT:
								b = y;
								a = x+1;
							break;								
							case SNAKE_DIR_UP:
								b = y-1;
								a = x;
							break;
							case SNAKE_DIR_DOWN:
								b = y+1;
								a = x;
							break;
						}
						
						c = check_snake_collision(a,b);
						
						if(c)
						{
							snake_array[b][a] = snake_size+1;
							
							if(c==2)
							{
								snake_size++;
								score+=100;
								//printf("%d\n", score);
								SsKeyOn(2);
								new_apple();
							}
						}
						else
						{
							vibration_cntdown = 10;
							game_over = 1;
							SsKeyOff(0);
							SsKeyOn(1);
							scc = 0;
						}
						
						if(snake_array[y][x] == 1 && c!=2)
							snake_array[y][x] = 0;
						
						goto out_of_collision_checking;
					}
				}
out_of_collision_checking:				
			for(y = 0; y < 29; y++)
				for(x = 0; x < 40; x++)
					if(snake_array[y][x]&&snake_array[y][x]<0x80&&c!=2)
						snake_array[y][x]--;
			
			scc = 0;
		}
		else if(game_over)
		{
			scc++;
			
			if(scc >= 510)
			{
				if((padbuf & PAD_CROSS) && !cross_pressed)
				{
					game_setup();
					cross_pressed = 1;
				}
				else if((padbuf & PAD_CIRCLE) && !circle_pressed)
				{
					circle_pressed = 1;
					GsSetVideoMode(320, 240, pal_or_ntsc_selection());
					game_setup();
				}
			
				if(!(padbuf & PAD_CROSS))
					cross_pressed = 0;
				
				if(!(padbuf & PAD_CIRCLE))
					circle_pressed = 0;
			}
		}
			
		speed_counter--;
	}
	

	if(screen_old)
	{
		game_rect.x = 0;
		game_rect.y = 0;
		game_rect.w = 320;
		game_rect.h = 240;
		game_rect.r = 0;
		game_rect.g = 0;
		game_rect.b = 0;
		game_rect.attribute = 0;
			
		GsSortRectangle(&game_rect);
		
		game_sprite.x = 0;
		game_sprite.y = 0;
		game_sprite.w = 256;
		game_sprite.h = 240;
		game_sprite.u = 0;
		game_sprite.v = 0;
		game_sprite.r = NORMAL_LUMINOSITY;
		game_sprite.g = NORMAL_LUMINOSITY;
		game_sprite.b = NORMAL_LUMINOSITY;
		game_sprite.tpage = 5;
		game_sprite.attribute = COLORMODE(COLORMODE_16BPP);
		
		GsSortSimpleSprite(&game_sprite);
		
		game_sprite.x += 256;
		game_sprite.w = 64;
		game_sprite.tpage = 9;
			
		GsSortSimpleSprite(&game_sprite);	
			
		game_rect.w = 8;
		game_rect.h = 8;
		game_rect.attribute = ENABLE_TRANS | TRANS_MODE(0);
			
		for(y = 0; y < 29; y++)
		{
			for(x = 0; x < 40; x++)
			{
				game_rect.x = x * 8;
				game_rect.y = y * 8;
					
				if(snake_array[y][x] >= 1 && snake_array[y][x] <= 0x7F)
				{
					game_rect.r = 0;
					game_rect.g = 255;
					game_rect.b = 0;
					GsSortRectangle(&game_rect);
				}
				else if(snake_array[y][x] == 0x80)
				{
					game_rect.r = 255;
					game_rect.g = 0;
					game_rect.b = 255;
					GsSortRectangle(&game_rect);
				}
				else if(snake_array[y][x] == 0x81)
				{
					game_rect.r = 0;
					game_rect.g = 0;
					game_rect.b = 128;
					GsSortRectangle(&game_rect);
				}
			}
		}
		
		sprintf(string_buf, "SCORE: %d", score);
		game_print(string_buf, 0, 232);

		if(game_over)
		{

			game_rect.w = 320;
			game_rect.h = 240;
			
			game_rect.x = 0;
			game_rect.y = 0;
			
			if(scc<=255)x=scc;else x=255;
			
			game_rect.r = x;
			game_rect.g = x;
			game_rect.b = x;
			game_rect.attribute = ENABLE_TRANS|TRANS_MODE(2);
					
			GsSortRectangle(&game_rect);
			
			if(scc>=300)
			{
				game_center_print("GAME OVER!", 160, 120);
			}
			
			if(scc>=420)
				game_center_print("WHAT DO YOU WANT TO DO NOW?", 160, 136);
				
			if(scc>=450)
				game_center_print("PRESS X TO RESTART THE GAME.",160, 152);
			
			if(scc>=480)
				game_center_print("PRESS O FOR PAL/NTSC SELECTION SCREEN.",160,168);	
				
			if(scc>=510)
				game_center_print("MADE WITH PSXSDK BY GIUSEPPE GATTA, 2010", 160, 200);
		}
			
		GsDrawList();
		
// While the graphic synthesizer (video card) is drawing
// just sleep.				
		while(GsIsDrawing());

// Swap drawing and display Y position, and swap list array
// to use. In this way we achieve a double buffer.
		
		if(game_dispenv.y == 0)
		{
			game_dispenv.y = 256;
			game_drawenv.y = 0;
		}
		else
		{
			game_dispenv.y = 0;
			game_drawenv.y = 256;
		}
			
		GsSetDispEnv(&game_dispenv);
		GsSetDrawEnv(&game_drawenv);
			
		screen_old = 0;
	}
}