summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Judson Rosen2017-03-27 01:32:33 -0400
committerJoshua Judson Rosen2017-03-28 22:07:50 -0400
commit1ddaf31890b4e1f5d80f3c0934d44a098dc935cd (patch)
treec6e89dc6aead1a69c684b082b665287a8ce7f0a0
parentREPL: just use guile's normal REPL (diff)
downloadgnurobots-1ddaf31890b4e1f5d80f3c0934d44a098dc935cd.tar.gz
UI: show for _what_ types of things robot is smelling/feeling/looking
-rw-r--r--include/ui-arena.h12
-rw-r--r--src/grobot.c7
-rw-r--r--src/main.c2
-rw-r--r--src/ui-arena.c41
4 files changed, 36 insertions, 26 deletions
diff --git a/include/ui-arena.h b/include/ui-arena.h
index 2fee88f..efcb32c 100644
--- a/include/ui-arena.h
+++ b/include/ui-arena.h
@@ -60,23 +60,25 @@ GtkWidget *ui_arena_new();
void ui_arena_set_map(UIArena *arena, Map *map);
void ui_arena_postinit(UIArena *arena);
void ui_arena_draw(UIArena *arena);
-void ui_arena_update_status(UIArena *arena, const gchar *s, glong energy,
- glong score, glong shields);
+void ui_arena_update_status(UIArena *arena, const gchar *fmt, const gchar *thing,
+ glong energy, glong score, glong shields);
void ui_arena_add_thing(UIArena *arena, gint x, gint y, gint thing);
void ui_arena_move_robot(UIArena *arena, gint from_x, gint from_y,
gint to_x, gint to_y, gint cdir, glong energy, glong score,
glong shields);
void ui_arena_robot_smell(UIArena *arena, gint x, gint y, gint cdir,
- glong energy, glong score, glong shields);
+ glong energy, glong score, glong shields, const gchar *thing);
void ui_arena_robot_zap(UIArena *arena, gint x, gint y, gint cdir,
gint x_to, gint y_to, glong energy, glong score, glong shields);
void ui_arena_robot_feel(UIArena *arena, gint x, gint y, gint cdir,
- gint x_to, gint y_to, glong energy, glong score, glong shields);
+ gint x_to, gint y_to, glong energy, glong score, glong shields,
+ const gchar *thing);
void ui_arena_robot_grab(UIArena *arena, gint x, gint y, gint cdir,
gint x_to, gint y_to, glong energy, glong score, glong shields);
void ui_arena_robot_look(UIArena *arena, gint x, gint y, gint cdir,
- gint x_to, gint y_to, glong energy, glong score, glong shields);
+ gint x_to, gint y_to, glong energy, glong score, glong shields,
+ const gchar *thing);
G_END_DECLS
diff --git a/src/grobot.c b/src/grobot.c
index 02fcc7d..3cacadc 100644
--- a/src/grobot.c
+++ b/src/grobot.c
@@ -490,7 +490,8 @@ gboolean g_robot_smell(GRobot *robot, gchar *str)
gdk_threads_enter();
ui_arena_robot_smell(robot->ui, robot->x, robot->y, robot->dir,
- robot->energy, robot->score, robot->shields);
+ robot->energy, robot->score, robot->shields,
+ str);
gdk_threads_leave();
/* Smell for the thing */
@@ -556,7 +557,7 @@ gboolean g_robot_feel(GRobot *robot, gchar *str)
gdk_threads_enter();
ui_arena_robot_feel(robot->ui, robot->x, robot->y, robot->dir, x_to,
- y_to, robot->energy, robot->score, robot->shields);
+ y_to, robot->energy, robot->score, robot->shields, str);
gdk_threads_leave();
if (MAP_GET_OBJECT(robot->map, x_to, y_to) == BADDIE)
@@ -620,7 +621,7 @@ gboolean g_robot_look(GRobot *robot, gchar *str)
gdk_threads_enter();
ui_arena_robot_look(robot->ui, robot->x, robot->y, robot->dir, x_to,
- y_to, robot->energy, robot->score, robot->shields);
+ y_to, robot->energy, robot->score, robot->shields, str);
gdk_threads_leave();
while (MAP_GET_OBJECT(robot->map, x_to, y_to) == SPACE)
diff --git a/src/main.c b/src/main.c
index fcc55f5..9867bcb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -370,7 +370,7 @@ void gui_main()
/* draw the map */
ui_arena_draw(arena);
- ui_arena_update_status(arena, "Welcome to GNU Robots",
+ ui_arena_update_status(arena, "Welcome to GNU Robots", NULL,
robot->energy, robot->score, robot->shields);
gtk_main();
diff --git a/src/ui-arena.c b/src/ui-arena.c
index fdc66fb..854d75d 100644
--- a/src/ui-arena.c
+++ b/src/ui-arena.c
@@ -246,11 +246,12 @@ static void put_tile(UIArena *arena, GdkPixmap *image, gint x, gint y)
GDK_DRAWABLE(image), 0, 0, x, y, TILE_SIZE, TILE_SIZE);
}
-void ui_arena_update_status(UIArena *arena, const gchar *s, glong energy,
- glong score, glong shields)
+void ui_arena_update_status(UIArena *arena, const gchar *fmt, const gchar *thing,
+ glong energy, glong score, glong shields)
{
gchar status[20];
gint x = 0;
+ gchar *s = NULL;
while(x < arena->priv->width)
{
@@ -261,9 +262,11 @@ void ui_arena_update_status(UIArena *arena, const gchar *s, glong energy,
x += 96;
}
+ s = g_strdup_printf(fmt, thing);
gdk_draw_string(arena->priv->buf, arena->priv->font,
GTK_WIDGET(arena)->style->white_gc, 3,
arena->priv->map_size->num_rows * TILE_SIZE + 16, s);
+ g_free(s);
if(energy > -1)
{
@@ -342,7 +345,8 @@ void ui_arena_move_robot(UIArena *arena, gint from_x, gint from_y,
g_assert(distance <= 1);
- ui_arena_update_status(arena, "Robot moves..", energy, score, shields);
+ ui_arena_update_status(arena, "Robot moves..", NULL,
+ energy, score, shields);
/* Check if robot is moving within a single box */
if (distance == 0)
@@ -423,11 +427,11 @@ void ui_arena_move_robot(UIArena *arena, gint from_x, gint from_y,
/* hooks to animate the robot */
void ui_arena_robot_smell(UIArena *arena, gint x, gint y, gint cdir,
- glong energy, glong score, glong shields)
+ glong energy, glong score, glong shields, const gchar *thing)
{
/* If we want to change the pic, do it here */
- ui_arena_update_status(arena, "Robot sniffs...", energy, score,
- shields);
+ ui_arena_update_status(arena, "Robot sniffs for %s...", thing,
+ energy, score, shields);
g_usleep(USLEEP_TIME);
}
@@ -435,17 +439,19 @@ void ui_arena_robot_smell(UIArena *arena, gint x, gint y, gint cdir,
void ui_arena_robot_zap(UIArena *arena, gint x, gint y, gint cdir,
gint x_to, gint y_to, glong energy, glong score, glong shields)
{
- ui_arena_update_status(arena, "Robot fires his little gun...", energy,
- score, shields);
+ ui_arena_update_status(arena, "Robot fires his little gun...", NULL,
+ energy, score, shields);
g_usleep(USLEEP_TIME);
}
-void ui_arena_robot_feel(UIArena *arena, gint x, gint y, gint cdir,
- gint x_to, gint y_to, glong energy, glong score, glong shields)
+void ui_arena_robot_feel(UIArena *arena,
+ gint x, gint y, gint cdir,
+ gint x_to, gint y_to, glong energy, glong score, glong shields,
+ const gchar *thing)
{
- ui_arena_update_status(arena, "Robot feels for a thing...", energy,
- score, shields);
+ ui_arena_update_status(arena, "Robot feels for %s...", thing,
+ energy, score, shields);
g_usleep(USLEEP_TIME);
}
@@ -453,17 +459,18 @@ void ui_arena_robot_feel(UIArena *arena, gint x, gint y, gint cdir,
void ui_arena_robot_grab(UIArena *arena, gint x, gint y, gint cdir,
gint x_to, gint y_to, glong energy, glong score, glong shields)
{
- ui_arena_update_status(arena, "Robot grabs thing...", energy, score,
- shields);
+ ui_arena_update_status(arena, "Robot grabs...", NULL,
+ energy, score, shields);
g_usleep(USLEEP_TIME);
}
void ui_arena_robot_look(UIArena *arena, gint x, gint y, gint cdir,
- gint x_to, gint y_to, glong energy, glong score, glong shields)
+ gint x_to, gint y_to, glong energy, glong score, glong shields,
+ const gchar *thing)
{
- ui_arena_update_status(arena, "Robot looks for a thing...", energy,
- score, shields);
+ ui_arena_update_status(arena, "Robot looks for %s...", thing,
+ energy, score, shields);
g_usleep(USLEEP_TIME);
}