Breach

Check-in [e2d78ca550]
Login

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

Overview
Comment:in editmode, boxes can be created by dragging in any direction. there is also a minimum dimension that must be satisifed to create the block. an outline will also draw to show you the box you are dragging out.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:e2d78ca550b3e0ea9bd53d87c5f35026f0785140
User & Date: donnyjward@gmail.com 2011-09-10 02:10:21
Context
2011-09-10
02:19
minor bugfix to drawing the outline for a box (StateEditing::UpdateGame()) check-in: 1ba914670e user: donnyjward@gmail.com tags: trunk
02:10
in editmode, boxes can be created by dragging in any direction. there is also a minimum dimension that must be satisifed to create the block. an outline will also draw to show you the box you are dragging out. check-in: e2d78ca550 user: donnyjward@gmail.com tags: trunk
2011-09-08
23:21
work on level editor has begun. start game with -edit. all you can do right now is drag blocks with the left mouse button. drag from top left corner or i dont know what will happen. work on more functionality like right click to change colors for example. then finally make a button to output the block data to a text file. maybe figure out how to choose your own background image check-in: d5c0385b9f user: donnyjward@gmail.com tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to breach.cpp.

56
57
58
59
60
61
62



63
64
65
66
67
68
69
//FIXME: artificially lengthen the collision of the paddle to
//	overcome the "short"comings of the current collision
//	detecting code
extern const int PADDLE_ARCERROR = 20;

extern const int MAX_GAMEOBJECTS = 50;




extern const int MAX_LIVES = 500;

extern const int PI = 3.14159265;

//Aircraft radius
extern const int AIRCRAFT_RADIUS = 10;








>
>
>







56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//FIXME: artificially lengthen the collision of the paddle to
//	overcome the "short"comings of the current collision
//	detecting code
extern const int PADDLE_ARCERROR = 20;

extern const int MAX_GAMEOBJECTS = 50;

extern const int MIN_BLOCKLENGTH = 50;
extern const int OUTLINE_THICKNESS = 3;

extern const int MAX_LIVES = 500;

extern const int PI = 3.14159265;

//Aircraft radius
extern const int AIRCRAFT_RADIUS = 10;

Changes to defs.h.

46
47
48
49
50
51
52




53
54
55
56
57
58
59
//FIXME: artificially lengthen the collision of the paddle to
//	overcome the "short"comings of the current collision
//	detecting code
extern const int PADDLE_ARCERROR;

extern const int MAX_GAMEOBJECTS;





extern const int MAX_LIVES;

extern const int PI;

//Aircraft radius
extern const int AIRCRAFT_RADIUS;








>
>
>
>







46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//FIXME: artificially lengthen the collision of the paddle to
//	overcome the "short"comings of the current collision
//	detecting code
extern const int PADDLE_ARCERROR;

extern const int MAX_GAMEOBJECTS;

//for editmode
extern const int MIN_BLOCKLENGTH;
extern const int OUTLINE_THICKNESS;

extern const int MAX_LIVES;

extern const int PI;

//Aircraft radius
extern const int AIRCRAFT_RADIUS;

Changes to g_gameobject.cpp.

767
768
769
770
771
772
773

774
775
776
777
778
779
780
				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
			if ( b_getDistance(xProjectileCenter, yProjectileCenter, cX, cY) < radius )







>







767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
				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
			if ( b_getDistance(xProjectileCenter, yProjectileCenter, cX, cY) < radius )

Changes to s_statemachine.cpp.

556
557
558
559
560
561
562





563
564
565
566
567
568
569
...
627
628
629
630
631
632
633
634

635
636
637
638
639
640
641
...
642
643
644
645
646
647
648
649






































650

651
652





653
654




655
656
657




658




659
660
661
662
663
664
665
...
677
678
679
680
681
682
683
684






















685
686
687
688
689
690
691
692
693

694


















































695
696
697
698
	//center mouse pointer above paddle for aesthetic value
	SDL_WarpMouse(PADDLE_CENTERX,150);
	
	//if (background == NULL && DEBUG)
		//cout << fileID << "load background image failed\n";

	createBoxNow = false;





}

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

void StateEditing::UpdateGame()
{


	//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);
		
	//move paddle to new position based on gathered mouse movement
................................................................................
	//thePaddle->TryMove(mouseX, mouseY);
	//theBall->TryMove(mouseX, mouseY);
	
	//update all the game objects
	Objects.Update();

	//check for win/loss conditions
	






































	//if a new box should be made, make it

	if (createBoxNow)
	{





		createBoxNow = false;
		cout << fileID << "editmode: creating a box\n";




//		Block(int startX, int startY, int width, int height, int hp, bool soft, color_t c);
//	addObject( new Block(0, 0, 50, 100, 100, true, COLOR_RED) );
		Objects.addObject( new Block(boxStartX, boxStartY, boxEndX-boxStartX, boxEndY-boxStartY, 100, true, COLOR_RED) );




	}




	//check if all lives ran out
	if (!Objects.getNumLivesLeft())
	{
		cout << fileID << "game over\n";
		s_setNextState(STATE_EXIT);
	}
}
................................................................................
		
	//blit the paddle with correct facing
	//thePaddle->Draw();
	//theBall->Draw();
	
	//draw all the game objects
	Objects.Draw();
	






















	SDL_Flip(screen);
}

void StateEditing::GetMouseCoords(int & x, int & y)
{
	x = mouseX;
	y = mouseY;
}





















































//STATE_EXIT
//STATE_NULL









>
>
>
>
>







 







|
>







 







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


<
>
>
>
>
|
>
>
>
>







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
...
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
...
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703

704
705
706
707
708
709

710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
...
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
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
	//center mouse pointer above paddle for aesthetic value
	SDL_WarpMouse(PADDLE_CENTERX,150);
	
	//if (background == NULL && DEBUG)
		//cout << fileID << "load background image failed\n";

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

StateEditing::~StateEditing()
{
	SDL_FreeSurface(background);
	Objects.deleteData();
	
................................................................................
				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);
		
	//move paddle to new position based on gathered mouse movement
................................................................................
	//thePaddle->TryMove(mouseX, mouseY);
	//theBall->TryMove(mouseX, mouseY);
	
	//update all the game objects
	Objects.Update();

	//check for win/loss conditions



	//if dragging a box, position the outline
	if (leftClickHeld)
	{
		boxEndX = Objects.mouseX;
		boxEndY = Objects.mouseY;
		fixBoxCoords();

		//check for minimum size
		if ( boxBottomRightX - boxTopLeftX < MIN_BLOCKLENGTH || boxBottomRightY - boxTopLeftY < MIN_BLOCKLENGTH)
		{
			goodBox = false;
			cout << fileID << "editmode: box doesn't meet minimum dimensions (" << MIN_BLOCKLENGTH << " x " << MIN_BLOCKLENGTH << ")\n";
			cout << fileID << "editmode: box was (" << boxBottomRightX - boxTopLeftX << " x " << boxBottomRightY - boxTopLeftY << ")\n";
		}

		outlineTop.x = boxTopLeftX;
		outlineTop.y = boxTopLeftY;
		outlineTop.w = boxBottomRightX - boxTopLeftX;
		outlineTop.h = OUTLINE_THICKNESS;

		outlineBottom.x = boxTopLeftX;
		outlineBottom.y = boxBottomRightY - OUTLINE_THICKNESS;
		outlineBottom.w = boxBottomRightX - boxTopLeftX;
		outlineBottom.h = OUTLINE_THICKNESS;

		outlineLeft.x = boxTopLeftX;
		outlineLeft.y = boxTopLeftY;
		outlineLeft.w = OUTLINE_THICKNESS;
		outlineLeft.h = boxBottomRightY - boxTopLeftY;
		
		outlineRight.x = boxBottomRightX - OUTLINE_THICKNESS;
		outlineRight.y = boxTopLeftY;
		outlineRight.w = OUTLINE_THICKNESS;
		outlineRight.h = boxBottomRightY - boxTopLeftY;

	}
	else if (createBoxNow) //if a new box should be made, make it
	{
		createBoxNow = false;

		fixBoxCoords();
		
		//check for minimum size
		if ( boxBottomRightX - boxTopLeftX < MIN_BLOCKLENGTH || boxBottomRightY - boxTopLeftY < MIN_BLOCKLENGTH)
		{
			goodBox = false;

			cout << fileID << "editmode: box doesn't meet minimum dimensions (" << MIN_BLOCKLENGTH << " x " << MIN_BLOCKLENGTH << ")\n";
			cout << fileID << "editmode: box was (" << boxBottomRightX - boxTopLeftX << " x " << boxBottomRightY - boxTopLeftY << ")\n";
		}

//		Block(int startX, int startY, int width, int height, int hp, bool soft, color_t c);
//	addObject( new Block(0, 0, 50, 100, 100, true, COLOR_RED) );

		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);
	}
}
................................................................................
		
	//blit the paddle with correct facing
	//thePaddle->Draw();
	//theBall->Draw();
	
	//draw all the game objects
	Objects.Draw();

	//draw the new box outline if applicable
	if (leftClickHeld)
	{
		if (goodBox)
			outlineColor = colors[COLOR_BLUE];
		else
			outlineColor = colors[COLOR_RED];

		//only draw if box size supports the outline thickness
		if ( boxBottomRightX - boxTopLeftX < OUTLINE_THICKNESS || boxBottomRightY - boxTopLeftY < OUTLINE_THICKNESS )
		{
			//dont draw
		}
		else
		{
			SDL_FillRect(screen, &outlineTop, outlineColor);
			SDL_FillRect(screen, &outlineBottom, outlineColor);
			SDL_FillRect(screen, &outlineLeft, outlineColor);	
			SDL_FillRect(screen, &outlineRight, outlineColor);
		}
	}

	SDL_Flip(screen);
}

void StateEditing::GetMouseCoords(int & x, int & y)
{
	x = mouseX;
	y = mouseY;
}

void StateEditing::fixBoxCoords()
{
	//figure out how the box was drawn so it can be
	//	created properly
	if (boxStartX < boxEndX) //started left
	{
		if (boxStartY < boxEndY) //started top left (end bottom right)
		{
			boxTopLeftX = boxStartX;
			boxTopLeftY = boxStartY;
			boxBottomRightX = boxEndX;
			boxBottomRightY = boxEndY;
		}
		else if (boxStartY > boxEndY) //started bottom left (end top right)
		{
			boxTopLeftX = boxStartX;
			boxTopLeftY = boxEndY;
			boxBottomRightX = boxEndX;
			boxBottomRightY = boxStartY;
		}
		else //Y equal, invalid
		{
			goodBox = false;
		}
	}
	else if (boxStartX > boxEndX) //started right
	{
		if (boxStartY < boxEndY) //started top right (end bottom left)
		{
			boxTopLeftX = boxEndX;
			boxTopLeftY = boxStartY;
			boxBottomRightX = boxStartX;
			boxBottomRightY = boxEndY;
		}
		else if (boxStartY > boxEndY) //started bottom right (end top left)
		{
			boxTopLeftX = boxEndX;
			boxTopLeftY = boxEndY;
			boxBottomRightX = boxStartX;
			boxBottomRightY = boxStartY;
		}
		else //Y equal, invalid
		{
			goodBox = false;
		}
	}
	else //X equal, invalid
	{
		goodBox = false;
	}
}

//STATE_EXIT
//STATE_NULL


Changes to s_statemachine.h.

201
202
203
204
205
206
207


208




209






210
211
212
213
		int mouseX;
		int mouseY;
		
		bool leftClickHeld;

		int boxStartX, boxStartY;
		int boxEndX, boxEndY;


	




		bool createBoxNow;






};


#endif







>
>
|
>
>
>
>

>
>
>
>
>
>




201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
		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
		//	coords appropriately
		void fixBoxCoords();
	
		bool createBoxNow;
		bool goodBox;

		//the outline for when you are dragging a box
		SDL_Rect outlineTop, outlineBottom, outlineLeft, outlineRight;

		Uint32 outlineColor;
};


#endif