• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
bluwind

GO home viking raiders "your drunk"

5 posts in this topic

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;
}
2

Share this post


Link to post
Share on other sites

Tip for your code. Within the switch call methods/functions instead of having the code display there. It will clean it up nice!  If you notice you are repeating yourself... create a method becuase the further you get the more the code blurs together. If you need to change a value... you are going to have to change it 9 times ... I know you don't want to do that. :)

 

Also for the switch statments, use a variable name that has some meaning so when you go back to look at it  say something meaningful like

private static final int DOWN = 0;
private static final int UP = 1;

switch(DIRECTION){

   case DOWN: 
            moveDown();
            break;
    
    case UP:
           moveUp();
           break;

     default:
            System.out.println("Doing something in default, Always good pratice to have a default");
            break;
}

private void moveDown(){
         // move that code from the switch statement here 
}

private void moveUp(){
       //move that code from the switch statement here
}

However,

My first game code was pretty rubish. While yours is nice a neat I do belever everything I wrote was declared public and condensed to one file haha. Felt like a lot of code at the time but I believe it was only 50 -100 lines and I have work projects that spread thousands of line that are easier to read then it was. haha

1

Share this post


Link to post
Share on other sites

Doesn't beat my wonderful "String to Char" function I designed back in 2008. A masterpiece. With original comments!

 

function StrToChr(S: String): Char;  // Fonction pour transformer un String en Char
begin                                // Je n'en disposait pas de préfaite... si vous connaissez un
     if UpperCase(S) = 'A' then Result := 'A';    // moyen plus rapide, faites le moi savoir :)
     if UpperCase(S) = 'B' then Result := 'B';
     if UpperCase(S) = 'C' then Result := 'C';
     if UpperCase(S) = 'D' then Result := 'D';
     if UpperCase(S) = 'E' then Result := 'E';
     if UpperCase(S) = 'F' then Result := 'F';
     if UpperCase(S) = 'G' then Result := 'G';
     if UpperCase(S) = 'H' then Result := 'H';
     if UpperCase(S) = 'I' then Result := 'I';
     if UpperCase(S) = 'J' then Result := 'J';
     if UpperCase(S) = 'K' then Result := 'K';
     if UpperCase(S) = 'L' then Result := 'L';
     if UpperCase(S) = 'M' then Result := 'M';
     if UpperCase(S) = 'N' then Result := 'N';
     if UpperCase(S) = 'O' then Result := 'O';
     if UpperCase(S) = 'P' then Result := 'P';
     if UpperCase(S) = 'Q' then Result := 'Q';
     if UpperCase(S) = 'R' then Result := 'R';
     if UpperCase(S) = 'S' then Result := 'S';
     if UpperCase(S) = 'T' then Result := 'T';
     if UpperCase(S) = 'U' then Result := 'U';
     if UpperCase(S) = 'V' then Result := 'V';
     if UpperCase(S) = 'W' then Result := 'W';
     if UpperCase(S) = 'X' then Result := 'X';
     if UpperCase(S) = 'Y' then Result := 'Y';
     if UpperCase(S) = 'Z' then Result := 'Z';
end;

Actually I enumerated the alphabet at least three times in the code (hangman game, if you must know).

 

At least this is self-documenting, in a redundant kind of way ph34r.png

 


However,
My first game code was pretty rubish. While yours is nice a neat I do belever everything I wrote was declared public and condensed to one file haha. Felt like a lot of code at the time but I believe it was only 50 -100 lines and I have work projects that spread thousands of line that are easier to read then it was. haha

 

Agreed. The joy of being a newbie.. everything felt new and exciting smile.png

0

Share this post


Link to post
Share on other sites

Doesn't beat my wonderful "String to Char" function I designed back in 2008. A masterpiece. With original comments!

 

function StrToChr(S: String): Char;  // Fonction pour transformer un String en Char
begin                                // Je n'en disposait pas de préfaite... si vous connaissez un
     if UpperCase(S) = 'A' then Result := 'A';    // moyen plus rapide, faites le moi savoir :)
     if UpperCase(S) = 'B' then Result := 'B';
     if UpperCase(S) = 'C' then Result := 'C';
     if UpperCase(S) = 'D' then Result := 'D';
     if UpperCase(S) = 'E' then Result := 'E';
     if UpperCase(S) = 'F' then Result := 'F';
     if UpperCase(S) = 'G' then Result := 'G';
     if UpperCase(S) = 'H' then Result := 'H';
     if UpperCase(S) = 'I' then Result := 'I';
     if UpperCase(S) = 'J' then Result := 'J';
     if UpperCase(S) = 'K' then Result := 'K';
     if UpperCase(S) = 'L' then Result := 'L';
     if UpperCase(S) = 'M' then Result := 'M';
     if UpperCase(S) = 'N' then Result := 'N';
     if UpperCase(S) = 'O' then Result := 'O';
     if UpperCase(S) = 'P' then Result := 'P';
     if UpperCase(S) = 'Q' then Result := 'Q';
     if UpperCase(S) = 'R' then Result := 'R';
     if UpperCase(S) = 'S' then Result := 'S';
     if UpperCase(S) = 'T' then Result := 'T';
     if UpperCase(S) = 'U' then Result := 'U';
     if UpperCase(S) = 'V' then Result := 'V';
     if UpperCase(S) = 'W' then Result := 'W';
     if UpperCase(S) = 'X' then Result := 'X';
     if UpperCase(S) = 'Y' then Result := 'Y';
     if UpperCase(S) = 'Z' then Result := 'Z';
end;

Actually I enumerated the alphabet at least three times in the code (hangman game, if you must know).

 

At least this is self-documenting, in a redundant kind of way ph34r.png

 

 

That's awesome! I use java and the first thing in my mind is a string to lowercase(or uppercase) then thake that string to to char array would solved have that problem.

 

My very first code was c# to back in 2004? I was like 14 and I only messed around with c# for 2 weeks but it was  a series of dialogbox not in a loop. I literally copy and pasted that many lines of code and I tought it was haularious to have people click the first one thinking it would go away.

Edited by dtkaos
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0