Breach

Check-in [06e2db82a3]
Login

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

Overview
Comment:colors can now be assigned to blocks in edit mode using right click! right clicking a block will cycle through all the available colors
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:06e2db82a36c2ceb9b91c1cf52d24b695192570c
User & Date: donnyjward@gmail.com 2011-09-10 04:39:53
Context
2011-09-10
06:55
cleaned up a bit of the game logic, namely checking for win/loss conditions and loading initial data for GameObjects (which isnt complete yet) check-in: 51b5178f61 user: donnyjward@gmail.com tags: trunk
04:39
colors can now be assigned to blocks in edit mode using right click! right clicking a block will cycle through all the available colors check-in: 06e2db82a3 user: donnyjward@gmail.com tags: trunk
02:19
minor bugfix to drawing the outline for a box (StateEditing::UpdateGame()) check-in: 1ba914670e user: donnyjward@gmail.com tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to defs.h.

123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
typedef enum color_e
{
	COLOR_RED = 0,
	COLOR_BLUE,
	COLOR_GREEN,
	COLOR_YELLOW,
	COLOR_ORANGE,
	COLOR_BLACK,
	COLOR_SIZE
} color_t;

struct StateOfInput
{
	int mouseX;
	int mouseY;
	bool leftClickDown;
	bool leftClickPressed;
};
#endif







|











123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
typedef enum color_e
{
	COLOR_RED = 0,
	COLOR_BLUE,
	COLOR_GREEN,
	COLOR_YELLOW,
	COLOR_ORANGE,
	COLOR_BLACK, //should always be last color
	COLOR_SIZE
} color_t;

struct StateOfInput
{
	int mouseX;
	int mouseY;
	bool leftClickDown;
	bool leftClickPressed;
};
#endif

Changes to g_gameobject.cpp.

231
232
233
234
235
236
237























238
239
240
241
242
243
244
...
586
587
588
589
590
591
592






















593
594
595
596
597
598
599
...
767
768
769
770
771
772
773

774
775
776
777
778
779
780
		return false;
	else
	{
		numBlocks--;
		return true;
	}
}
























/************************************************
*                                               *
*	GameObject                              *
*                                               *
************************************************/
GameObject::GameObject()
................................................................................
}

bool Block::isSoft()
{
	return soft;
}























/************************************************
*                                               *
*	Projectile                              *
*                                               *
************************************************/
Projectile::Projectile(int startX, int startY, int velocityX, int velocityY, objectType_t newWeaponType)
: xVelocity(velocityX), yVelocity(velocityY)
................................................................................
				cX = blockX + blk->GetWidth();
			else //x point is somewhere in between rect sides
				cX = xProjectileCenter;

			//find rect's y point that is closest to the center of circle
			if (yProjectileCenter < blockY)
				cY = blockY;


			else if (yProjectileCenter > blockY + blk->GetHeight())
				cY = blockY + blk->GetHeight();
			else //y point is somewhere in between rect sides
				cY = yProjectileCenter;

			//if c(x, y) is inside the circles radius then they collided







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>







231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
...
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
...
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
		return false;
	else
	{
		numBlocks--;
		return true;
	}
}

GameObject * GameObjects::getMouseTarget(bool reverse)
{
	int i;

	Block * blk;
	//stop at the first object thats on the mouse
	for (i = ObjectsSize-1; i >=0 ; i--)
	{
		if (ObjectsList[i]->GetObjectType() == OBJECT_BLOCK)
		{
			blk = dynamic_cast<Block *>(ObjectsList[i]);
			if ( blk->containsPoint(mouseX, mouseY) )
			{
				//cout << fileID << "getMouseTarget found one, i = " << i << endl;
				return ObjectsList[i];
			}
		}
	}

	//cout << fileID << "getMouseTarget found nothing...\n";
	return NULL;
}

/************************************************
*                                               *
*	GameObject                              *
*                                               *
************************************************/
GameObject::GameObject()
................................................................................
}

bool Block::isSoft()
{
	return soft;
}

bool Block::containsPoint(int x, int y)
{
	if ( (rect.x <= x) && (x <= rect.x + rect.w ) && (rect.y <= y) && (y <= rect.y + rect.h) )
	{
		//cout << fileID << "contains point true, (x,y) = (" << x << "," << y << ")\n";
		//cout << fileID << "block (x,y) = (" << rect.x << "," << rect.y << ")\n";
		return true;
	}
	else
		return false;
}

color_t Block::getColor()
{
	return color;
}

void Block::setColor(color_t c)
{
	color = c;
}
		
/************************************************
*                                               *
*	Projectile                              *
*                                               *
************************************************/
Projectile::Projectile(int startX, int startY, int velocityX, int velocityY, objectType_t newWeaponType)
: xVelocity(velocityX), yVelocity(velocityY)
................................................................................
				cX = blockX + blk->GetWidth();
			else //x point is somewhere in between rect sides
				cX = xProjectileCenter;

			//find rect's y point that is closest to the center of circle
			if (yProjectileCenter < blockY)
				cY = blockY;


			else if (yProjectileCenter > blockY + blk->GetHeight())
				cY = blockY + blk->GetHeight();
			else //y point is somewhere in between rect sides
				cY = yProjectileCenter;

			//if c(x, y) is inside the circles radius then they collided

Changes to g_gameobject.h.

152
153
154
155
156
157
158






159
160
161
162
163
164
165
...
290
291
292
293
294
295
296








297
298
299
300
301
302
303
		//int GetSpeed();
		//int GetAngle();
		
		~Block();

		bool TryMove(int x, int y);
		bool isSoft();		






	private:
		bool soft;
		Item * containedItem;

		int health; //hit points, colliding with a projectile takes away hitpoints

		//SDL_Surface * image;
................................................................................
		//	if there are no lives or ammo to remove
		bool removeLife();
		bool removeAmmo();

		int getNumBlocks(); //get # of soft blocks in the level
		bool addBlock(); //add to the # of soft blocks
		bool subtractBlock(); //remove from # of soft blocks








	private:
		Paddle * GamePaddle;
		//array containing all of a level's game objects,
		//	which is not global and designed to be
		//	accessed by functions from breach.cpp
		//	and included in defs.h
		//FIXME: array/vector storage or linked list implementation?







>
>
>
>
>
>







 







>
>
>
>
>
>
>
>







152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
...
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
		//int GetSpeed();
		//int GetAngle();
		
		~Block();

		bool TryMove(int x, int y);
		bool isSoft();		

		//returns true if (x,y) is inside this object
		bool containsPoint(int x, int y);

		color_t getColor();
		void setColor(color_t c);
	private:
		bool soft;
		Item * containedItem;

		int health; //hit points, colliding with a projectile takes away hitpoints

		//SDL_Surface * image;
................................................................................
		//	if there are no lives or ammo to remove
		bool removeLife();
		bool removeAmmo();

		int getNumBlocks(); //get # of soft blocks in the level
		bool addBlock(); //add to the # of soft blocks
		bool subtractBlock(); //remove from # of soft blocks

		//gets the object that the mouse is pointing at
		//	(use in conjunction with mouse clicks)
		//	set reverse = true to traverse gameobjects
		//	list backwards (to get the top item in the case
		//	of an overlap
		//	currently for blocks only
		GameObject * getMouseTarget(bool reverse = false);
	private:
		Paddle * GamePaddle;
		//array containing all of a level's game objects,
		//	which is not global and designed to be
		//	accessed by functions from breach.cpp
		//	and included in defs.h
		//FIXME: array/vector storage or linked list implementation?

Changes to s_statemachine.cpp.

561
562
563
564
565
566
567

568
569
570
571
572
573
574
...
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
...
637
638
639
640
641
642
643




644
645
646
647
648
649
650
...
715
716
717
718
719
720
721




























722
723
724
725
726
727
728

	createBoxNow = false;
	leftClickHeld = false;
	boxStartX = boxStartY = 0;
	boxEndX = boxEndY = 0;
	boxTopLeftX = boxTopLeftY = 0;
	boxBottomRightX = boxBottomRightY = 0;

}

StateEditing::~StateEditing()
{
	SDL_FreeSurface(background);
	Objects.deleteData();
	
................................................................................

						//cosmetic bugfix 
						boxEndX = boxStartX+1;
						boxEndY = boxStartY+1;
						fixBoxCoords();
						break;
					case SDL_BUTTON_RIGHT:

						break;
				}
				break;
			case SDL_MOUSEBUTTONUP:
				switch (event.button.button)
				{
					case SDL_BUTTON_LEFT:
................................................................................
				break;
		}
	}
}

void StateEditing::UpdateGame()
{




	//bool goodBox = true;
	goodBox = true;
	//warp mouse back to center but dont register
	//	it as an event
	SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
	//SDL_WarpMouse(400,300);
	SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
................................................................................
		if (goodBox)
		{
			cout << fileID << "editmode: creating a (" << boxBottomRightX - boxTopLeftX << " x " << boxBottomRightY - boxTopLeftY << ") box\n";
			Objects.addObject( new Block(boxTopLeftX, boxTopLeftY, boxBottomRightX-boxTopLeftX, boxBottomRightY-boxTopLeftY, 100, true, COLOR_RED) );
		}
		else
			cout << fileID << "editmode: error creating box\n";




























	}

	//check if all lives ran out
	if (!Objects.getNumLivesLeft())
	{
		cout << fileID << "game over\n";
		s_setNextState(STATE_EXIT);







>







 







|







 







>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
...
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
...
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
...
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761

	createBoxNow = false;
	leftClickHeld = false;
	boxStartX = boxStartY = 0;
	boxEndX = boxEndY = 0;
	boxTopLeftX = boxTopLeftY = 0;
	boxBottomRightX = boxBottomRightY = 0;
	rightClickClicked = false;
}

StateEditing::~StateEditing()
{
	SDL_FreeSurface(background);
	Objects.deleteData();
	
................................................................................

						//cosmetic bugfix 
						boxEndX = boxStartX+1;
						boxEndY = boxStartY+1;
						fixBoxCoords();
						break;
					case SDL_BUTTON_RIGHT:
						rightClickClicked = true;
						break;
				}
				break;
			case SDL_MOUSEBUTTONUP:
				switch (event.button.button)
				{
					case SDL_BUTTON_LEFT:
................................................................................
				break;
		}
	}
}

void StateEditing::UpdateGame()
{
	GameObject * obj = NULL;
	Block * blk = NULL;
	int c;

	//bool goodBox = true;
	goodBox = true;
	//warp mouse back to center but dont register
	//	it as an event
	SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
	//SDL_WarpMouse(400,300);
	SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
................................................................................
		if (goodBox)
		{
			cout << fileID << "editmode: creating a (" << boxBottomRightX - boxTopLeftX << " x " << boxBottomRightY - boxTopLeftY << ") box\n";
			Objects.addObject( new Block(boxTopLeftX, boxTopLeftY, boxBottomRightX-boxTopLeftX, boxBottomRightY-boxTopLeftY, 100, true, COLOR_RED) );
		}
		else
			cout << fileID << "editmode: error creating box\n";
	}
	else if (rightClickClicked) //if doing nothign else then accept right clicks (color change)
	{
		rightClickClicked = false;

		obj = Objects.getMouseTarget();

		if (obj != NULL)
		{
			blk = dynamic_cast<Block *>(obj);

			cout << fileID << "changing color...\n";

			//cycle through all the defined colors
			if (blk->getColor() == COLOR_BLACK)
				blk->setColor(COLOR_RED);
			else
			{
				c = blk->getColor();
				c++;

				blk->setColor( (color_e)c );
			}
		}
		else
		{
			//cout << fileID << "didnt right click on a block!\n";
		}
	}

	//check if all lives ran out
	if (!Objects.getNumLivesLeft())
	{
		cout << fileID << "game over\n";
		s_setNextState(STATE_EXIT);

Changes to s_statemachine.h.

198
199
200
201
202
203
204

205
206
207
208
209
210
211
		SDL_Surface * background;
		
		//every frame will be updated
		int mouseX;
		int mouseY;
		
		bool leftClickHeld;


		int boxStartX, boxStartY;
		int boxEndX, boxEndY;
		int boxTopLeftX, boxTopLeftY;
		int boxBottomRightX, boxBottomRightY;

		//takes start and end coords and sets topleft and bottomright







>







198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
		SDL_Surface * background;
		
		//every frame will be updated
		int mouseX;
		int mouseY;
		
		bool leftClickHeld;
		bool rightClickClicked;

		int boxStartX, boxStartY;
		int boxEndX, boxEndY;
		int boxTopLeftX, boxTopLeftY;
		int boxBottomRightX, boxBottomRightY;

		//takes start and end coords and sets topleft and bottomright