楼主的源码:
- /*
- 飞机大战游戏,你可以通过按键控制飞机躲避障碍,直到30000分通关
- 你要控制飞机在乌云中飞行并躲避一切障碍物
- 碰到 乌云(黑白间隔方块) -1 生命
- 碰到 小鸟(白色方块) -2 生命
- 碰到 加油机(一个圆圈中间一个x) 随机1-3生命 并进行加分
- 碰到 其他飞机(内嵌正方形的正方形) 随机扣1生命或加1生命
- 如果遇到障碍物无法躲避可以进行加速俯冲(持续右键),有一定几率减少伤害
- 遇到加油机可以进行减速(左键),这样可以加到更多油(生命)和更多分数
- 并且按B键可以暂停游戏 (暂停图像改了下Mystic-Balloon 神秘气球中的一个素材 如果有问题请联系我删除这个素材 你们可以到https://github.com/Gaveno/ID-34-Mystic-Balloon查看这个神秘气球的游戏)
- Copyright (c) 2018 HWT团队 作者:LHW
- 如果修改并发布务必留下原作者信息,不能修改程序中的QR码数组信息
- 如果发现BUG 请把BUG发送到1281702594@qq.com 或 createskyblue@outlook.com 谢谢!
- */
- //#include <EEPROM.h> //EEPROM 存储库
- #include "U8glib.h"//引用U8G头文件
- U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);//设置设备名称:I2C-SSD1306-128*64(OLED)
- //如果屏幕不同请自行修改 如果第一次使用u8glib并且遇到显示不正确,请自行修改u8g配置
- /***********************************************/
- #define UP 11//定义方向键上为Arduino上的11号引脚
- #define DOWN 10//定义方向键上为Arduino上的10号引脚
- #define LEFT 9//定义方向键上为Arduino上的9号引脚
- #define RIGHT 8//定义方向键上为Arduino上的8号引脚
- #define A 7//定义方向键上为Arduino上的7号引脚
- #define B 6//定义方向键上为Arduino上的6号引脚
- /***********************************************/
- //初始化变量
- byte wait = 40; //延迟
- int HP = 20; //HP
- byte PPX = 4; //初始化玩家X位置
- byte PPY = 2; //初始化玩家Y位置
- byte PX = 0; //初始化玩家x轴坐标
- byte PY = 0; //初始化玩家y轴坐标
- int RT = 1; //初始化运行周期
- int S = 0; //分数
- byte OA; //障碍物
- byte OB; //障碍物
- byte OC; //障碍物
- byte OD; //障碍物
- int Atmp = 0; //缓存A
- int Btmp; //缓存B
- byte CA[50]; //A列
- byte CB[50]; //B列
- byte CC[50]; //C列
- byte CD[50]; //D列
- byte CAX[50]; //A列_X轴
- byte CBX[50]; //B列_X轴
- byte CCX[50]; //C列_X轴
- byte CDX[50]; //D列_X轴
- byte CAY[50]; //A列_Y轴
- byte CBY[50]; //B列_Y轴
- byte CCY[50]; //C列_Y轴
- byte CDY[50]; //D列_Y轴
- //载入位图
- const uint8_t title[] PROGMEM = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x98, 0x81, 0x31, 0xF3, 0x20, 0x45, 0x1F, 0x44, 0x8A, 0x00, 0xA0, 0x00, 0x00, 0x81, 0x00, 0x00,
- 0x68, 0x41, 0x4A, 0x92, 0x20, 0x45, 0x04, 0x44, 0x8A, 0x00, 0xB0, 0x01, 0x00, 0x40, 0x01, 0x00,
- 0x14, 0x02, 0x49, 0xF2, 0xE0, 0x45, 0xC4, 0xC4, 0x8B, 0x00, 0x4E, 0x06, 0x00, 0x80, 0x00, 0x00,
- 0x14, 0x82, 0x48, 0x92, 0x20, 0x55, 0xC4, 0x44, 0xAA, 0x00, 0xB0, 0x01, 0x00, 0x00, 0x00, 0x00,
- 0x68, 0x41, 0x48, 0x92, 0x20, 0x29, 0x04, 0x44, 0x52, 0x08, 0xA8, 0x00, 0x3E, 0x00, 0x00, 0x00,
- 0x98, 0xC1, 0x33, 0xF7, 0x20, 0x29, 0x04, 0x5C, 0x52, 0x00, 0x40, 0xC0, 0x61, 0x00, 0x00, 0x30,
- 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x38, 0xC3, 0x00, 0x00, 0x0C,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE7, 0xC6, 0xFF, 0x07, 0x03,
- 0x00, 0x40, 0x00, 0x04, 0x52, 0x00, 0x00, 0x00, 0x00, 0x02, 0xE0, 0x0C, 0xFE, 0xFF, 0xF9, 0x00,
- 0xC0, 0xF3, 0x1D, 0x04, 0x12, 0x00, 0x08, 0x00, 0x00, 0x00, 0x30, 0xE8, 0x81, 0x0F, 0xFC, 0x40,
- 0x00, 0x42, 0x94, 0x3F, 0x7E, 0x00, 0x14, 0x40, 0x00, 0x00, 0x1C, 0x1F, 0x00, 0x8E, 0x7F, 0x00,
- 0x00, 0xE5, 0x14, 0x04, 0x12, 0x00, 0x08, 0x00, 0x00, 0x00, 0xF6, 0x00, 0x00, 0xFC, 0x1F, 0x08,
- 0x00, 0xE3, 0x14, 0x0A, 0x57, 0x01, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0xFC, 0x0F, 0x00,
- 0x00, 0xE5, 0x14, 0x0A, 0x25, 0x00, 0x00, 0x00, 0x20, 0x00, 0x76, 0x00, 0x00, 0xF8, 0x03, 0x00,
- 0x00, 0x51, 0x15, 0x11, 0x55, 0x00, 0x00, 0x00, 0x00, 0x80, 0xF1, 0x00, 0x00, 0xF6, 0x01, 0x00,
- 0x00, 0x52, 0xA3, 0x20, 0x47, 0x00, 0x02, 0x20, 0x00, 0x60, 0xFC, 0x00, 0x80, 0x79, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x18, 0xFA, 0x01, 0x60, 0x36, 0x10, 0x14,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x38, 0x84, 0xF1, 0x03, 0x90, 0x09, 0x00, 0x02,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x1D, 0x00, 0x76, 0x43, 0xF0, 0x03, 0x7C, 0x07, 0x00, 0x54,
- 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0xCD, 0x00, 0xF8, 0x07, 0x9B, 0x01, 0x20, 0x00,
- 0x00, 0xE6, 0x00, 0x00, 0x00, 0x00, 0x02, 0x60, 0x33, 0x00, 0xEA, 0xC3, 0x44, 0x00, 0x02, 0x05,
- 0x00, 0x11, 0x03, 0x00, 0x00, 0x40, 0x02, 0xD8, 0x0C, 0x00, 0xE5, 0x31, 0x33, 0x00, 0x00, 0x28,
- 0xC0, 0xCC, 0x1C, 0x00, 0x00, 0x00, 0x70, 0x36, 0x03, 0x40, 0xDA, 0xC8, 0x1E, 0x00, 0x40, 0x75,
- 0x20, 0x32, 0x61, 0x80, 0x00, 0x00, 0x88, 0x8F, 0x00, 0xB0, 0x36, 0x36, 0x03, 0x00, 0x00, 0x20,
- 0x98, 0x0A, 0x81, 0x03, 0x00, 0x00, 0xE8, 0x70, 0x00, 0xE8, 0x8D, 0xC9, 0x20, 0x10, 0x50, 0x14,
- 0x64, 0x0C, 0x02, 0x1C, 0x00, 0x00, 0x78, 0x18, 0x00, 0x5E, 0x63, 0x36, 0x00, 0x02, 0x00, 0x00,
- 0x13, 0x08, 0x04, 0xE0, 0x00, 0x00, 0x08, 0x06, 0x80, 0xE7, 0x90, 0x19, 0x00, 0x00, 0x15, 0x75,
- 0x08, 0x08, 0x04, 0x00, 0x1F, 0x00, 0x90, 0x01, 0x40, 0x31, 0x6C, 0x06, 0x06, 0x00, 0x00, 0x20,
- 0x06, 0x10, 0x08, 0x00, 0xE0, 0xFF, 0x5F, 0x00, 0xF0, 0x10, 0x9B, 0x01, 0x00, 0x44, 0x50, 0x55,
- 0x01, 0x10, 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, 0x28, 0xC8, 0x64, 0x00, 0x00, 0x00, 0x00, 0x20,
- 0x80, 0x10, 0x10, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x1E, 0x38, 0x13, 0x00, 0x00, 0x11, 0x75, 0x65,
- 0x00, 0x20, 0x20, 0x00, 0x00, 0x00, 0x03, 0x80, 0x07, 0xCC, 0x0C, 0x00, 0x00, 0x00, 0x02, 0xA0,
- 0x00, 0x20, 0x40, 0x00, 0x00, 0xC0, 0x00, 0x40, 0x01, 0x34, 0x03, 0x00, 0x44, 0x55, 0x55, 0x5D,
- 0x00, 0x40, 0x40, 0x00, 0x00, 0x20, 0x00, 0xF0, 0x00, 0xCE, 0x00, 0x00, 0x00, 0x80, 0x82, 0x28,
- 0x04, 0x50, 0x80, 0x00, 0x00, 0x18, 0x00, 0x38, 0x00, 0x23, 0x00, 0x00, 0x11, 0x15, 0x57, 0x65,
- 0x00, 0x40, 0x00, 0x01, 0x00, 0x06, 0x00, 0x0E, 0x00, 0x19, 0x20, 0x00, 0x00, 0x8A, 0x08, 0x20,
- 0x00, 0x80, 0x00, 0x01, 0x80, 0x01, 0x80, 0x07, 0x80, 0x06, 0x00, 0x44, 0xD1, 0x25, 0x44, 0x15,
- 0x00, 0x80, 0x00, 0x03, 0x60, 0x00, 0xC0, 0x01, 0xC0, 0x81, 0x00, 0x00, 0xA8, 0x60, 0xA0, 0x22,
- 0x00, 0x80, 0xC0, 0x00, 0x18, 0x00, 0x70, 0x00, 0x40, 0x00, 0x00, 0x45, 0x76, 0xC7, 0x30, 0x03,
- 0x00, 0x00, 0x31, 0x00, 0x04, 0x00, 0x78, 0x00, 0x20, 0x00, 0x00, 0x00, 0x22, 0xCA, 0x81, 0x00,
- 0x40, 0x00, 0x8D, 0x00, 0x03, 0x00, 0x4E, 0x00, 0x20, 0x00, 0x40, 0x00, 0x10, 0x80, 0x41, 0x05,
- 0x00, 0x80, 0xE3, 0xC0, 0x00, 0x80, 0x27, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x14,
- 0x00, 0x80, 0x18, 0x31, 0x00, 0xC0, 0x21, 0x00, 0xC8, 0x4B, 0x8F, 0x17, 0x66, 0x3A, 0x06, 0x04,
- 0x00, 0x20, 0x07, 0x0D, 0x00, 0x40, 0x20, 0x00, 0x08, 0x49, 0x81, 0x14, 0xA9, 0x0A, 0x1E, 0x04,
- 0x00, 0x00, 0x00, 0x02, 0x00, 0x20, 0x10, 0x00, 0x04, 0x79, 0x87, 0x17, 0xAF, 0x3A, 0xFF, 0xE4,
- 0x00, 0x00, 0xC0, 0x03, 0x00, 0x20, 0x10, 0x00, 0x04, 0x49, 0x81, 0x10, 0x29, 0x0B, 0xFE, 0xF3,
- 0x00, 0x00, 0xC0, 0x03, 0x00, 0x2A, 0x10, 0x00, 0x02, 0x49, 0x8F, 0x70, 0x29, 0x3A, 0xBF, 0xDF,
- 0x20, 0x00, 0xF0, 0x03, 0x00, 0x15, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x0C,
- 0x00, 0x80, 0xF8, 0x07, 0xA0, 0x1E, 0x08, 0x00, 0x01, 0x00, 0x88, 0xCC, 0x01, 0xC0, 0x7F, 0x44,
- 0x00, 0x40, 0x79, 0x07, 0x54, 0x13, 0x08, 0x80, 0x00, 0x00, 0x88, 0x52, 0x21, 0xC4, 0x5B, 0x34,
- 0x00, 0x80, 0xA8, 0xA7, 0xEA, 0x1C, 0x04, 0x80, 0x00, 0xFE, 0x88, 0x5E, 0x71, 0x97, 0x9F, 0x39,
- 0x00, 0x18, 0xD8, 0x5F, 0x35, 0x0B, 0x04, 0x5F, 0x80, 0xF9, 0xA8, 0xD2, 0xA8, 0x8A, 0x17, 0xE0,
- 0x00, 0x86, 0xD8, 0xBC, 0xFE, 0x0C, 0xE4, 0x30, 0x60, 0xF8, 0x50, 0x52, 0xD1, 0x45, 0x07, 0x90,
- 0x80, 0xAA, 0xD8, 0xFA, 0x13, 0x0B, 0x1E, 0x3C, 0x18, 0xF0, 0x50, 0x52, 0xA9, 0x08, 0xA7, 0x86,
- 0xF0, 0xCF, 0xF1, 0xFF, 0xD0, 0x04, 0xE2, 0x13, 0x06, 0x60, 0x00, 0x00, 0x74, 0x01, 0x07, 0x05,
- 0xAC, 0x72, 0xF7, 0x1F, 0x30, 0x04, 0x1E, 0x90, 0x01, 0x18, 0x00, 0x00, 0xA8, 0x86, 0x85, 0x22,
- 0x57, 0xDD, 0xE1, 0x07, 0x10, 0x04, 0x01, 0x68, 0x00, 0x06, 0x00, 0xC0, 0x5D, 0xFE, 0x49, 0x05,
- 0xAA, 0x8A, 0xC0, 0x00, 0x08, 0xFE, 0x01, 0x04, 0x80, 0x01, 0x28, 0xA8, 0x0A, 0x18, 0xC9, 0xA3,
- 0x77, 0xBF, 0x34, 0x00, 0x04, 0x02, 0x01, 0x04, 0x70, 0x00, 0x76, 0x76, 0x77, 0xE3, 0x50, 0x01,
- 0xAA, 0x0A, 0x17, 0x00, 0x04, 0x82, 0x00, 0x02, 0x0C, 0x07, 0xA2, 0x8A, 0xAA, 0x42, 0xE1, 0x02,
- 0xD5, 0xC1, 0x16, 0x00, 0x04, 0x82, 0x00, 0x01, 0xC3, 0x08, 0xD1, 0xC5, 0xD5, 0x45, 0x40, 0x47,
- 0xAA, 0xB8, 0x08, 0x00, 0x02, 0x81, 0x80, 0xC1, 0x30, 0x06, 0xAA, 0x0A, 0x80, 0x4A, 0xF2, 0x2F,
- };
- const uint8_t QR[] PROGMEM = {
- 0x7F, 0xAD, 0x41, 0x4C, 0x0D, 0xFD, 0x01, 0x41, 0x6D, 0x9D, 0x01, 0xCD, 0x05, 0x01, 0x5D, 0x3F,
- 0xC9, 0xFE, 0xB2, 0x75, 0x01, 0x5D, 0x9F, 0xA3, 0x2A, 0x9B, 0x74, 0x01, 0x5D, 0xCE, 0xE7, 0x8F,
- 0x14, 0x74, 0x01, 0x41, 0x57, 0x49, 0x0C, 0x5B, 0x04, 0x01, 0x7F, 0x55, 0x55, 0x55, 0x55, 0xFD,
- 0x01, 0x00, 0x04, 0x7A, 0x24, 0xF6, 0x01, 0x00, 0x73, 0x3A, 0xD1, 0xCF, 0x00, 0xE9, 0x01, 0x10,
- 0x16, 0x49, 0xA2, 0x1F, 0x2B, 0x00, 0x67, 0x7C, 0xB5, 0x7E, 0xC2, 0x5F, 0x01, 0xB2, 0x41, 0xB6,
- 0x49, 0xFB, 0x32, 0x00, 0xC6, 0x88, 0xB2, 0x3C, 0x4E, 0xBE, 0x00, 0xB0, 0x61, 0x1C, 0xA7, 0x16,
- 0x23, 0x00, 0xEF, 0x55, 0x6D, 0x65, 0xCB, 0x47, 0x01, 0x96, 0xB6, 0x65, 0x6A, 0xBC, 0x34, 0x00,
- 0x50, 0x22, 0x81, 0xC7, 0xEA, 0xCA, 0x00, 0x23, 0x23, 0xC9, 0x99, 0x35, 0xB9, 0x00, 0xF3, 0x09,
- 0x6B, 0x54, 0xE5, 0xBC, 0x01, 0x22, 0x36, 0x89, 0x19, 0x29, 0x39, 0x01, 0xD2, 0x6D, 0x5C, 0x96,
- 0x26, 0x2F, 0x00, 0x02, 0xD9, 0xE7, 0x07, 0xB4, 0x71, 0x00, 0xFB, 0x93, 0xD0, 0xC7, 0x39, 0xBF,
- 0x01, 0x1B, 0x17, 0x78, 0x1C, 0x6F, 0x31, 0x00, 0x52, 0x1B, 0x6B, 0x75, 0x42, 0x75, 0x01, 0x1A,
- 0xB5, 0x61, 0x94, 0xA5, 0xF1, 0x01, 0xFD, 0x7D, 0xE4, 0x97, 0xBF, 0xFF, 0x01, 0xB8, 0xCB, 0x7E,
- 0x61, 0x50, 0x0C, 0x00, 0xE2, 0x88, 0x72, 0xD5, 0xE0, 0xDB, 0x01, 0x8A, 0x76, 0x7C, 0x1B, 0x35,
- 0x2C, 0x01, 0x43, 0x66, 0xE9, 0xC4, 0x06, 0xBE, 0x01, 0x9E, 0xE4, 0xE1, 0x92, 0xE2, 0x8B, 0x01,
- 0x53, 0xA5, 0x98, 0x90, 0xE4, 0xD8, 0x01, 0xB9, 0x17, 0x4D, 0x36, 0x09, 0x4D, 0x00, 0x41, 0x9A,
- 0xE2, 0xF4, 0x43, 0x4E, 0x01, 0x1B, 0xAF, 0xB8, 0x69, 0xF9, 0xAB, 0x01, 0x5C, 0x76, 0xBC, 0x5B,
- 0xA8, 0x0B, 0x00, 0xBD, 0xCB, 0x27, 0x3F, 0x9F, 0x45, 0x00, 0x62, 0xFD, 0x56, 0x64, 0x53, 0x6C,
- 0x01, 0x0E, 0x17, 0x1E, 0x8C, 0xDF, 0xA7, 0x01, 0x47, 0x28, 0xE0, 0x9F, 0xEA, 0x7F, 0x00, 0x00,
- 0x61, 0x69, 0x8C, 0x39, 0x91, 0x00, 0x7F, 0x6A, 0x7D, 0xCD, 0x02, 0xF5, 0x01, 0x41, 0x47, 0x5F,
- 0x9C, 0x32, 0xB1, 0x00, 0x5D, 0x99, 0xF2, 0x97, 0x00, 0x3F, 0x00, 0x5D, 0x74, 0x1C, 0x06, 0xBC,
- 0xAB, 0x01, 0x5D, 0x60, 0x2F, 0xAD, 0xB9, 0xFA, 0x01, 0x41, 0x8B, 0x47, 0x09, 0x8F, 0xB5, 0x00,
- 0x7F, 0x05, 0xEB, 0x76, 0x60, 0xC9, 0x01,
- };
- const uint8_t pause[] PROGMEM = {
- 0xA7, 0xAA, 0xAA, 0xAA, 0x3A, 0x55, 0x55, 0x55, 0x55, 0x29, 0x07, 0x00, 0x00, 0x00, 0x38, 0xF0,
- 0xF7, 0xFB, 0xF7, 0x03, 0x19, 0x1C, 0x8E, 0x1C, 0x26, 0x8A, 0xCF, 0x04, 0xC8, 0x14, 0x89, 0x08,
- 0x24, 0x09, 0x24, 0x8A, 0x08, 0x24, 0xC9, 0x17, 0x89, 0xC9, 0x24, 0x09, 0x24, 0x1A, 0xCC, 0x24,
- 0x19, 0x16, 0xF1, 0xFF, 0xFF, 0xFF, 0x23, 0x0A, 0x86, 0x4C, 0x18, 0x16, 0xC9, 0x34, 0x4D, 0xC8,
- 0x24, 0x0A, 0x04, 0x4D, 0x0E, 0x14, 0x09, 0x02, 0xCD, 0xD9, 0x27, 0xCA, 0x33, 0x41, 0x10, 0x14,
- 0xC9, 0x33, 0x21, 0x18, 0x26, 0xFA, 0xFF, 0xFF, 0xFF, 0x17, 0x70, 0xFC, 0xDE, 0xEF, 0x03, 0x07,
- 0x00, 0x00, 0x00, 0x38, 0x55, 0x55, 0x55, 0x55, 0x29, 0xA7, 0xAA, 0xAA, 0xAA, 0x3A,
- };
- const uint8_t plane[] PROGMEM = {0x8, 0xC, 0x8C, 0xFF, 0xFF, 0x8C, 0xC, 0x8};
- const uint8_t BOA[] PROGMEM = {0xCC, 0xCC, 0x33, 0x33, 0xCC, 0xCC, 0x33, 0x33};
- const uint8_t BOB[] PROGMEM = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- const uint8_t BOC[] PROGMEM = {0x18, 0x66, 0x7E, 0xBD, 0xBD, 0x7E, 0x66, 0x18};
- const uint8_t BOD[] PROGMEM = {0x0, 0x7E, 0x42, 0x5A, 0x5A, 0x42, 0x7E, 0x0};
- const uint8_t life[] PROGMEM = {0x0, 0x66, 0xFF, 0xCF, 0xDF, 0x7E, 0x3C, 0x18};
- /***********************************************/
- void setup(void) {
- //串口通讯波特率设置
- Serial.begin(9600);
- //初始化按钮
- pinMode(UP, INPUT);//定义方向UP引脚状态
- pinMode(DOWN, INPUT);//定义方向DOWN引脚状态
- pinMode(LEFT, INPUT);//定义方向LEFT引脚状态
- pinMode(RIGHT, INPUT);//定义方向RIGHT引脚状态
- pinMode(A, INPUT);//定义按键A引脚状态
- pinMode(B, INPUT);//定义按键B引脚状态
- randomSeed(analogRead(A0)); //伪随机数pin
- u8g.firstPage();
- do
- {
- u8g.drawXBMP( 0, 0, 128, 64, title);
- } while ( u8g.nextPage() );
- delay(1024);
- }
- /***********************************************/
- void(* resetFunc) (void) = 0; //制造重启命令
- void loop(void) {
- if (HP < 0 || S > 30000) {
- //循环检测按钮
- while (1) {
- if (digitalRead(A) == HIGH) {
- //软复位指令
- if (HP < 0) resetFunc(); //重启程序开始
- if (S >= 30000) {
- while (1) {
- u8g.setColorIndex(1);
- u8g.firstPage();
- do
- {
- u8g.drawXBMP(40, 8, 56, 49, QR);
- } while ( u8g.nextPage() );
- }
- }
- }
- }
- }
- //按键输入 如果按钮是接入GND 请修改程序 默认按钮接VCC
- if (digitalRead(UP) == HIGH) {
- if (PPY > 0) PPY -= 1;
- }
- if (digitalRead(DOWN) == HIGH) {
- if (PPY < 4) PPY += 1;
- }
- if (digitalRead(LEFT) == HIGH) {
- if (PPX > 1) PPX -= 1;
- }
- if (digitalRead(RIGHT) == HIGH) {
- if (PPX < 15) PPX += 1;
- }
- if (digitalRead(B) == HIGH) {
- delay (200);
- u8g.firstPage();
- do
- {
- draw();
- u8g.setColorIndex(0);
- u8g.drawBox(42, 10, 46, 28); //先覆盖掉原屏幕,避免下面的图片变透明
- u8g.setColorIndex(1);
- u8g.drawXBMP(45, 13, 40, 22, pause);
- } while ( u8g.nextPage() );
- while (1) {
- if (digitalRead(B) == HIGH) {
- delay (200);
- break;
- }
- }
- }
- /***********************************************/
- //计算
- S += 1;
- PX = PPX * 8;
- PY = PPY * 8;
- OA = 9;
- OB = 9;
- OC = 9;
- OD = 9;
- if (RT < 16) {
- //障碍物生成
- //障碍物
- Atmp = random(1, 100);
- if (Atmp <= 70) {
- OA = random(0, 5);
- }
- //TNT
- Atmp = random(1, 100);
- if (Atmp <= 30) {
- OB = random(0, 5);
- }
- //加血
- Atmp = random(1, 100);
- if (Atmp <= 5) {
- OC = random(0, 5);
- }
- //随机buff
- Atmp = random(1, 100);
- if (Atmp <= 50) {
- OD = random(0, 5);
- }
- }
- if (HP > 12) HP = 12;
- //保存障碍物位置
- CAY[RT] = OA * 8;
- CBY[RT] = OB * 8;
- CCY[RT] = OC * 8;
- CDY[RT] = OD * 8;
- CA[RT] = OA;
- CB[RT] = OB;
- CC[RT] = OC;
- CD[RT] = OD;
- CAX[RT] = 120;
- CBX[RT] = 120;
- CCX[RT] = 120;
- CDX[RT] = 120;
- //伤害判断
- Btmp = 15 - PPX;
- if (RT > Btmp) {
- Atmp = RT - Btmp;
- if (PPY == CA[Atmp]) {
- HP -= 1;
- }
- if (PPY == CB[Atmp]) {
- HP -= 2;
- }
- if (PPY == CC[Atmp]) {
- Atmp = random(1, 3);
- HP += Atmp;
- S += 30;
- }
- if (PPY == CD[Atmp]) {
- Atmp = random(1, 100);
- if (Atmp < 50) {
- HP += 1;
- S += 15;
- } else {
- HP -= 1;
- }
- }
- }
- /***********************************************/
- //绘图
- u8g.firstPage();
- do {
- draw();
- } while ( u8g.nextPage() );
- /***********************************************/
- //把障碍物往下移
- Atmp = RT - 16;
- if (Atmp < 1) {
- Atmp = 1;
- }
- for (Atmp; Atmp <= RT; Atmp ++) {
- CAX[Atmp] -= 8;
- CBX[Atmp] -= 8;
- CCX[Atmp] -= 8;
- CDX[Atmp] -= 8;
- }
- RT += 1;
- if (RT >= 32) {
- RT = 1;
- }
- delay(wait); //防止游戏运行到只有神才能玩的级别
- }
- void draw() {
- //障碍物循环初始化计算
- Atmp = RT - 16;
- if (Atmp < 1) {
- Atmp = 1;
- }
- //障碍物显示
- for (Atmp; Atmp <= RT; Atmp ++) {
- if (CCX[Atmp] > 0) {
- u8g.drawBitmapP(CCX[Atmp], CCY[Atmp], 1, 8, BOC);
- }
- if (CDX[Atmp] > 0) {
- u8g.drawBitmapP(CDX[Atmp], CDY[Atmp], 1, 8, BOD);
- }
- if (CAX[Atmp] > 0) {
- u8g.drawBitmapP(CAX[Atmp], CAY[Atmp], 1, 8, BOA);
- }
- if (CBX[Atmp] > 0) {
- u8g.drawBitmapP(CBX[Atmp], CBY[Atmp], 1, 8, BOB);
- }
- }
- //显示玩家
- u8g.drawBitmapP(PX, PY, 1, 8, plane);
- //生命以及分数
- u8g.setFont(u8g_font_helvB08);
- if (HP > 0) {
- u8g.setPrintPos(8, 54);
- u8g.print("HP:");
- for (Atmp = 1; Atmp <= HP; Atmp ++) {
- Btmp = Atmp * 8 + 20;
- u8g.drawBitmapP(Btmp, 45, 1, 8, life);
- }
- }
- u8g.setPrintPos(8, 62);
- u8g.print("score:");
- u8g.print(S);
- if (HP < 0 || S >= 30000) {
- //读取EEPROM 地址0
- //Atmp=EEPROM.read(1);
- //if (S > HS) {
- //破纪录啦
- //EEPROM.write(1,S);
- // HS = S;
- // Atmp = S;
- // }
- u8g.setColorIndex(255);
- u8g.drawBox(0, 0, 128, 64);
- u8g.setFont(u8g_font_fub14);
- u8g.setColorIndex(0);
- u8g.setPrintPos(4, 21);
- if (HP < 0) u8g.print("GAME OVER");
- if (S >= 30000) u8g.print(" YOU WIN");
- u8g.setFont(u8g_font_helvB08);
- //u8g.setPrintPos(35, 34);
- //u8g.print("history:");
- //u8g.print(Atmp);
- if (Atmp == S) {
- //破了纪录
- u8g.print(" NEW");
- }
- u8g.setPrintPos(35, 39);
- u8g.print("score:");
- if (HP < 0) u8g.print(S);
- if (S >= 30000) u8g.print("30000");
- u8g.setPrintPos(2, 62);
- if (HP < 0) u8g.print("Please push A to RESET");
- if (S >= 30000) u8g.print(" Push A to QR code");
- }
- }
复制代码 |