C481 B581 Computer Graphics
Dana Vrajitoru

Games Programming

Arcade Games

Implementation Ideas Basic Program Structure Character in the Game Drawing the Table
A pixmap for each type of cell.

for (x=0, x<t_width, x++)
  for (y=0; y<t_height; y++) {
    pixmap = select_pixmap(table[x][y]);
    draw_pixmap(area, pixmap, 0, 0,   //src
                c_width*x, c_height*y,//dest
                c_width, c_height);   //dim
  }

Accelerate the Display Origin and Orientation Multiple Players at Various Speed
class Player { ... int speed ... };
Player players[nr_players];
void next_frame() {
  for (int i=0; i<nr_players; i++) {
    pl = players[i];
   if (pl.counter == 0)
      pl.Move();
    pl.counter = (pl.counter+1) % pl.speed;
  }
}
Animated Players
class Player {
  ... int frame=0, nr_frames;
  GdkPixmap pixmaps[nr_frames]...
};
next_frame() {
  for (int i=0; i<nr_players; i++) {
    pl = players[i];
    pixmap = pl.pixmaps[pl.frame];
    Draw(pixmap, pl.position);
    pl.frame = (pl.frame +1)%pl.nr_frames;
  }
}
Game Interaction
  • Link some events to actions in the game.
  • Keyboard and mouse events
  • Timeout event linked to a call for a function next_frame().
  • Connecting any signal to a function that determines the type of event and what to be done with it.
Connecting the signals
stateStruct state;

gtk_signal_connect(object, "event", GTK_SIGNAL_FUNC(Event_mouse), &state);

gtk_signal_connect(GTK_OBJECT(app), "key_press_event", 
GTK_SIGNAL_FUNC(Event_press_key), (gpointer)area);