Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions software/game/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ alt_up_character_lcd_dev * char_lcd_dev;
void initialize_lcd() {
char_lcd_dev = alt_up_character_lcd_open_dev ("/dev/character_lcd_0");
if ( char_lcd_dev == NULL)
alt_printf ("Error: could not open character LCD device\n");
alt_printf ("\nError: could not open character LCD device\n");
else
alt_printf ("Opened character LCD device\n");
alt_printf ("\nOpened character LCD device\n");
alt_up_character_lcd_init (char_lcd_dev);
}
#endif /* LCD_H_ */
29 changes: 7 additions & 22 deletions software/game/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#define keys (volatile char *) BUTTONS_BASE

void init() {
initialize_lcd();
initialize_vga();
initialize_sdcard();
}
Expand All @@ -22,30 +21,16 @@ int main(void)
{
alt_timestamp_start();
init();
printf("\nSeed %d", (unsigned int)alt_timestamp());
srand((unsigned int)alt_timestamp());
bool game_on = true;

<<<<<<< HEAD
srand((int)alt_timestamp());
Player *player1 = construct_player(get_screen_name());
printf("\nPlayer created with name %s, screen %s", player1->screen_name, get_screen_name());
Map *map = construct_map();

=======
>>>>>>> Moved test method from main() to test()
test();

//Player player1;
Map map;
Obstacle obstacle1, obstacle2;

obstacle1.type = WALL;
set_coordinates(obstacle1, 0, 0);

Map map;
Player player1;
char* phrases[PHRASES_COUNT] = {"Pow", "Nice Job", "You Suck", "", ""};

construct_player(&player1, get_screen_name());
construct_map(&map, phrases, 10);

while (player1.health != 0 && game_on) {
while (player1->health != 0 && game_on) {
printf("\nGame playing");
// read player controls
// calc player next move
// check interactions
Expand Down
20 changes: 10 additions & 10 deletions software/game/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
#define MAP_H_

#include "obstacle.h"

/* Following info will usually come from a map structure in the sdcard */
#define PHRASES_COUNT 5
#define MAP_VELOCITY 10
char* phrases[PHRASES_COUNT] = {"Pow", "Nice Job", "You Suck", "", ""};
/**/

typedef struct{
int graphics[640][240];
int velocity;
char *phrases[PHRASES_COUNT];
Obstacle obstacles [];
Obstacle * obstacles;
} Map;

void construct_map(Map* map, char* phrases[PHRASES_COUNT], int velocity) {
Obstacle obstacle1, obstacle2;

construct_obstacle(&obstacle1, WALL, 0, 0);
construct_obstacle(&obstacle2, POTION, 10, 10);

map->velocity = velocity;
Map * construct_map() {
Map * map;
map->velocity = MAP_VELOCITY;
memcpy(map->phrases, phrases, sizeof(phrases));
map->obstacles[0] = obstacle1;
map->obstacles[1] = obstacle1;
map->obstacles = construct_obstacle(WALL, 100, 100);
}

#endif /* LCD_H_ */
17 changes: 10 additions & 7 deletions software/game/obstacle.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,27 @@

typedef enum {
WALL,
POTION
POTION,
WENCH,
CHEST,
COIN,
POISION
} ObstacleType;

typedef struct{
ObstacleType type;
int coordinates_x;
int coordinates_y;
struct Obstacle * next;
} Obstacle;

void construct_obstacle(Obstacle* obstacle, ObstacleType type, int xpos, int ypos) {
Obstacle * construct_obstacle(ObstacleType type, int xpos, int ypos) {
Obstacle * obstacle;
obstacle->type = type;
obstacle->coordinates_x = xpos;
obstacle->coordinates_y = ypos;
}

void set_obstacle_coordinates(Obstacle *obstacle, int x, int y){
obstacle->coordinates_x = x;
obstacle->coordinates_y = y;
obstacle->next = NULL;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make a function for setting, obstacle->next. Also we're probably going to need set_obstacle_coordinates later on when we start moving the obstacle, I think we should leave it in there.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from that, all the changes look good.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method to add new obcstacles will be covered in a separate PR.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding keeping this method, I don;t agree. It isn't used anywhere right now (and unused in the code I'm righting to generate new obstacles).

Having usused code, creates problems. We have to remember exactly where something was referenced and keep chaning it as we modify or create new code. Since its isnt used anywhere, the problems arent obvious either. When someone wants to use this, they can add it later. Its only 4 lines.

return obstacle;
}

#endif /* OBSTACLE_H_ */
6 changes: 3 additions & 3 deletions software/game/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ typedef struct{
int coordinates_y;
} Player;

void construct_player(Player* player, char* screen_name) {
Player * construct_player(char* screen_name) {
Player * player;
player->screen_name = screen_name;
player->score = START_SCORE;
player->time = START_TIME;
Expand All @@ -32,8 +33,7 @@ void construct_player(Player* player, char* screen_name) {
player->velocity_y = START_VELOCITY_Y;
player->coordinates_x = START_COORDINATE_X;
player->coordinates_y = START_COORDINATE_Y;

printf("\nPlayer created with name %s ", player->screen_name);
return player;
}

void set_player_coordinates(Player* player) {
Expand Down