资源简介
俄罗斯方块 SDL 版,游戏逻辑与 Qt 版完全一样,只是渲染引擎换成了 SDL。
Qt 版 : http://download.csdn.net/detail/sssooonnnggg/7053143
代码片段和文件信息
#include “Animation.h“
#include “base.h“
#include
#include
BlockAnimation::BlockAnimation(Renderer* renderer)
: Animation(renderer)
m_lastTickcount(GetTickCount())
m_start(true)
{
for ( int i = 0; i < 20; i++ )
{
Block* block = Block::CreateBlock(m_renderer Point(std::rand()%WindowWidth std::rand()%WindowHeight));
m_blockList.push_back(block);
}
InitBlockSpeed();
}
void BlockAnimation::InitBlockSpeed()
{
BlockList::iterator it = m_blockList.begin();
while ( it != m_blockList.end() )
{
//(*it)->Rotate(true);
int x = std::rand() % 21 - 10;
int y = std::rand() % 21 - 10;
(*it)->SetSpeed(Point(x y));
++it;
}
}
BlockAnimation::~BlockAnimation()
{
BlockList::iterator it = m_blockList.begin();
while ( it != m_blockList.end() )
{
delete (*it);
++it;
}
}
void BlockAnimation::Draw()
{
if ( m_start && OnframeChange() )
OnAnimationStep();
BlockList::iterator it = m_blockList.begin();
while ( it != m_blockList.end() )
{
(*it)->Draw();
++it;
}
}
bool BlockAnimation::OnframeChange()
{
if ( GetTickCount() - m_lastTickcount > 16 )
{
m_lastTickcount = GetTickCount();
return true;
}
return false;
}
void BlockAnimation::OnAnimationStep()
{
BlockList::iterator it = m_blockList.begin();
while ( it != m_blockList.end() )
{
Block* block = *it;
Point speed(block->GetSpeed());
Rect boundingRect(GetBlockBoundingRect(block));
if ( boundingRect.x < 0 )
speed.x = abs(speed.x);
if ( boundingRect.x + boundingRect.w > WindowWidth )
speed.x = -abs(speed.x);
if ( boundingRect.y < 0 )
speed.y = abs(speed.y);
if ( boundingRect.y + boundingRect.h > WindowHeight )
speed.y = -abs(speed.y);
(*it)->SetSpeed(speed);
(*it)->Move(speed);
++it;
}
}
Rect BlockAnimation::GetBlockBoundingRect(Block* block)
{
const BlockUnit* unit = block->GetFirstBlock();
int top = unit->y;
int left = unit->x;
int right = unit->x + unit->w;
int bottom = unit->y + unit->h;
while ( NULL != unit )
{
int ctop = unit->y;
int cleft = unit->x;
int cright = unit->x + unit->w;
int cbottom = unit->y + unit->h;
top = ctop < top ? ctop : top;
left = cleft < left ? cleft : left;
right = cright > right ? cright : right;
bottom = cbottom > bottom ? cbottom : bottom;
unit = block->GetNextBlock();
}
return Rect(left top right-left bottom-top);
} 属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 53784 2012-08-10 08:59 Tetris\Release\bg.png
文件 3241748 2002-10-29 20:17 Tetris\Release\FZYTK.TTF
文件 501760 2013-08-10 10:42 Tetris\Release\libfreetype-6.dll
文件 200704 2013-08-10 10:39 Tetris\Release\libpng16-16.dll
文件 880640 2013-10-23 21:07 Tetris\Release\SDL2.dll
文件 107520 2013-08-10 10:39 Tetris\Release\SDL2_image.dll
文件 52224 2013-08-10 10:42 Tetris\Release\SDL2_ttf.dll
文件 58880 2014-03-14 14:13 Tetris\Release\Tetris.exe
文件 123904 2013-08-10 10:39 Tetris\Release\zlib1.dll
文件 2496 2014-03-14 14:04 Tetris\Tetris\Animation.cpp
文件 773 2014-03-14 11:01 Tetris\Tetris\Animation.h
文件 3236 2014-03-14 10:02 Tetris\Tetris\ba
文件 1768 2014-03-12 14:44 Tetris\Tetris\EventHandler.cpp
文件 717 2014-03-12 14:24 Tetris\Tetris\EventHandler.h
文件 9402 2014-03-14 10:31 Tetris\Tetris\GameManager.cpp
文件 2367 2014-03-14 10:28 Tetris\Tetris\GameManager.h
文件 11834 2014-03-14 10:44 Tetris\Tetris\Gameob
文件 2735 2014-03-14 10:44 Tetris\Tetris\Gameob
文件 2476 2014-03-13 13:51 Tetris\Tetris\GameState.cpp
文件 2247 2014-03-13 13:51 Tetris\Tetris\GameState.h
文件 1573 2014-03-13 13:37 Tetris\Tetris\GameUI.cpp
文件 1178 2014-03-14 09:25 Tetris\Tetris\GameUI.h
文件 341 2014-03-13 13:29 Tetris\Tetris\main.cpp
文件 3776 2014-03-13 14:30 Tetris\Tetris\SDLRenderer.cpp
文件 2290 2014-03-14 09:30 Tetris\Tetris\SDLRenderer.h
文件 6156 2014-03-14 14:13 Tetris\Tetris\Tetris.vcproj
文件 1409 2014-03-14 14:26 Tetris\Tetris\Tetris.vcproj.ibm-PC.ibm.user
文件 1318 2014-03-11 16:50 Tetris\Tetris\UIManager.cpp
文件 485 2014-03-11 16:28 Tetris\Tetris\UIManager.h
文件 2100 2014-03-12 16:18 Tetris\Tetris\Utils.h
............此处省略8个文件信息
相关资源
- VisualStudioUninstaller vs卸载工具
- 组态王驱动开发包3.0.0.7(中文)
- 多窗口后台鼠标连点器
- 使用选择性重传协议实现UDP可靠通信
- VC 获得文件属性 获取文件的创建时
- 读者写者问题(读者优先,写者优先
- 用VC 编写的仿QQ聊天室程序源代码
- 外点法程序
- 外罚函数程序
- qt-电子点菜系统
- 推箱子及人工智能寻路C 源代码
- 自己写的航空订票系统c 版--数据结构
- 数据结构实验魔王语言
- MUSIC算法c 实现
- C 餐厅叫号系统(QT平)
- 国际象棋c 完整版
-
ob
jectARX给Auto CAD加工具条 - 画图程序MFC/VC/VC CRectTracker 串行化
- MFC网络编程实例
- c 课程设计 职工信息管理系统
- VC 游戏编程—附源代码
- IpHlpApi.h&IpHlpApi.lib
- 清华大学 c 郑莉 ppt课件
- c 程序判断离散数学中命题公式
- 多项式求和(数据结构C 版)
- vc 6.0开发的流程图编辑器
- VC 天空盒(skyBox)实现(附源代码)
- c MFC 画多边形
- 用C 实现的对网络上的ARP数据包进行
- Microsoft基本类库 (MFC)(C 库)
川公网安备 51152502000135号
评论
共有 条评论