[gnome-games] Make gnobots2 work with GTK3/cairo
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] Make gnobots2 work with GTK3/cairo
- Date: Tue, 30 Nov 2010 04:16:49 +0000 (UTC)
commit 1a30c7ad90848280f58e245ebf709352d84c3b82
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Nov 30 15:16:23 2010 +1100
Make gnobots2 work with GTK3/cairo
configure.in | 4 +-
gnobots2/game.c | 398 +++++++++++++++++++++++----------------------------
gnobots2/game.h | 2 +
gnobots2/gnobots.c | 4 +-
gnobots2/graphics.c | 143 ++++++-------------
gnobots2/graphics.h | 6 +-
6 files changed, 228 insertions(+), 329 deletions(-)
---
diff --git a/configure.in b/configure.in
index b06839e..428c6cb 100644
--- a/configure.in
+++ b/configure.in
@@ -23,9 +23,9 @@ AM_MAINTAINER_MODE([enable])
# we support and which features to check for
# This is the canonical list of all game subdirectories.
-allgames="aisleriot glines gnect gnibbles gnotravex gnotski gtali iagno quadrapassel"
+allgames="aisleriot glines gnect gnibbles gnobots2 gnotravex gnotski gtali iagno quadrapassel"
AC_SUBST([allgames])
-staginggames="gnomine swell-foop mahjongg glchess gnobots2 gnome-sudoku lightsoff"
+staginggames="gnomine swell-foop mahjongg glchess gnome-sudoku lightsoff"
AC_SUBST([staginggames])
gamelist=""
diff --git a/gnobots2/game.c b/gnobots2/game.c
index b144fb4..4b3cfcb 100644
--- a/gnobots2/game.c
+++ b/gnobots2/game.c
@@ -46,6 +46,7 @@
/* Exported Variables */
/**********************************************************************/
gint game_state = STATE_PLAYING;
+gint arena[GAME_WIDTH][GAME_HEIGHT];
/**********************************************************************/
@@ -60,14 +61,11 @@ static gint score = 0;
static gint kills = 0;
static gint score_step = 0;
static gint safe_teleports = 0;
-static gboolean display_updated = 0;
static gint player_xpos = 0;
static gint player_ypos = 0;
static gint push_xpos = -1;
static gint push_ypos = -1;
static gint game_timer_id = -1;
-static gint arena[GAME_WIDTH][GAME_HEIGHT];
-static gint old_arena[GAME_WIDTH][GAME_HEIGHT];
static gint temp_arena[GAME_WIDTH][GAME_HEIGHT];
/**********************************************************************/
@@ -81,7 +79,6 @@ static void add_kill (gint type);
static void clear_arena (void);
static gint check_location (gint x, gint y);
static void generate_level (void);
-static void draw_graphics (void);
static void update_arena (void);
static gint timeout_cb (void *data);
static void destroy_game_timer (void);
@@ -117,7 +114,7 @@ message_box (gchar * msg)
GtkWidget *box;
box = gtk_message_dialog_new (GTK_WINDOW (app), GTK_DIALOG_MODAL,
- GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", msg);
+ GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", msg);
gtk_dialog_run (GTK_DIALOG (box));
gtk_widget_destroy (box);
}
@@ -145,19 +142,19 @@ show_scores (gint pos, gboolean endofgame)
gtk_window_present (GTK_WINDOW (sorrydialog));
} else {
sorrydialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (app),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_INFO,
- GTK_BUTTONS_NONE,
- "<b>%s</b>\n%s",
- _
- ("Game over!"),
- _
- ("Great work, but unfortunately your score did not make the top ten."));
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_NONE,
+ "<b>%s</b>\n%s",
+ _
+ ("Game over!"),
+ _
+ ("Great work, but unfortunately your score did not make the top ten."));
gtk_dialog_add_buttons (GTK_DIALOG (sorrydialog), GTK_STOCK_QUIT,
- GTK_RESPONSE_REJECT, _("_New Game"),
- GTK_RESPONSE_ACCEPT, NULL);
+ GTK_RESPONSE_REJECT, _("_New Game"),
+ GTK_RESPONSE_ACCEPT, NULL);
gtk_dialog_set_default_response (GTK_DIALOG (sorrydialog),
- GTK_RESPONSE_ACCEPT);
+ GTK_RESPONSE_ACCEPT);
gtk_window_set_title (GTK_WINDOW (sorrydialog), "");
}
dialog = sorrydialog;
@@ -167,33 +164,33 @@ show_scores (gint pos, gboolean endofgame)
gtk_window_present (GTK_WINDOW (scoresdialog));
} else {
scoresdialog = games_scores_dialog_new (GTK_WINDOW (app),
- highscores, _("Robots Scores"));
+ highscores, _("Robots Scores"));
games_scores_dialog_set_category_description (GAMES_SCORES_DIALOG
- (scoresdialog),
- _("Map:"));
+ (scoresdialog),
+ _("Map:"));
}
if (pos > 0) {
play_sound (SOUND_VICTORY);
games_scores_dialog_set_hilight (GAMES_SCORES_DIALOG (scoresdialog),
- pos);
+ pos);
message = g_strdup_printf ("<b>%s</b>\n\n%s",
- _("Congratulations!"),
+ _("Congratulations!"),
pos == 1 ? _("Your score is the best!") :
- _("Your score has made the top ten."));
+ _("Your score has made the top ten."));
games_scores_dialog_set_message (GAMES_SCORES_DIALOG (scoresdialog),
- message);
+ message);
g_free (message);
} else {
games_scores_dialog_set_message (GAMES_SCORES_DIALOG (scoresdialog),
- NULL);
+ NULL);
}
if (endofgame) {
games_scores_dialog_set_buttons (GAMES_SCORES_DIALOG (scoresdialog),
- GAMES_SCORES_QUIT_BUTTON |
- GAMES_SCORES_NEW_GAME_BUTTON);
+ GAMES_SCORES_QUIT_BUTTON |
+ GAMES_SCORES_NEW_GAME_BUTTON);
} else {
games_scores_dialog_set_buttons (GAMES_SCORES_DIALOG (scoresdialog), 0);
}
@@ -226,11 +223,11 @@ log_score (gint sc)
if (properties_super_safe_moves ()) {
sbuf =
g_strdup_printf ("%s-super-safe",
- game_config_filename (current_game_config ()));
+ game_config_filename (current_game_config ()));
} else if (properties_safe_moves ()) {
sbuf =
g_strdup_printf ("%s-safe",
- game_config_filename (current_game_config ()));
+ game_config_filename (current_game_config ()));
} else {
sbuf =
g_strdup_printf ("%s", game_config_filename (current_game_config ()));
@@ -314,7 +311,7 @@ add_kill (gint type)
}
gnobots_statusbar_set (score, current_level + 1, safe_teleports,
- num_robots1, num_robots2);
+ num_robots1, num_robots2);
}
@@ -332,7 +329,6 @@ clear_arena (void)
for (i = 0; i < GAME_WIDTH; ++i) {
for (j = 0; j < GAME_HEIGHT; ++j) {
arena[i][j] = OBJECT_NONE;
- old_arena[i][j] = OBJECT_FOO;
}
}
@@ -355,9 +351,9 @@ load_temp_arena (void)
for (i = 0; i < GAME_WIDTH; ++i) {
for (j = 0; j < GAME_HEIGHT; ++j) {
if (arena[i][j] != OBJECT_PLAYER) {
- temp_arena[i][j] = arena[i][j];
+ temp_arena[i][j] = arena[i][j];
} else {
- temp_arena[i][j] = OBJECT_NONE;
+ temp_arena[i][j] = OBJECT_NONE;
}
}
}
@@ -412,7 +408,7 @@ generate_level (void)
current_level = 0;
num_robots1 = game_config ()->initial_type1;
message_box (_
- ("Congratulations, You Have Defeated the Robots!! \nBut Can You do it Again?"));
+ ("Congratulations, You Have Defeated the Robots!! \nBut Can You do it Again?"));
play_sound (SOUND_VICTORY);
}
@@ -428,7 +424,7 @@ generate_level (void)
num_robots1 = game_config ()->initial_type1;
num_robots2 = game_config ()->initial_type2;
message_box (_
- ("Congratulations, You Have Defeated the Robots!! \nBut Can You do it Again?"));
+ ("Congratulations, You Have Defeated the Robots!! \nBut Can You do it Again?"));
play_sound (SOUND_VICTORY);
}
@@ -444,8 +440,8 @@ generate_level (void)
yp = rand () % GAME_HEIGHT;
if (check_location (xp, yp) == OBJECT_NONE) {
- arena[xp][yp] = OBJECT_ROBOT1;
- break;
+ arena[xp][yp] = OBJECT_ROBOT1;
+ break;
}
}
}
@@ -457,8 +453,8 @@ generate_level (void)
yp = rand () % GAME_HEIGHT;
if (check_location (xp, yp) == OBJECT_NONE) {
- arena[xp][yp] = OBJECT_ROBOT2;
- break;
+ arena[xp][yp] = OBJECT_ROBOT2;
+ break;
}
}
}
@@ -466,37 +462,6 @@ generate_level (void)
}
/**
- * draw_graphics
- *
- * Description:
- * Draws all of the game objects
- **/
-static void
-draw_graphics (void)
-{
- gint i, j;
-
- for (i = 0; i < GAME_WIDTH; ++i) {
- for (j = 0; j < GAME_HEIGHT; ++j) {
- if (arena[i][j] == OBJECT_NONE) {
- if (arena[i][j] != old_arena[i][j]) {
- draw_object (i, j, arena[i][j]);
- }
- } else {
- draw_object (i, j, arena[i][j]);
- }
-
- old_arena[i][j] = arena[i][j];
- }
- }
-
- draw_bubble ();
-
- display_updated = TRUE;
-}
-
-
-/**
* update_arena
*
* Description:
@@ -515,27 +480,27 @@ update_arena (void)
if ((temp_arena[i][j] == OBJECT_HEAP) &&
- (push_xpos == i) && (push_ypos == j)) {
- if (arena[i][j] == OBJECT_ROBOT1) {
- add_splat_bubble (i, j);
- play_sound (SOUND_SPLAT);
- push_xpos = push_ypos = -1;
- score += game_config ()->score_type1_splatted;
- }
- if (arena[i][j] == OBJECT_ROBOT2) {
- add_splat_bubble (i, j);
- play_sound (SOUND_SPLAT);
- push_xpos = push_ypos = -1;
- score += game_config ()->score_type2_splatted;
- }
+ (push_xpos == i) && (push_ypos == j)) {
+ if (arena[i][j] == OBJECT_ROBOT1) {
+ add_splat_bubble (i, j);
+ play_sound (SOUND_SPLAT);
+ push_xpos = push_ypos = -1;
+ score += game_config ()->score_type1_splatted;
+ }
+ if (arena[i][j] == OBJECT_ROBOT2) {
+ add_splat_bubble (i, j);
+ play_sound (SOUND_SPLAT);
+ push_xpos = push_ypos = -1;
+ score += game_config ()->score_type2_splatted;
+ }
}
arena[i][j] = temp_arena[i][j];
if (arena[i][j] == OBJECT_ROBOT1) {
- num_robots1 += 1;
+ num_robots1 += 1;
} else if (arena[i][j] == OBJECT_ROBOT2) {
- num_robots2 += 1;
+ num_robots2 += 1;
}
}
}
@@ -556,10 +521,8 @@ update_arena (void)
}
}
- display_updated = FALSE;
-
gnobots_statusbar_set (score, current_level + 1, safe_teleports,
- num_robots1, num_robots2);
+ num_robots1, num_robots2);
}
@@ -578,23 +541,19 @@ timeout_cb (void *data)
animate_game_graphics ();
- draw_graphics ();
+ clear_game_area ();
if ((game_state == STATE_TYPE2) || (game_state == STATE_WTYPE2)) {
- if (display_updated) {
- move_type2_robots ();
- update_arena ();
- if (game_state == STATE_TYPE2) {
- game_state = STATE_PLAYING;
- } else if (game_state == STATE_WTYPE2) {
- game_state = STATE_WAITING;
- }
+ move_type2_robots ();
+ update_arena ();
+ if (game_state == STATE_TYPE2) {
+ game_state = STATE_PLAYING;
+ } else if (game_state == STATE_WTYPE2) {
+ game_state = STATE_WAITING;
}
} else if (game_state == STATE_WAITING) {
- if (display_updated) {
- remove_splat_bubble ();
- move_robots ();
- }
+ remove_splat_bubble ();
+ move_robots ();
} else if (game_state == STATE_COMPLETE) {
++endlev_counter;
if (endlev_counter >= CHANGE_DELAY) {
@@ -606,13 +565,13 @@ timeout_cb (void *data)
game_state = STATE_PLAYING;
set_move_menu_sensitivity (TRUE);
gnobots_statusbar_set (score, current_level + 1, safe_teleports,
- num_robots1, num_robots2);
+ num_robots1, num_robots2);
}
} else if (game_state == STATE_DEAD) {
++endlev_counter;
if (endlev_counter >= DEAD_DELAY) {
if (score > 0) {
- sp = log_score (score);
+ sp = log_score (score);
if (show_scores (sp, TRUE) == GTK_RESPONSE_REJECT) {
quit_game ();
}
@@ -670,7 +629,7 @@ init_game (void)
create_game_timer ();
g_signal_connect (GTK_WIDGET (app), "key_press_event",
- G_CALLBACK (keyboard_cb), 0);
+ G_CALLBACK (keyboard_cb), 0);
start_new_game ();
}
@@ -727,7 +686,7 @@ start_new_game (void)
game_state = STATE_PLAYING;
gnobots_statusbar_set (score, current_level + 1, safe_teleports,
- num_robots1, num_robots2);
+ num_robots1, num_robots2);
set_move_menu_sensitivity (TRUE);
}
@@ -747,9 +706,9 @@ move_all_robots (void)
for (i = 0; i < GAME_WIDTH; ++i) {
for (j = 0; j < GAME_HEIGHT; ++j) {
if ((arena[i][j] == OBJECT_PLAYER) || (arena[i][j] == OBJECT_HEAP)) {
- temp_arena[i][j] = arena[i][j];
+ temp_arena[i][j] = arena[i][j];
} else {
- temp_arena[i][j] = OBJECT_NONE;
+ temp_arena[i][j] = OBJECT_NONE;
}
}
}
@@ -757,27 +716,27 @@ move_all_robots (void)
for (i = 0; i < GAME_WIDTH; ++i) {
for (j = 0; j < GAME_HEIGHT; ++j) {
if ((arena[i][j] == OBJECT_ROBOT1) || (arena[i][j] == OBJECT_ROBOT2)) {
- nx = i;
- ny = j;
- if (player_xpos < nx)
- nx -= 1;
- if (player_xpos > nx)
- nx += 1;
- if (player_ypos < ny)
- ny -= 1;
- if (player_ypos > ny)
- ny += 1;
-
- if (temp_arena[nx][ny] == OBJECT_HEAP) {
- add_kill (arena[i][j]);
- } else if ((temp_arena[nx][ny] == OBJECT_ROBOT1) ||
- (temp_arena[nx][ny] == OBJECT_ROBOT2)) {
- add_kill (arena[i][j]);
- add_kill (temp_arena[nx][ny]);
- temp_arena[nx][ny] = OBJECT_HEAP;
- } else {
- temp_arena[nx][ny] = arena[i][j];
- }
+ nx = i;
+ ny = j;
+ if (player_xpos < nx)
+ nx -= 1;
+ if (player_xpos > nx)
+ nx += 1;
+ if (player_ypos < ny)
+ ny -= 1;
+ if (player_ypos > ny)
+ ny += 1;
+
+ if (temp_arena[nx][ny] == OBJECT_HEAP) {
+ add_kill (arena[i][j]);
+ } else if ((temp_arena[nx][ny] == OBJECT_ROBOT1) ||
+ (temp_arena[nx][ny] == OBJECT_ROBOT2)) {
+ add_kill (arena[i][j]);
+ add_kill (temp_arena[nx][ny]);
+ temp_arena[nx][ny] = OBJECT_HEAP;
+ } else {
+ temp_arena[nx][ny] = arena[i][j];
+ }
}
}
}
@@ -800,10 +759,10 @@ move_type2_robots (void)
for (i = 0; i < GAME_WIDTH; ++i) {
for (j = 0; j < GAME_HEIGHT; ++j) {
if ((arena[i][j] == OBJECT_PLAYER) ||
- (arena[i][j] == OBJECT_ROBOT1) || (arena[i][j] == OBJECT_HEAP)) {
- temp_arena[i][j] = arena[i][j];
+ (arena[i][j] == OBJECT_ROBOT1) || (arena[i][j] == OBJECT_HEAP)) {
+ temp_arena[i][j] = arena[i][j];
} else {
- temp_arena[i][j] = OBJECT_NONE;
+ temp_arena[i][j] = OBJECT_NONE;
}
}
}
@@ -811,27 +770,27 @@ move_type2_robots (void)
for (i = 0; i < GAME_WIDTH; ++i) {
for (j = 0; j < GAME_HEIGHT; ++j) {
if (arena[i][j] == OBJECT_ROBOT2) {
- nx = i;
- ny = j;
- if (player_xpos < nx)
- nx -= 1;
- if (player_xpos > nx)
- nx += 1;
- if (player_ypos < ny)
- ny -= 1;
- if (player_ypos > ny)
- ny += 1;
-
- if (temp_arena[nx][ny] == OBJECT_HEAP) {
- add_kill (arena[i][j]);
- } else if ((temp_arena[nx][ny] == OBJECT_ROBOT1) ||
- (temp_arena[nx][ny] == OBJECT_ROBOT2)) {
- add_kill (arena[i][j]);
- add_kill (temp_arena[nx][ny]);
- temp_arena[nx][ny] = OBJECT_HEAP;
- } else {
- temp_arena[nx][ny] = arena[i][j];
- }
+ nx = i;
+ ny = j;
+ if (player_xpos < nx)
+ nx -= 1;
+ if (player_xpos > nx)
+ nx += 1;
+ if (player_ypos < ny)
+ ny -= 1;
+ if (player_ypos > ny)
+ ny += 1;
+
+ if (temp_arena[nx][ny] == OBJECT_HEAP) {
+ add_kill (arena[i][j]);
+ } else if ((temp_arena[nx][ny] == OBJECT_ROBOT1) ||
+ (temp_arena[nx][ny] == OBJECT_ROBOT2)) {
+ add_kill (arena[i][j]);
+ add_kill (temp_arena[nx][ny]);
+ temp_arena[nx][ny] = OBJECT_HEAP;
+ } else {
+ temp_arena[nx][ny] = arena[i][j];
+ }
}
}
}
@@ -887,10 +846,10 @@ check_safe (gint x, gint y)
for (i = 0; i < GAME_WIDTH; ++i) {
for (j = 0; j < GAME_HEIGHT; ++j) {
if ((temp_arena[i][j] == OBJECT_PLAYER) ||
- (temp_arena[i][j] == OBJECT_HEAP)) {
- temp2_arena[i][j] = temp_arena[i][j];
+ (temp_arena[i][j] == OBJECT_HEAP)) {
+ temp2_arena[i][j] = temp_arena[i][j];
} else {
- temp2_arena[i][j] = OBJECT_NONE;
+ temp2_arena[i][j] = OBJECT_NONE;
}
}
}
@@ -898,25 +857,25 @@ check_safe (gint x, gint y)
for (i = 0; i < GAME_WIDTH; ++i) {
for (j = 0; j < GAME_HEIGHT; ++j) {
if ((temp_arena[i][j] == OBJECT_ROBOT1) ||
- (temp_arena[i][j] == OBJECT_ROBOT2)) {
- nx = i;
- ny = j;
- if (x < nx)
- nx -= 1;
- if (x > nx)
- nx += 1;
- if (y < ny)
- ny -= 1;
- if (y > ny)
- ny += 1;
-
- if ((temp2_arena[nx][ny] == OBJECT_ROBOT1) ||
- (temp2_arena[nx][ny] == OBJECT_ROBOT2) ||
- (temp2_arena[nx][ny] == OBJECT_HEAP)) {
- temp2_arena[nx][ny] = OBJECT_HEAP;
- } else {
- temp2_arena[nx][ny] = temp_arena[i][j];
- }
+ (temp_arena[i][j] == OBJECT_ROBOT2)) {
+ nx = i;
+ ny = j;
+ if (x < nx)
+ nx -= 1;
+ if (x > nx)
+ nx += 1;
+ if (y < ny)
+ ny -= 1;
+ if (y > ny)
+ ny += 1;
+
+ if ((temp2_arena[nx][ny] == OBJECT_ROBOT1) ||
+ (temp2_arena[nx][ny] == OBJECT_ROBOT2) ||
+ (temp2_arena[nx][ny] == OBJECT_HEAP)) {
+ temp2_arena[nx][ny] = OBJECT_HEAP;
+ } else {
+ temp2_arena[nx][ny] = temp_arena[i][j];
+ }
}
}
}
@@ -927,10 +886,10 @@ check_safe (gint x, gint y)
for (i = 0; i < GAME_WIDTH; ++i) {
for (j = 0; j < GAME_HEIGHT; ++j) {
if ((temp2_arena[i][j] == OBJECT_PLAYER) ||
- (temp2_arena[i][j] == OBJECT_HEAP)) {
- temp3_arena[i][j] = temp2_arena[i][j];
+ (temp2_arena[i][j] == OBJECT_HEAP)) {
+ temp3_arena[i][j] = temp2_arena[i][j];
} else {
- temp3_arena[i][j] = OBJECT_NONE;
+ temp3_arena[i][j] = OBJECT_NONE;
}
}
}
@@ -938,24 +897,24 @@ check_safe (gint x, gint y)
for (i = 0; i < GAME_WIDTH; ++i) {
for (j = 0; j < GAME_HEIGHT; ++j) {
if (temp2_arena[i][j] == OBJECT_ROBOT2) {
- nx = i;
- ny = j;
- if (x < nx)
- nx -= 1;
- if (x > nx)
- nx += 1;
- if (y < ny)
- ny -= 1;
- if (y > ny)
- ny += 1;
-
- if ((temp3_arena[nx][ny] == OBJECT_ROBOT1) ||
- (temp3_arena[nx][ny] == OBJECT_ROBOT2) ||
- (temp3_arena[nx][ny] == OBJECT_HEAP)) {
- temp3_arena[nx][ny] = OBJECT_HEAP;
- } else {
- temp3_arena[nx][ny] = temp2_arena[i][j];
- }
+ nx = i;
+ ny = j;
+ if (x < nx)
+ nx -= 1;
+ if (x > nx)
+ nx += 1;
+ if (y < ny)
+ ny -= 1;
+ if (y > ny)
+ ny += 1;
+
+ if ((temp3_arena[nx][ny] == OBJECT_ROBOT1) ||
+ (temp3_arena[nx][ny] == OBJECT_ROBOT2) ||
+ (temp3_arena[nx][ny] == OBJECT_HEAP)) {
+ temp3_arena[nx][ny] = OBJECT_HEAP;
+ } else {
+ temp3_arena[nx][ny] = temp2_arena[i][j];
+ }
}
}
}
@@ -1033,8 +992,8 @@ try_player_move (gint dx, gint dy)
if (temp_arena[nx][ny] == OBJECT_HEAP) {
if (game_config ()->moveable_heaps) {
if (!push_heap (nx, ny, dx, dy)) {
- push_xpos = push_ypos = -1;
- return FALSE;
+ push_xpos = push_ypos = -1;
+ return FALSE;
}
} else {
return FALSE;
@@ -1127,7 +1086,7 @@ safe_teleport_available (void)
for (x = 0; x < GAME_WIDTH; x++) {
for (y = 0; y < GAME_HEIGHT; y++) {
if (check_safe (x, y))
- return TRUE;
+ return TRUE;
}
}
@@ -1163,10 +1122,10 @@ player_move (gint dx, gint dy)
return FALSE;
} else {
if (!check_safe (nx, ny)) {
- if (properties_super_safe_moves () || safe_move_available ()) {
- play_sound (SOUND_BAD);
- return FALSE;
- }
+ if (properties_super_safe_moves () || safe_move_available ()) {
+ play_sound (SOUND_BAD);
+ return FALSE;
+ }
}
}
} else {
@@ -1211,9 +1170,9 @@ random_teleport (void)
for (i = 0; i < GAME_WIDTH; ++i) {
for (j = 0; j < GAME_HEIGHT; ++j) {
if (arena[i][j] != OBJECT_PLAYER) {
- temp_arena[i][j] = arena[i][j];
+ temp_arena[i][j] = arena[i][j];
} else {
- temp_arena[i][j] = OBJECT_NONE;
+ temp_arena[i][j] = OBJECT_NONE;
}
}
}
@@ -1239,7 +1198,7 @@ random_teleport (void)
xp = 0;
++yp;
if (yp >= GAME_HEIGHT) {
- yp = 0;
+ yp = 0;
}
}
@@ -1284,9 +1243,9 @@ safe_teleport (void)
for (i = 0; i < GAME_WIDTH; ++i) {
for (j = 0; j < GAME_HEIGHT; ++j) {
if (arena[i][j] != OBJECT_PLAYER) {
- temp_arena[i][j] = arena[i][j];
+ temp_arena[i][j] = arena[i][j];
} else {
- temp_arena[i][j] = OBJECT_NONE;
+ temp_arena[i][j] = OBJECT_NONE;
}
}
}
@@ -1314,7 +1273,7 @@ safe_teleport (void)
xp = 0;
++yp;
if (yp >= GAME_HEIGHT) {
- yp = 0;
+ yp = 0;
}
}
}
@@ -1336,64 +1295,61 @@ safe_teleport (void)
void
game_keypress (gint key)
{
- if (!display_updated)
- return;
-
if (game_state == STATE_PLAYING) {
switch (key) {
case KBD_NW:
if (player_move (-1, -1)) {
- move_robots ();
+ move_robots ();
}
break;
case KBD_N:
if (player_move (0, -1)) {
- move_robots ();
+ move_robots ();
}
break;
case KBD_NE:
if (player_move (1, -1)) {
- move_robots ();
+ move_robots ();
}
break;
case KBD_W:
if (player_move (-1, 0)) {
- move_robots ();
+ move_robots ();
}
break;
case KBD_STAY:
if (player_move (0, 0)) {
- move_robots ();
+ move_robots ();
}
break;
case KBD_E:
if (player_move (1, 0)) {
- move_robots ();
+ move_robots ();
}
break;
case KBD_SW:
if (player_move (-1, 1)) {
- move_robots ();
+ move_robots ();
}
break;
case KBD_S:
if (player_move (0, 1)) {
- move_robots ();
+ move_robots ();
}
break;
case KBD_SE:
if (player_move (1, 1)) {
- move_robots ();
+ move_robots ();
}
break;
case KBD_TELE:
if (safe_teleport ()) {
- move_robots ();
+ move_robots ();
}
break;
case KBD_RTEL:
if (random_teleport ()) {
- move_robots ();
+ move_robots ();
}
break;
case KBD_WAIT:
diff --git a/gnobots2/game.h b/gnobots2/game.h
index 4ef32e6..b53f68f 100644
--- a/gnobots2/game.h
+++ b/gnobots2/game.h
@@ -1,6 +1,7 @@
#ifndef GAME_H
#define GAME_H
+#include "gbdefs.h"
/**********************************************************************/
/* Game Object Structure */
@@ -36,6 +37,7 @@ gboolean move_cb (GtkWidget * widget, GdkEventMotion * e, gpointer data);
/* Exported Variables */
/**********************************************************************/
extern gint game_state;
+extern gint arena[GAME_WIDTH][GAME_HEIGHT];
/**********************************************************************/
diff --git a/gnobots2/gnobots.c b/gnobots2/gnobots.c
index dc304cf..4693da1 100644
--- a/gnobots2/gnobots.c
+++ b/gnobots2/gnobots.c
@@ -288,8 +288,8 @@ main (int argc, char *argv[])
G_CALLBACK (move_cb), NULL);
g_signal_connect (G_OBJECT (game_area), "configure-event",
G_CALLBACK (resize_cb), NULL);
- g_signal_connect (G_OBJECT (game_area), "expose-event",
- G_CALLBACK (expose_cb), NULL);
+ g_signal_connect (G_OBJECT (game_area), "draw",
+ G_CALLBACK (draw_cb), NULL);
gridframe = games_grid_frame_new (GAME_WIDTH, GAME_HEIGHT);
gtk_container_add (GTK_CONTAINER (gridframe), game_area);
diff --git a/gnobots2/graphics.c b/gnobots2/graphics.c
index 80d3ecb..50e0a80 100644
--- a/gnobots2/graphics.c
+++ b/gnobots2/graphics.c
@@ -39,6 +39,7 @@
#include "find-file.h"
#include "graphics.h"
#include "gbdefs.h"
+#include "game.h"
#include "gnobots.h"
#include "properties.h"
@@ -80,8 +81,10 @@ gint tile_height = 0;
static gboolean load_bubble_graphic (gchar *, GdkPixbuf **);
static gboolean load_bubble_graphics (void);
-static void clear_bubble_area (void);
-static void add_bubble (gint, gint);
+static void draw_bubble (cairo_t * cr);
+static void add_bubble (gint, gint, gint);
+static void draw_tile_pixmap (gint, gint, gint, cairo_t * cr);
+static void draw_object (gint x, gint y, gint type, cairo_t * cr);
/**********************************************************************/
@@ -92,7 +95,7 @@ static void
render_graphics (void)
{
theme_pixbuf = games_preimage_render (theme_preimage,
- 14 * tile_width, tile_height);
+ 14 * tile_width, tile_height);
rerender_needed = FALSE;
}
@@ -115,23 +118,18 @@ resize_cb (GtkWidget * w, GdkEventConfigure * e, gpointer data)
}
gboolean
-expose_cb (GtkWidget * w, GdkEventExpose * e, gpointer data)
+draw_cb (GtkWidget * w, cairo_t * cr, gpointer data)
{
int i, j;
- int x1, y1, x2, y2;
- x1 = e->area.x / tile_width;
- y1 = e->area.y / tile_height;
- x2 = x1 + e->area.width / tile_width + 1;
- y2 = y1 + e->area.height / tile_height + 1;
-
- for (j = y1; j <= y2; j++) {
- for (i = x1; i <= x2; i++) {
- /* Draw a blank space. Animation fills the objects in. */
- draw_tile_pixmap (-1, i, j, w);
+ for (j = 0; j < GAME_HEIGHT; j++) {
+ for (i = 0; i < GAME_WIDTH; i++) {
+ draw_object (i, j, arena[i][j], cr);
}
}
+ draw_bubble (cr);
+
return TRUE;
}
@@ -298,16 +296,16 @@ set_background_color (GdkColor color)
* which actually depends on how light or dark the base colour is. */
brightness = color.red + color.green + color.blue;
- if (brightness > 0xe8ba) { /* 0xe8ba = 0x10000/1.1 */
+ if (brightness > 0xe8ba) { /* 0xe8ba = 0x10000/1.1 */
/* Darken light colours. */
light_background.red = 0.9 * color.red;
light_background.green = 0.9 * color.green;
light_background.blue = 0.9 * color.blue;
- } else if (brightness > 0xa00) { /* Lighten darker colours. */
+ } else if (brightness > 0xa00) { /* Lighten darker colours. */
light_background.red = 1.1 * color.red;
light_background.green = 1.1 * color.green;
light_background.blue = 1.1 * color.blue;
- } else { /* Very dark colours, add ratehr than multiply. */
+ } else { /* Very dark colours, add ratehr than multiply. */
light_background.red += 0xa00;
light_background.green += 0xa00;
light_background.blue += 0xa00;
@@ -338,19 +336,15 @@ set_background_color_from_name (gchar * name)
* @pno: Number of graphics set
* @x: x position in grid squares
* @y: y position in grid squares
- * @area: Pointer to drawing area widget
+ * @cr: context to draw on
*
* Description:
* Draws tile pixmap @tileno from graphics set @pno at (@x, @y) in
* a widget @area
**/
-void
-draw_tile_pixmap (gint tileno, gint x, gint y, GtkWidget * area)
+static void
+draw_tile_pixmap (gint tileno, gint x, gint y, cairo_t * cr)
{
- cairo_t *cr;
-
- cr = gdk_cairo_create (gtk_widget_get_window (area));
-
if ((x & 1) ^ (y & 1)) {
gdk_cairo_set_source_color (cr, &dark_background);
} else {
@@ -362,7 +356,6 @@ draw_tile_pixmap (gint tileno, gint x, gint y, GtkWidget * area)
cairo_rectangle (cr, x, y, tile_width, tile_height);
cairo_fill (cr);
- cairo_destroy (cr);
if (rerender_needed)
render_graphics ();
@@ -370,11 +363,9 @@ draw_tile_pixmap (gint tileno, gint x, gint y, GtkWidget * area)
if ((tileno < 0) || (tileno >= SCENARIO_PIXMAP_WIDTH)) {
/* nothing */
} else {
- gdk_draw_pixbuf (gtk_widget_get_window (area),
- gtk_widget_get_style (area)->black_gc, theme_pixbuf,
- tileno * tile_width, 0,
- x, y, tile_width, tile_height,
- GDK_RGB_DITHER_NORMAL, 0, 0);
+ gdk_cairo_set_source_pixbuf (cr, theme_pixbuf, x - tileno * tile_width, y);
+ cairo_rectangle (cr, x, y, tile_width, tile_height);
+ cairo_fill (cr);
}
}
@@ -384,12 +375,13 @@ draw_tile_pixmap (gint tileno, gint x, gint y, GtkWidget * area)
* @x: x position
* @y: y position
* @type: object type
+ * @cr: context to draw on
*
* Description:
* Draws graphics for an object at specified location
**/
-void
-draw_object (gint x, gint y, gint type)
+static void
+draw_object (gint x, gint y, gint type, cairo_t * cr)
{
if (game_area == NULL)
return;
@@ -397,21 +389,21 @@ draw_object (gint x, gint y, gint type)
switch (type) {
case OBJECT_PLAYER:
draw_tile_pixmap (SCENARIO_PLAYER_START + player_animation,
- x, y, game_area);
+ x, y, cr);
break;
case OBJECT_ROBOT1:
draw_tile_pixmap (SCENARIO_ROBOT1_START + robot_animation,
- x, y, game_area);
+ x, y, cr);
break;
case OBJECT_ROBOT2:
draw_tile_pixmap (SCENARIO_ROBOT2_START + robot_animation,
- x, y, game_area);
+ x, y, cr);
break;
case OBJECT_HEAP:
- draw_tile_pixmap (SCENARIO_HEAP_POS, x, y, game_area);
+ draw_tile_pixmap (SCENARIO_HEAP_POS, x, y, cr);
break;
case OBJECT_NONE:
- draw_tile_pixmap (-1, x, y, game_area);
+ draw_tile_pixmap (-1, x, y, cr);
break;
}
}
@@ -434,47 +426,6 @@ clear_game_area (void)
/**
- * clear_bubble_area
- *
- * Description:
- * clears the area underneath a bubble
- **/
-static void
-clear_bubble_area (void)
-{
- int t0i, t0j; /* (i,j) coordinates of bubble's top/left tile */
- int ntiles_hor, ntiles_ver; /* number of tiles hotizontal/vertically affected */
- int delta; /* pixels from tile's left/top border to bubble's left/top border */
- int i, j;
-
- if (game_area == NULL)
- return;
-
- t0i = bubble_xpos / tile_width;
- t0j = bubble_ypos / tile_height;
- ntiles_hor = (BUBBLE_WIDTH + tile_width - 1) / tile_width; /* first shot at number of tiles affected */
- delta = bubble_xpos % tile_width;
- if (delta > 0) { /* buble does not start at a tile's left boundary */
- if ((BUBBLE_WIDTH + delta) > ntiles_hor * tile_width) { /* catches an extra tile */
- ntiles_hor++;
- }
- }
- ntiles_ver = (BUBBLE_HEIGHT + tile_height - 1) / tile_height;
- delta = bubble_ypos % tile_height;
- if (delta > 0) { /* buble does not start at a tile's top boundary */
- if ((BUBBLE_HEIGHT + delta) > ntiles_ver * tile_height) { /* catches an extra tile */
- ntiles_ver++;
- }
- }
- for (i = t0i; i < t0i + ntiles_hor; ++i) {
- for (j = t0j; j < t0j + ntiles_ver; ++j) {
- draw_tile_pixmap (-1, i, j, game_area);
- }
- }
-}
-
-
-/**
* reset_player_animation
*
* Description:
@@ -535,7 +486,7 @@ animate_game_graphics (void)
player_animation = 1;
++player_num_waves;
if (player_num_waves >= PLAYER_NUM_WAVES) {
- reset_player_animation ();
+ reset_player_animation ();
}
}
}
@@ -548,8 +499,8 @@ animate_game_graphics (void)
* Description:
* Draws a bubble if there is one
**/
-void
-draw_bubble (void)
+static void
+draw_bubble (cairo_t * cr)
{
GdkPixbuf *pmap;
@@ -564,10 +515,9 @@ draw_bubble (void)
pmap = splat_pixbuf;
}
- gdk_draw_pixbuf (gtk_widget_get_window (game_area),
- gtk_widget_get_style (game_area)->black_gc, pmap,
- bubble_xo, bubble_yo, bubble_xpos, bubble_ypos,
- BUBBLE_WIDTH, BUBBLE_HEIGHT, GDK_RGB_DITHER_NORMAL, 0, 0);
+ gdk_cairo_set_source_pixbuf (cr, pmap, bubble_xpos - bubble_xo, bubble_ypos - bubble_yo);
+ cairo_rectangle (cr, bubble_xpos, bubble_ypos, BUBBLE_WIDTH, BUBBLE_HEIGHT);
+ cairo_fill (cr);
}
@@ -580,8 +530,9 @@ draw_bubble (void)
* adds a bubble at @x,@y
**/
static void
-add_bubble (gint x, gint y)
+add_bubble (gint type, gint x, gint y)
{
+ bubble_type = type;
bubble_xpos = x * tile_width - BUBBLE_WIDTH + BUBBLE_XOFFSET;
bubble_ypos = y * tile_height - BUBBLE_HEIGHT + BUBBLE_YOFFSET;
@@ -596,7 +547,7 @@ add_bubble (gint x, gint y)
bubble_xo = BUBBLE_WIDTH;
bubble_xpos += BUBBLE_WIDTH;
}
-
+ gtk_widget_queue_draw (game_area);
}
@@ -612,8 +563,8 @@ remove_bubble (void)
if (bubble_type == BUBBLE_NONE)
return;
- clear_bubble_area ();
bubble_type = BUBBLE_NONE;
+ gtk_widget_queue_draw (game_area);
}
@@ -629,8 +580,8 @@ remove_splat_bubble (void)
if (bubble_type != BUBBLE_SPLAT)
return;
- clear_bubble_area ();
bubble_type = BUBBLE_NONE;
+ gtk_widget_queue_draw (game_area);
}
@@ -645,9 +596,7 @@ remove_splat_bubble (void)
void
add_yahoo_bubble (gint x, gint y)
{
- remove_bubble ();
- add_bubble (x, y);
- bubble_type = BUBBLE_YAHOO;
+ add_bubble (BUBBLE_YAHOO, x, y);
}
@@ -662,9 +611,7 @@ add_yahoo_bubble (gint x, gint y)
void
add_aieee_bubble (gint x, gint y)
{
- remove_bubble ();
- add_bubble (x, y);
- bubble_type = BUBBLE_AIEEE;
+ add_bubble (BUBBLE_AIEEE, x, y);
}
/**
@@ -678,12 +625,8 @@ add_aieee_bubble (gint x, gint y)
void
add_splat_bubble (gint x, gint y)
{
- remove_bubble ();
- add_bubble (x, y);
-
+ add_bubble (BUBBLE_SPLAT, x, y);
bubble_ypos += BUBBLE_YOFFSET;
-
- bubble_type = BUBBLE_SPLAT;
}
/**********************************************************************/
diff --git a/gnobots2/graphics.h b/gnobots2/graphics.h
index 913c286..4e18767 100644
--- a/gnobots2/graphics.h
+++ b/gnobots2/graphics.h
@@ -9,7 +9,7 @@ extern gint tile_height;
/* Exported functions */
/**********************************************************************/
gboolean resize_cb (GtkWidget * w, GdkEventConfigure * e, gpointer data);
-gboolean expose_cb (GtkWidget * w, GdkEventExpose * e, gpointer data);
+gboolean draw_cb (GtkWidget * w, cairo_t * cr, gpointer data);
gboolean load_game_graphics (void);
gboolean free_game_graphics (void);
gint num_game_graphics (void);
@@ -22,10 +22,8 @@ void add_aieee_bubble (gint, gint);
void add_splat_bubble (gint, gint);
void remove_bubble (void);
void remove_splat_bubble (void);
-void draw_bubble (void);
-void draw_tile_pixmap (gint, gint, gint, GtkWidget *);
-void draw_object (gint, gint, gint);
+void redraw (void);
void clear_game_area (void);
void animate_game_graphics (void);
void reset_player_animation (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]