Main Menu

News:

SyntaxBoom, now with pwetty syntax highlighted code boxes! \o/ 

https://www.syntaxboom.com/forum/index.php?topic=96

Shoutbox

Dabzy

Today at 17:36:22
Well, just have to keep an eyes, even though they said they sorted it like

Jackdaw

Today at 17:22:26
When I saw it. It was in the very early hours when normal people are fast asleep. Lasted for around half an hour before back to normal.

Dabzy

Today at 15:02:27
First time I seen it, having me cuppa at work and had a browse... Saw it and I was like "WTF is that!?!", so got on the blower!

Baggey

Today at 11:22:52
Oh goody. Was getting withdraw symptons!

Jackdaw

Today at 10:38:44
I saw that the other week, and forgot to query it. Redirects to sedo.parking.

Dabzy

Today at 10:33:24
Seems we lost the site for a bit there, sorted, basically htaccess went a bit screwy and it was diverting to one of them stupid default search pages... Been on to ionos the host provider and they fixered it! \o/ Had meself a bit of a sweat on there!  ;D

Jackdaw

2025-10-16, 20:00:40
Going to have to try bourbon and beans. That should be an explosive combination.

Baggey

2025-10-16, 13:15:42
I sometimes mix a chicken vindaloo and a Tika Masala together. Awesome  :P

Dabzy

2025-10-16, 05:49:34
And doing the act was the realisation I went for an indian when out... 20mins I was in the thunderbox waiting for me back chaff to cool down!

Dabzy

2025-10-16, 05:48:11
When I was on my "Year On The Blur", aka drinking after getting divorced, I was minging one night, couldnt remember getting home. Anyway, next day, went to work, and needed a poo...

Members
Stats
  • Total Posts: 1,816
  • Total Topics: 226
  • Online today: 29
  • Online ever: 232 (Oct 08, 2025, 09:18 AM)
Users Online
  • Users: 0
  • Guests: 13
  • Total: 13
Welcome to SyntaxBoom. Please login or sign up.

Recent

Learning Game for C - "Rescue Rambo"

Started by Matty, Oct 01, 2025, 06:48 AM

Previous topic - Next topic

Matty

Greetings folks,

I started learning the C language under the tutelage of ChatGPT (I ask it for tutorial exercises and it provides them to me as I learn the language).

Here's a sample 'roguelike' game I made this morning (the C code). You'll need a compiler to create an executable and run it. The objective of the game is to find the hut with the prisoner in it before the time runs out and avoid the booby traps and the enemy soldiers wandering about.

//Rescue Rambo C Learning Program

#include <stdlib.h>
#include <stdio.h>

struct GameItem
{
		int category; //0 = gametimer, 1 = player, 2 = vc, 3 = booby trap, 4 = hut, 5 = prisoner hut, 6 = extraction point, 7 = jungle trees, 8 = clearing
		int x;
		int y;
		int mode; //walk, sneak, run, observe, "hero" 
		int action; //wa(l)k,snea(k),(r)un,(o)bserve,(h)ero,(n)orth,(s)outh,(e)ast,(w)est,(q)uit,(z)restart
		int visible; //0/1 for booby trap
		int playerspotted; 
		float timeleft; //time until 'dawn' (the execution)
			
};

int updateworld(int action,struct GameItem *world,int size, int *seed);
void initworld(struct GameItem *world,int size, int *seed);
void drawworld(struct GameItem *world,int size);
int diceroll(int *seed);
int random(int *seed);
char getworlditem(struct GameItem *world,int size,int x,int y);
void updateboobytraps(struct GameItem *world,int size,int sx,int sy);

int main(void)
{
	system("cls");
	int seed = 123;
	int gameover = 0;
	struct GameItem world[300];
	initworld(world,300,&seed);
	int action = -1;
	
	char input;
	while(gameover<=0)
	{
		action = -1;
		system("cls");
		while(action==-1)
		{
			drawworld(world,300);
			if(gameover==-1)
			{
				printf("\nYou assassinated an enemy combatant!\n");
			}
			printf("You are in the dense Vietnamese Jungle. Somewhere out here the prisoner is held in a hut.\nBeware there are booby traps and enemy soldiers moving about!\n");
			printf("\nYou are represented by a @ symbol, VC soldiers are X symbols, t are trees, * are booby traps you've uncovered, H are huts that may or may not have a prisoner in them.\n");
			printf("\nYour options are:(q)uit, (z)restart, e(go east), w(go west),s(go south),n(go north),o(search for traps),r(run),wa(l)k,snea(k)\n,(a)ssassinate.\n");
			scanf(" %c",&input);
			gameover = 0;
			switch(input)
			{
				case 'q': //quit
					gameover = 1;
					action = 99;
				break;
				case 'z': //restart
					action = 98;
				break;
				case 'e': //go east in current mode
					action = 1;
				break;
				case 'w': //go west in current mode
					action = 2;
				break;
				case 's': //go south in current mode
					action = 3;
				break;
				case 'n': //go north in current mode
					action = 4;
				break;
				case 'h': //be a hero at current location
					action = 5;
				break;
				case 'o': //observe at current location
					action = 6;
				break;
				case 'r': //run mode
					action = 7;
				break;
				case 'k': //sneak mode
					action = 8;
				break;
				case 'l': //walk mode
					action = 9;
				break;
				case 'a': //assassinate
					action = 10;
				break;
			}
		}
		if(action<98)
		{
			gameover = updateworld(action,world,300,&seed);
		}
		if(action==98)
		{
			initworld(world,300,&seed);
		}
	}
	if(gameover==2)
	{
		printf("\nYou ran out of time, the prisoner was executed. You failed in your mission.\nGame Over.\n");
	}
	if(gameover==3)
	{
		printf("\nYou successfully rescued Rambo!\nThe End\n");
	}
	if(gameover==4)
	{
		printf("\nYou triggered a booby trap and died!\nGame Over.\n");
	}
	if(gameover==5)
	{
		printf("\nYou were caught and captured by the VC!\nGame Over.\n");
	}
	if(gameover==6)
	{
		printf("\nYou were spotted by the VC. They then sounded the alarm and executed all the prisoners at once.\nGame Over.\n");
	}
	printf("\nThanks for playing Rescue Rambo.\n");
	printf("\n\nType Something and Press Enter To Exit.\n\n");
	scanf(" %c",&input);
	return 0;
}

int diceroll(int *seed)
{
	*seed = (438328 * *seed + 548383 + *seed) % 16777216;
	if(*seed<0)
	{
		*seed*=-1;
	}
	printf("Dice Roll:%d\n",(*seed % 6) + 1);
	return (*seed % 6) + 1;
}

int random(int *seed)
{
	*seed = (438328 * *seed + 548383 + *seed) % 16777216;
	if(*seed<0)
	{
		*seed*=-1;
	}
	return *seed;
}

int updateworld(int action,struct GameItem *world,int size, int *seed)
{
	float timechunk = 1.0;
	if((world+1)->mode==7) //run
	{
		timechunk = 0.5;
	}
	if((world+1)->mode==8) //sneak
	{
		timechunk = 1.5;
	}
	//check if we're standing on a booby trap that has not been triggered...if so...we die!
	int px = (world+1)->x;
	int py = (world+1)->y;
	if(action==10)
	{
		//try and kill any adjacent VC
		for(int i=2;i<12;i++)
		{
			if((world+i)->x>=px-1 && (world+i)->y>=py-1 && (world+i)->x<=px+1 && (world+i)->y<=py+1)
			{
				if(diceroll(seed)>=2) //anything but a 1 on a dice roll
				{
					(world+i)->x = -1000; //effectively out of the game
					(world+i)->y = -1000; //easier than having a dead flag....just move them miles away from the player
					world->timeleft--;	
					if((world->timeleft)<=0)
					{
						return 2;
					}	
					return -1;
					break;
				}
				else
				{
					return 5;
				}
			}
		}
		
	}
	for(int i=12;i<24;i++)
	{
		if((world+i)->x == px && (world+i)->y == py)
		{
			return 4;
		}
	}
	if((world+26)->x==px && (world+26)->y==py) //you rescued the prisoner
	{
		return 3;
	}
	if(world->timeleft<=0)
	{
		return 2;
	}
	for(int i=2;i<12;i++)
	{
		if((world+i)->x==px && (world+i)->y==py)
		{
			return 5;
		}
		if((world+i)->x>=px-2 && (world+i)->y>=py-2 && (world+i)->x<=px+2 && (world+i)->y<=py+2)
		{
			switch((world+1)->mode)
			{
				case 9: //walking
					if(diceroll(seed)>=5)
					{
						(world+1)->playerspotted = 1;
					}
				break;
				case 8: //sneaking
					if(diceroll(seed)==6)
					{
						(world+1)->playerspotted = 1;
					}
				break;
				case 7: //running
					if(diceroll(seed)>=3)
					{
						(world+1)->playerspotted = 1;
					}
				break;
			}
			if((world+1)->playerspotted==1)
			{
				return 6;
			}
		}
	}
	switch(action)
	{
		case 7: //run
			(world+1)->mode = action;
		break;
		case 8: //sneak
			(world+1)->mode = action;
		break;
		case 9: //walk
			(world+1)->mode = action;
		break;
		case 2: //west
			if((world+1)->mode == 6)
			{
				(world+1)->mode = 9; //walk after observing
			}
			
			if((world+1)->x>0)
			{
				(world+1)->x--;
				world->timeleft-=timechunk;	
				if((world->timeleft)<=0)
				{
					return 2;
				}
			}
		break;
		case 1: //east
			if((world+1)->mode == 6)
			{
				(world+1)->mode = 9; //walk after observing
			}
			
			if((world+1)->x<30)
			{
				(world+1)->x++;
				world->timeleft-=timechunk;
				if((world->timeleft)<=0)
				{
					return 2;
				}
			}
		break;
		case 3: //south
			if((world+1)->mode == 6)
			{
				(world+1)->mode = 9; //walk after observing
			}
			
			if((world+1)->y<30)
			{
				(world+1)->y++;
				world->timeleft-=timechunk;
				if((world->timeleft)<=0)
				{
					return 2;
				}
			}
		break;
		case 4://north
			if((world+1)->mode == 6)
			{
				(world+1)->mode = 9; //walk after observing
			}
			if((world+1)->y>0)
			{
				(world+1)->y--;
				world->timeleft-=timechunk;
				if((world->timeleft)<=0)
				{
					return 2;
				}
			}
		break;
		case 6: //observe
			timechunk = 2;
			(world+1)->mode = 6;
			world->timeleft-=timechunk;
			//check for nearby booby traps....
			updateboobytraps(world,size,(world+1)->x,(world+1)->y);
			if((world->timeleft)<=0)
			{
					return 2;
			}
		break;
		
	}
	for(int i=2;i<12;i++)
	{
		int dice = diceroll(seed);
		switch(dice)
		{
			case 1:
				(world+i)->x--;
			break;
			case 2:
				(world+i)->x++;
			break;
			case 3:
				(world+i)->y--;
			break;
			case 4:
				(world+i)->y++;
			break;
		}
	}
	return 0;
}

void updateboobytraps(struct GameItem *world,int size,int sx,int sy)
{
	int a = 2;
	if((world+1)->mode==8)
	{
		a = 3;
	}
	if((world+1)->mode==7)
	{
		a = 1;
	}
	for(int x=sx-a;x<=sx+a;x++)
	{
		for(int y=sy-a;y<=sy+a;y++)
		{
			for(int i=12;i<24;i++)//booby traps
			{
				if((world+i)->x==x && (world+i)->y==y)
				{
					(world+i)->visible = 1;
				}
			}
		}
	}
}


void drawworld(struct GameItem *world, int size)
{
	//get the player's coordinates
	int x = (world + 1)->x - 4;
	int y = (world + 1)->y - 4;
	int px = x + 4;
	int py = y + 4;
	int mode = (world + 1)->mode;
	int radius = 4;
	if(mode==8)//sneak
	{
		radius = 3;
	}
	if(mode==7)//run
	{
		radius = 2;
	}
	if(mode==6)
	{
		radius = 5;
	}
	for(int sy=y;sy<y+9;sy++)
	{
		for(int sx=x;sx<x+9;sx++)
		{
			//check if inside radius.....
			if(sx>px-radius && sx<px+radius && sy>py-radius && sy<py+radius)
			{
				//check what's here.....
				char w = getworlditem(world,size,sx,sy);
				printf("%c",w);
			}
			else
			{
				if(sy>=0 && sy<30 && sx>=0 && sx<30)
				{
					printf(" ");
				}
				else
				{
					printf("#");
				}
			}
		}
		printf("\n");
	}
	printf("\n");
	printf("\nThere is %d time left before the prisoners are executed.\n",(int)(world->timeleft));
	switch((world+1)->mode)
	{
		case 9: //walk
		printf("\nYou are walking/standing currently.\n");
		break;
		case 8://sneak
		printf("\nYou are sneaking/crouching currently.\n");
		break;
		case 7://running
		printf("\nYou are running currently.\n");
		break;
	}
}

char getworlditem(struct GameItem *world,int size,int x,int y)
{
	for(int i=1;i<size;i++)
	{
		if((world+i)->x==x && (world+i)->y==y)
		{
			switch((world+i)->category)
			{
				case 1: //player
					return '@';
				break;
				case 2: //vc
					if((world+1)->playerspotted==0)
					{
						return 'x';
					}
					else
					{
						return 'X';
					}
				break;
				case 3: //booby trap
					if((world+i)->visible==1)
					{
						return '*';
					}
				break;
				case 4: //hut
					return 'H';
				break;
				case 5: //prisoner hut
					return 'H';
				break;
				case 6:
					return 'Z';
				break;
				case 7: //trees
					return 't';
				break;
			}
			return '.';
		}
	}
	return '.';
}

void initworld(struct GameItem *world, int size,int *seed)
{
	//set up the game timer
	world->category = 0;
	world->timeleft = 60.0;
	(world + 1)->category = 1;
	(world + 1)->x = 15;
	(world + 1)->y = 25;
	(world + 1)->mode = 9;
	(world + 1)->action = 0;
	(world + 1)->playerspotted = 0;
	for(int i=2;i<12;i++)//vc
	{
		(world + i)->category = 2;
		(world + i)->x = random(seed) % 30;
		(world + i)->y = random(seed) % 20;
	}
	for(int i=12;i<24;i++)//booby trap
	{
		(world + i)->category = 3;
		(world + i)->x = random(seed) % 30;
		(world + i)->y = random(seed) % 20;
	}	
	for(int i=24;i<26;i++)//empty hut
	{
		(world + i)->category = 4;
		(world + i)->x = random(seed) % 30;
		(world + i)->y = random(seed) % 6;
	}
	for(int i=26;i<27;i++)//prisoner
	{
		(world + i)->category = 5;
		(world + i)->x = random(seed) % 30;
		(world + i)->y = random(seed) % 6;
	}
	(world + 27)->category = 6; //extraction point
	(world + 27)->x = 18;
	(world + 27)->y = 27;
	for(int i=28;i<300;i++) //jungle trees
	{
		(world + i)->category = 7;
		(world + i)->x = random(seed) % 30;
		(world + i)->y = random(seed) % 30;
	}
	
}

So far I've been learning the basic things you can see above, plus a little about strings not shown here. I've had two or three lessons so far.

from Matt.

Baggey

Quote from: Matty on Oct 01, 2025, 06:48 AMGreetings folks,

I started learning the C language under the tutelage of ChatGPT (I ask it for tutorial exercises and it provides them to me as I learn the language).

Here's a sample 'roguelike' game I made this morning (the C code). You'll need a compiler to create an executable and run it. The objective of the game is to find the hut with the prisoner in it before the time runs out and avoid the booby traps and the enemy soldiers wandering about.

//Rescue Rambo C Learning Program

#include <stdlib.h>
#include <stdio.h>

struct GameItem
{
		int category; //0 = gametimer, 1 = player, 2 = vc, 3 = booby trap, 4 = hut, 5 = prisoner hut, 6 = extraction point, 7 = jungle trees, 8 = clearing
		int x;
		int y;
		int mode; //walk, sneak, run, observe, "hero" 
		int action; //wa(l)k,snea(k),(r)un,(o)bserve,(h)ero,(n)orth,(s)outh,(e)ast,(w)est,(q)uit,(z)restart
		int visible; //0/1 for booby trap
		int playerspotted; 
		float timeleft; //time until 'dawn' (the execution)
			
};

int updateworld(int action,struct GameItem *world,int size, int *seed);
void initworld(struct GameItem *world,int size, int *seed);
void drawworld(struct GameItem *world,int size);
int diceroll(int *seed);
int random(int *seed);
char getworlditem(struct GameItem *world,int size,int x,int y);
void updateboobytraps(struct GameItem *world,int size,int sx,int sy);

int main(void)
{
	system("cls");
	int seed = 123;
	int gameover = 0;
	struct GameItem world[300];
	initworld(world,300,&seed);
	int action = -1;
	
	char input;
	while(gameover<=0)
	{
		action = -1;
		system("cls");
		while(action==-1)
		{
			drawworld(world,300);
			if(gameover==-1)
			{
				printf("\nYou assassinated an enemy combatant!\n");
			}
			printf("You are in the dense Vietnamese Jungle. Somewhere out here the prisoner is held in a hut.\nBeware there are booby traps and enemy soldiers moving about!\n");
			printf("\nYou are represented by a @ symbol, VC soldiers are X symbols, t are trees, * are booby traps you've uncovered, H are huts that may or may not have a prisoner in them.\n");
			printf("\nYour options are:(q)uit, (z)restart, e(go east), w(go west),s(go south),n(go north),o(search for traps),r(run),wa(l)k,snea(k)\n,(a)ssassinate.\n");
			scanf(" %c",&input);
			gameover = 0;
			switch(input)
			{
				case 'q': //quit
					gameover = 1;
					action = 99;
				break;
				case 'z': //restart
					action = 98;
				break;
				case 'e': //go east in current mode
					action = 1;
				break;
				case 'w': //go west in current mode
					action = 2;
				break;
				case 's': //go south in current mode
					action = 3;
				break;
				case 'n': //go north in current mode
					action = 4;
				break;
				case 'h': //be a hero at current location
					action = 5;
				break;
				case 'o': //observe at current location
					action = 6;
				break;
				case 'r': //run mode
					action = 7;
				break;
				case 'k': //sneak mode
					action = 8;
				break;
				case 'l': //walk mode
					action = 9;
				break;
				case 'a': //assassinate
					action = 10;
				break;
			}
		}
		if(action<98)
		{
			gameover = updateworld(action,world,300,&seed);
		}
		if(action==98)
		{
			initworld(world,300,&seed);
		}
	}
	if(gameover==2)
	{
		printf("\nYou ran out of time, the prisoner was executed. You failed in your mission.\nGame Over.\n");
	}
	if(gameover==3)
	{
		printf("\nYou successfully rescued Rambo!\nThe End\n");
	}
	if(gameover==4)
	{
		printf("\nYou triggered a booby trap and died!\nGame Over.\n");
	}
	if(gameover==5)
	{
		printf("\nYou were caught and captured by the VC!\nGame Over.\n");
	}
	if(gameover==6)
	{
		printf("\nYou were spotted by the VC. They then sounded the alarm and executed all the prisoners at once.\nGame Over.\n");
	}
	printf("\nThanks for playing Rescue Rambo.\n");
	printf("\n\nType Something and Press Enter To Exit.\n\n");
	scanf(" %c",&input);
	return 0;
}

int diceroll(int *seed)
{
	*seed = (438328 * *seed + 548383 + *seed) % 16777216;
	if(*seed<0)
	{
		*seed*=-1;
	}
	printf("Dice Roll:%d\n",(*seed % 6) + 1);
	return (*seed % 6) + 1;
}

int random(int *seed)
{
	*seed = (438328 * *seed + 548383 + *seed) % 16777216;
	if(*seed<0)
	{
		*seed*=-1;
	}
	return *seed;
}

int updateworld(int action,struct GameItem *world,int size, int *seed)
{
	float timechunk = 1.0;
	if((world+1)->mode==7) //run
	{
		timechunk = 0.5;
	}
	if((world+1)->mode==8) //sneak
	{
		timechunk = 1.5;
	}
	//check if we're standing on a booby trap that has not been triggered...if so...we die!
	int px = (world+1)->x;
	int py = (world+1)->y;
	if(action==10)
	{
		//try and kill any adjacent VC
		for(int i=2;i<12;i++)
		{
			if((world+i)->x>=px-1 && (world+i)->y>=py-1 && (world+i)->x<=px+1 && (world+i)->y<=py+1)
			{
				if(diceroll(seed)>=2) //anything but a 1 on a dice roll
				{
					(world+i)->x = -1000; //effectively out of the game
					(world+i)->y = -1000; //easier than having a dead flag....just move them miles away from the player
					world->timeleft--;	
					if((world->timeleft)<=0)
					{
						return 2;
					}	
					return -1;
					break;
				}
				else
				{
					return 5;
				}
			}
		}
		
	}
	for(int i=12;i<24;i++)
	{
		if((world+i)->x == px && (world+i)->y == py)
		{
			return 4;
		}
	}
	if((world+26)->x==px && (world+26)->y==py) //you rescued the prisoner
	{
		return 3;
	}
	if(world->timeleft<=0)
	{
		return 2;
	}
	for(int i=2;i<12;i++)
	{
		if((world+i)->x==px && (world+i)->y==py)
		{
			return 5;
		}
		if((world+i)->x>=px-2 && (world+i)->y>=py-2 && (world+i)->x<=px+2 && (world+i)->y<=py+2)
		{
			switch((world+1)->mode)
			{
				case 9: //walking
					if(diceroll(seed)>=5)
					{
						(world+1)->playerspotted = 1;
					}
				break;
				case 8: //sneaking
					if(diceroll(seed)==6)
					{
						(world+1)->playerspotted = 1;
					}
				break;
				case 7: //running
					if(diceroll(seed)>=3)
					{
						(world+1)->playerspotted = 1;
					}
				break;
			}
			if((world+1)->playerspotted==1)
			{
				return 6;
			}
		}
	}
	switch(action)
	{
		case 7: //run
			(world+1)->mode = action;
		break;
		case 8: //sneak
			(world+1)->mode = action;
		break;
		case 9: //walk
			(world+1)->mode = action;
		break;
		case 2: //west
			if((world+1)->mode == 6)
			{
				(world+1)->mode = 9; //walk after observing
			}
			
			if((world+1)->x>0)
			{
				(world+1)->x--;
				world->timeleft-=timechunk;	
				if((world->timeleft)<=0)
				{
					return 2;
				}
			}
		break;
		case 1: //east
			if((world+1)->mode == 6)
			{
				(world+1)->mode = 9; //walk after observing
			}
			
			if((world+1)->x<30)
			{
				(world+1)->x++;
				world->timeleft-=timechunk;
				if((world->timeleft)<=0)
				{
					return 2;
				}
			}
		break;
		case 3: //south
			if((world+1)->mode == 6)
			{
				(world+1)->mode = 9; //walk after observing
			}
			
			if((world+1)->y<30)
			{
				(world+1)->y++;
				world->timeleft-=timechunk;
				if((world->timeleft)<=0)
				{
					return 2;
				}
			}
		break;
		case 4://north
			if((world+1)->mode == 6)
			{
				(world+1)->mode = 9; //walk after observing
			}
			if((world+1)->y>0)
			{
				(world+1)->y--;
				world->timeleft-=timechunk;
				if((world->timeleft)<=0)
				{
					return 2;
				}
			}
		break;
		case 6: //observe
			timechunk = 2;
			(world+1)->mode = 6;
			world->timeleft-=timechunk;
			//check for nearby booby traps....
			updateboobytraps(world,size,(world+1)->x,(world+1)->y);
			if((world->timeleft)<=0)
			{
					return 2;
			}
		break;
		
	}
	for(int i=2;i<12;i++)
	{
		int dice = diceroll(seed);
		switch(dice)
		{
			case 1:
				(world+i)->x--;
			break;
			case 2:
				(world+i)->x++;
			break;
			case 3:
				(world+i)->y--;
			break;
			case 4:
				(world+i)->y++;
			break;
		}
	}
	return 0;
}

void updateboobytraps(struct GameItem *world,int size,int sx,int sy)
{
	int a = 2;
	if((world+1)->mode==8)
	{
		a = 3;
	}
	if((world+1)->mode==7)
	{
		a = 1;
	}
	for(int x=sx-a;x<=sx+a;x++)
	{
		for(int y=sy-a;y<=sy+a;y++)
		{
			for(int i=12;i<24;i++)//booby traps
			{
				if((world+i)->x==x && (world+i)->y==y)
				{
					(world+i)->visible = 1;
				}
			}
		}
	}
}


void drawworld(struct GameItem *world, int size)
{
	//get the player's coordinates
	int x = (world + 1)->x - 4;
	int y = (world + 1)->y - 4;
	int px = x + 4;
	int py = y + 4;
	int mode = (world + 1)->mode;
	int radius = 4;
	if(mode==8)//sneak
	{
		radius = 3;
	}
	if(mode==7)//run
	{
		radius = 2;
	}
	if(mode==6)
	{
		radius = 5;
	}
	for(int sy=y;sy<y+9;sy++)
	{
		for(int sx=x;sx<x+9;sx++)
		{
			//check if inside radius.....
			if(sx>px-radius && sx<px+radius && sy>py-radius && sy<py+radius)
			{
				//check what's here.....
				char w = getworlditem(world,size,sx,sy);
				printf("%c",w);
			}
			else
			{
				if(sy>=0 && sy<30 && sx>=0 && sx<30)
				{
					printf(" ");
				}
				else
				{
					printf("#");
				}
			}
		}
		printf("\n");
	}
	printf("\n");
	printf("\nThere is %d time left before the prisoners are executed.\n",(int)(world->timeleft));
	switch((world+1)->mode)
	{
		case 9: //walk
		printf("\nYou are walking/standing currently.\n");
		break;
		case 8://sneak
		printf("\nYou are sneaking/crouching currently.\n");
		break;
		case 7://running
		printf("\nYou are running currently.\n");
		break;
	}
}

char getworlditem(struct GameItem *world,int size,int x,int y)
{
	for(int i=1;i<size;i++)
	{
		if((world+i)->x==x && (world+i)->y==y)
		{
			switch((world+i)->category)
			{
				case 1: //player
					return '@';
				break;
				case 2: //vc
					if((world+1)->playerspotted==0)
					{
						return 'x';
					}
					else
					{
						return 'X';
					}
				break;
				case 3: //booby trap
					if((world+i)->visible==1)
					{
						return '*';
					}
				break;
				case 4: //hut
					return 'H';
				break;
				case 5: //prisoner hut
					return 'H';
				break;
				case 6:
					return 'Z';
				break;
				case 7: //trees
					return 't';
				break;
			}
			return '.';
		}
	}
	return '.';
}

void initworld(struct GameItem *world, int size,int *seed)
{
	//set up the game timer
	world->category = 0;
	world->timeleft = 60.0;
	(world + 1)->category = 1;
	(world + 1)->x = 15;
	(world + 1)->y = 25;
	(world + 1)->mode = 9;
	(world + 1)->action = 0;
	(world + 1)->playerspotted = 0;
	for(int i=2;i<12;i++)//vc
	{
		(world + i)->category = 2;
		(world + i)->x = random(seed) % 30;
		(world + i)->y = random(seed) % 20;
	}
	for(int i=12;i<24;i++)//booby trap
	{
		(world + i)->category = 3;
		(world + i)->x = random(seed) % 30;
		(world + i)->y = random(seed) % 20;
	}	
	for(int i=24;i<26;i++)//empty hut
	{
		(world + i)->category = 4;
		(world + i)->x = random(seed) % 30;
		(world + i)->y = random(seed) % 6;
	}
	for(int i=26;i<27;i++)//prisoner
	{
		(world + i)->category = 5;
		(world + i)->x = random(seed) % 30;
		(world + i)->y = random(seed) % 6;
	}
	(world + 27)->category = 6; //extraction point
	(world + 27)->x = 18;
	(world + 27)->y = 27;
	for(int i=28;i<300;i++) //jungle trees
	{
		(world + i)->category = 7;
		(world + i)->x = random(seed) % 30;
		(world + i)->y = random(seed) % 30;
	}
	
}

So far I've been learning the basic things you can see above, plus a little about strings not shown here. I've had two or three lessons so far.

from Matt.

What compiler / IDE are you using to run this?
Running a Pc that just aint. Faster nough. I7-4Ghz, 32Gb Ram, 4Gb Nvidia, 2 x 1Tb SSD's, 2 x 24" LCD's

RETRO everything!

Jesus was only famous because of his Dad

Matty


Baggey

#3
Quote from: Matty on Oct 01, 2025, 10:06 AMMingGw64 with msys2 (gcc)

Sorry to sound nieve :-[ But is this going down the lines of creating the .exe to run :-X

I loved the Rambo Series of games on the Speccy. But they were hard to play.

Kind Regards Baggey
Running a Pc that just aint. Faster nough. I7-4Ghz, 32Gb Ram, 4Gb Nvidia, 2 x 1Tb SSD's, 2 x 24" LCD's

RETRO everything!

Jesus was only famous because of his Dad

Matty

Yeah - you have to compile it to an exe to run. It was more a learning exercise for C for me.

Baggey

Quote from: Matty on Oct 01, 2025, 08:30 PMYeah - you have to compile it to an exe to run. It was more a learning exercise for C for me.

Would you be prepared to do a little tutorial off how you got it working to an .exe

Im still learning new stuff day to day  :-X

I to am interested in C.

Kind Regards Baggey
Running a Pc that just aint. Faster nough. I7-4Ghz, 32Gb Ram, 4Gb Nvidia, 2 x 1Tb SSD's, 2 x 24" LCD's

RETRO everything!

Jesus was only famous because of his Dad

Matty

This is what I did:

First go to ChatGPT and ask it what do I need to install to have a C compiler. It said Mingw64 and gave me a website.

I followed the website instructions on how to download and install the compiler. It's very clear and straightforward.

I then asked ChatGPT to give me some tutorial exercises on the basics of C starting as if I were a beginner, but with some programming knowledge.

I completed the tutorials.

I then decided to try something a little more complicated so came up with a design that used the skills I'd learned so far - structs, a little bit of pointers, scanf and printf, arrays, and a few other bits and pieces. RescueRambo was born.

Not sure what else I can say really.

3dzForMeStill

About 20 years ago I used Kernighan and ritchie's Learninig C book, and got their quiz / answer book too. TBH, their quiz / answer book proved too much hassle....so I wrote my own Space Invaders game in a DOS terminal, it had levels and all that jazz! No ChatGPT back then!

Dabzy

Many moons ago, I found Hisoft-C for sale on eBay, for my Amstrad, so I bought it for a play, and aye...

Created before C was standardised, it was a frigging nightmare! :D

Swung my head around it eventually, it just didnt swing "C" as I know it, obviously due to my grey matter having learnt standard C and know in the most part what that expects!

All in all, even though it was a mare, I had fun with it! :)

Dabz
Intel i7-13620H, nVidia GerForce RTX 4060 Laptop GPU (8GB GDDR6), 16GB LPDDR5X, 1TB SSD, Windows 11 x64 piss flap of an OS!

Jackdaw

If you want a basic tutorial on how to set up a build environment.
I've just added a tutorial on setting up a GCC/MinGW tool chain and information on the types build systems and code editors.
You can find the link here
If you've dug yourself into a hole. Just keep digging. You're bound to come out the other side eventually.