Fastest I've ever made a game.

Pages: 123
I agree, that was an epic game! I think some improved graphics would vastly improve the overall gameplay. And perhaps some animations and options? Haha, that and the other ... chips adventures or something like that?
Hmm, any of you guys skype, msn, irc or anything? Would be good to get to know some of you better :)
Some four-in-a-row console game, took me about 30 mins to an hour, not really sure. Rather buggy though, typing in anything else than a number will cause it to go batshit insane.

Here's the code if a anyone's slightly interested. Wonder how many sins I managed to pack in that chunk of code...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <iostream>
#include <string>
using namespace std;

int Winner = 0;
int WhosTurn = 1;
int atPos[8][10] = {0};
int heightAt[10] = {0};
string pl1Piece = "0";
string pl2Piece = "8";
void ClearConsole()
{
	cout << string( 300, '\n' );
}
void ClearBoard()
{
	for(int row = 0; row < 8; row += 1)
	{
		heightAt[row] = 0;
		for(int col = 0; col < 10; col += 1)
		{
			atPos[row][col] = 0;
		}
	}
}
void RenderBoard()
{
	cout << "____________" << endl;
	for(int row = 0; row < 8; row += 1)
	{
		string _thisRow = "";
		for(int col = 0; col < 10; col += 1)
		{
			switch(atPos[row][col])
			{
			case 1:
				_thisRow = _thisRow + pl1Piece;
				break;
			case 2:
				_thisRow = _thisRow + pl2Piece;
				break;
			default:
				_thisRow = _thisRow + " ";
			}
		}
		cout << "|" << _thisRow << "|" << endl;
	}
	cout << "************" << endl;
	cout << "*0123456789*" << endl;
}
void AddPiece(int Player, int Col)
{
	heightAt[Col] += 1;
	atPos[8 - heightAt[Col]][Col] = Player;
}
void NextPlayersTurn()
{
	bool _changed = false;
	if(WhosTurn == 1 && !_changed)
	{
		WhosTurn = 2;
		_changed = true;
	}
	if(WhosTurn == 2 && !_changed)
	{
		WhosTurn = 1;
		_changed = true;
	}
}
bool ColIsFull(int Col)
{
	return(heightAt[Col] >= 8);
}
bool CheckForWinner()
{
	for(int row = 0; row < 8; row += 1)
	{
		for(int col = 0; col < 10; col += 1)
		{
			if(atPos[row][col] != 0)
			{
				// Across
				if(col <= 6)
				{
					if (atPos[row][col] == atPos[row][col+1] &&
						atPos[row][col] == atPos[row][col+2] &&
						atPos[row][col] == atPos[row][col+3])
					{
						Winner = atPos[row][col];
					}
				}
				// Upwards/downwards
				if(row <= 4)
				{
					if (atPos[row][col] == atPos[row+1][col] &&
						atPos[row][col] == atPos[row+2][col] &&
						atPos[row][col] == atPos[row+3][col])
					{
						Winner = atPos[row][col];
					}
				}
				//Diagonal down-right or up-left
				if(row <= 4 && col <= 6)
				{
					if (atPos[row][col] == atPos[row+1][col+1] &&
						atPos[row][col] == atPos[row+2][col+2] &&
						atPos[row][col] == atPos[row+3][col+3])
					{
						Winner = atPos[row][col];
					}
				}
				//Diagonal down-left or up-right
				if(row >= 4 && col <= 6)
				{
					if (atPos[row][col] == atPos[row-1][col+1] &&
						atPos[row][col] == atPos[row-2][col+2] &&
						atPos[row][col] == atPos[row-3][col+3])
					{
						Winner = atPos[row][col];
					}
				}
			}
		}
	}
	return (Winner != 0);
}
int main()
{
	bool running = true;
	ClearConsole();
	ClearBoard();
	WhosTurn = 1;
	while(running)
	{
		ClearConsole();
		RenderBoard();
		cout << "Player " << WhosTurn << "'s turn" << endl;
		int _whereToPlace = 800;
		while(_whereToPlace < 0 || _whereToPlace > 9 || ColIsFull(_whereToPlace))
		{
			cout << "Enter a number: ";
			cin >> _whereToPlace;
		}
		AddPiece(WhosTurn, _whereToPlace);
		NextPlayersTurn();
		if(CheckForWinner())
		{
			ClearConsole();
			RenderBoard();
			running = false;
		}
	}
	cout << "Player " << Winner << " won!" << endl;
	system("pause");
	return 0;
}
Last edited on
Mythios,
sfmlcoder@gmail.com
SFMLCoder on skype (I rarely use this account, though)
Last edited on
Mythios:
ultifinitus@gmail.com
ultifinitus on skype (I also rarely use this account)

=]
I'd post some stuff, but to be honest none of my projects have really been done in a small time-frame. I feel like I spend too much of my time worrying about how the API should work for various things, in-case I want to reuse the code later. And even then, for things where I am supposed to be writing reusable code, I spend a large chunk just staring at the screen and trying to figure out what would work best. Does anyone have any advice?
closed account (3hM2Nwbp)
ultifinitus wrote:
I agree, that was an epic game! I think some improved graphics would vastly improve the overall gameplay. And perhaps some animations and options?


And networked multiplayer mode...I think I'm going to start making this. (At least a 2-Dimensional multiplayer one)

Rodent's Revenge II: Rodent Warfaretm

And it gives me a reason to learn how to set up GitHub.
Last edited on
Added you both Xander314 and ultifinitus :) -- To skype that is. I'm usually always on heh. -- Anyone who wants to add me - mythios2
I shall add everyone too, but only when my exams are over. Until then I certainly can't afford to log on to that Skype account...


EDIT: Got bored with work and have now added you all :)
Last edited on
Add me as well my skype name is deitaka
closed account (D80DSL3A)
Reporting back. I have completed my Asteroids game.
The details took a bit more time. Now there are ufo baddies that fire at the players ship (accurate fire - you're toast if you don't move), sound effects (I found good free wav files online for laser fire, explosions and background music loops) plus score and spare ship displays.
There are presently 4 levels with more asteroids and more frequent ufo appearances (and more rapid fire) upping the difficulty.

Level play screenshot: http://img819.imageshack.us/img819/6969/screenshottg.jpg
I'm about to get smoked by a ufo shot.

There's a welcome menu with asteroid animations and choice of mouse or keyboard based control. The mouse can actually do it all using the scroll wheel to rotate the ship and a scroll wheel click for hyperjump. Left/right buttons for thrust/fire of course. Keyboard control makes for easier play though, hence both options.
screenshot: http://img823.imageshack.us/img823/2705/screenshotmz.jpg

Finally, a game over menu offers replay or quit option buttons.
screenshot: http://img848.imageshack.us/img848/6242/screenshottp.jpg
The ufo crossing the screen is firing at the mouse cursor.
Of course, you only get to the game over menu by losing. As in the original game play continues indefinitely until you run out of spare ships. You get another spare ship every 10,000 points.
I used to be able to make a game last forever in the old arcade version. I could get 2 hours of play for a single quarter!

What's new for me on this game is a heavy use of std::vector as a container for asteroids and shots. This was very handy for the asteroids, which split in two when hit ( I alter the existing one and push_back the new one ). I have always used dynamically allocated arrays in the past.
It was a good project and fairly simple too.
I used SFML, which makes all the graphics and sound almost shamefully easy!
Last edited on
Way to go fun2code! I love when projects are followed through with! What's next?

Did you learn anything else particularly useful?

How did you do your collision system?

How long is your code?

What did you do your graphics in/ how long did they take you?

I'm actually making a similar game, though I planned mine as "Space Invaders with asteroids" rather than the other way round. I'll probably post on here when it's done, but it won't be for a few weeks (T_T) as I never really get the chance to just sit down and code without other commitments nagging at me.

I may as well answer some of your questions too ultifinitus ;)

My collisions are detected as though everything is a sphere of radius
0.5f * (max_sprite_width + min_sprite_width)
and then collision physics is computed according the laws of linear momentum in 2D.

I made my graphics in blender3d and then used the 2D render as the sprite. Originally, it was ~5 minutes per sprite (player, enemy, asteroid 1, asteroid 2), but since then I have modelled a shell and changed the asteroids, which took a little longer.

EDIT: Oooh our post counts match XD

EDIT EDIT: Also, on the subject of graphics, I haven't done my proper background yet, and you can see the sprites scaled up massively here:
http://sfmlcoder.wordpress.com/projects/present/space-fight/
(They don't look great large, but obviously they will be smaller in game)
Last edited on
I was talking with a friend of mine at work one day and something about game design came up that I want to run past you guys. We ended up agreeing that since both SDL and SFML can use switch statements to detect key presses that 'w', 'a', 's', 'd', the arrow keys, 2, 4, 6 and 8 on the number pad should all move the ship in their respectful directions, and in a simple game like astroids the default case on the switch case should be fire. What do you all think? Of course you'd put the pause, escape keys and everything else before the default case but I thought the idea of using any button you want to fire was subtle yet brilliant.
That does sound like a nice idea (perhaps make it optional though as it could annoy some people, especially if ammo is finite).

both SDL and SFML can use switch statements to detect key presses

With SFML, it might be a shame to handle input with a switch statement, as it would preclude you from using sf::Input and thus force you do detect both keypresses and releases manually yourself.
closed account (D80DSL3A)
@ultifinitus
Did you learn anything else particularly useful?

Not really I'm sad to say. I used skills that I already knew. The practice with using vectors of objects was useful though since it's somewhat new to me. I kept things simple. Down and dirty, which is why development was quick.

How did you do your collision system?

Thought I'd try keeping the collision tests really simple. I did like Xander314 described and treated everything as circles, except shots, which are small so I treated them as points. It works pretty well.
Here's the collision detection function for the player ship hitting an asteroid:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
bool ship::hitRock(ani& rAni)// asteroids are ani (simple animated) objects
{
	// find square of center to center distance
	float distSq = (posx-rAni.posx-rAni.szx/2.0f)*(posx-rAni.posx-rAni.szx/2.0f)
                            + (posy-rAni.posy-rAni.szy/2.0f)*(posy-rAni.posy-rAni.szy/2.0f);
	if( setNow == setG && distSq < (szx+rAni.szx)*(szx+rAni.szx)/4.0f )// setG = "normal" frame set
	{
		chSpeed = false;// thruster off
		velx = rAni.velx;// explosion travels
		vely = rAni.vely;// with rock
		setNow = setK;// switch to explosion frame set
		frIndex = 0;// start at 1st frame
		return true;// hit
	}
	return false;// miss
}// end of hitRock() 

The one for ship hit by a shot is simpler:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
bool ship::hitShot(shot& rShot)
{
	float distSq = (posx-rShot.posx)*(posx-rShot.posx) + (posy-rShot.posy)*(posy-rShot.posy);
	if( distSq < szx*szx/4.0f )
	{		
		chSpeed = false;
		velx = vely = 0.0f;// explosion in place
		setNow = setK;
		frIndex = 0;
		rShot.inAir = false;// stops shot animation
		return true;
	}
	else
		return false;	
}

The one for an asteroid hit by a shot is similar.

How long is your code?

Asteroids.ccp has 1,026 lines of code. This is everything except the .h and .cpp files for the classes. There's probably at least another 1,000 lines of code in them (total, not each).

What did you do your graphics in/ how long did they take you?

I used SFML in the game. I used Photoshop/Imageready to create the animations. This is very tedious. Each animation takes me an hour or two. I re-use them from game to game for this reason. Only one is new for this game (the player ship with a flickering rocket plume when it is accelerating).

@Xander314. The graphics I see at your site look great! I'll look into using blender3d. Anything that makes creating animations easier.

@Computergeek01: Your idea for control key usage sounds good. I'm not using keys to move the ship up/down/left/right though. The ship rotates (left/right arrow) and accelerates in the direction it is facing (up arrow). Any key (not used for something else) as fire? Why not.
I'm using the spacebar, which is pretty easy to find/hit.

What's next?

Uh... dunno right now.
Do you ever suffer from post project completion euphoria/blues ?
It's a weird combination of "YEAH!!" and "What now? My project's done and I feel lost."
Last edited on
Do you ever suffer from post project completion euphoria/blues ?
It's a weird combination of "YEAH!!" and "What now? My project's done and I feel lost."


Yeah indeed. It happen to me too. Although not doing C++ development but of mobile genre, the experience is the same. You feel abit lost after finishing something that you set yourself up earlier.

I also did not develop app of gaming genre, more on apps a non-gamer will need with a smart-phone. Yes non-gamer still need apps to "survive" :P
Umm, OP. Did your game actually have graphics in it or all console?

It took me a few hours to make my first pong game. two paddles moving up and down hiting a ball back n forth. Then I just finished making the whole thing with classes and adding an ai to it.

I'm about to redesign/remake it again with graphics and music all incorporated.

EDIT: I'm a serious procrastinator and a master at it. I swear if you gave me an hour to do something I would do 5% of it in the first 50 minutes and browse web... the rest in the last 10 minutes. I guess creativity flies when you have a time limit.
Last edited on
I'm rather bad at console programming, but I'm making a math program with ncurses.
Pages: 123