Adrien Boucaud пре 12 година
родитељ
комит
a4148c5079
4 измењених фајлова са 34 додато и 10 уклоњено
  1. 1 0
      hexagon.c
  2. 16 3
      struct.h
  3. 9 5
      wall.c
  4. 8 2
      wall.h

+ 1 - 0
hexagon.c

@@ -20,6 +20,7 @@ int player_angle=0;
 Camera cam = {64, 32, 0};
 
 //linked list of obstacles
+//at the moment, there is only a list, but at term, we should be using the lists from the Line struct. (And thus remove the "line" member from the Wall struct
 Wall *list = NULL;
 
 //delta angle: defines the 'speed' of the player

+ 16 - 3
struct.h

@@ -1,24 +1,35 @@
 #ifndef STRUCT_H
 #define STRUCT_H
 
+//constants
 #define PI 3.14159265
 #define SIN_60 0.866025404
 #define COS_60 0.5
-#define abs(x) x>0 ? x : -x
 #define true 1
 #define false 0
 #define bool unsigned char
 
+//macros
+#define abs(x) x>0 ? x : -x
+
 typedef struct Camera Camera;
 typedef struct Wall Wall;
 typedef struct Line Line;
-
+//the camera is defined by its center
+// ! and not by its upper left corner !
+//and an angle
 struct Camera{
     int cX;
     int cY;
     int angle;
 };
 
+//a simple obstacle structure
+//d is the distance from the lowest face of the trapeze to the center of the screen
+//h is the thickness of the wall
+//line indicates the line that contains this obstacle
+//id is self explanatory
+//nxt is used by the linked list
 struct Wall{
     int d;
     int h;
@@ -28,9 +39,11 @@ struct Wall{
     Wall *nxt;
 };
 
+//a line. There are six lines (by default) in the game, numeroted from 0 to 5
+//each list has a list of obstacles and an angle
 struct Line{
     int id;
     Wall *list;
     int angle;
 };
-#endif
+#endif

+ 9 - 5
wall.c

@@ -26,7 +26,7 @@ Wall *addWall(Wall *list, int d, int h, int id, int line)
 
 }
 
-Wall *removeWall(Wall *list, int id)
+Wall *removeWall(Wall *list, int d)
 {
 	Wall *tmp1;
 	Wall *tmp2;
@@ -67,12 +67,15 @@ void update(Wall *list)
 	do{
 		if(tmp != NULL)
 		{
+			//just reducing the distance from the center
 			tmp->d-=1;
 		}
 		tmp = tmp->nxt;
 	}while(tmp != NULL);
 }
 
+//these are the actual drawing functions
+//they should the rewritten from scratch
 int getSlopeIndex(int dot1, int dot2)
 {
 	if(dot2 - dot1 == 1)
@@ -186,6 +189,7 @@ void show(Wall *list, Camera *cam)
 	}while(tmp != NULL);
 }
 
+//tests every Wall in the list
 bool isColliding(Wall *list, int player_angle)
 {
 	Wall *tmp;
@@ -194,10 +198,10 @@ bool isColliding(Wall *list, int player_angle)
 	do{
 		if(tmp != NULL)
 		{
-			if(tmp-> d <= 8)
-			{
+			if(tmp-> d <= 8)//if the wall is close enough from the center of the screen
+			{	//and is on the same line than the player
 				if(tmp->line == (int)(player_angle/60)) //&& tmp->line * 60 + 60 > player_angle)
-				{
+				{	//BOOM
 					return true;
 				}
 			}
@@ -205,4 +209,4 @@ bool isColliding(Wall *list, int player_angle)
 		tmp = tmp->nxt;
 	}while(tmp != NULL);
 	return false;
-}
+}

+ 8 - 2
wall.h

@@ -5,9 +5,15 @@
 #include "struct.h"
 #include "MonochromeLib.h"
 #include "math.h"
+//adds a wall to the linked list specified in the parameter "list"
 Wall *addWall(Wall *list, int d, int h, int id, int line);//returns a new pointer to the first element
-Wall *removeWall(Wall *list, int id); //returns a new pointer to the first element
+//removes every wall from "list" whose d member is smaller than the "d" passed as argument
+Wall *removeWall(Wall *list, int d); //returns a new pointer to the first element
+
+//show the ll "list"
 void show(Wall *list, Camera *cam);
+//updates the ll "list"
 void update(Wall *list);
+//simple collision test. Returns true if a Wall from the list collides with the player
 bool isColliding(Wall *list, int player_angle);
-#endif
+#endif