Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


bluwind

Member Since 17 Jul 2007
Offline Last Active Jul 17 2013 12:03 AM

Topics I've Started

GO home viking raiders "your drunk"

23 June 2013 - 01:05 PM

Ok, so this is my first C++ code, I am not making any excuses though because I have been programming off and on in VB for a few years so I am aware of a number of bad practises I committed here.

So here is some code for you to feast your eyes upon, you can see how I jumped from one preferred grid referencing method to another, Coordsx, VX, GridRefx... that's what happens when you don't have a clear plan though.

I am currently restarting the project in a much more manageable way because even I have lost track of what is going on in may sections.

I posted the game running (or at least doing a good imitation of running) on youtube here http://www.youtube.com/watch?v=Hp5wsjfUNjY

The game is a Viking raiders (spectrum) remake.

int Player1::Check_Collision(int Directions)
{
	int i;
	switch (Directions)
	{
	case 1:
		//Bottom Left
		if (Coordsx - vx <= -30 || Coordsy + vy >= (SCREEN_HEIGHT - 90) || Map[GridRefx - 1][GridRefy + 1].style == 1 || Map[GridRefx - 1][GridRefy + 1].Occupied == 1)
		{
			
			if (Map[GridRefx - 1][GridRefy + 1].Occupied == 1)
			{
				Fighting = true;	
				Stepinto = 2;
			
				AnimOverlord = 0;
				
			
			}
			
			LockPSel = false;
			Active = false;
			Direction = 0;
			return 1;
			
		}
		break;
		//Down
	case 2:
		if (Coordsy + vy >= (SCREEN_HEIGHT - 90) || Map[GridRefx][GridRefy + 1].style == 1 || Map[GridRefx][GridRefy + 1].Occupied == 1) 
		{
			if (Map[GridRefx][GridRefy + 1].Occupied == 1)
			{
				Fighting = true;	
				Stepinto = 2;
				
				AnimOverlord = 0;
				
			}
			Direction = 0;
			LockPSel = false;
			Active = false;
			return 1;
		}
		break;
	case 3:
		//Bottom Right
		if (Coordsx + vx >= SCREEN_WIDTH || Coordsy + vy >= (SCREEN_HEIGHT - 90) || Map[GridRefx + 1][GridRefy + 1].style == 1 || Map[GridRefx + 1][GridRefy + 1].Occupied == 1)
		{ 
			if (Map[GridRefx + 1][GridRefy + 1].Occupied == 1)
			{
				Fighting = true;	
				Stepinto = 2;
			
				AnimOverlord = 0;
				
			}
			Direction = 0;
			LockPSel = false;
			Active = false;
			return 1;
		}
		break;
	case 4:
		//left
		if (Coordsx - vx <= -30 || Map[GridRefx - 1][GridRefy].style == 1 || Map[GridRefx - 1][GridRefy].Occupied == 1)
		{ 
			if (Map[GridRefx - 1][GridRefy].Occupied == 1)
			{
				Fighting = true;	
				Stepinto = 2;
				
				AnimOverlord = 0;
			
			}
			Direction = 0;
			LockPSel = false;
			Active = false;
			return 1;
			
		}
		break;
	case 6:
		//right
		if (Coordsx + vx >= SCREEN_WIDTH || Map[GridRefx + 1][GridRefy].style == 1 || Map[GridRefx + 1][GridRefy].Occupied == 1 )
		{ 
			if (Map[GridRefx + 1][GridRefy].Occupied == 1)
			{
				Fighting = true;	
				Stepinto = 2;
			
				AnimOverlord = 0;
			

			}
			Direction = 0;
			LockPSel = false;
			Active = false;
			return 1;
			
		}
		break;
	case 7:
		//top left
		if (Coordsx - vx <= -30 || Coordsy - vy <= -30 || Map[GridRefx - 1][GridRefy - 1].style == 1 || Map[GridRefx - 1][GridRefy - 1].Occupied == 1)
		{ 
			if (Map[GridRefx - 1][GridRefy - 1].Occupied == 1)
			{
				Fighting = true;	
				Stepinto = 2;
			
				AnimOverlord = 0;
			
			}
			Direction = 0;
			LockPSel = false;
			Active = false;
			return 1;
		}
		break;
	case 8:
		//up
		if (Coordsy - vy <= -30 || Map[GridRefx][GridRefy - 1].style == 1 || Map[GridRefx][GridRefy - 1].Occupied == 1 )
		{ 
			if (Map[GridRefx][GridRefy - 1].Occupied == 1)
			{
				Fighting = true;
				Stepinto = 2;
				AnimationCycle = true;
				AnimOverlord = 0;
			
			}
			Direction = 0;
			LockPSel = false;
			Active = false;
			return 1;
			
		}
		break;
	case 9:
		//top right
		if (Coordsx +vx >= SCREEN_WIDTH || Coordsy - vy <= -30 || Map[GridRefx + 1][GridRefy - 1].style == 1 || Map[GridRefx + 1][GridRefy - 1].Occupied == 1)
		{ 
			
			if (Map[GridRefx + 1][GridRefy - 1].Occupied == 1)
			{
				Fighting = true;
				Stepinto = 2;
				AnimationCycle = true;
				AnimOverlord = 0;
			}
			
				Direction = 0;
				LockPSel = false;
				Active = false;
			 return 1;

			
		}
		break;
	}
	return 0;
}

Back to the grindstone

17 June 2013 - 04:46 AM

currently experiencing a Coding Horror - for the past three days I have been stuck on a section of my game which switches between different phases (buy menu - move cycle).. and no matter what I try it throws back trouble. Its going to make me that much more happier with the finished product though in the end.. so ummm yeah.. back to it.


Header file placement.

15 June 2013 - 02:15 PM

Language is C++.

Ok, so their is no such thing as a stupid question..

I know the Name says it all with "Header File", but does it matter where I include the header file - I am using header files to contain my different classes, E.G  Players.h, MapBuilder.h, GameLogic.h.

You can pretty much guess what each header contains. Now because the Players.H file uses Global variables from my main .cpp I have #include the header file after the variables have been initialized. Will this cause me problems later down the line and if it will can someone point me in the direction of a better solution?.

 

 

Cheers Rob

 

 

~~~~~~Please remember I am posting in the beginner forum for a reason - so please don't flame~~~~~~


C++ SDL switch not working properly

13 June 2013 - 01:25 AM

Can anyone spot an error in this small code section?, when I separate it up and manual enter the coords for .x and .y it works fine, but as the clipboard size is likely to grow by quite a bit, I wanted to automate the loading process.

The error I am getting is that when Blit-ing a clip that's loaded in the for loop - its coming up blank. my loaded graphic (clipboard) has 7 images across and 4 images down, each image is 30 pixels across.

anyway the code :

void Player1::Set_CLips()
{
	int i,n;
	
	for (i=0; i < totalFrames; i++)
	{
		  switch(i)
        {
		  case 0: case 1: case 2: case 3: case 4: case 5: case 6:
		  	  CLip[i].x = (i * 30);
			  CLip[i].y = 0;
			  CLip[i].h = 30;
			  CLip[i].y = 30;
			  break;
		  case 7:case 8:case 9:case 10:case 11:case 12:case 13:
			n = i-7;
			  CLip[i].x = (n * 30);
			  CLip[i].y = 31;
			  CLip[i].h = 30;
			  CLip[i].y = 30;
			 break;
		  case 14:case 15:case 16: case 17:case 18:case 19:case 20:
			  n = i - 14;
			  CLip[i].x = (n * 30);
			  CLip[i].y = 61;
			  CLip[i].h = 30;
			  CLip[i].y = 30;
			  break;
		  case 21:case 22:case 23:case 24:case 25:case 26:case 27:
			  n = i - 21;
			  CLip[i].x = (n * 30);
			  CLip[i].y = 91;
			  CLip[i].h = 30;
			  CLip[i].y = 30;
			 break;    
		}
	}


}

C++ Problem with loop

11 June 2013 - 03:49 AM

Hi guys, maybe its because I am tired after staying up all night watching the E3 conference but I cant wrap my head round this..

 

It is a very simple map builder, written in SDL. Its blit-ing all the squares to screen ok, but its not putting in the very first square.

anyway the code :

void Build_Map()
{
	int hor = 0,ver = 0;
	
	while (hor < MAP_SIZE)
	{
		 while (ver < MAP_SIZE)
		{
				
			Map[hor][ver].x = (hor * 30);
			Map[hor][ver].y = (ver * 30);
			
			Map[hor][ver].Set_CLips();
			ver++;
		}
			
				ver = 0;
			
		hor++;
	} 

}


int Drawtoscreen()
{
		
      apply_surface(0,0,background, screen);
		int hor=0,ver=0;
		
		while (hor<=MAP_SIZE)
		{
			while (ver<=MAP_SIZE)
			{
				apply_surface(Map[hor][ver].x ,Map[hor][ver].y , Clipboard[1] , screen , &Map[hor][ver].CLip[2]);
				ver++;
			}
			
			ver = 0;
		hor++;
		}
		//hor = 0;
		//ver = 0;
		
	    apply_surface(0,(SCREEN_HEIGHT - 28), message, screen);
	    
		
		// Draw Player
		apply_surface( 100 , player.Coordsy , Clipboard[0], screen, &player.CLip[ player.ImageChoice ] );
		

	return 0;
}







 


PARTNERS