|

楼主 |
发表于 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
一个类对像,类中的方法按照
图形库的要求,绘出简单图形并以
改变座标位置的方式造成的视觉差
来实现移动,碰撞等效果.
输入控制:
使用图形库自带的输入函数.
- #include "./include/e.h"
- int main(int argc, char *argv[])
- {
- //FreeConsole();
- initwindow(800,600,"e3 退出--点击关闭");
- e ball(0,32,5,WHITE); // 0==ball 1==bar 2==slug 3==block
- e bar (1,5,80,7,LIGHTGRAY,1);
- e slug(2,16,5,15,LIGHTRED,2);
- e block(3,160,45,20,1,0);
- cout<< getactivepage();
- MMtimer myy;
- while( !bar.rexit() && bar.rewin()>-1 ) // ball.alive() && block.towin()
- {
- if( !bar.running(block) )
- block.stageinitial(ball,bar,slug );
- else if( bar.running(block) ) //block.towin()
- {
- bar.input();
- bar.control(ball);
- bar.work(ball,block,slug); // block.stagerunning( ball,bar,slug );
- }
- myy.myySleep(20);
- //delay(20);
- // designed a pause key there can be...
- // also save it can be...
- }
- //exited thank you for your playing...
- getch();
- return EXIT_SUCCESS;
- }
复制代码
- #ifndef MMTIME_H_INCLUDED
- #define MMTIME_H_INCLUDED
- #pragma once
- #include <windows.h>
- class MMtimer
- {
- private:
- static LARGE_INTEGER m_clk; // 保存时钟信息
- static LONGLONG m_oldclk; // 保存开始时钟和结束时钟
- static int m_freq; // 时钟频率(时钟时间换算率),时间差
- public:
- static void myySleep(int ms);
- };
- #endif // MMTIME_H_INCLUDED
复制代码
- #ifndef E_H_INCLUDED
- #define E_H_INCLUDED
- #include <cstdlib>
- #include <iostream>
- //#include "./include/MMtime.h"
- #include "../lib_h/graphics.h"
- #include "../include/mmtime.h"
- //-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
- //-lwinmm -mwindows
- using namespace std;
- static char tstage[10],tlife[10],tscore[20];
- struct e
- {
- struct o{ int s,*p,left,top,right,bottom,l,w,c,x,y,xy,status;
- void init(int,int);
- void moving();
- void angle(o&);
- void screen();
- bool crash(o&,e&);
- void stopby(o&);
- void fire(e&);
- void crash(e&);
- void touch(o&,e&,e&); };
- o*p;
- int F,N,LK,RK,M,f,name,win,stage,score,life,exit,run; // 0==ball 1==bar 2==slug 3==block
- e();
- ~e(){ for(int i=0;i<N;i++)delete [] p[i].p; delete [] p; };
- e(int,int,int,int);
- e(int,int,int,int,int,int);
- bool alive();
- bool towin();
- void init01(e&,e&);
- void input(int m=mousex(),int lk=ismouseclick(WM_LBUTTONDOWN),int rk=ismouseclick(WM_RBUTTONDOWN));//实际可以不要形参,我也是新手,为了看清逻辑写上
- void control(e&);
- void mutiball();
- void work(e&,e&,e&);
- bool rexit(){return exit;};
- bool rewin(){return win;};
- bool running(e&);
- void stageinitial(e&,e&,e&);
- };
- #endif // E_H_INCLUDED
复制代码
实际上,类方法里面的代码,还存在很多不合理的地方,实在是精力有限,改不动了.如有要挑战改细节的(如,球正好碰到2块之间,没有正常弹回的等等 )跟贴,我发源码.
|
|