Breach

Check-in [da18852a26]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Paddle::DoMove is now functional. the function simply takes the mouse movement from the last frame and makes the paddle point in that direction. so just a 1 pixel movement will change the angle of the paddle. a person on gamedev.net suggested to update the angle every 4 or 5 frames to smooth it out so ill try that soon
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:da18852a2677196b7a1bf3c52ab4c1c8c897f30b
User & Date: donnyjward@gmail.com 2010-09-13 06:19:29
Context
2010-09-14
06:04
a ball now appears in the bottom left corner of the screen and begins moving at a constant velocity. it currently has no collision detection, but next i will make a function to call every frame that will check for collision against the screen borders, and then bounce off accordingly (angle in = angle out). check-in: 5ffb9c724c user: donnyjward@gmail.com tags: trunk
2010-09-13
06:19
Paddle::DoMove is now functional. the function simply takes the mouse movement from the last frame and makes the paddle point in that direction. so just a 1 pixel movement will change the angle of the paddle. a person on gamedev.net suggested to update the angle every 4 or 5 frames to smooth it out so ill try that soon check-in: da18852a26 user: donnyjward@gmail.com tags: trunk
2010-09-12
00:59
Paddle::DoMove is an absolute mess. the function must take the relative x and y mouse movement since the last frame (which is accurate to my knowledge, calculated in StatePlaying::HandleInput) and calculate the new angle to display the paddle at for that frame. currently this function fails miserably check-in: 8cfac02cb1 user: donnyjward@gmail.com tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to g_gameobject.cpp.

157
158
159
160
161
162
163
164
165
166
167
168
169
170



171
172
173
174
175
176
177
178
179
180
181
182
183
184


185
186
187
188
189
190
191
...
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265



266

267
268
269
270


271
272
273

274
275

276
277


278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308

309
310
311
312
313
314
315

316
/************************************************
*                                               *
*	Paddle                                  *
*                                               *
************************************************/
Paddle::Paddle()
{
	int i;
	SDL_Surface * image;
	image = r_loadImage("./graphics/paddle1-315deg.bmp");

	if (DEBUG)
		cout << fileID << "paddle created\n";
		



	angle = 0;
	//change this to point to a preloaded image of paddle with correct facing (prerendering done during load screeN?)
	//image = r_loadImage("./graphics/paddle1-315deg.bmp");
	
	if (image == NULL && DEBUG)
		cout << fileID << "load paddle image failed\n";
		
	//render all 360 rotations of the paddle
	for (i = 0; i < 360; i++)
	{
		paddles[i] = r_rotateImage(image, i);
		if (paddles[i] == NULL && DEBUG)
			cout << fileID << "paddle rotation failed to load (# " << i << ")\n";
	}


	
	if (DEBUG)
		cout << fileID << "finished prerendering paddle\n";
}
		
Paddle::~Paddle()
{
................................................................................
	
	//the rotated instances of the paddle have different sizes, so the center must be recalculated each time
	if ( !r_blitSurface(((screen->w - rotated->w)/2), ((screen->h - rotated->h)/2), rotated, screen) && DEBUG )
		cout << fileID << "blit paddle image failed\n";

	if (DEBUG)
		cout << fileID << "paddle current angle = " << angle << "\n";
		
	//angle += 1;
}

void Paddle::OnCollide(GameObject * otherObject)
{

}

................................................................................
		angle -= 360;
}

//takes x and y mouse movement since last frame, and calculates the new
//angle to set the paddle to
bool Paddle::DoMove(int x, int y)
{
	cout << fileID << "begin DoMove\n";
	int newAngle = 0;
	double rawMouseAngle = 0;
	double normalizedMouseAngle = 0; //angle (in degrees) lies in the 1st quadrant
	double angleDifference; //difference between the 
	double d;
	int quadrant = 1;
	bool shouldMove = true;
	
	int angleFixed;



	

	if (x == 0 && y == 0)
		shouldMove = false;
		
	if (x == 0)


	{
		if (y > 0)
			normalizedMouseAngle = 90;

		else if (y < 0)
			normalizedMouseAngle = 270;

	}
	else if (y == 0)


	{
		if (x > 0)
			normalizedMouseAngle = 0;
		else if (x < 0)
			normalizedMouseAngle = 180;
	}
	else
	{
		double quotient = abs( (y*1.0) / (x*1.0) );
	
	
		//the distance the mouse moved from last update
		d = sqrt( (x*x) + (y*y) );
	
		normalizedMouseAngle = atan(quotient) * 180 / PI;
	
		/*
		if (x < 0 && y > 0)
			normalizedMouseAngle += 90;
		else if (x < 0 && y < 0)
			normalizedMouseAngle += 180;
		else if (x > 0 && y < 0)
			normalizedMouseAngle += 270;
			*/
		cout << fileID << "else block\n";
		
	}
		
	cout << fileID << "normalizedMouseAngle = " << normalizedMouseAngle << "\n";
	if (shouldMove)
		angle = normalizedMouseAngle;

	FixAngle(angle);
	
	angleFixed = angle+45;
	FixAngle(angleFixed);
	cout << fileID << "angle+45 = " << angleFixed << "\n";
	cout << fileID << "end DoMove\n";
	return true;

}







<
<
<
<



>
>
>

<
<











>
>







 







<
<







 







|
<
<
<
<
|
<
<

<
>
>
>

>

|
|
<
>
>
|
<
<
>
|
<
>
|
<
>
>
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
<
<
<
<
<
>
|
<
<
<
|
|
<
>

157
158
159
160
161
162
163




164
165
166
167
168
169
170


171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
...
207
208
209
210
211
212
213


214
215
216
217
218
219
220
...
246
247
248
249
250
251
252
253




254


255

256
257
258
259
260
261
262
263

264
265
266


267
268

269
270

271
272
273























274
275





276
277



278
279

280
281
/************************************************
*                                               *
*	Paddle                                  *
*                                               *
************************************************/
Paddle::Paddle()
{




	if (DEBUG)
		cout << fileID << "paddle created\n";
		
	int i;
	SDL_Surface * image;
	image = r_loadImage("./graphics/paddle1-0deg.bmp");
	angle = 0;


	
	if (image == NULL && DEBUG)
		cout << fileID << "load paddle image failed\n";
		
	//render all 360 rotations of the paddle
	for (i = 0; i < 360; i++)
	{
		paddles[i] = r_rotateImage(image, i);
		if (paddles[i] == NULL && DEBUG)
			cout << fileID << "paddle rotation failed to load (# " << i << ")\n";
	}
	
	SDL_FreeSurface(image);
	
	if (DEBUG)
		cout << fileID << "finished prerendering paddle\n";
}
		
Paddle::~Paddle()
{
................................................................................
	
	//the rotated instances of the paddle have different sizes, so the center must be recalculated each time
	if ( !r_blitSurface(((screen->w - rotated->w)/2), ((screen->h - rotated->h)/2), rotated, screen) && DEBUG )
		cout << fileID << "blit paddle image failed\n";

	if (DEBUG)
		cout << fileID << "paddle current angle = " << angle << "\n";


}

void Paddle::OnCollide(GameObject * otherObject)
{

}

................................................................................
		angle -= 360;
}

//takes x and y mouse movement since last frame, and calculates the new
//angle to set the paddle to
bool Paddle::DoMove(int x, int y)
{
	double angleRad = 0;




	double angleDeg = 0;


	

	//the x and y passed are SDL coordinates. arctan2
	//	uses cartesian coordinates;
	y = y*-1;
	
	//no mouse movement, do nothing
	if (x == 0 && y == 0)
		return false;


	angleRad = atan2(y, x);
	angleDeg = angleRad*180/PI;
	


	//atan2 reports angles in 3rd and 4th quadrant as negative. fix by adding 360
	if (y < 0)

		angleDeg += 360;
		

	angle = angleDeg;
	return true;
	























	//cout << fileID << "x = " << x << ", y = " << y << "\n";






	//cout << fileID << "angleRad = " << angleRad << ", angleDeg = " << angleDeg << " angle PREFIX = " << angle << "\n";
	//FixAngle(angle);



	//cout << fileID << "angle POSTFX = " << angle << "\n";
	//cout << fileID << "end DoMove\n";

	//angle = betterAngle;
}

Added graphics/paddle1-0deg.bmp.

cannot compute difference between binary files

Deleted graphics/paddle1-315deg.bmp.

cannot compute difference between binary files

Changes to s_statemachine.cpp.

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
	
	if (background == NULL && DEBUG)
		cout << fileID << "load background image failed\n";
		
	frame = 0;
	
	//hide cursor during splash screen
	//SDL_ShowCursor(SDL_DISABLE);
}

StateSplash::~StateSplash()
{
	SDL_FreeSurface(background);
	
	if (DEBUG)







|







105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
	
	if (background == NULL && DEBUG)
		cout << fileID << "load background image failed\n";
		
	frame = 0;
	
	//hide cursor during splash screen
	SDL_ShowCursor(SDL_DISABLE);
}

StateSplash::~StateSplash()
{
	SDL_FreeSurface(background);
	
	if (DEBUG)

Changes to s_statemachine.h.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{
	public:
		virtual void HandleInput() =0;
		virtual void UpdateGame() =0;
		virtual void Render() =0;
		
		virtual ~StateMachine() { };
		
	private:

};

//splash screen
//	current behavior is to just display splash image
//	for about 2 seconds, ignoring all input (except exit)
//	and then moving to the next state
class StateSplash : public StateMachine







<
<
<







18
19
20
21
22
23
24



25
26
27
28
29
30
31
{
	public:
		virtual void HandleInput() =0;
		virtual void UpdateGame() =0;
		virtual void Render() =0;
		
		virtual ~StateMachine() { };



};

//splash screen
//	current behavior is to just display splash image
//	for about 2 seconds, ignoring all input (except exit)
//	and then moving to the next state
class StateSplash : public StateMachine