网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
04月25日漏签0天
easyx吧 关注:10,957贴子:47,074
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 2回复贴,共1页
<<返回easyx吧
>0< 加载中...

彩色泡泡 -- Bubbles

  • 只看楼主
  • 收藏

  • 回复
  • FomeLayer
  • 学前班
    3
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
楼主忙里偷闲做的小玩意
使用VS2019编译,用C++写的
大概效果如下图(泡泡产生的位置就是鼠标啦)
泡泡会变小然后上升:

代码如下:
#include <graphics.h>
#include <vector>
#include <random>
#include <ctime>
using namespace std;
// Global sets
const int WINDOW_WID = 648;
const int WINDOW_HEI = 480;
const int ANIMAT_TME = 12;
const int TREMBL_FAC = 10;
const int MAXBBL_RAD = 35;
const int MAXBBL_SPD = 25;
const int RELOAD_TME = 4;
const int RELOAD_SPD = 2;
// Data
struct Bubble
{
float radius;
COLORREF color;
float posx;
float posy;
float spdx;
float spdy;
bool ACTIVE;
Bubble(float rd, float px, float py, float sx, float sy, bool A = true, COLORREF col = WHITE)
{
radius = rd;
posx = px;
posy = py;
spdx = sx;
spdy = sy;
ACTIVE = A;
color = col;
}
};
vector<Bubble*> bubbles;
bool IsRunning;
bool trigger;
int CDtime;
float mouse_x;
float mouse_y;
// Main frame
void Initialize();
void ProcessInput();
void Updating();
void GenerateOutput();
void Delay(DWORD ms);
void RunLoop();
void ShutDown();
// Other functions:
int Abs(int n);
float Abs(float n);
int main()
{
Initialize();
RunLoop();
ShutDown();
return 0;
}
void Initialize()
{
initgraph(WINDOW_WID, WINDOW_HEI);
BeginBatchDraw();
IsRunning = true;
trigger = false;
mouse_x = 0.0f;
mouse_y = 0.0f;
CDtime = RELOAD_TME;
srand(unsigned int(time(NULL)));
}
void ProcessInput()
{
MOUSEMSG m;
while (MouseHit())
{
m = GetMouseMsg();
switch (m.uMsg)
{
case WM_MOUSEMOVE:
mouse_x = m.x;
mouse_y = m.y;
break;
case WM_LBUTTONDOWN:
trigger = true;
break;
case WM_LBUTTONUP:
trigger = false;
break;
case WM_RBUTTONDOWN:
IsRunning = false;
}
}
}
void Updating()
{
// Add new bubble
if (CDtime <= 0)
{
float sx = float((rand() % MAXBBL_SPD) * (rand() % 2 ? 1 : -1));
float sy = float((rand() % MAXBBL_SPD / 2.0f) * (rand() % 2 ? 1 : -1));
float rd = float(rand() % MAXBBL_RAD + 10);
COLORREF col = RGB(rand() % 256, rand() % 256, rand() % 256);
Bubble* temp = new Bubble(rd, mouse_x, mouse_y, sx, sy, true, col);
bubbles.push_back(temp);
CDtime = RELOAD_TME;
}
if (CDtime > 0)
CDtime -= RELOAD_SPD;
// Change bubbles speed and radius
int len = bubbles.size();
for (int i = 0; i < len; ++i)
{
if (Abs(bubbles[i]->spdx) < float(MAXBBL_SPD))
{
bubbles[i]->spdx -= bubbles[i]->spdx / 4.0f;
}
if (bubbles[i]->spdy > (-1.0f * MAXBBL_SPD) / 2.0f)
{
bubbles[i]->spdy += -0.5f;
}
bubbles[i]->radius -= bubbles[i]->radius / 10.0f;
bubbles[i]->posx += bubbles[i]->spdx;
bubbles[i]->posy += bubbles[i]->spdy;
}
// Mark the overboundary bubbles
for (int i = 0; i < len; ++i)
{
if (bubbles[i]->posx < -10.0f || bubbles[i]->posx > float(WINDOW_WID + 10))
{
bubbles[i]->ACTIVE = false;
}
else if (bubbles[i]->posy < -40.0f || bubbles[i]->posy > float(WINDOW_HEI + 40))
{
bubbles[i]->ACTIVE = false;
}
else
{
}
}
// Delete the overboundary bubbles
for (auto iter = bubbles.begin(); iter != bubbles.end();)
{
if (!(*iter)->ACTIVE)
{
delete (*iter);
iter = bubbles.erase(iter);
continue;
}
++iter;
}
}
void GenerateOutput()
{
cleardevice();
if (bubbles.size())
{
int len = bubbles.size();
for (int i = 0; i < len; ++i)
{
setfillcolor(bubbles[i]->color);
fillcircle(bubbles[i]->posx, bubbles[i]->posy, bubbles[i]->radius);
setlinecolor(bubbles[i]->color);
setlinestyle(PS_SOLID, 3);
circle(bubbles[i]->posx, bubbles[i]->posy, bubbles[i]->radius + 4);
}
FlushBatchDraw();
}
}
void Delay(DWORD ms)
{
static DWORD oldtime = GetTickCount();
while (GetTickCount() - oldtime < ms)
Sleep(1);
oldtime = GetTickCount();
}
void RunLoop()
{
while (IsRunning)
{
ProcessInput();
Updating();
GenerateOutput();
Delay(ANIMAT_TME);
}
}
void ShutDown()
{
closegraph();
EndBatchDraw();
bubbles.clear();
}
// Other functions:
int Abs(int n)
{
if (n < 0)
return -n;
return n;
}
float Abs(float n)
{
if (n < 0.0f)
return -n;
return n;
}


  • 你亲爱的客服
  • 托儿所
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
牛B


2026-04-25 05:24:46
广告
不感兴趣
开通SVIP免广告
  • yangw80
  • 初三年级
    12
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
感觉气泡有点多,少一点可能效果会更好。


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 2回复贴,共1页
<<返回easyx吧
分享到:
©2026 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示