鱼C论坛

 找回密码
 立即注册
查看: 2527|回复: 6

[作品展示] C++写的弹球快完善了,跑的试试.

[复制链接]
发表于 2022-10-26 14:36:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
gcc4.9.2编译_弹球x86.zip (505.14 KB, 下载次数: 17) 使用了慢羊羊的MMTime对延时修正后,基本上输出帧稳定了.
大家试试








sshot-2.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-10-26 15:54:41 | 显示全部楼层
本帖最后由 howzyao 于 2022-10-26 16:03 编辑

000 main_cpp基于
gcc4.9.2支持的dos版图形库: (好处是无视win api的使用,更容易让c/c++学习上手,若有需要,请发贴,我再发附件)
graphics.h
libbgi.a

图形:
需要手动设置以下6个链接器参数
才能正常使用此图形库
-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32

声音:
使用以下2个链接器参数
才能正常使用windows的多媒体接口
-lwinmm
-mwindows

图形的帧控制:
001 mmtime_h
是得到函数执行时间的长度,
加上手动指定延时的时间长度,
最终每次执行绘图时的延迟一致,
以保证函数运行的不定长时间导
至的忽快忽慢现象,以证画面稳定

图形的绘制:
002 e_h
一个类对像,类中的方法按照
图形库的要求,绘出简单图形并以
改变座标位置的方式造成的视觉差
来实现移动,碰撞等效果.

输入控制:
使用图形库自带的输入函数.

  1. #include "./include/e.h"


  2. int main(int argc, char *argv[])
  3. {

  4.     //FreeConsole();
  5.     initwindow(800,600,"e3  退出--点击关闭");
  6.     e ball(0,32,5,WHITE);              // 0==ball 1==bar 2==slug 3==block
  7.     e bar (1,5,80,7,LIGHTGRAY,1);
  8.     e slug(2,16,5,15,LIGHTRED,2);
  9.     e block(3,160,45,20,1,0);
  10.     cout<< getactivepage();

  11.     MMtimer myy;

  12.     while( !bar.rexit() && bar.rewin()>-1 ) //  ball.alive() && block.towin()
  13.     {

  14.         if( !bar.running(block) )
  15.         block.stageinitial(ball,bar,slug );
  16.         else if( bar.running(block)  )                      //block.towin()
  17.         {
  18.             bar.input();
  19.             bar.control(ball);
  20.             bar.work(ball,block,slug); // block.stagerunning( ball,bar,slug );

  21.         }

  22.         myy.myySleep(20);
  23.         //delay(20);

  24.         // designed a pause key there can be...
  25.         // also save it can be...
  26.     }
  27.     //exited thank you for your playing...

  28.     getch();

  29.     return EXIT_SUCCESS;
  30. }
复制代码


  1. #ifndef MMTIME_H_INCLUDED
  2. #define MMTIME_H_INCLUDED

  3. #pragma once
  4. #include <windows.h>

  5. class MMtimer
  6. {
  7. private:
  8.         static LARGE_INTEGER m_clk;                        // 保存时钟信息
  9.         static LONGLONG m_oldclk;                        // 保存开始时钟和结束时钟
  10.         static int m_freq;                                        // 时钟频率(时钟时间换算率),时间差

  11. public:
  12.         static void myySleep(int ms);
  13. };

  14. #endif // MMTIME_H_INCLUDED
复制代码



  1. #ifndef E_H_INCLUDED
  2. #define E_H_INCLUDED


  3. #include <cstdlib>
  4. #include <iostream>
  5. //#include "./include/MMtime.h"
  6. #include "../lib_h/graphics.h"
  7. #include "../include/mmtime.h"
  8. //-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
  9. //-lwinmm  -mwindows


  10. using namespace std;
  11. static char tstage[10],tlife[10],tscore[20];

  12. struct e
  13. {
  14.     struct o{ int s,*p,left,top,right,bottom,l,w,c,x,y,xy,status;
  15.              void init(int,int);
  16.              void moving();
  17.              void angle(o&);
  18.              void screen();
  19.              bool crash(o&,e&);
  20.              void stopby(o&);
  21.              void fire(e&);
  22.              void crash(e&);
  23.              void touch(o&,e&,e&); };
  24.     o*p;
  25.     int F,N,LK,RK,M,f,name,win,stage,score,life,exit,run; // 0==ball 1==bar 2==slug 3==block
  26.     e();
  27.     ~e(){ for(int i=0;i<N;i++)delete [] p[i].p; delete [] p; };
  28.     e(int,int,int,int);
  29.     e(int,int,int,int,int,int);
  30.     bool alive();
  31.     bool towin();
  32.     void init01(e&,e&);
  33.     void input(int m=mousex(),int lk=ismouseclick(WM_LBUTTONDOWN),int rk=ismouseclick(WM_RBUTTONDOWN));//实际可以不要形参,我也是新手,为了看清逻辑写上
  34.     void control(e&);
  35.     void mutiball();
  36.     void work(e&,e&,e&);
  37.     bool rexit(){return exit;};
  38.     bool rewin(){return win;};
  39.     bool running(e&);
  40.     void stageinitial(e&,e&,e&);
  41. };


  42. #endif // E_H_INCLUDED
复制代码



实际上,类方法里面的代码,还存在很多不合理的地方,实在是精力有限,改不动了.如有要挑战改细节的(如,球正好碰到2块之间,没有正常弹回的等等 )跟贴,我发源码.
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-10-27 19:17:05 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-11-16 21:57:22 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-11-18 00:15:48 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-11-18 09:32:04 | 显示全部楼层
真不错~
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-12-9 22:32:38 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-10 23:07

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表