<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>中文 &#187; LC-SOFT</title>
	<atom:link href="http://software.intel.com/zh-cn/blogs/author/lc-soft/feed/" rel="self" type="application/rss+xml" />
	<link>http://software.intel.com/zh-cn/blogs</link>
	<description></description>
	<lastBuildDate>Sat, 26 May 2012 06:34:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>我的一个游戏的部分源码</title>
		<link>http://software.intel.com/zh-cn/blogs/2011/09/15/400008559/</link>
		<comments>http://software.intel.com/zh-cn/blogs/2011/09/15/400008559/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 06:43:54 +0000</pubDate>
		<dc:creator>LC-SOFT</dc:creator>
				<category><![CDATA[博客征文专栏]]></category>
		<category><![CDATA[并行计算]]></category>
		<category><![CDATA[游戏]]></category>

		<guid isPermaLink="false">http://software.intel.com/zh-cn/blogs/2011/09/15/400008559/</guid>
		<description><![CDATA[  下面是源码，现在使用的按键控制方法的效果不理想。 linux系统环境，按键判断，使用了getch()和kbhit()函数，函数是模拟实现的。 为了判断按键是否为按住状态，我使用一个变量count来计数，每循环一次自增，也就是按键检测延迟的最大时间，超过了这段时间，如果geth()函数没有再次返回接受到同样的按键的键值，那么就判断为这个按键已经释放，否则，该按键处于按住状态，并继续显示之前的动作。 问个问题，有没有发现，用你的电脑，在文本框里输入文本，按住某个字母键，需要等待比较长的时间，字母才会连续出现，例如： 按w键，刚刚按下去的时候，字母w迅速显示出来了，可是我不松开手，需要等一段时间才会连续显示出字母w； 内容类似于这样：(刚刚按下w键)w (等待一段时间) wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww(连续显示)； view plain #include "define.h" //头文件暂时不写 //全局变量 int jump_max_hight = 99;//跳跃的最大高度 int temp_status;//备份的状态，因为有时动作会有重叠，例如：正处于跳跃状态，又进行攻击 int temp_frames; int screen_hight; int screen_width; int can_use_next; int need_move; int speed; int temp_site_x;//备份 int man_site_x;//x轴坐标 int man_site_y;//y轴坐标 int next_action; int frames;//帧数，每循环一次自动增加，如果是站立状态，每+1，人物的画面就会换一张，从而实现动画的目的。 int status; int direction;//人物朝向 int ichigo() { int temp = 0; if(status [...]]]></description>
			<content:encoded><![CDATA[<p> </p>
<p>下面是源码，现在使用的按键控制方法的效果不理想。</p>
<p>linux系统环境，按键判断，使用了getch()和kbhit()函数，函数是模拟实现的。</p>
<p>为了判断按键是否为按住状态，我使用一个变量count来计数，每循环一次自增，也就是按键检测延迟的最大时间，超过了这段时间，如果geth()函数没有再次返回接受到同样的按键的键值，那么就判断为这个按键已经释放，否则，该按键处于按住状态，并继续显示之前的动作。</p>
<p>问个问题，有没有发现，用你的电脑，在文本框里输入文本，按住某个字母键，需要等待比较长的时间，字母才会连续出现，例如：</p>
<p>按w键，刚刚按下去的时候，字母w迅速显示出来了，可是我不松开手，需要等一段时间才会连续显示出字母w；</p>
<p>内容类似于这样：(刚刚按下w键)w (等待一段时间) wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww(连续显示)；</p>
<p>view plain<br />
#include "define.h"<br />
//头文件暂时不写</p>
<p>//全局变量<br />
int jump_max_hight = 99;//跳跃的最大高度<br />
int temp_status;//备份的状态，因为有时动作会有重叠，例如：正处于跳跃状态，又进行攻击<br />
int temp_frames;<br />
int screen_hight;<br />
int screen_width;<br />
int can_use_next;<br />
int need_move;<br />
int speed;<br />
int temp_site_x;//备份<br />
int man_site_x;//x轴坐标<br />
int man_site_y;//y轴坐标<br />
int next_action;<br />
int frames;//帧数，每循环一次自动增加，如果是站立状态，每+1，人物的画面就会换一张，从而实现动画的目的。<br />
int status;<br />
int direction;//人物朝向<br />
int ichigo()<br />
{<br />
int temp = 0;<br />
if(status == STANCE){//如果是站立的状态<br />
stance_ichigo();//画站立的姿势<br />
temp_status = STANCE;<br />
status = next_action;<br />
next_action = 0;<br />
can_use_next = 0;//可以使用下一个动作<br />
}<br />
else if(status == WALK){//走路<br />
temp = walk_ichigo();//画走路的动画<br />
temp_status = WALK;<br />
can_use_next = 0;<br />
if(temp == 0){//如果走路的动画播放完了<br />
status = next_action;//使用下一个动作<br />
next_action = 0;<br />
frames = 0;//帧数序列归零<br />
}<br />
}<br />
else if(status == JUMP || (temp_status == JUMP &amp;&amp; can_use_next == 1))//跳跃<br />
{<br />
temp = jump_ichigo();//画跳跃的动画<br />
temp_status = JUMP;<br />
can_use_next = 1;//不可以使用下一个动作<br />
if(temp == 0){<br />
status = next_action;//使用下一个动作<br />
next_action = 0;<br />
frames = 0;//帧数序列归零<br />
}<br />
}<br />
else if(status == BLOCK || temp_status == BLOCK)<br />
{<br />
temp = block_ichigo();<br />
can_use_next = 1;<br />
if(temp == 2 || (status == BLOCK &amp;&amp; temp_status == BLOCK)){//如果是在第2帧<br />
speed = 0;<br />
if(next_action == BLOCK){//如果下一个动作还是防御<br />
status = BLOCK;<br />
speed = 0;//锁定<br />
next_action = 0;<br />
}<br />
else {//否则<br />
status = next_action;<br />
next_action = 0;//清空下一个动作<br />
frames = 0;<br />
speed = 1;<br />
}<br />
}<br />
temp_status = BLOCK;<br />
}<br />
else if(status == FIRST_ATTACK || (temp_status == FIRST_ATTACK &amp;&amp; can_use_next == 1 &amp;&amp; status == FIRST_ATTACK)){<br />
speed = 1;<br />
temp = first_attack_ichigo();<br />
temp_status = FIRST_ATTACK;<br />
can_use_next = 1;//不可以使用下一个动作<br />
if(temp == 0) {<br />
status = next_action;<br />
next_action = 0;//清空下一个动作<br />
frames = 0;<br />
can_use_next = 0;//可以使用下一个动作<br />
}<br />
}<br />
else if(status == SECOND_ATTACK || (temp_status == SECOND_ATTACK &amp;&amp; status == SECOND_ATTACK &amp;&amp; can_use_next == 1))//二段攻击<br />
{<br />
speed = 1;<br />
temp = second_attack_ichigo();<br />
temp_status = SECOND_ATTACK;<br />
can_use_next = 1;<br />
if(temp == 0) {<br />
status = next_action;<br />
next_action = 0;//清空下一个动作<br />
frames = 0;<br />
can_use_next = 0;//可以使用下一个动作<br />
}<br />
}<br />
else if(status == THIRD_ATTACK || (temp_status == THIRD_ATTACK &amp;&amp; can_use_next == 1))//三段攻击<br />
{<br />
speed = 1;<br />
can_use_next = 1;//可以使用下一个动作<br />
temp = third_attack_ichigo();<br />
temp_status = THIRD_ATTACK;<br />
if(temp == 0) {<br />
status = next_action;<br />
next_action = 0;//清空下一个动作<br />
frames = 0;<br />
can_use_next = 0;//可以使用下一个动作<br />
}<br />
}<br />
return 0;<br />
}<br />
int main()//main()函数<br />
{<br />
int temp_key = 0,count = 0,key,man_id;//人物代号<br />
man_id = ICHIGO;//人物动画选择黑崎一护<br />
direction = IS_LEFT;//RIGHT;//人物朝向右边<br />
man_site_x = 100;<br />
man_site_y = 220;<br />
speed = 1;<br />
need_move = 0;//不需要移动<br />
can_use_next = 0;//可以使用下一个动作<br />
status = STANCE;//初始人物状态是站立的<br />
init_game();//初始化游戏<br />
while(1){<br />
load_map();//载入地图，测试版中只是白色的<br />
//接受按键输入<br />
if(kbhit()){//用kbhit()函数检测是否有按键输入，如果有<br />
key = getch();//用getch()函数接受按键的键值<br />
if(key == 'd' || key == 'D' || key == KEY_RIGHT){//如果按的是a键或者左键<br />
if((temp_key == 'd' || temp_key == 'D' || temp_key == KEY_RIGHT)&amp;&amp; count &lt; 5) {</p>
<p>next_action = WALK;//下一个动作还是行走<br />
}<br />
else if(can_use_next == 0){//如果之前没有按过a键或者左键,并且，可以使用下一个动作<br />
if(temp_status != JUMP) {//如果之前不是跳跃状态<br />
status = WALK;<br />
if(temp_status != WALK) frames = 0;//如果之前不是行走状态<br />
else if(temp_status == WALK){//如果之前是行走状态<br />
next_action = WALK;//下一个动作还是行走<br />
}<br />
}<br />
else need_move = 1;//否则，需要移动<br />
}<br />
direction = IS_RIGHT;//方向为右边<br />
need_move = 1;<br />
temp_key = key;<br />
count = 0;//计数清零<br />
}<br />
else if(key == 'a' || key == 'A' || key == KEY_LEFT){//如果按的是a键或者左键<br />
if((temp_key == 'a' || temp_key == 'A' || temp_key == KEY_LEFT)&amp;&amp; count &lt; 5) {<br />
next_action = WALK;//下一个动作还是行走<br />
}<br />
else if(can_use_next == 0){//如果之前没有按过a键或者左键,并且，可以使用下一个动作<br />
if(temp_status != JUMP) {//如果之前不是跳跃状态<br />
status = WALK;<br />
if(temp_status != WALK) frames = 0;//如果之前不是行走状态<br />
else if(temp_status == WALK){//如果之前是行走状态<br />
next_action = WALK;//下一个动作还是行走<br />
}<br />
}<br />
else need_move = 1;//否则，需要移动<br />
}<br />
direction = IS_LEFT;//方向为左边<br />
need_move = 1;<br />
temp_key = key;<br />
count = 0;//计数清零<br />
}<br />
else if(key == 's' || key == 'S' || key == KEY_DOWN){//如果按的是s键或者是下键<br />
if((temp_key == 's' || temp_key == 'S' || temp_key == KEY_DOWN) &amp;&amp; count &lt;5){<br />
//如果之前按过s键或者是下键,并且在最大延迟时间内<br />
if(temp_status == BLOCK)//如果之前的动作是防御<br />
{<br />
speed = 0;<br />
frames = 2;//固定在第二帧<br />
next_action = BLOCK;<br />
}<br />
else frames = 0;//帧数归零<br />
}<br />
else if(temp_status == BLOCK) {<br />
frames = 2;<br />
speed = 0;<br />
}<br />
else frames = 0;//帧数归零<br />
temp_key = key;//保存按键的键值<br />
status = BLOCK;//人物为防御状态<br />
count = 0;//计数归零<br />
}<br />
else if(key == 'j' || key == 'J'){//如果按的是j键<br />
if((temp_key == 'j' || temp_key == 'J') &amp;&amp; count 5 &amp;&amp; can_use_next == 0) {//如果还没有接收到按键输入，并且可以使用下一个动作<br />
status = STANCE;//状态改为站立<br />
count = 0;//计数清零<br />
}<br />
if(need_move == 1){//如果需要移动<br />
if(count &lt;5 &amp;&amp; status != STANCE) {//如果不是站立状态<br />
if(direction == IS_RIGHT) {//如果朝向右边<br />
if(status == WALK) man_site_x += 5;//如果是行走<br />
else if(status == JUMP) man_site_x += 15;//如果是跳跃<br />
}<br />
else{<br />
if(status ==WALK) man_site_x -= 5;<br />
else if(status == JUMP) man_site_x -= 15;<br />
}<br />
}<br />
else need_move = 0;<br />
}<br />
if(man_id == ICHIGO) ichigo();//黑崎一护<br />
write_to_fb(screen_red,screen_green,screen_blue);//显示图形<br />
frames+=speed;<br />
//usleep(50000);//使用usleep的话，按键的效果会更好一些，但是，游戏画面的刷新速度就慢了<br />
count++;<br />
}<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://software.intel.com/zh-cn/blogs/2011/09/15/400008559/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

