Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 54dedac8 authored by SZCZEPANSKI Marin's avatar SZCZEPANSKI Marin
Browse files

Déplacements up/down/left/right dans fullgame

parent 56d56f1f
No related branches found
No related tags found
No related merge requests found
......@@ -4,10 +4,12 @@ OBJECTS := items.o map.o action.o shop.o monster.o common.o events.o events_map.
CC := gcc
CFLAGS := -g
DEFINES := -Dshow_solution
all: main
main: $(OBJECTS) main.c
$(CC) $(CFLAGS) -o $@ main.c $(OBJECTS)
$(CC) $(CFLAGS) -o $@ main.c $(OBJECTS) $(DEFINES)
clean:
rm *.o
......
......@@ -33,10 +33,10 @@ void turn_right (void)
{
int d;
switch (player_direction) {
case 8: d=6; break;
case 4: d=8; break;
case 2: d=4; break;
case 6: d=2; break;
case UP: d=RIGHT; break;
case LEFT: d=UP; break;
case DOWN: d=LEFT; break;
case RIGHT: d=DOWN; break;
default: assert(false);
}
player_direction = d;
......@@ -46,10 +46,10 @@ void turn_left (void)
{
int d;
switch (player_direction) {
case 8: d=4; break;
case 4: d=2; break;
case 2: d=6; break;
case 6: d=8; break;
case UP: d=LEFT; break;
case LEFT: d=DOWN; break;
case DOWN: d=RIGHT; break;
case RIGHT: d=UP; break;
default: assert(false);
}
player_direction = d;
......@@ -120,6 +120,45 @@ int player_idx_in_dir_n(int n)
return coord_idx (y, x);
}
void up() {
player_direction = UP;
forward();
}
void up_n(unsigned n) {
player_direction = UP;
forward_n(n);
}
void down() {
player_direction = DOWN;
forward();
}
void down_n(unsigned n) {
player_direction = DOWN;
forward_n(n);
}
void left() {
player_direction = LEFT;
forward();
}
void left_n(unsigned n) {
player_direction = LEFT;
forward_n(n);
}
void right() {
player_direction = RIGHT;
forward();
}
void right_n(unsigned n) {
player_direction = RIGHT;
forward_n(n);
}
void forward (void)
......
......@@ -9,6 +9,11 @@
// the height of the screen, in tiles
#define SCREEN_HEIGHT 8
#define UP 8
#define DOWN 2
#define LEFT 4
#define RIGHT 6
/**
* pos_x : current x position of the character
* pos_y : current y position of the character
......@@ -32,8 +37,18 @@ void coord_in_dir (int y, int x, int dir, int *cy, int *cx);
*/
void coord_in_dir_n (int y, int x, int dir, int *cy, int *cx, int n);
// Functions to move the character
void up();
void up_n(unsigned n);
void down();
void down_n(unsigned n);
void left();
void left_n(unsigned n);
void right();
void right_n(unsigned n);
void forward (void);
void forward_n (unsigned int);
void forward_n (unsigned num_steps);
/**
* Verifies if the player can move to tile (x, y).
......@@ -44,8 +59,6 @@ void forward_n (unsigned int);
*/
int collision(int x, int y);
void talk(void);
void fight(equipment eq);
......
FORWARD_N 18
TURN_LEFT
FORWARD
FORWARD
FORWARD
FORWARD
RIGHT_N 18
UP_N 4
TALK
BUY_WEAPON
BUY_ARMOR
TURN_RIGHT
TURN_RIGHT
FORWARD
FORWARD
FORWARD
FORWARD
TURN_LEFT
FORWARD_N 27
DOWN_N 4
RIGHT_N 27
FIGHT
FORWARD_N 10
RIGHT_N 10
......@@ -68,14 +68,22 @@ void apply_input(Command * c, equipment * eq) {
#else
void apply_input(Command * c, equipment eq) {
#endif
if (!strcmp(c->command_buffer, "FORWARD")) {
forward();
} else if (!strcmp(c->command_buffer, "FORWARD_N")) {
forward_n(atoi(c->args[0]));
} else if (!strcmp(c->command_buffer, "TURN_LEFT")) {
turn_left();
} else if (!strcmp(c->command_buffer, "TURN_RIGHT")) {
turn_right();
if (!strcmp(c->command_buffer, "UP")) {
up();
} else if (!strcmp(c->command_buffer, "UP_N")) {
up_n(atoi(c->args[0]));
} else if (!strcmp(c->command_buffer, "DOWN")) {
down();
} else if (!strcmp(c->command_buffer, "DOWN_N")) {
down_n(atoi(c->args[0]));
} else if (!strcmp(c->command_buffer, "LEFT")) {
left();
} else if (!strcmp(c->command_buffer, "LEFT_N")) {
left_n(atoi(c->args[0]));
} else if (!strcmp(c->command_buffer, "RIGHT")) {
right();
} else if (!strcmp(c->command_buffer, "RIGHT_N")) {
right_n(atoi(c->args[0]));
} else if (!strcmp(c->command_buffer, "TALK")) {
talk();
} else if (!strcmp(c->command_buffer, "BUY_WEAPON")) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment