当前位置:   article > 正文

C++像素游戏_像素游戏编程

像素游戏编程

我的作品:

鼠标板:黑科技之橡素

代码:

  1. #include <bits/stdc++.h>
  2. #include <windows.h>
  3. #include <ctime>
  4. #include "conio.h"
  5. using namespace std;
  6. #define leftspace 3
  7. #define upspace 3
  8. #define up 119
  9. #define down 115
  10. #define right 100
  11. #define left 97
  12. #define UP 72
  13. #define DOWN 80
  14. #define RIGHT 77
  15. #define LEFT 75
  16. #define esc 27
  17. #define enter 13
  18. #define tab 9
  19. #define space 32
  20. //主要函数
  21. void game();
  22. void gaming(); //"开始游戏"
  23. void introduce(); //"游戏介绍"
  24. void setgame(); //"游戏设置"
  25. //其它函数
  26. void start(); //开始游戏动画
  27. void go(int x,int y); //改变光标坐标
  28. void color(int a); //设置颜色
  29. void savefile(); //保存数据
  30. void readfile(); //读取数据
  31. void full_screen(); //全屏窗口
  32. void hide_cursor(); //隐藏光标
  33. int Map[45][45];
  34. int cc=247;
  35. int dc=15;
  36. int x,y;
  37. int main(){
  38. COORD coord;coord.X=100,coord.Y=100;
  39. SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),coord);
  40. go(5,5);color(13);printf("本游戏可能加载较慢,请耐心等待......(游戏本身无延迟)");
  41. go(5,6);printf("(。··)ノ");
  42. system("mode con cols=150 lines=200");//设置控制台大小90 28
  43. for(int i=0;i<45;i++)
  44. for(int j=0;j<45;j++)
  45. Map[i][j]=dc;//初始化Map(并不是不会用memset,而是我的memset有问题qaq)
  46. CONSOLE_CURSOR_INFO cursor_info={1,0};
  47. SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);//隐藏光标
  48. color(dc);
  49. start();
  50. game();//进入游戏
  51. return 0;
  52. }
  53. void hide_cursor(){
  54. CONSOLE_CURSOR_INFO cursor_info={1,0};
  55. SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);//隐藏光标
  56. }
  57. void go(int x,int y) //光标移动函数,X表示横坐标,Y表示纵坐标。
  58. {
  59. COORD coord; //使用头文件自带的坐标结构
  60. coord.X=(x+leftspace)*2; //这里将int类型值传给short,不过程序中涉及的坐标值均不会超过short范围
  61. coord.Y=y+upspace;
  62. HANDLE a=GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出句柄
  63. SetConsoleCursorPosition(a,coord); //以标准输出的句柄为参数设置控制台光标坐标
  64. }
  65. void full_screen(){
  66. HWND hwnd = GetForegroundWindow();
  67. int cx = GetSystemMetrics(SM_CXSCREEN); /* 屏幕宽度 像素 */
  68. int cy = GetSystemMetrics(SM_CYSCREEN); /* 屏幕高度 像素 */
  69. LONG l_WinStyle = GetWindowLong(hwnd,GWL_STYLE); /* 获取窗口信息 */
  70. /* 设置窗口信息 最大化 取消标题栏及边框 */
  71. SetWindowLong(hwnd,GWL_STYLE,(l_WinStyle | WS_POPUP | WS_MAXIMIZE) & ~WS_CAPTION & ~WS_THICKFRAME & ~WS_BORDER);
  72. SetWindowPos(hwnd, HWND_TOP, 0, 0, cx, cy, 0);
  73. }
  74. void game()
  75. {
  76. system("cls");
  77. system("color 0F");
  78. color(15);
  79. system("cls");
  80. color(15);
  81. go(13,1);printf("像素game");
  82. go(12,16);printf("WS/上下控制选择");
  83. go(12,9);printf(" 游戏介绍 ");
  84. go(12,13);printf(" 游戏设置 ");
  85. color(127);
  86. go(12,4);printf("■■■■■■");
  87. go(12,5);printf("■");color(124)
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号