Skip to content
Browse files

final version

  • Loading branch information...
1 parent f77be22 commit 49f66288349295374348ff4340569c89e04d0a5c @davidwparker committed Jun 30, 2011
Showing with 144 additions and 77 deletions.
  1. +1 −1 Makefile
  2. +98 −47 README
  3. +0 −1 animate.c
  4. +0 −1 drawing.c
  5. +17 −0 gameplay.c
  6. +0 −1 general.c
  7. +4 −0 initialize.c
  8. +2 −1 models.c
  9. +1 −0 prototypes.h
  10. +1 −6 screen.c
  11. +8 −8 sidebar.c
  12. +12 −11 window.c
View
2 Makefile
@@ -15,7 +15,7 @@ all: $(TARGET)
# Generic compile and link
%: %.c project.a
- gcc -Wall -O3 -o ./$@ $^ $(LIBS)
+ gcc -Wall -O3 -o ./hw6 $^ $(LIBS)
# Delete unwanted files - Linux or OS/X
clean:;rm -f $(TARGET) *.o *.a *~
View
145 README
@@ -1,38 +1,76 @@
+333333 DDD ffff
+ 3 D D f
+ 3 D D ee ffff ee n nnn sss ee
+ 333 D D e e f e e nn n s e e
+ 3 D D eeeeee f eeeeee n n sss eeeeee
+ 3 D D e f e n n s e
+ 3333 DDD eee f eee n n ssss eee
+
+
Project - 3Defense
David Parker
-Total time spent on code: 10 hours
--X hours - research
+Total time spent on code: 40+ hours
+(not exactly sure how I broke down time spent, I just know it was a lot)
+don't worry, I didn't spend very much time on the ASCII art above.
-TODO:
-Top 4 issues are probably going to be priority, unless you say otherwise...
-with #1 getting the majority of my focus.
+GETTING RIGHT TO IT:
+Spacebar => Begin the game. Once a wave of enemies is completely killed, then press spacebar
+ to send the next wave.
+1-6, shift+(1-8) => Select a tower. Then place the tower on the map by find a location and left-clicking.
+Escape => Exit the program
-???? #1) FIX FRAMERATE ISSUE. This Ubuntu/Freeglut thing is haunting me. Since adding shadows and minions,
-whenever I use gluUnProject, some of the times I get a bad Z value (and by some, I mean quite often if
-the framerate is higher). By adding a delay (currently ~80-100 ms), then it works, but if I drop down
-to ~30 then it doesn't work on my Ubuntu machine. It works perfectly on my Macbook Pro.
+-----------------------
+THINGS:
+REALLY COOL:
+1) Not so sure about this... I finally fixed the framerate issues with Ubuntu. It had to deal with how
+ glutIdle was working and how often it was getting called. By getting rid of it altogether and using
+ glutTimerFunc after the game begun and it seemed to clear things all up.
-If you have time, I would like to meet with you if you have any knowledge of what I could do to fix
-this issue.
+COOL:
+1) I like the fact that my code is organized. I think well organized and refactored code is key.
+2) (collision.c): My collision detection and checking the tower range functions were okay. For
+ collision detection I'm only checking the x/z origins vs. the scale of the object, and not
+ really doing real normal vs object detection.
+3) (drawing.c > drawObjects): I like the way I set up my structs to draw specific types of objects. I
+ liked using the blend func to set up a decent looking "preview" tower that will be placed. I also
+ made sure to render differently based on whether the user was clicking on the board so that they could
+ select objects using color coding, giving each object a unique color code.
+4) (general.c > findPreviewPostion): I made sure to set up a grid of viable positions around the map.
+ I wanted the user to be able to place a tower in a specific location and to make sure that they couldn't
+ place it otherwise. I also liked using gluUnProject and glReadPixels to figure out the mouse position
+ in findMousePosition.
+5) (general.c > processPicks): this method used the color coding before and actually processed which tower
+ we selected.
+6) (shapes.c, models.c, towers.c): again, I just like the way I organized things.
-Gameplay:
-DONE #2) Add 'waves' of minions, where a group of minions will go, then X time later, a second wave will go,
-and so on.
-DONE #3) Add the ability for the towers to "attack" the minions by shooting things.
-#4) By way of #3, add collision detection for those attacks when hitting the minions.
-#5) Ensure that the user earns money for kills, and is able to only buy certain towers.
-#6) Provide ability to upgrade towers (example: fire tower becomes advanced fire tower).
+-----------------------
+Really, I have a lot of things I think were cool, but in reality, I don't think anything here is
+extraordinary. I do think it could be cleaned up a lot more. I also have a good sized TODO list, and
+known bugs:
-Graphics (These would be nice, but probably won't happen considering my timing):
-#7) It would be "cool" to have realistic shadows (towers shading each other), but I DON'T think I'll
-be able to get to that.
-#8) Clean up the sidebar to add textures, icons for towers (I would have to draw these), icons for
-money, lives, etc.
-#9) Add pop-ups, etc, on hover-over for icons, etc. to show the statistics of the towers.
-#10) Show area of attack for the towers.
+TODO:
+1) Dynamic paths would be cool. I'd have to change how the pathing is set up completely (as well as the
+ preview points), but that would be neat to be able to have random maps.
+2) Don't allow users to buy every tower. All of the "advanced" towers should be upgrade only.
+3) Adding shadow maps would be really cool.
+4) Clean up the sidebar to add textures/icons for the towers, money, lives, scrolls, etc.
+5) Add pop-ups (hover-overs) to show statistics for each tower, rather than text in lower right.
+6) Object selection for minions with specific stats
+7) Variety of minions. textures, colors, objs, etc
+8) GAME OVER. There is no way to lose the game right now.
+9) Short game. There is only 5 waves of enemies.
+
+KNOWN BUGS:
+1) Fix bug where user clicks on sidebar instead of using keyboard, they won't get the preview
+2) If a minion is killed and is the last one in the wave, then extra shots will stick around until the
+ next wave.
+3) I'm using straight arrays and no-where am I re-sorting those arrays if we "sell" a tower, etc. so
+ it's possible to lose towers after the array loops back to the beginning.
+4) If the game is paused, the timers don't pause, so it is possible to pause the game and have several
+ shots created when they shouldn't be.
-(SOME OF THESE MAY BE WRONG...)
+-----------------------
The following interactions are provided:
Keyboard interactions:
Special Keys:
@@ -45,20 +83,26 @@ Shift+Left => -5 th angle
Shift+Up => +5 ph angle
Shift+Down => -5 ph angle
-
Regular Keys:
Escape => close the program
+Spacebar => begin the game. Once a wave of enemies is completely killed, press spacebar to send
+ the next wave.
r or R => reset to original parameters
+q => money cheat (money += 100)
x or X => toggle axes on/off (default off)
-f or F => toggle draw default objects (must reset "r" after toggling)
-v or V => toggle draw values on bottom of screen
-- => decrease the field of view (for perspective) by 1
-+ => increase the field of view (for perspective) by 1
+g or G => toggle grid on/off (default off)
+c or C => toggle show attack radius (default off)
+v or V => toggle draw values on bottom of screen (default off)
+- => decrease the field of view by 1
++ => increase the field of view by 1
i => decrease the dimensions by 0.2
I => increase the dimensions by 0.2
-l or L => toggle light on/off (default on)
+// ANIMATION:
+z => increment the animation by 1 (used when game paused for debugging)
m => toggle light movement (default on)
-M => toggle tops rotate movement (default on)
+p => toggle game paused
+M => toggle tower tops moving (default on)
+// LIGHTING:
< => decrease the light th by 1
> => increase the light th by 1
[ => decrease the light Y by 0.1
@@ -73,17 +117,23 @@ e => decrease the emission by 5
E => increase the emission by 5
n => decrease the shininess by 5
N => increase the shininess by 5
-select tower to draw:
-0 => none
-1 => fire
-2 => advanced fire
-3 => ice
-4 => advanced ice
-5 => earth
-6 => advanced earth
-7 => poison
-8 => advanced poison
-w or W => toggle preview mode (slightly buggy)
+// OBJECT SELECTION
+0 => none
+1 => basic
+2 => advanced
+3 => cone
+4 => advanced cone
+5 => square
+6 => advanced square
+shift+1 (!) => fire
+shift+2 (@) => advanced fire
+shift+3 (#) => ice
+shift+4 ($) => advanced ice
+shift+5 (%) => earth
+shift+6 (^) => advanced earth
+shift+7 (&) => poison
+shift+8 (*) => advanced poison
+w or W => toggle preview mode
delete or backspace => if a tower is selected on screen, then delete it
Mouse interactions:
@@ -92,20 +142,21 @@ Mouse interactions:
--left-click:
find the x,y,z position of the mouse and place the object in that position
the object will be reset to 'none' after placing the object
-NOTE: only 20 objects may be placed. If you place more than 20, then it starts to
+NOTE: only 57 objects may be placed. If you place more than 57, then it starts to
replace item 1, 2, etc
--shift+left-click:
same as left click, but object will not be reset to 'none' after click
-if tower selected is 'none', then select a tower on the left side:
--left-click a tower
+---able to view the statistics of the tower in lower right corner
---press 'delete' or 'backspace' and the tower should be deleted
"Sidebar" side (right side):
-left-click:
--click on a tower name to select it.
-if selecting a non-elemental tower, also select a texture to apply:
-click on a texture name to select it
+---able to view the statistics of the selected tower in the lower right corner
+---able to place the tower on the screen side if you have enough money
NOTE: there are two ways to select a shape:
1) keyboard shortcuts
View
1 animate.c
@@ -175,7 +175,6 @@ void moveShot(int i, int j, int k)
*/
void moveShots(void)
{
- /* TODO: stub for moving the shots */
int i,j;
for (i=0;i<lastShot;i++){
// shot s = shots[i];
View
1 drawing.c
@@ -62,7 +62,6 @@ void drawParameters(void)
* drawGrid
* ------
* Draws the grid if desired
- * TODO: polygon offset grid with the path
*/
void drawGrid(void)
{
View
17 gameplay.c
@@ -16,6 +16,23 @@ int calculateDamageToMinion(int k, int j, int i)
}
/*
+ * canUserBuyTower
+ * ------
+ * determines if user can buy the selected tower and sets the appropriate variables
+ */
+void canUserBuyTower(int newObjectSelected)
+{
+ if (money >= tower_data[objectSelected-1].cost) {
+ info = "cha-ching$ thanks buddy.";
+ setCurrentTowerData(objectSelected);
+ } else {
+ info = "Not enough $$$.";
+ objectSelected = DEF_OBJ_SEL;
+ preview_tower.id = DEF_OBJ_SEL;
+ }
+}
+
+/*
* modifyLives
* ------
* changes life +/- depending on buying or dying
View
1 general.c
@@ -167,7 +167,6 @@ void processPicks(void)
/* Found the object we need, break out of loop */
if (pixel[0] == red && pixel[1] == green && pixel[2] == blue) {
objectPicked = i;
- printf("tower type :%d\n",towers[i].type);
setCurrentTowerData(towers[i].type);
break;
}
View
4 initialize.c
@@ -164,6 +164,10 @@ void initWaves()
minions[i].damage += k;
minions[i].health += (15*k);
minions[i].money += (5*k);
+ /* this should be a factor 0-100 */
+ minions[i].rgb.r = 27+k*10+i*02;
+ minions[i].rgb.g = 27+k*10+i*02;
+ minions[i].rgb.b = 27+k*10+i*02;
if (k < 3)
minions[i].speed = 5-k;
View
3 models.c
@@ -499,6 +499,7 @@ void minionModel(minion m)
glTranslated(m.translation.x,m.translation.y,m.translation.z);
glRotated(m.rotation.y,0,1,0);
glScaled(m.scale.x,m.scale.y,m.scale.z);
+ glColor3f((double)m.rgb.r/100,(double)m.rgb.g/100,(double)m.rgb.b/100);
glCallList(m.type);
/* sphere for reference with collision detection
@@ -509,8 +510,8 @@ void minionModel(minion m)
glColor3f(1,1,0);
glTranslated(-2,4,-0.5);
glutSolidSphere(5,16,16);
- glColor3fv(white);
}
+ glColor3fv(white);
glPopMatrix();
}
View
1 prototypes.h
@@ -160,6 +160,7 @@ void sidebarMouse(int btn, int state, int x, int y);
/* Gameplay (gameplay.c) */
int calculateDamageToMinion(int k, int j, int i);
+void canUserBuyTower(int newObjectSelected);
void modifyLives(int die, int damage);
void modifyMoney(int what, int amount);
void modifyScore(int k);
View
7 screen.c
@@ -120,12 +120,7 @@ void screenMouse(int btn, int state, int x, int y)
/* game data */
if (money >= tower_data[objectSelected-1].cost) {
info = "cha-ching$ thanks buddy.";
- currentTextureSelected = tower_data[objectSelected-1].texture;
- currentTowerName = tower_data[objectSelected-1].name;
- currentTowerRange = tower_data[objectSelected-1].range;
- currentTowerDamage = tower_data[objectSelected-1].damage;
- currentTowerFireRate = tower_data[objectSelected-1].fireRate;
- currentTowerCost = tower_data[objectSelected-1].cost;
+ setCurrentTowerData(objectSelected);
} else {
info = "Not enough $$$.";
objectSelected = DEF_OBJ_SEL;
View
16 sidebar.c
@@ -48,14 +48,14 @@ void sidebarDisplay(void)
sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_ADV_CONE, "[4] advanced cone");
sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_SQUARE, "[5] square");
sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_ADV_SQUARE, "[6] advanced square");
- sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_FIRE, "[CTRL+1] fire");
- sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_FIRE2, "[CTRL+2] advanced fire");
- sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_ICE, "[CTRL+3] ice");
- sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_ICE2, "[CTRL+4] advanced ice");
- sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_EARTH, "[CTRL+5] earth");
- sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_EARTH2, "[CTRL+6] advanced earth");
- sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_POISON, "[CTRL+7] poison");
- sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_POISON2, "[CTRL+8] advanced poison");
+ sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_FIRE, "[SHIFT+1] fire");
+ sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_FIRE2, "[SHIFT+2] advanced fire");
+ sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_ICE, "[SHIFT+3] ice");
+ sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_ICE2, "[SHIFT+4] advanced ice");
+ sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_EARTH, "[SHIFT+5] earth");
+ sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_EARTH2, "[SHIFT+6] advanced earth");
+ sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_POISON, "[SHIFT+7] poison");
+ sidebarRow(10, windowHeight-DEF_TEXT_Y_OFFSET*++line, OBJ_POISON2, "[SHIFT+8] advanced poison");
++line;
setFont("helvetica",12);
View
23 window.c
@@ -24,7 +24,6 @@ void windowDisplay(void)
*/
void windowKey(unsigned char key,int x,int y)
{
- int modifiers = glutGetModifiers();
/* Exit on ESC */
if (key == 27) exit(0);
/* Spacebar to begin game or send next wave */
@@ -47,6 +46,8 @@ void windowKey(unsigned char key,int x,int y)
}
/* reset to default screen */
else if (key == 'r' || key == 'R') reset();
+ /* money cheat */
+ else if (key == 'q') money += 100;
/* toggle axes */
else if (key == 'x' || key == 'X') axes = 1-axes;
/* toggle grid */
@@ -61,7 +62,7 @@ void windowKey(unsigned char key,int x,int y)
/* change dim */
else if (key == 'i' && dim>1) dim -= 0.2;
else if (key == 'I') dim += 0.2;
- /* BEGIN ANIMATION FUNCTIANALITY */
+ /* BEGIN ANIMATION FUNCTIONALITY */
/* Slow animate */
else if (key == 'z') slowAnimate();
/* Toggle light movement */
@@ -96,22 +97,22 @@ void windowKey(unsigned char key,int x,int y)
else if (key == 'N' && shininess<7) shininess += 1;
/* BEGIN OPTION SELECTION FUNCTIONALITY */
/* Select object */
- else if (modifiers == GLUT_ACTIVE_CTRL && key == '1') changeObjectSelected(OBJ_FIRE);
- else if (modifiers == GLUT_ACTIVE_CTRL && key == '2') changeObjectSelected(OBJ_FIRE2);
- else if (modifiers == GLUT_ACTIVE_CTRL && key == '3') changeObjectSelected(OBJ_ICE);
- else if (modifiers == GLUT_ACTIVE_CTRL && key == '4') changeObjectSelected(OBJ_ICE2);
- else if (modifiers == GLUT_ACTIVE_CTRL && key == '5') changeObjectSelected(OBJ_EARTH);
- else if (modifiers == GLUT_ACTIVE_CTRL && key == '6') changeObjectSelected(OBJ_EARTH2);
- else if (modifiers == GLUT_ACTIVE_CTRL && key == '7') changeObjectSelected(OBJ_POISON);
- else if (modifiers == GLUT_ACTIVE_CTRL && key == '8') changeObjectSelected(OBJ_POISON2);
+ else if (key == '!') changeObjectSelected(OBJ_FIRE);
+ else if (key == '@') changeObjectSelected(OBJ_FIRE2);
+ else if (key == '#') changeObjectSelected(OBJ_ICE);
+ else if (key == '$') changeObjectSelected(OBJ_ICE2);
+ else if (key == '%') changeObjectSelected(OBJ_EARTH);
+ else if (key == '^') changeObjectSelected(OBJ_EARTH2);
+ else if (key == '&') changeObjectSelected(OBJ_POISON);
+ else if (key == '*') changeObjectSelected(OBJ_POISON2);
else if (key == '0') changeObjectSelected(DEF_OBJ_SEL);
else if (key == '1') changeObjectSelected(OBJ_BASIC);
else if (key == '2') changeObjectSelected(OBJ_ADV);
else if (key == '3') changeObjectSelected(OBJ_CONE);
else if (key == '4') changeObjectSelected(OBJ_ADV_CONE);
else if (key == '5') changeObjectSelected(OBJ_SQUARE);
else if (key == '6') changeObjectSelected(OBJ_ADV_SQUARE);
- /* Toggle preview mode (slightly buggy) */
+ /* Toggle preview mode */
else if (key == 'w' || key == 'W') {
preview = 1-preview;
/* Reset preview object if preview is turned off */

0 comments on commit 49f6628

Please sign in to comment.
Something went wrong with that request. Please try again.