Re: Fast image manipulation : the truth about it (I hope)
- From: Danne Lundqvist <danne opv se>
- CC: gnome-list gnome org
- Subject: Re: Fast image manipulation : the truth about it (I hope)
- Date: Fri, 20 Nov 1998 10:53:03 +0000
This discussion is very valuable to me since I am a newbie
to Gnome/imlib. And I decided I want to make a try on a
small battle game a couple of days ago.
I started out to study the small games shipped in the
package gnome-games. When I studied the code in the game
gnobots I saw that the approach described here is basically
the approach in the game. I think reading the code there
may be a quite nice, practical example of this.
/Danne
[SNIP]
> The game startup looks like :
>
> - Init everything.
> - Load the three .png files in GdkImlibImages using gdk_imlib.
> - Convert the three GdkImlibImages to GdkPixmaps using gdk_imlib.
> - Destroy the three GdkImlibImages since we'll never need them again (you need
> to take care of pixmap referencing if you want them not to be destroyed -
> perhaps having a look at imlib's source code would help ?)
> - Load all the sprite coordinate tables into appropriates structures - please
> don't hardcode them in your program (1).
> - Create a new GdkPixmap of the size of your game area. It will be your virtual
> screen buffer.
> - Create your main window, with a GdkDrawingArea of the size of the game area.
>
> Ok, now what we need is the main game loop. It should look like the following
> function :
>
> /* NOTE: this is pseudo-but-looks-like-real-code,
> so cut'n'paste won't work :) */
> void game_loop_do_one_iteration(void)
> {
> /* tile the background */
> for(first_tile; last_tile; tile++) {
> tid = get_tile_from_map_at_coordinates(x, y);
> get_tile_coordinates_from_table(tid, tile_table,
> &tile_x, &tile_y);
> gdk_draw_pixmap(double_buffer, scr_x, scr_y, tile_pixmap,
> tile_x, tile_y, TILE_WIDTH, TILE_HEIGHT);
> }
> /* draw the buddies */
> for(first_buddy; last_buddy; buddy++) {
> get_buddy_frame_from_table(buddy->type, buddy->frame++,
> buddy->table, &buddy_x, &buddy_y,
> &buddy_width, &buddy_height);
> /* of course, since buddies are not rectangular, there should
> be a bit of masking, etc., but ... */
> gdk_draw_pixmap(double_buffer, buddy->pos_x, buddy->pos_y,
> buddy->pixmap, buddy_x, buddy_y,
> buddy_width, buddy_height);
> }
> /* update the screen */
> gdk_draw_pixmap(drawing_area->window, 0, 0, double_buffer, 0, 0,
> game_area_width, game_area_height);
> /* this will be the trickier part */
> move_buddies_with_at_least_a_bit_of_AI();
> }
>
> Then you connect that function to a timeout, and you're done. The AI part is
> left as an exercise to the reader :). There are some facts you should examine :
[SNIP]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]