资源简介
Linux下Gtk开发的贪吃蛇游戏:
1. 可用鼠标或键盘操作移动蛇
2. 蛇会自动移动
3. 可暂停和重新开始
4. 积分并计时,给出积分计时比
代码片段和文件信息
#include
#include
#include
#include
#include
#include “snake.h“
#include “wall.h“
#define OVER_STRING “Game Over!\nPress Start again.“
#define UP_KEY 65362
#define DOWN_KEY 65364
#define LEFT_KEY 65361
#define RIGHT_KEY 65363
#define SPACE_KEY 32
#define ENTER_KEY 65293
GtkWidget *score_label;
GtkWidget *time_label;
GtkWidget *ratio_label;
static guint id = 0;
static time_t time_start = 0;
static time_t time_end = 0;
static time_t pause_time = 0;
/////////////////////////////////////////////
/////////////////////////////////////////////
static void
destroy_cb(GtkWidget *widgetgpointer data)
{
g_print(“=======>>in destroy_cb()\n“);
wall_t *wall = (wall_t*)data;
g_return_if_fail(wall != NULL);
snake_t *snake = wall->snake;
if (snake)
{
snake_destroy(snake);
snake = NULL;
}
if (wall)
{
wall_destroy(wall);
wall = NULL;
}
g_print(“=======>>out destroy_cb()\n“);
gtk_main_quit();
}
////////////////////button press call back
static void
up_button_press_cb(GtkButton *button gpointer user_data)
{
g_print(“up\n“);
wall_t *wall = (wall_t*)user_data;
if (wall->snake->direction != DOWN)
wall->snake->direction = UP;
}
static void
down_button_press_cb(GtkButton *button gpointer user_data)
{
g_print(“Down\n“);
wall_t *wall = (wall_t*)user_data;
if (wall->snake->direction != UP)
wall->snake->direction = DOWN;
}
static void
left_button_press_cb(GtkButton *button gpointer user_data)
{
g_print(“Left\n“);
wall_t *wall = (wall_t*)user_data;
if (wall->snake->direction != RIGHT)
wall->snake->direction = LEFT;
}
static void
right_button_press_cb(GtkButton *button gpointer user_data)
{
g_print(“Right\n“);
wall_t *wall = (wall_t*)user_data;
if (wall->snake->direction != LEFT)
wall->snake->direction = RIGHT;
}
////////////////////////////////
static gboolean
draw_expose_cb(GtkWidget *daGdkEventExpose *eventgpointer data )
{
g_print(“=======>>in draw_expose_cb()\n“);
wall_t *wall = (wall_t*)data;
wall_snake_food_draw(wall);
wall_wall_draw(wall->draw);
g_print(“=======>>out draw_expose_cb()\n“);
return TRUE;
}
static gboolean
position_update(gpointer data)
{
g_print(“=======>>in position_update()\n“);
gboolean ret = TRUE;
char score[10];
char times[10];
char ratio[10];
int int_score = 0;
int int_times = 0;
double double_ratio = 0.0;
GdkGC *gc_blue;
GdkColor color;
PangoLayout *string_layout = NULL;
GDK_THREADS_ENTER();
wall_t *wall = (wall_t*)data;
snake_t *snake = wall->snake;
gc_blue = gdk_gc_new(wall->draw->window);
color.red = 0;
color.green = 0;
color.blue = 65535;
gdk_gc_set_rgb_fg_color(gc_blue&color);
if (!wall_snake_head_tail_update(wall))
{
string_layout = gtk_widget_create_pango_layout(wall->draw OVER_STRING);
gdk_draw_layout(wall->draw->window gc_blue DRAW_SIZE_WIDTH/2-BUTTON_SIZE
DRAW_SIZE_HEIGHT/2-BUTTON_SIZE string_layout);
ret
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 624 2009-09-22 13:38 新建文件夹\snake.h
文件 930 2009-09-22 20:27 新建文件夹\wall.h
文件 9281 2009-09-22 21:17 新建文件夹\main.c
文件 1277 2009-09-22 20:27 新建文件夹\snake.c
文件 6679 2009-09-22 20:26 新建文件夹\wall.c
文件 680 2009-09-22 22:37 新建文件夹\Makefile
目录 0 2009-09-22 22:36 新建文件夹
----------- --------- ---------- ----- ----
19471 7
相关资源
- grub引导文件
- linux为服务器,Windows为客户端的简单
- snake 贪吃蛇汇编原代码 能在MASM FOR
- VmwareHorizonView6ForLinuxVDI全套解决方案所
- 学生信息管理系统项 Linux
- 操作系统接口:兼容Unix/Linux命令接口
- OpenVPN在Linux教程.pdf
- gtk背景图片设置
- Linux 常用C函数中文版
- linux c下acc打包成RTP并在VLC上播放
- 用net-snmp的api实现trap接收,windows+li
- 基于Linux嵌入式网络视频监控系统
- linux网络编程源码
- 把Linux中的文本文件格式转为Windows的
- Live555基于h264嵌入式linux下rtsp项目的裁
- OK6410 linux混杂设备驱动LED
- Linux RS485 通信代码
- Linux系统下dhcp源码
- arm开发板上摄像头抓图源代码(v4l通
- Bluez5.50 arm交叉编译脚本亲测成功
- IIC Linux 应用层的两种操作方式
- nmon工具linux性能32位的
- linux网络设备驱动
- Linux Wi-Fi open source drivers-mac80211 ath9k
- Linux Device Driver 中文版第三版
- 理发师问题Linux,c
- linux下cp2101/2102驱动
- kali linux 2019最新镜像包.txt
- 实战Linux编程精髓源代码
- qt贪吃蛇游戏源码
评论
共有 条评论