qiaobaaa / response3

0 stars 0 forks source link

hahhahh #19

Open qiaobaaa opened 7 months ago

qiaobaaa commented 7 months ago

struct Warrior { int Highlevel; int Clevel; int Hp; int Attack; int Defense; int Money; int Yellow_key; int Blue_key; int Red_key; int Sword; int Shield; int Buycount; int getLevel() { return Clevel; } int getHp() { return Hp; } int getAttack() { return Attack; } int getDefend() { return Defense; } int getMoney() { return Money; } int getYellow_Key() { return Yellow_key; } int getBlue_Key() { return Blue_key; } int getRed_Key() { return Red_key; } int getClevel() { return Clevel; } int getSword() { return Sword; } int getShield() { return Shield; }

void LevelUp() { Clevel++; }
void LevelDown() { Clevel--; }
void Raise_Hp(int hp) { Hp += hp; }
void Lose_Hp(int hp) { Hp -= hp; }
void Raise_Attack(int att) { Attack += att; }
void Raise_Defend(int def) { Defense += def; }
void Get_Money(int money) { Money += money; }
void Spend_Money(int money) { Money -= money; }
void Get_Yellow_Key() { Yellow_key++; }
void Get_Blue_Key() { Blue_key++; }
void Get_Red_Key() { Red_key++; }
void Spend_Yellow_Key() { Yellow_key--; }
void Spend_Blue_Key() { Blue_key--; }
void Spend_Red_Key() { Red_key--; }
void HighLevelUp() { Highlevel++; }
void SetSword(int s) { Sword = s; }
void SetShield(int s) { Shield = s; }
int getBuyCount() { return Buycount; }
void Buy() { Buycount++; }
// void setItems(vector<int> &a) { return ITEMS; }
//bool Fight(Monster m);    // 攻击怪物

};

struct Monster {

};

Warrior w;

qiaobaaa commented 7 months ago

pragma once

define SHOP_M /shop_m.jpg

define SHOP_L /shop_l.jpg

define SHOP_R /shop_r.jpg

//1

define GATE_KEEPER /gate_keeper.jpg

define SKELETON_A /skeleton_a.jpg

//2

define BIG_SLIME /big_slime.jpg

define BIG_BAT /big_bat.jpg

define ROCK /rock.jpg

define SUPER_PRIEST /super_priest.jpg

define VAMPIRE /vampire.jpg

define ZOMBINE /zombine.jpg

define ZOMBINE_KNIGHT /zombine_knight.jpg

//3

define GATE_KEEPER_B /gate_keeper_b.jpg

define GHOST_SOLIDER /ghost_solider.jpg

define GOLD_KNIGHT /gold_knight.jpg

define KNIGHT /knight.jpg

define SLIME_MAN /slime_man.jpg

define SOLIDER /solider.jpg

define SWORDS_MAN /swords_man.jpg

//5

define DARK_KNIGHT /dark_knight.jpg

define GATE_KEEPER_A /gate_keeper_a.jpg

define MAGICIAN_A /magician_a.jpg

define MAGICIAN_B /magician_b.jpg

define MAGIC_SERGEANT /magic_sergeant.jpg

define SLIME_LORD /slime_lord.jpg

define VAMPIRE_BAT /vampire_bat.jpg

//dragon

define DRAGON_WN /dragon_wn.jpg

define DRAGON_N /dragon_n.jpg

define DRAGON_EN /dragon_en.jpg

define DRAGON_W /dragon_w.jpg

define DRAGON_M /dragon_m.jpg

define DRAGON_E /dragon_e.jpg

define DRAGON_WS /dragon_ws.jpg

define DRAGON_S /dragon_s.jpg

define DRAGON_ES /dragon_es.jpg

//octopus

define OCTOPUS_WN /octopus_wn.jpg

define OCTOPUS_N /octopus_n.jpg

define OCTOPUS_EN /octopus_en.jpg

define OCTOPUS_W /octopus_w.jpg

define OCTOPUS_M /octopus_m.jpg

define OCTOPUS_E /octopus_e.jpg

define OCTOPUS_WS /octopus_ws.jpg

define OCTOPUS_S /octopus_s.jpg

define OCTOPUS_ES /octopus_es.jpg

//

define GREAT_MAGIC_MASTER /great_magic_master.jpg

define BOSS /boss.jpg

qiaobaaa commented 7 months ago

define SNOW_CRYSTAL /snow_crystal.jpg

define IRONGATE /iron_gate.jpg

define PRINCESS /princess.jpg

define OLDMAN /oldman.jpg

define THIEF /thief.jpg

define MERCHANT /merchant.jpg

define IRON_SWORD /iron_sword.jpg

define SACRED_SWORD /sacred_sword.jpg

define HOLY_SWORD /holy_sword.jpg

define KNIGHT_SWORD /knight_sword.jpg

define SILVER_SWORD /silver_sword.jpg

define IRON_SHIELD /iron_shield.jpg

define SACRED_SHIELD /sacred_shield.jpg

define HOLY_SHIELD /holy_shield.jpg

define KNIGHT_SHIELD /knight_shield.jpg

define SILVER_SHIELDD /silver_shield.jpg

define LAVA /lava.jpg

define STAR /star.jpg

define STEEL_GATE /steel_gate.jpg

define LUCKY_GOLD /lucky_gold.jpg

define CROSS /cross.jpg

qiaobaaa commented 7 months ago

void FindRole(int& prow, int& pcol) { for (prow = 1; prow <= NUM; prow++) { for (pcol = 1; pcol <= NUM; pcol++) { switch (map[w.getLevel()][prow][pcol]) { case 16: case 17: case 18: case 19: return; } } } } switch在不任意break的情况,他就是顺序往下执行的

qiaobaaa commented 7 months ago

bool getLuckyCoin = false; //是否有幸运金币 bool getConvey = false; //是否得到传送法杖 bool getNotebook = false;//是否获得记事本 bool getCross = false; //是否得到十字架 bool getAxe = false; //是否获得破墙稿 bool getHolyWater = false; //是否获得圣水 int getCentred_tp = 0; // 还剩几个中心对称飞行器 bool getBomb = false; //是否有炸弹 bool geticemagic = false; //是否有冰冻徽章 bool getflyup = false; //是否有向上飞行器 bool getflydown = false; //是否有向下飞行器 bool getearthquake = false; //是否获得地震卷轴 bool getmagickey = false; //是否获得魔法钥匙 bool getdragonkiller = false; //是否获得屠龙匕

int money = 20; // 商店的初始价格,每买一次就涨价

qiaobaaa commented 7 months ago

import os,sys,struct 2 from PIL import Image 3 4 def main(): 5 infile = "1.jpg" 6 outfile = "res.bin" 7 im = Image.open(infile) 8 im.show() 9 print("read %s %d %d \n" % (infile,im.size[0],im.size[1])) 10 11 f = open(outfile,"wb") 12 pix = im.load() 13 for h in range(im.size[1]): 14 for w in range(im.size[0]): 15 R = pix[w,h][0]>>3 16 G = pix[w,h][1]>>2 17 B = pix[w,h][2]>>3 18 rgb = (R<<11)|(G<<5)|B 19 f.write(struct.pack('B',rgb&255)) 20 f.write(struct.pack('B',(rgb>>8)&255)) 21 22 f.close() 23 print("write to %s" % outfile) 24 25 26 if name == "main": 27 sys.exit(main())

qiaobaaa commented 7 months ago

ifndef BMP_H

define BMP_H

/位图文件头/ //14个字节

pragma pack(1)//单字节对齐

typedef struct tagBITMAPFILEHEADER { unsigned short bfType; //unsigned char bfType[2]; //文件格式 unsigned int bfSize; // 文件大小 以字节为单位(2-5字节) unsigned short bfReserved1; // 保留,必须设置为0 (6-7字节) unsigned short bfReserved2; // 保留,必须设置为0 (8-9字节) unsigned int bfOffBits; // 从文件头到像素数据的偏移 (10-13字节) }BITMAPFILEHEADER;

pragma pack()

/位图信息头/ //40个字节

pragma pack(1)

typedef struct tagBITMAPINFOHEADER { unsigned int biSize; // 此结构体的大小 (14-17字节) long biWidth; // 图像的宽 (18-21字节) long biHeight; // 图像的高 (22-25字节) unsigned short biPlanes; // 表示bmp图片的平面属,显然显示器只有一个平面,所以恒等于1 (26-27字节) unsigned short biBitCount; // 一像素所占的位数,(28-29字节)当biBitCount=24时,该BMP图像就是24Bit真彩图,没有调色板项。 unsigned int biCompression; // 说明图象数据压缩的类型,0为不压缩。 (30-33字节) unsigned int biSizeImage; // 像素数据所占大小, 这个值应该等于上面文件头结构中bfSize-bfOffBits (34-37字节) long biXPelsPerMeter; // 说明水平分辨率,用象素/米表示。一般为0 (38-41字节) long biYPelsPerMeter; // 说明垂直分辨率,用象素/米表示。一般为0 (42-45字节) unsigned int biClrUsed; // 说明位图实际使用的彩色表中的颜色索引数(设为0的话,则说明使用所有调色板项)。 (46-49字节) unsigned int biClrImportant; // 说明对图象显示有重要影响的颜色索引的数目,如果是0,表示都重要。(50-53字节) }BITMAPINFOHEADER;

pragma pack()

/调色板结构/ //4字节

pragma pack(1)

typedef struct tagRGBQUAD { unsigned char rgbBlue; //该颜色的蓝色分量 (值范围为0-255) unsigned char rgbGreen; //该颜色的绿色分量 (值范围为0-255) unsigned char rgbRed; //该颜色的红色分量 (值范围为0-255) unsigned char rgbReserved;// 保留,必须为0 }RGBQUAD;

pragma pack()

typedef struct allpixel { unsigned short bfType; //unsigned char bfType[2]; //文件格式 unsigned int bfSize; // 文件大小 以字节为单位(2-5字节) unsigned short bfReserved1; // 保留,必须设置为0 (6-7字节) unsigned short bfReserved2; // 保留,必须设置为0 (8-9字节) unsigned int bfOffBits; // 从文件头到像素数据的偏移 (10-13字节)

unsigned int    biSize;          // 此结构体的大小 (14-17字节)
/*long*/int            biWidth;         // 图像的宽  (18-21字节)
/*long*/int            biHeight;        // 图像的高  (22-25字节)
unsigned short  biPlanes;        // 表示bmp图片的平面属,显然显示器只有一个平面,所以恒等于1 (26-27字节)
unsigned short  biBitCount;      // 一像素所占的位数,(28-29字节)当biBitCount=24时,该BMP图像就是24Bit真彩图,没有调色板项。
unsigned int    biCompression;   // 说明图象数据压缩的类型,0为不压缩。 (30-33字节)
unsigned int    biSizeImage;     // 像素数据所占大小, 这个值应该等于上面文件头结构中bfSize-bfOffBits (34-37字节)
long            biXPelsPerMeter; // 说明水平分辨率,用象素/米表示。一般为0 (38-41字节)
long            biYPelsPerMeter; // 说明垂直分辨率,用象素/米表示。一般为0 (42-45字节)
unsigned int    biClrUsed;       // 说明位图实际使用的彩色表中的颜色索引数(设为0的话,则说明使用所有调色板项)。 (46-49字节)
unsigned int    biClrImportant;  // 说明对图象显示有重要影响的颜色索引的数目,如果是0,表示都重要。(50-53字节)

unsigned char ImgData[270000];
//unsigned char ImgData[300][300][3];
//unsigned char ImgData[128][128][3];
//unsigned char ImgData[200][200][3];
unsigned char empty[274];

}ALLPIXELS;

pragma pack()

pragma pack(1)

typedef struct allgraypixel { unsigned short bfType; //unsigned char bfType[2]; //文件格式 unsigned int bfSize; // 文件大小 以字节为单位(2-5字节) unsigned short bfReserved1; // 保留,必须设置为0 (6-7字节) unsigned short bfReserved2; // 保留,必须设置为0 (8-9字节) unsigned int bfOffBits; // 从文件头到像素数据的偏移 (10-13字节)

unsigned int    biSize;          // 此结构体的大小 (14-17字节)
/*long*/int            biWidth;         // 图像的宽  (18-21字节)
/*long*/int            biHeight;        // 图像的高  (22-25字节)
unsigned short  biPlanes;        // 表示bmp图片的平面属,显然显示器只有一个平面,所以恒等于1 (26-27字节)
unsigned short  biBitCount;      // 一像素所占的位数,(28-29字节)当biBitCount=24时,该BMP图像就是24Bit真彩图,没有调色板项。
unsigned int    biCompression;   // 说明图象数据压缩的类型,0为不压缩。 (30-33字节)
unsigned int    biSizeImage;     // 像素数据所占大小, 这个值应该等于上面文件头结构中bfSize-bfOffBits (34-37字节)
long            biXPelsPerMeter; // 说明水平分辨率,用象素/米表示。一般为0 (38-41字节)
long            biYPelsPerMeter; // 说明垂直分辨率,用象素/米表示。一般为0 (42-45字节)
unsigned int    biClrUsed;       // 说明位图实际使用的彩色表中的颜色索引数(设为0的话,则说明使用所有调色板项)。 (46-49字节)
unsigned int    biClrImportant;  // 说明对图象显示有重要影响的颜色索引的数目,如果是0,表示都重要。(50-53字节)

RGBQUAD RGB[256];

//unsigned char ImgData[128][128];
unsigned char ImgData[90000];
//unsigned char ImgData[40000];
//unsigned char ImgData[16384];
unsigned char grayempty[3122];

}ALLGRAYPIXELS;

qiaobaaa commented 7 months ago

include

include

include

include"bmp.h"

include

include

using namespace std;

int main() {

unsigned char ImgData[3000][3];//将位图信息转为灰度 存储RGB图像的一行像素点
unsigned char ImgData2[30000];//将灰度图的像素存到一个一维数组中
int i, j, k;
FILE* fpBMP, * fpGray;
BITMAPFILEHEADER* fileHeader;
BITMAPINFOHEADER* infoHeader;
RGBQUAD* ipRGB;
char filename1[20], filename2[20];

// printf("输入图像文件名:"); //scanf("%s", filename1); if ((fpBMP = fopen("30000.bmp", "rb")) == NULL) { printf("打开图片失败"); exit(0); } // printf("输出图像文件名:"); //scanf("%s", filename2); if ((fpGray = fopen("999.bmp", "wb")) == NULL) { printf("创建图片失败"); exit(0); } //给定义的结构体变量申请这个结构体大小的内存空间 fileHeader = (BITMAPFILEHEADER)malloc(sizeof(BITMAPFILEHEADER)); infoHeader = (BITMAPINFOHEADER)malloc(sizeof(BITMAPINFOHEADER)); //从bmp文件中读取数据块给文件信息头和图片信息头 fread(fileHeader, sizeof(BITMAPFILEHEADER), 1, fpBMP); // printf("@@@%c\n", fileHeader->bfType[0]); // printf("@@@%c\n", fileHeader->bfType[1]); if (fileHeader->bfType==0x4d42) { printf("图片识别正确%x\n", fileHeader->bfType); } //printf("@@@%x\n", fileHeader->bfType); fread(infoHeader, sizeof(BITMAPINFOHEADER), 1, fpBMP); //经过这两条程序把BMP图像的信息头、文件头赋给fileHeader和infoHeader变量,可以根据fileHeader和infoHeader得到图像的各种属性。 printf("原始图片每个像素的位数:%d\n", infoHeader->biBitCount); printf("原始图片每个像素的长:%d\n", infoHeader->biWidth); printf("原始图片每个像素的宽:%d\n", infoHeader->biHeight); printf("原始图片每个像素像素数据偏移:%d\n", fileHeader->bfOffBits);

//修改信息头
//信息头共有11部分,灰度化时需要修改两部分
infoHeader->biBitCount = 8;//将24位真彩图转换成8位灰度图
infoHeader->biSizeImage = ((infoHeader->biWidth * 3 + 3) / 4) * 4 * infoHeader->biHeight;//24Bit真彩图每一行占的实际字节数
//修改文件头
//文件头共有5部分,灰度化时需要修改两部分
fileHeader->bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
fileHeader->bfSize = fileHeader->bfOffBits + infoHeader->biSizeImage;
printf("修改后的图片每个像素的位数:%d\n", infoHeader->biBitCount);
printf("修改后的图片每个像素数据偏移:%d\n", fileHeader->bfOffBits);

//创建调色版 应为灰度图像的调色板是 R=G=B.而真彩图的三值不相等
ipRGB = (RGBQUAD*)malloc(256 * sizeof(RGBQUAD));
for (i = 0; i < 256; i++)
{
    ipRGB[i].rgbBlue = ipRGB[i].rgbGreen = ipRGB[i].rgbRed = i;
}
//读取BMP图像的信息头、文件头、BMP调色板到新建的图片

fwrite(fileHeader, sizeof(BITMAPFILEHEADER), 1, fpGray);
fwrite(infoHeader, sizeof(BITMAPINFOHEADER), 1, fpGray);
fwrite(ipRGB, sizeof(RGBQUAD), 256, fpGray);
//读取RGB图像素并转换为灰度值
for (i = 0; i < infoHeader->biHeight; i++)//一行一行的扫描
{

    //24Bit真彩图每一行占的实际字节数:[(biWidth*3+3)/4*4]  故biHeight行每行扫描[(biWidth*3+3)/4*4]次
    for (j = 0; j < (infoHeader->biWidth + 3) / 4 * 4; j++)//写BMP图像的位图数据部分
    {
        for (k = 0; k < 3; k++) {
            fread(&ImgData[j][k], 1, 1, fpBMP);////每次只读取一个字节,存入数组
            //读取顺序B,G,R
            printf("%d %d %d %d\n", i, j,k, ImgData[j][k]);
        }
    }
    //printf("........%d      %d\n", infoHeader->biWidth, (infoHeader->biWidth + 3) / 4 * 4);
    //修改位图数据部分这部分主要是由原真彩图的rgbRed、rgbGreen、rgbBlue分量值得到灰度图像的灰度值Y,可以用下面公式得到:
    for (j = 0; j < (infoHeader->biWidth + 3) / 4 * 4; j++)
    {
        ImgData2[i*128+j] = (int)((float)ImgData[j][0] * 0.114 +
            (float)ImgData[j][1] * 0.587 +
            (float)ImgData[j][2] * 0.299);
       // printf("%d %d\n", infoHeader->biHeight, ImgData2[j]);
    }
    //将灰度图信息写入
    //printf("%d\n",ImgData2[])
    //fwrite(ImgData2, j, 1, fpGray);//按顺序写入BMP图像的各个部分
}
fwrite(ImgData2, 16384, 1, fpGray);

free(fileHeader);
free(infoHeader);
free(ipRGB);
fclose(fpBMP);
fclose(fpGray);
printf("bmp图片背景去除完成\n");

return 0;

}

qiaobaaa commented 7 months ago

if LV_BIG_ENDIAN_SYSTEM

typedef struct {

uint32_t h : 11; /*Height of the image map*/
uint32_t w : 11; /*Width of the image map*/
uint32_t reserved : 2; /*Reserved to be used later*/
uint32_t always_zero : 3; /*It the upper bits of the first byte. Always zero to look like a
                             non-printable character*/
uint32_t cf : 5;          /* Color format: See `lv_img_color_format_t`*/

} lv_img_header_t;

else

typedef struct {

uint32_t cf : 5;          /* Color format: See `lv_img_color_format_t`*/
uint32_t always_zero : 3; /*It the upper bits of the first byte. Always zero to look like a
                             non-printable character*/

uint32_t reserved : 2; /*Reserved to be used later*/

uint32_t w : 11; /*Width of the image map*/
uint32_t h : 11; /*Height of the image map*/

} lv_img_header_t;

endif

qiaobaaa commented 7 months ago

short abc = 0x7804; short abd = 0x3c0; short w = 0; w = w | (abc >> 10); w = (abd << 11) | w;

int h = abd >> 5;
cout << w <<"  "<< h << endl;
unsigned short temm=0;
temm = temm | (0xe5 << 8);
cout << temm << endl;
temm = temm | (0xf0);
cout << temm << endl;
qiaobaaa commented 7 months ago

define PNG_FILENAME "/people_down.png"

define PNG_4BPP_FILENAME "/octocat-4bpp.png"

define FILEEE "/333.bin"

include

include

include

//#include

include

include

include

include

include

//#include

//#include "FS.h" //#include "FFat.h"

//#define GFX_BL DF_GFX_BL // default backlight pin, you may replace DF_GFX_BL to actual backlight pin

/ More dev device declaration: https://github.com/moononournation/Arduino_GFX/wiki/Dev-Device-Declaration /

define GFX_BL 48 // default backlight pin, you may replace DF_GFX_BL to actual backlight pin

const int yyy = 13;

//Arduino_DataBus bus = new Arduino_ESP32SPI(41 / DC /, 40 / CS /, 12, 11, 13); Arduino_DataBus bus = new Arduino_ESP32SPI(41 / DC /, 10 / CS /, 12 / SCK /, 11 / MOSI /, GFX_NOT_DEFINED / MISO /); //Arduino_HWSPI bus = new Arduino_HWSPI(41 / DC /, 40 / CS /, 6, 7, MISO); Arduino_ST7789 gfx = new Arduino_ST7789(bus, 42 / RST /, 0 / rotation /, true / IPS /, 240, 320, 0, 0); //Arduino_ILI9341 gfx = new Arduino_ILI9341(bus, 42, 0 / rotation /, false / IPS */); int rc;

/*

define SDMMC_D2 33 // SDMMC Data2

define SDMMC_D3 4 //34 // SDMMC Data3 / SPI CS

define SDMMC_CMD 5 // SDMMC CMD / SPI MOSI

define SDMMC_CLK 6 // SDMMC CLK / SPI SCK

define SDMMC_D0 7 // SDMMC Data0 / SPI MISO

define SDMMC_D1 38 // SDMMC Data1

*/

define SDMMC_D2 16 // SDMMC Data2

define SDMMC_D3 4 //34 // SDMMC Data3 / SPI CS

define SDMMC_CMD 5 // SDMMC CMD / SPI MOSI

define SDMMC_CLK 6 // SDMMC CLK / SPI SCK

define SDMMC_D0 7 // SDMMC Data0 / SPI MISO

define SDMMC_D1 15 // SDMMC Data1

include

PNG png;

int16_t w, h, xOffset, yOffset; uint16_t *buffer;

// Functions to access a file on the SD card File pngFile;

void logMemoryy() { log_d("Used PSRAM: %d", ESP.getPsramSize()); } void logMemory() { log_d("Used PSRAM: %d", ESP.getPsramSize() - ESP.getFreePsram()); }

void myOpen(const char filename, int32_t *size) {

pngFile = SD_MMC.open(filename, "r");

if (!pngFile || pngFile.isDirectory()) { Serial.println(F("ERROR: Failed to open " PNG_FILENAME " file for reading")); gfx->println(F("ERROR: Failed to open " PNG_FILENAME " file for reading")); } else { size = pngFile.size(); Serial.printf("Opened '%s', size: %d\n", filename, size); }

return &pngFile; }

void myClose(void *handle) { if (pngFile) pngFile.close(); }

int32_t myRead(PNGFILE handle, uint8_t buffer, int32_t length) { if (!pngFile) return 0; return pngFile.read(buffer, length); }

int32_t mySeek(PNGFILE *handle, int32_t position) { if (!pngFile) return 0; return pngFile.seek(position); }

// Function to draw pixels to the display void PNGDraw(PNGDRAW *pDraw) { uint16_t usPixels[320]; uint8_t usMask[320];

// Serial.printf("Draw..... pos = 0,%d. size = %d x 1 %d\n", pDraw->y, pDraw->iWidth,sizeof(usPixels)); png.getLineAsRGB565(pDraw, usPixels, PNG_RGB565_LITTLE_ENDIAN, 0x00000000); png.getAlphaMask(pDraw, usMask, 1); //gfx->draw16bitRGBBitmap(xOffset, yOffset, usPixels, usMask, pDraw->iWidth, 1); gfx->draw16bitRGBBitmap(xOffset, yOffset + pDraw->y, usPixels, usMask, pDraw->iWidth, 1); }

void setup() { Serial.begin(115200); // Serial.setDebugOutput(true); // while(!Serial); Serial.println("PNG Image Viewer");

ifdef GFX_EXTRA_PRE_INIT

GFX_EXTRA_PRE_INIT();

endif

// Init Display gfx->begin();

gfx->fillScreen(BLACK); gfx->setUTF8Print(true);

ifdef GFX_BL

pinMode(GFX_BL, OUTPUT); //digitalWrite(GFX_BL, HIGH); analogWrite(GFX_BL, 180);

endif

// pinMode(SDMMC_D3 / CS /, OUTPUT); // digitalWrite(SDMMC_D3 / CS /, HIGH); //#if defined(SOC_SDMMC_USE_GPIO_MATRIX) // SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); //#endif

if defined(SOC_SDMMC_USE_GPIO_MATRIX)

SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3);

endif

if (!SD_MMC.begin("/root", true)) { //if(!FFat.begin(true)){ Serial.println("FFat Mount Failed"); return; } else {

unsigned long start = millis();
int rc;
rc = png.open(PNG_FILENAME, myOpen, myClose, myRead, mySeek, PNGDraw);
if (rc == PNG_SUCCESS)
{
  int16_t pw = png.getWidth();
  int16_t ph = png.getHeight();

  xOffset = 0;
  yOffset = 0;

  rc = png.decode(NULL, 0);

 // Serial.printf("Draw offset: (%d, %d), time used: %lu\n", xOffset, yOffset, millis() - start);
 // Serial.printf("image specs: (%d x %d), %d bpp, pixel type: %d\n", png.getWidth(), png.getHeight(), png.getBpp(), png.getPixelType());
  png.close();
}
else
{
  Serial.println("png.open() failed!");
}

}

delay(5000); // 5 seconds if(psramInit()){ Serial.printf("Total PSRAM: %d", ESP.getPsramSize()); Serial.println("\nPSRAM is correctly initialized"); } //rc = png.open(PNG_FILENAME, myOpen, myClose, myRead, mySeek, PNGDraw); }

void loop() { logMemory(); logMemory(); buffer = (uint16_t )ps_malloc(10); Serial.printf("Free.... PSRAM: %d\n",ESP.getPsramSize()- ESP.getFreePsram()); logMemory(); //uint16_t (buffer)[2]=(int()[2])malloc(sizeof(int)32); File bmpFile = SD_MMC.open(FILEEE, "r"); if (! bmpFile|| bmpFile.isDirectory()) { Serial.println(F("ERROR: Failed to open " PNG_FILENAME " file for reading")); gfx->println(F("ERROR: Failed to open " PNG_FILENAME " file for reading")); } else { //bmpFile.readBytes(buffer, 80004); byte lo, hi; uint16_t tem; // int a=0; unsigned long starttt = millis(); for (int y = 0; y < 30; y++) { //invert in calculation (y=0 is bottom) bmpFile.seek(4 + (y 60)); //seek at start of line

        for (int x = 0; x < 30; x++)
        {
            lo = bmpFile.read();
            hi = bmpFile.read();
            tem = lo;
            tem =tem<<8;
            tem = tem | hi;
            buffer[y*30+x]=tem;
            //Serial.printf("%d %x  \n",a,tem);
            //gfx->draw16bitRGBBitmap(30, y, buffer, 30, 1);

        }
        //gfx->draw16bitRGBBitmap(30, y, buffer, 30, 1);
    }
Serial.printf(" time used: %lu\n",  millis() - starttt);

unsigned long startt = millis();

for(int x=0;x<320;x+=30)
{
  for(int y=0;y<240;y+=30)
  {
    for (int i=0;i<30;i++) {
      gfx->draw16bitRGBBitmap(y, i+x, buffer+(i*30), 30, 1);
      }
  }
}
//for (int i=0;i<30;i++) {

// gfx->draw16bitRGBBitmap(30, i, buffer+(i*30), 30, 1); // } Serial.printf(" time used: %lu\n", millis() - starttt); }

delay(100000000);

unsigned long start = millis(); uint16_t bitmap[40000]={0xFC60}; gfx->fillScreen(BLUE); / gfx->startWrite(); gfx->writeAddrWindow(0, 0, 30, 30); uint16_t bitmap[900]={RED}; gfx->writePixels(bitmap, (uint32_t)30 30);

gfx->endWrite();
*/

int16_t x, y, w, h; x =0; y=0; w=24; h=32; int32_t offset = 0; uint16_t p; gfx->startWrite(); for (int16_t j = 0; j < h; j++, y++) { for (int16_t i = 0; i < w; i=+6) { / p = bitmap[offset++]; MSB_16_SET(p, p); gfx->writePixel(x + i, y, p); //Serial.printf("pos =%d %d,%d %d %d\n",x, x+i, y,w,h); //acc_data_all[ii]=p; //ii++; / gfx->writePixelPreclipped(i,j,0xFFDF);

  //    gfx ->   writePixel(i, j, 0xFFDF);
  //    gfx ->   writePixel(i+1, j, 0xFFDF);
   //   gfx ->   writePixel(i+2, j, 0xFFDF);

  //    gfx ->   writePixel(i+3, j, 0xFFDF);
  //    gfx ->   writePixel(i+4, j, 0xFFDF);
  //    gfx ->   writePixel(i+5, j, 0xFFDF);

// gfx->fillScreen(BLUE); / if(j%2==0) { gfx->fillScreen(BLACK); } else { gfx->fillScreen(BLUE); } / } } gfx->endWrite(); //gfx->fillScreen(BLUE); // gfx->draw16bitRGBBitmap(0, 0, bitmap, 30, 30); Serial.printf(" time used: %lu\n", millis() - start); / unsigned long start = millis(); int rc; // rc = png.open(PNG_FILENAME, myOpen, myClose, myRead, mySeek, PNGDraw); for(int i=0;i<240;i+=20) { for(int j=0;j<320;j+=20) { xOffset = i; yOffset = j; //rc = png.open(PNG_FILENAME, myOpen, myClose, myRead, mySeek, PNGDraw); rc = png.decode(NULL, 0); } } / //Serial.printf("Draw offset: (%d, %d), time used: %lu\n", xOffset, yOffset, millis() - start); /* if (rc == PNG_SUCCESS) { // random draw position int16_t pw = png.getWidth(); int16_t ph = png.getHeight(); xOffset = 20; yOffset = 20;

rc = png.decode(NULL, 0);

Serial.printf("Draw offset: (%d, %d), time used: %lu\n", xOffset, yOffset, millis() - start);
Serial.printf("image specs: (%d x %d), %d bpp, pixel type: %d\n", png.getWidth(), png.getHeight(), png.getBpp(), png.getPixelType());
png.close();

} else { Serial.println("png.open() failed!"); } */ delay(5000); // 1 second }

qiaobaaa commented 7 months ago

void intpsarm(char file,uint16_t buffer) { buffer = (uint16_t)ps_malloc(10); Serial.printf("Free.... PSRAM: %d\n", ESP.getPsramSize() - ESP.getFreePsram()); File bmpFile = SD_MMC.open(file, "r"); if (!bmpFile || bmpFile.isDirectory()) { Serial.println(F("ERROR: Failed to open " PNG_FILENAME " file for reading")); } else { byte lo, hi; uint16_t tem; for (int y = 0; y < 20; y++) { bmpFile.seek(4 + (y 40)); //seek at start of line for (int x = 0; x < 20; x++) { lo = bmpFile.read(); hi = bmpFile.read(); tem = lo; tem = tem << 8; tem = tem | hi; buffer[y 30 + x] = tem; } } } bmpFile.close(); }

qiaobaaa commented 7 months ago

uint16_t shop_p; uint16_t shop_l; uint16_t* shop_r;

//1 uint16_t gate_keeper; uint16_t skeleton_a;

//2 uint16_t big_slime; uint16_t big_bat;

uint16_t rock; uint16_t super_priest;

uint16_t vampire; uint16_t zombine; uint16_t* zombine_knight;

//3 uint16_t gate_keeper_b; uint16_t ghost_solider; uint16_t gold_knight; uint16_t knight; uint16_t slime_man; uint16_t solider; uint16_t* swords_man;

//5 uint16_t dark_knight; uint16_t gate_keeper_a;

uint16_t magician_a; uint16_t magician_b;

uint16_t magic_sergeant; uint16_t slime_lord; uint16_t* vampire_bat;

//dragon

uint16_t dragon_wn; uint16_t dragon_n; uint16_t* dragon_en;

uint16_t dragon_w; uint16_t dragon_m; uint16_t* dragon_e;

uint16_t dragon_ws; uint16_t dragon_s; uint16_t* dragon_es;

//octopus uint16_t octopus_wn; uint16_t octopus_n; uint16_t* octopus_en;

uint16_t octopus_w; uint16_t octopus_m; uint16_t* octopus_e;

uint16_t octopus_ws; uint16_t octopus_s; uint16_t* octopus_es;

// uint16_t great_magic_master; uint16_t boss;

uint16_t* snow_crystal;

uint16_t* iron_gate;

uint16_t princess; uint16_t oldman; uint16_t thief; uint16_t merchant;

uint16_t iron_sword; uint16_t sacred_sword; uint16_t holy_sword; uint16_t knight_sword; uint16_t* silver_sword;

uint16_t iron_shield; uint16_t sacred_shield; uint16_t holy_shield; uint16_t knight_shield; uint16_t* silver_shield;

uint16_t lava; uint16_t star;

uint16_t steel_gate; uint16_t lucky_gold;

uint16_t* cross;

qiaobaaa commented 7 months ago

void display_picture(int h, int w, uint16_t data) { for (int i = 0; i < 20; i++) { gfx->draw16bitRGBBitmap(w, i + h, buffer + (i * 20), 20, 1); } }

qiaobaaa commented 7 months ago

void display_picture(int h, int w, uint16_t data) { for (int i = 0; i < 20; i++) { gfx->draw16bitRGBBitmap(w, i + h, data + (i * 20), 20, 1); } }

qiaobaaa commented 6 months ago

//author: Liu Heng

include

include

include

include

include

include

include

include

include "material.h"

include "map.h"

include "mota_bin.h"

include "warrior.h"

include "monster.h"

define GFX_BL 48 // default backlight pin, you may replace DF_GFX_BL to actual backlight pin

const int yyy = 13;

Arduino_DataBus bus = new Arduino_ESP32SPI(41 / DC /, 10 / CS /, 12 / SCK /, 11 / MOSI /, GFX_NOT_DEFINED / MISO /); Arduino_ST7789 gfx = new Arduino_ST7789(bus, 42 / RST /, 0 / rotation /, true / IPS /, 240, 320, 0, 0); int rc;

/*

define SDMMC_D2 33 // SDMMC Data2

define SDMMC_D3 4 //34 // SDMMC Data3 / SPI CS

define SDMMC_CMD 5 // SDMMC CMD / SPI MOSI

define SDMMC_CLK 6 // SDMMC CLK / SPI SCK

define SDMMC_D0 7 // SDMMC Data0 / SPI MISO

define SDMMC_D1 38 // SDMMC Data1

*/

define SDMMC_D2 16 // SDMMC Data2

define SDMMC_D3 4 //34 // SDMMC Data3 / SPI CS

define SDMMC_CMD 5 // SDMMC CMD / SPI MOSI

define SDMMC_CLK 6 // SDMMC CLK / SPI SCK

define SDMMC_D0 7 // SDMMC Data0 / SPI MISO

define SDMMC_D1 15 // SDMMC Data1

int16_t w, h, xOffset, yOffset;

//所有游戏图片的像素指针

//商店 uint16_t shop_m; uint16_t shop_l; uint16_t *shop_r;

//@@@@@@@@@@ 敌人 //1 //初级卫兵 uint16_t gate_keeper_c; //绿史莱姆 uint16_t green_slime; //红史莱姆 uint16_t red_slime; //蝙蝠 uint16_t bat; //法师 uint16_t priest; //骷髅队长 uint16_t skeleton_a; //骷髅士兵 uint16_t skeleton_b; //骷髅人 uint16_t skeleton_c;

//2 //大史莱姆 uint16_t big_slime; //大蝙蝠 uint16_t big_bat; //石头人 uint16_t rock; //高级法师 uint16_t super_priest; //吸血鬼 uint16_t vampire; //兽人武士 uint16_t zombine_knight; //兽人 uint16_t *zombine;

//3 //中级卫兵 uint16_t gate_keeper_b; //鬼战士 uint16_t ghost_solider; //骑士队长 uint16_t gold_knight; //骑士 uint16_t knight; //幽灵 uint16_t slime_man; //战士 uint16_t solider; //双手剑士 uint16_t *swords_man;

//5 //黑暗骑士 uint16_t dark_knight; //高级卫兵 uint16_t gate_keeper_a; //高级巫师 uint16_t magician_a; //初级巫师 uint16_t magician_b; //魔法警卫 uint16_t magic_sergeant; //史莱姆王 uint16_t slime_lord; //吸血蝙蝠 uint16_t *vampire_bat;

//dragon 龙 uint16_t dragon_wn; uint16_t dragon_n; uint16_t *dragon_en;

uint16_t dragon_w; uint16_t dragon_m; uint16_t *dragon_e;

uint16_t dragon_ws; uint16_t dragon_s; uint16_t *dragon_es;

//octopus 章鱼 uint16_t octopus_wn; uint16_t octopus_n; uint16_t *octopus_en;

uint16_t octopus_w; uint16_t octopus_m; uint16_t *octopus_e;

uint16_t octopus_ws; uint16_t octopus_s; uint16_t *octopus_es;

//大魔导师 uint16_t great_magic_master; //魔王 uint16_t boss;

//.............. 特殊物品 //冰冻水晶 uint16_t snow_crystal; //幸运金币 uint16_t lucky_gold; //十字架 uint16_t cross; //传送道具 uint16_t orbof_flying; //屠龙匕首 uint16_t dragon_slayer; //向上飞行器 uint16_t wings_to_flyup; //向下飞行器 uint16_t wings_to_flydown; //中心对称飞行器 uint16_t warp_staff; //破墙镐 uint16_t mattock; //魔法钥匙 uint16_t magic_key; //炸药 uint16_t *bomb;

//............. npc //公主 uint16_t princess; //指引者 uint16_t oldman; //小偷 uint16_t thief; //商人 uint16_t merchant;

//.......... 剑的分类 //铁剑 uint16_t iron_sword; //神圣剑 uint16_t sacred_sword; //圣剑 uint16_t holy_sword; //骑士剑 uint16_t knight_sword; //银剑 uint16_t *silver_sword;

//......... 盾的分类 uint16_t iron_shield; uint16_t sacred_shield; uint16_t holy_shield; uint16_t knight_shield; uint16_t *silver_shield;

//............ 背景 //铁门 or 笼子 uint16_t iron_gate; //钢门 or 花门 uint16_t steel_gate; //熔岩 uint16_t lava; //星空 uint16_t star;

uint16_t road; uint16_t wall;

uint16_t upstair; uint16_t downstair;

uint16_t yellow_door; uint16_t red_door; uint16_t *blue_door;

uint16_t yellow_key; uint16_t red_key; uint16_t *blue_key;

uint16_t yellow_keyy; uint16_t red_keyy; uint16_t *blue_keyy;

uint16_t attack; uint16_t defend; uint16_t life; uint16_t gold;

//物品 uint16_t red_crystal; uint16_t blue_crystal; uint16_t red_elixir; uint16_t blue_elixir;

//人物CRYSTAL uint16_t people_up; uint16_t people_down; uint16_t people_right; uint16_t people_left;

//enemy

uint16_t background; uint16_t backgroundd; //uint16_t MOTA "/motaa.jpg" //uint16_t ZHUANGBEI "/zhuangbeii.jpg" //uint16_t * III "/iii.jpg"

GFXfont *f = NULL;

void logMemoryy() { log_d("Used PSRAM: %d", ESP.getPsramSize()); } void logMemory() { log_d("Used PSRAM: %d", ESP.getPsramSize() - ESP.getFreePsram()); }

//void initpsarm(char file, uint16_t buffer);

void display_picture(int h, int w, uint16_t data) { for (int i = 0; i < 20; i++) { gfx->draw16bitRGBBitmap(w, i + h, data + (i 20), 20, 1); } }

void display_picture2(int h, int w, uint16_t data) { for (int i = 0; i < 20; i++) { gfx->draw16bitRGBBitmap(w, i + h, data + (i 10), 10, 1); } }

void setup() { Serial.begin(115200); // Serial.setDebugOutput(true); // while(!Serial); Serial.println("PNG Image Viewer");

ifdef GFX_EXTRA_PRE_INIT

GFX_EXTRA_PRE_INIT();

endif

// Init Display gfx->begin();

gfx->fillScreen(BLACK); gfx->setUTF8Print(true);

ifdef GFX_BL

pinMode(GFX_BL, OUTPUT); //digitalWrite(GFX_BL, HIGH); analogWrite(GFX_BL, 180);

endif

// pinMode(SDMMC_D3 / CS /, OUTPUT); // digitalWrite(SDMMC_D3 / CS /, HIGH); //#if defined(SOC_SDMMC_USE_GPIO_MATRIX) // SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); //#endif

if defined(SOC_SDMMC_USE_GPIO_MATRIX)

SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3);

endif

if (!SD_MMC.begin("/root", true)) { //if(!FFat.begin(true)){ Serial.println("FFat Mount Failed"); return; } else { if (psramInit()) { Serial.printf("Total PSRAM: %d", ESP.getPsramSize()); Serial.println("\nPSRAM is correctly initialized"); } } //rc = png.open(PNG_FILENAME, myOpen, myClose, myRead, mySeek, PNGDraw); }

void loop() { logMemoryy(); //给所有的图片素材申请空间 shop_m = (uint16_t )ps_malloc(800); shop_l = (uint16_t )ps_malloc(800); shop_r = (uint16_t )ps_malloc(800); //@@@@@@@@@@@ 敌人 //1 gate_keeper_c = (uint16_t )ps_malloc(800); green_slime = (uint16_t )ps_malloc(800); red_slime = (uint16_t )ps_malloc(800); bat = (uint16_t )ps_malloc(800); priest = (uint16_t )ps_malloc(800); skeleton_a = (uint16_t )ps_malloc(800); skeleton_b = (uint16_t )ps_malloc(800); skeleton_c = (uint16_t *)ps_malloc(800);

//2 big_slime = (uint16_t )ps_malloc(800); big_bat = (uint16_t )ps_malloc(800); rock = (uint16_t )ps_malloc(800); super_priest = (uint16_t )ps_malloc(800); vampire = (uint16_t )ps_malloc(800); zombine_knight = (uint16_t )ps_malloc(800); zombine = (uint16_t *)ps_malloc(800);

//3 gate_keeper_b = (uint16_t )ps_malloc(800); ghost_solider = (uint16_t )ps_malloc(800); gold_knight = (uint16_t )ps_malloc(800); knight = (uint16_t )ps_malloc(800); slime_man = (uint16_t )ps_malloc(800); solider = (uint16_t )ps_malloc(800); swords_man = (uint16_t *)ps_malloc(800);

//5 dark_knight = (uint16_t )ps_malloc(800); gate_keeper_a = (uint16_t )ps_malloc(800); magician_a = (uint16_t )ps_malloc(800); magician_b = (uint16_t )ps_malloc(800); magic_sergeant = (uint16_t )ps_malloc(800); slime_lord = (uint16_t )ps_malloc(800); vampire_bat = (uint16_t *)ps_malloc(800);

//dragon 龙 dragon_wn = (uint16_t )ps_malloc(800); dragon_n = (uint16_t )ps_malloc(800); dragon_en = (uint16_t *)ps_malloc(800);

dragon_w = (uint16_t )ps_malloc(800); dragon_m = (uint16_t )ps_malloc(800); dragon_e = (uint16_t *)ps_malloc(800);

dragon_ws = (uint16_t )ps_malloc(800); dragon_s = (uint16_t )ps_malloc(800); dragon_es = (uint16_t *)ps_malloc(800);

//octopus 章鱼 octopus_wn = (uint16_t )ps_malloc(800); octopus_n = (uint16_t )ps_malloc(800); octopus_en = (uint16_t *)ps_malloc(800);

octopus_w = (uint16_t )ps_malloc(800); octopus_m = (uint16_t )ps_malloc(800); octopus_e = (uint16_t *)ps_malloc(800);

octopus_ws = (uint16_t )ps_malloc(800); octopus_s = (uint16_t )ps_malloc(800); octopus_es = (uint16_t *)ps_malloc(800);

//大魔导师 great_magic_master = (uint16_t )ps_malloc(800); //魔王 boss = (uint16_t )ps_malloc(800);

//.............. 特殊物品 snow_crystal = (uint16_t )ps_malloc(800); //幸运金币 lucky_gold = (uint16_t )ps_malloc(800); //十字架 cross = (uint16_t )ps_malloc(800); //传送道具 orbof_flying = (uint16_t )ps_malloc(800); dragon_slayer = (uint16_t )ps_malloc(800); wings_to_flyup = (uint16_t )ps_malloc(800); wings_to_flydown = (uint16_t )ps_malloc(800); warp_staff = (uint16_t )ps_malloc(800); //破墙镐 mattock = (uint16_t )ps_malloc(800); magic_key = (uint16_t )ps_malloc(800); bomb = (uint16_t *)ps_malloc(800);

//............. npc princess = (uint16_t )ps_malloc(800); oldman = (uint16_t )ps_malloc(800); thief = (uint16_t )ps_malloc(800); merchant = (uint16_t )ps_malloc(800);

//.......... 剑的分类 iron_sword = (uint16_t )ps_malloc(800); //神圣剑 sacred_sword = (uint16_t )ps_malloc(800); //圣剑 holy_sword = (uint16_t )ps_malloc(800); knight_sword = (uint16_t )ps_malloc(800); silver_sword = (uint16_t *)ps_malloc(800);

//......... 盾的分类 iron_shield = (uint16_t )ps_malloc(800); sacred_shield = (uint16_t )ps_malloc(800); holy_shield = (uint16_t )ps_malloc(800); knight_shield = (uint16_t )ps_malloc(800); silver_shield = (uint16_t *)ps_malloc(800);

//............ 背景 //铁门 or 笼子 iron_gate = (uint16_t )ps_malloc(800); //钢门 or 花门 steel_gate = (uint16_t )ps_malloc(800); //熔岩 lava = (uint16_t )ps_malloc(800); star = (uint16_t )ps_malloc(800);

road = (uint16_t )ps_malloc(800); wall = (uint16_t )ps_malloc(800);

upstair = (uint16_t )ps_malloc(800); downstair = (uint16_t )ps_malloc(800);

yellow_door = (uint16_t )ps_malloc(800); red_door = (uint16_t )ps_malloc(800); blue_door = (uint16_t *)ps_malloc(800);

yellow_key = (uint16_t )ps_malloc(800); red_key = (uint16_t )ps_malloc(800); blue_key = (uint16_t *)ps_malloc(800);

yellow_keyy = (uint16_t )ps_malloc(800); red_keyy = (uint16_t )ps_malloc(800); blue_keyy = (uint16_t *)ps_malloc(800);

attack = (uint16_t )ps_malloc(800); defend = (uint16_t )ps_malloc(800); life = (uint16_t )ps_malloc(800); gold = (uint16_t )ps_malloc(800);

//物品 red_crystal = (uint16_t )ps_malloc(800); blue_crystal = (uint16_t )ps_malloc(800); red_elixir = (uint16_t )ps_malloc(800); blue_elixir = (uint16_t )ps_malloc(800);

//人物 people_up = (uint16_t )ps_malloc(800); people_down = (uint16_t )ps_malloc(800); people_right = (uint16_t )ps_malloc(800); people_left = (uint16_t )ps_malloc(800); //2020 background = (uint16_t )ps_malloc(800); //1020 backgroundd = (uint16_t )ps_malloc(800);

//buffer = (uint16_t )heap_caps_malloc(80000, MALLOC_CAP_SPIRAM); //Serial.printf("@@@@@@ %d %f\n", sizeof(uint16_t), sizeof(byte)); //big_bat = (uint16_t )ps_malloc(400); logMemory();

// loadpsarm(SHOP_M, shop_m); //loadpsarm(SHOP_L,shop_l); //loadpsarm(SHOP_R,shop_r);

/ //@@@@@@@@@@ 敌人 //1 loadpsarm(gate_keeper_a,gate_keeper_c; //绿史莱姆 uint16_t green_slime; //红史莱姆 uint16_t red_slime; //蝙蝠 uint16_t bat; //法师 uint16_t priest; //骷髅队长 uint16_t skeleton_a; //骷髅士兵 uint16_t skeleton_b; //骷髅人 uint16_t skeleton_c; */ loadpsarm(SHOP_M, shop_m); loadpsarm(SHOP_L, shop_l); loadpsarm(SHOP_R, shop_r);

//1 loadpsarm(GATE_KEEPER_C, gate_keeper_c); loadpsarm(GREEN_SLIME, green_slime); loadpsarm(RED_SLIME, red_slime); loadpsarm(BAT, bat); loadpsarm(PRIEST, priest); loadpsarm(SKELETON_A, skeleton_a); loadpsarm(SKELETON_B, skeleton_b); loadpsarm(SKELETON_C, skeleton_c);

loadpsarm(ORBOFFLY, orbof_flying);

// loadpsarm(BIG_BAT, big_bat); loadpsarm(ROAD, road); loadpsarm(WALL, wall);

loadpsarm(YELLOWDOOR, yellow_door); loadpsarm(REDDOOR, red_door); loadpsarm(BLUEDOOR, blue_door);

loadpsarm(YELLOWKEY, yellow_key); loadpsarm(REDKEY, red_key); loadpsarm(BLUEKEY, blue_key);

loadpsarm(YELLOWKEYY, yellow_keyy); loadpsarm(REDKEYY, red_keyy); loadpsarm(BLUEKEYY, blue_keyy);

loadpsarm(ATTACK ,attack); loadpsarm( DEFEND ,defend); loadpsarm( LIFE ,life); loadpsarm( GOLD ,gold);

loadpsarm(REDCRYSTAL, red_crystal); loadpsarm(BLUECRYSTAL, blue_crystal); loadpsarm(REDELIXIR, red_elixir); loadpsarm(BLUEELIXIR, blue_elixir);

loadpsarm(PEOPLEUP, people_up); loadpsarm(PEOPLEDOWN, people_down); loadpsarm(PEOPLERIGHT, people_right); loadpsarm(PEOPLELEFT, people_left);

loadpsarm(BACKGROUND, background); loadpsarm(BACKGROUNDD, backgroundd);

loadpsarm(UPSTAIR, upstair);

//gfx->fillScreen(BLACK); unsigned long start = millis(); //gfx->fillScreen(RED); initfirstfloor(); information(); Serial.printf(" time used: %lu\n", millis() - start); / gfx->fillScreen(BLACK); for (int x = 0; x < 11; x += 20) { for (int y = 0; y < 1; y += 20) { display_picture(x, y, wall); } } //for (int i=0;i<30;i++) { // gfx->draw16bitRGBBitmap(30, i, buffer+(i30), 30, 1); // } Serial.printf(" time used: %lu\n", millis() - start); */ delay(100000000); }

void loadpsarm(char file, uint16_t buffer) { File bmpFile = SD_MMC.open(file, "r"); if (!bmpFile || bmpFile.isDirectory()) { Serial.println("ERROR: Failed to open file for reading"); } else { byte lo, hi; uint16_t tem; if (strcmp(BACKGROUNDD, file) == 0) { for (int y = 0; y < 20; y++) { bmpFile.seek(4 + (y 20)); //seek at start of line for (int x = 0; x < 10; x++) { lo = bmpFile.read(); hi = bmpFile.read(); tem = lo; tem = tem << 8; tem = tem | hi; //Serial.printf(" %d %d %x %x %x\n", y, x, lo, hi, tem); buffer[y 10 + x] = tem; } } } else { for (int y = 0; y < 20; y++) { bmpFile.seek(4 + (y 40)); //seek at start of line for (int x = 0; x < 20; x++) { lo = bmpFile.read(); hi = bmpFile.read(); tem = lo; tem = tem << 8; tem = tem | hi; //Serial.printf(" %d %d %x %x %x\n", y, x, lo, hi, tem); buffer[y 20 + x] = tem; } } } } bmpFile.close(); }

void drawmap(int floor) { for (int x = 1; x < 12; x++) { for (int y = 0; y < 13; y++) { int tem = mappp[floor][x][y]; switch (tem) { case 0: if (y == 0) { display_picture2((x - 1) 20, y 20, backgroundd); } else if (y == 12) { display_picture2((x - 1) 20, (y 20) - 10, backgroundd); } else { display_picture((x - 1) 20, (y 20) - 10, wall); } break; case 1: display_picture((x - 1) 20, (y 20) - 10, road); break; case 6: display_picture((x - 1) 20, (y 20) - 10, yellow_door); break; case 8: display_picture((x - 1) 20, (y 20) - 10, red_door); break; case 11: display_picture((x - 1) 20, (y 20) - 10, upstair); break; case 17: display_picture((x - 1) 20, (y 20) - 10, people_down); break; case 21: display_picture((x - 1) 20, (y 20) - 10, yellow_key); break; case 22: display_picture((x - 1) 20, (y 20) - 10, blue_key); case 23: display_picture((x - 1) 20, (y 20) - 10, red_key); break; case 24: display_picture((x - 1) 20, (y 20) - 10, red_crystal); break; case 25: display_picture((x - 1) 20, (y 20) - 10, blue_crystal); break; case 26: display_picture((x - 1) 20, (y 20) - 10, red_elixir); break; case 27: display_picture((x - 1) 20, (y 20) - 10, blue_elixir); break; case 41: display_picture((x - 1) 20, (y 20) - 10, orbof_flying); break; case 251: display_picture((x - 1) 20, (y 20) - 10, green_slime); break; case 252: display_picture((x - 1) 20, (y 20) - 10, red_slime); break; case 253: display_picture((x - 1) 20, (y 20) - 10, bat); break; case 254: display_picture((x - 1) 20, (y 20) - 10, priest); break; case 255: display_picture((x - 1) 20, (y 20) - 10, skeleton_c); break; case 256: display_picture((x - 1) 20, (y 20) - 10, skeleton_b); break; } } } }

void initfirstfloor() {

for (int x = 1; x < 12; x++) { for (int y = 0; y < 13; y++) { int tem = mappp[1][x][y]; switch (tem) { case 0: if (y == 0) { display_picture2((x - 1) 20, y 20, backgroundd); } else if (y == 12) { display_picture2((x - 1) 20, (y 20) - 10, backgroundd); } else { display_picture((x - 1) 20, (y 20) - 10, wall); } break; case 1: display_picture((x - 1) 20, (y 20) - 10, road); break; case 6: display_picture((x - 1) 20, (y 20) - 10, yellow_door); break; case 8: display_picture((x - 1) 20, (y 20) - 10, red_door); break; case 11: display_picture((x - 1) 20, (y 20) - 10, upstair); break; case 17: display_picture((x - 1) 20, (y 20) - 10, people_down); break; case 21: display_picture((x - 1) 20, (y 20) - 10, yellow_key); break; case 22: display_picture((x - 1) 20, (y 20) - 10, blue_key); case 23: display_picture((x - 1) 20, (y 20) - 10, red_key); break; case 24: display_picture((x - 1) 20, (y 20) - 10, red_crystal); break; case 25: display_picture((x - 1) 20, (y 20) - 10, blue_crystal); break; case 26: display_picture((x - 1) 20, (y 20) - 10, red_elixir); break; case 27: display_picture((x - 1) 20, (y 20) - 10, blue_elixir); break; case 41: display_picture((x - 1) 20, (y 20) - 10, orbof_flying); break; case 251: display_picture((x - 1) 20, (y 20) - 10, green_slime); break; case 252: display_picture((x - 1) 20, (y 20) - 10, red_slime); break; case 253: display_picture((x - 1) 20, (y 20) - 10, bat); break; case 254: display_picture((x - 1) 20, (y 20) - 10, priest); break; case 255: display_picture((x - 1) 20, (y 20) - 10, skeleton_c); break; case 256: display_picture((x - 1) 20, (y 20) - 10, skeleton_b); break; } } } }

void information() {

for (int x = 0; x < 240; x += 20) { display_picture(220, x, background);
} for (int x = 0; x < 130; x += 20) { display_picture(280, x, background); } display_picture(240, 0, life); display_picture(240, 70, gold); display_picture(260, 0, attack); display_picture(260, 70, defend);

display_picture(240, 135, yellow_keyy); display_picture(260, 135, blue_keyy); display_picture(280, 135, red_keyy);

displaymota(); displayzhuangbei(); }

void displaymota() { gfx->setFont(u8g2_font_unifont_t_chinese); gfx->setTextColor(WHITE); gfx->setCursor(188, 265); gfx->println("魔 塔"); gfx->setCursor(183, 290); gfx->println("第 层"); //displayfloor(); gfx->setFont(f); }

void displayzhuangbei() { gfx->setFont(u8g2_font_unifont_t_chinese); gfx->setTextColor(WHITE); gfx->setCursor(0, 315); gfx->println("装备"); gfx->setFont(f); }

qiaobaaa commented 6 months ago

pragma once

define SHOP_M "/shop_m.bin"

define SHOP_L "/shop_l.bin"

define SHOP_R "/shop_r.bin"

//1

define GATE_KEEPER_C "/gate_keeper_c.bin"

define GREEN_SLIME "/green_slime.bin"

define RED_SLIME "/red_slime.bin"

define BAT "/bat.bin"

define PRIEST "/priest.bin"

define SKELETON_A "/skeleton_a.bin"

define SKELETON_B "/skeleton_b.bin"

define SKELETON_C "/skeleton_c.bin"

//2

define BIG_SLIME "/big_slime.bin"

define BIG_BAT "/big_bat.bin"

define ROCK "/rock.bin"

define SUPER_PRIEST "/super_priest.bin"

define VAMPIRE "/vampire.bin"

define ZOMBINE "/zombine.bin"

define ZOMBINE_KNIGHT "/zombine_knight.bin"

//3

define GATE_KEEPER_B "/gate_keeper_b.bin"

define GHOST_SOLIDER "/ghost_solider.bin"

define GOLD_KNIGHT "/gold_knight.bin"

define KNIGHT "/knight.bin"

define SLIME_MAN "/slime_man.bin"

define SOLIDER "/solider.bin"

define SWORDS_MAN "/swords_man.bin"

//5

define DARK_KNIGHT "/dark_knight.bin"

define GATE_KEEPER_A "/gate_keeper_a.bin"

define MAGICIAN_A "/magician_a.bin"

define MAGICIAN_B "/magician_b.bin"

define MAGIC_SERGEANT "/magic_sergeant.bin"

define SLIME_LORD "/slime_lord.bin"

define VAMPIRE_BAT "/vampire_bat.bin"

//dragon

define DRAGON_WN "/dragon_wn.bin"

define DRAGON_N "/dragon_n.bin"

define DRAGON_EN "/dragon_en.bin"

define DRAGON_W "/dragon_w.bin"

define DRAGON_M "/dragon_m.bin"

define DRAGON_E "/dragon_e.bin"

define DRAGON_WS "/dragon_ws.bin"

define DRAGON_S "/dragon_s.bin"

define DRAGON_ES "/dragon_es.bin"

//octopus

define OCTOPUS_WN "/octopus_wn.bin"

define OCTOPUS_N "/octopus_n.bin"

define OCTOPUS_EN "/octopus_en.bin"

define OCTOPUS_W "/octopus_w.bin"

define OCTOPUS_M "/octopus_m.bin"

define OCTOPUS_E "/octopus_e.bin"

define OCTOPUS_WS "/octopus_ws.bin"

define OCTOPUS_S "/octopus_s.bin"

define OCTOPUS_ES "/octopus_es.bin"

//

define GREAT_MAGIC_MASTER "/great_magic_master.bin"

define BOSS "/boss.bin"

//.............. 特殊物品 //冰冻水晶

define SNOW_CRYSTAL "/snow_crystal.bin"

define LUCKY_GOLD "/lucky_gold.bin"

define CROSS "/cross.bin"

define ORBOFFLY "/orbof_flying.bin"

//屠龙匕首

define DRAGON_SLAYER "/dragon_slayer.bin"

//向上飞行器

define WINGS_TO_FLYUP "/wings_to_flyup.bin"

//向下飞行器

define WINGS_TO_FLYDOWN "/wings_to_flydown.bin"

//中心对称飞行器

define WARP_STAFF "/warp_staff.bin"

//破墙镐

define MATTOCK "/mattock.bin"

//魔法钥匙

define MAGIC_KEY "/magic_key"

//炸药

define BOMB "/bomb"

//............. npc //公主

define PRINCESS "/princess.bin"

define OLDMAN "/oldman.bin"

define THIEF "/thief.bin"

define MERCHANT "/merchant.bin"

define IRON_SWORD "/iron_sword.bin"

define SACRED_SWORD "/sacred_sword.bin"

define HOLY_SWORD "/holy_sword.bin"

define KNIGHT_SWORD "/knight_sword.bin"

define SILVER_SWORD "/silver_sword.bin"

define IRON_SHIELD "/iron_shield.bin"

define SACRED_SHIELD "/sacred_shield.bin"

define HOLY_SHIELD "/holy_shield.bin"

define KNIGHT_SHIELD "/knight_shield.bin"

define SILVER_SHIELDD "/silver_shield.bin"

define IRONGATE "/iron_gate.bin"

define STEEL_GATE "/steel_gate.bin"

define LAVA "/lava.bin"

define STAR "/star.bin"

define ROAD "/road.bin"

define WALL "/wall.bin"

define UPSTAIR "/upstair.bin"

define DOWNSTAIR "/downstair.bin"

define YELLOWDOOR "/yellow_door.bin"

define REDDOOR "/red_door.bin"

define BLUEDOOR "/blue_door.bin"

define YELLOWKEY "/yellow_key.bin"

define REDKEY "/red_key.bin"

define BLUEKEY "/blue_key.bin"

define YELLOWKEYY "/yellow_keyy.bin"

define REDKEYY "/red_keyy.bin"

define BLUEKEYY "/blue_keyy.bin"

define ATTACK "/attack.bin"

define DEFEND "/defend.bin"

define LIFE "/life.bin"

define GOLD "/gold.bin"

//物品

define REDCRYSTAL "/red_crystal.bin"

define BLUECRYSTAL "/blue_crystal.bin"

define REDELIXIR "/red_elixir.bin"

define BLUEELIXIR "/blue_elixir.bin"

//人物CRYSTAL

define PEOPLEUP "/people_up.bin"

define PEOPLEDOWN "/people_down.bin"

define PEOPLERIGHT "/people_right.bin"

define PEOPLELEFT "/people_left.bin"

define BACKGROUND "/background.bin"

define BACKGROUNDD "/backgroundd.bin"

qiaobaaa commented 6 months ago

//author: Liu Heng

include

include

include

include

include

include

include

include

include "material.h"

include "map.h"

include "mota_bin.h"

include "warrior.h"

include "monster.h"

define GFX_BL 48 // default backlight pin, you may replace DF_GFX_BL to actual backlight pin

const int yyy = 13;

Arduino_DataBus bus = new Arduino_ESP32SPI(41 / DC /, 10 / CS /, 12 / SCK /, 11 / MOSI /, GFX_NOT_DEFINED / MISO /); Arduino_ST7789 gfx = new Arduino_ST7789(bus, 42 / RST /, 0 / rotation /, true / IPS /, 240, 320, 0, 0); int rc;

/*

define SDMMC_D2 33 // SDMMC Data2

define SDMMC_D3 4 //34 // SDMMC Data3 / SPI CS

define SDMMC_CMD 5 // SDMMC CMD / SPI MOSI

define SDMMC_CLK 6 // SDMMC CLK / SPI SCK

define SDMMC_D0 7 // SDMMC Data0 / SPI MISO

define SDMMC_D1 38 // SDMMC Data1

*/

define SDMMC_D2 16 // SDMMC Data2

define SDMMC_D3 4 //34 // SDMMC Data3 / SPI CS

define SDMMC_CMD 5 // SDMMC CMD / SPI MOSI

define SDMMC_CLK 6 // SDMMC CLK / SPI SCK

define SDMMC_D0 7 // SDMMC Data0 / SPI MISO

define SDMMC_D1 15 // SDMMC Data1

int16_t w, h, xOffset, yOffset;

//所有游戏图片的像素指针

//商店 uint16_t shop_m; uint16_t shop_l; uint16_t *shop_r;

//@@@@@@@@@@ 敌人 //1 //初级卫兵 uint16_t gate_keeper_c; //绿史莱姆 uint16_t green_slime; //红史莱姆 uint16_t red_slime; //蝙蝠 uint16_t bat; //法师 uint16_t priest; //骷髅队长 uint16_t skeleton_a; //骷髅士兵 uint16_t skeleton_b; //骷髅人 uint16_t skeleton_c;

//2 //大史莱姆 uint16_t big_slime; //大蝙蝠 uint16_t big_bat; //石头人 uint16_t rock; //高级法师 uint16_t super_priest; //吸血鬼 uint16_t vampire; //兽人武士 uint16_t zombine_knight; //兽人 uint16_t *zombine;

//3 //中级卫兵 uint16_t gate_keeper_b; //鬼战士 uint16_t ghost_solider; //骑士队长 uint16_t gold_knight; //骑士 uint16_t knight; //幽灵 uint16_t slime_man; //战士 uint16_t solider; //双手剑士 uint16_t *swords_man;

//5 //黑暗骑士 uint16_t dark_knight; //高级卫兵 uint16_t gate_keeper_a; //高级巫师 uint16_t magician_a; //初级巫师 uint16_t magician_b; //魔法警卫 uint16_t magic_sergeant; //史莱姆王 uint16_t slime_lord; //吸血蝙蝠 uint16_t *vampire_bat;

//dragon 龙 uint16_t dragon_wn; uint16_t dragon_n; uint16_t *dragon_en;

uint16_t dragon_w; uint16_t dragon_m; uint16_t *dragon_e;

uint16_t dragon_ws; uint16_t dragon_s; uint16_t *dragon_es;

//octopus 章鱼 uint16_t octopus_wn; uint16_t octopus_n; uint16_t *octopus_en;

uint16_t octopus_w; uint16_t octopus_m; uint16_t *octopus_e;

uint16_t octopus_ws; uint16_t octopus_s; uint16_t *octopus_es;

//大魔导师 uint16_t great_magic_master; //魔王 uint16_t boss;

//.............. 特殊物品 //冰冻水晶 uint16_t snow_crystal; //幸运金币 uint16_t lucky_gold; //十字架 uint16_t cross; //传送道具 uint16_t orbof_flying; //屠龙匕首 uint16_t dragon_slayer; //向上飞行器 uint16_t wings_to_flyup; //向下飞行器 uint16_t wings_to_flydown; //中心对称飞行器 uint16_t warp_staff; //破墙镐 uint16_t mattock; //魔法钥匙 uint16_t magic_key; //炸药 uint16_t *bomb;

//............. npc //公主 uint16_t princess; //指引者 uint16_t oldman; //小偷 uint16_t thief; //商人 uint16_t merchant;

//.......... 剑的分类 //铁剑 uint16_t iron_sword; //神圣剑 uint16_t sacred_sword; //圣剑 uint16_t holy_sword; //骑士剑 uint16_t knight_sword; //银剑 uint16_t *silver_sword;

//......... 盾的分类 uint16_t iron_shield; uint16_t sacred_shield; uint16_t holy_shield; uint16_t knight_shield; uint16_t *silver_shield;

//............ 背景 //铁门 or 笼子 uint16_t iron_gate; //钢门 or 花门 uint16_t steel_gate; //熔岩 uint16_t lava; //星空 uint16_t star;

uint16_t road; uint16_t wall;

uint16_t upstair; uint16_t downstair;

uint16_t yellow_door; uint16_t red_door; uint16_t *blue_door;

uint16_t yellow_key; uint16_t red_key; uint16_t *blue_key;

uint16_t yellow_keyy; uint16_t red_keyy; uint16_t *blue_keyy;

uint16_t attack; uint16_t defend; uint16_t life; uint16_t gold;

//物品 uint16_t red_crystal; uint16_t blue_crystal; uint16_t red_elixir; uint16_t blue_elixir;

//人物CRYSTAL uint16_t people_up; uint16_t people_down; uint16_t people_right; uint16_t people_left;

//enemy

uint16_t background; uint16_t backgroundd; //uint16_t MOTA "/motaa.jpg" //uint16_t ZHUANGBEI "/zhuangbeii.jpg" //uint16_t * III "/iii.jpg"

GFXfont *f = NULL;

void logMemoryy() { log_d("Used PSRAM: %d", ESP.getPsramSize()); } void logMemory() { log_d("Used PSRAM: %d", ESP.getPsramSize() - ESP.getFreePsram()); }

//void initpsarm(char file, uint16_t buffer);

void display_picture(int h, int w, uint16_t data) { for (int i = 0; i < 20; i++) { gfx->draw16bitRGBBitmap(w, i + h, data + (i 20), 20, 1); } }

void display_picture2(int h, int w, uint16_t data) { for (int i = 0; i < 20; i++) { gfx->draw16bitRGBBitmap(w, i + h, data + (i 10), 10, 1); } }

void setup() { Serial.begin(115200); // Serial.setDebugOutput(true); // while(!Serial); Serial.println("PNG Image Viewer");

ifdef GFX_EXTRA_PRE_INIT

GFX_EXTRA_PRE_INIT();

endif

// Init Display gfx->begin();

gfx->fillScreen(BLACK); gfx->setUTF8Print(true);

ifdef GFX_BL

pinMode(GFX_BL, OUTPUT); //digitalWrite(GFX_BL, HIGH); analogWrite(GFX_BL, 180);

endif

// pinMode(SDMMC_D3 / CS /, OUTPUT); // digitalWrite(SDMMC_D3 / CS /, HIGH); //#if defined(SOC_SDMMC_USE_GPIO_MATRIX) // SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); //#endif

if defined(SOC_SDMMC_USE_GPIO_MATRIX)

SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3);

endif

if (!SD_MMC.begin("/root", true)) { //if(!FFat.begin(true)){ Serial.println("FFat Mount Failed"); return; } else { if (psramInit()) { Serial.printf("Total PSRAM: %d", ESP.getPsramSize()); Serial.println("\nPSRAM is correctly initialized"); } } //rc = png.open(PNG_FILENAME, myOpen, myClose, myRead, mySeek, PNGDraw); }

void loop() { logMemoryy(); //给所有的图片素材申请空间 shop_m = (uint16_t )ps_malloc(800); shop_l = (uint16_t )ps_malloc(800); shop_r = (uint16_t )ps_malloc(800); //@@@@@@@@@@@ 敌人 //1 gate_keeper_c = (uint16_t )ps_malloc(800); green_slime = (uint16_t )ps_malloc(800); red_slime = (uint16_t )ps_malloc(800); bat = (uint16_t )ps_malloc(800); priest = (uint16_t )ps_malloc(800); skeleton_a = (uint16_t )ps_malloc(800); skeleton_b = (uint16_t )ps_malloc(800); skeleton_c = (uint16_t *)ps_malloc(800);

//2 big_slime = (uint16_t )ps_malloc(800); big_bat = (uint16_t )ps_malloc(800); rock = (uint16_t )ps_malloc(800); super_priest = (uint16_t )ps_malloc(800); vampire = (uint16_t )ps_malloc(800); zombine_knight = (uint16_t )ps_malloc(800); zombine = (uint16_t *)ps_malloc(800);

//3 gate_keeper_b = (uint16_t )ps_malloc(800); ghost_solider = (uint16_t )ps_malloc(800); gold_knight = (uint16_t )ps_malloc(800); knight = (uint16_t )ps_malloc(800); slime_man = (uint16_t )ps_malloc(800); solider = (uint16_t )ps_malloc(800); swords_man = (uint16_t *)ps_malloc(800);

//5 dark_knight = (uint16_t )ps_malloc(800); gate_keeper_a = (uint16_t )ps_malloc(800); magician_a = (uint16_t )ps_malloc(800); magician_b = (uint16_t )ps_malloc(800); magic_sergeant = (uint16_t )ps_malloc(800); slime_lord = (uint16_t )ps_malloc(800); vampire_bat = (uint16_t *)ps_malloc(800);

//dragon 龙 dragon_wn = (uint16_t )ps_malloc(800); dragon_n = (uint16_t )ps_malloc(800); dragon_en = (uint16_t *)ps_malloc(800);

dragon_w = (uint16_t )ps_malloc(800); dragon_m = (uint16_t )ps_malloc(800); dragon_e = (uint16_t *)ps_malloc(800);

dragon_ws = (uint16_t )ps_malloc(800); dragon_s = (uint16_t )ps_malloc(800); dragon_es = (uint16_t *)ps_malloc(800);

//octopus 章鱼 octopus_wn = (uint16_t )ps_malloc(800); octopus_n = (uint16_t )ps_malloc(800); octopus_en = (uint16_t *)ps_malloc(800);

octopus_w = (uint16_t )ps_malloc(800); octopus_m = (uint16_t )ps_malloc(800); octopus_e = (uint16_t *)ps_malloc(800);

octopus_ws = (uint16_t )ps_malloc(800); octopus_s = (uint16_t )ps_malloc(800); octopus_es = (uint16_t *)ps_malloc(800);

//大魔导师 great_magic_master = (uint16_t )ps_malloc(800); //魔王 boss = (uint16_t )ps_malloc(800);

//.............. 特殊物品 snow_crystal = (uint16_t )ps_malloc(800); //幸运金币 lucky_gold = (uint16_t )ps_malloc(800); //十字架 cross = (uint16_t )ps_malloc(800); //传送道具 orbof_flying = (uint16_t )ps_malloc(800); dragon_slayer = (uint16_t )ps_malloc(800); wings_to_flyup = (uint16_t )ps_malloc(800); wings_to_flydown = (uint16_t )ps_malloc(800); warp_staff = (uint16_t )ps_malloc(800); //破墙镐 mattock = (uint16_t )ps_malloc(800); magic_key = (uint16_t )ps_malloc(800); bomb = (uint16_t *)ps_malloc(800);

//............. npc princess = (uint16_t )ps_malloc(800); oldman = (uint16_t )ps_malloc(800); thief = (uint16_t )ps_malloc(800); merchant = (uint16_t )ps_malloc(800);

//.......... 剑的分类 iron_sword = (uint16_t )ps_malloc(800); //神圣剑 sacred_sword = (uint16_t )ps_malloc(800); //圣剑 holy_sword = (uint16_t )ps_malloc(800); knight_sword = (uint16_t )ps_malloc(800); silver_sword = (uint16_t *)ps_malloc(800);

//......... 盾的分类 iron_shield = (uint16_t )ps_malloc(800); sacred_shield = (uint16_t )ps_malloc(800); holy_shield = (uint16_t )ps_malloc(800); knight_shield = (uint16_t )ps_malloc(800); silver_shield = (uint16_t *)ps_malloc(800);

//............ 背景 //铁门 or 笼子 iron_gate = (uint16_t )ps_malloc(800); //钢门 or 花门 steel_gate = (uint16_t )ps_malloc(800); //熔岩 lava = (uint16_t )ps_malloc(800); star = (uint16_t )ps_malloc(800);

road = (uint16_t )ps_malloc(800); wall = (uint16_t )ps_malloc(800);

upstair = (uint16_t )ps_malloc(800); downstair = (uint16_t )ps_malloc(800);

yellow_door = (uint16_t )ps_malloc(800); red_door = (uint16_t )ps_malloc(800); blue_door = (uint16_t *)ps_malloc(800);

yellow_key = (uint16_t )ps_malloc(800); red_key = (uint16_t )ps_malloc(800); blue_key = (uint16_t *)ps_malloc(800);

yellow_keyy = (uint16_t )ps_malloc(800); red_keyy = (uint16_t )ps_malloc(800); blue_keyy = (uint16_t *)ps_malloc(800);

attack = (uint16_t )ps_malloc(800); defend = (uint16_t )ps_malloc(800); life = (uint16_t )ps_malloc(800); gold = (uint16_t )ps_malloc(800);

//物品 red_crystal = (uint16_t )ps_malloc(800); blue_crystal = (uint16_t )ps_malloc(800); red_elixir = (uint16_t )ps_malloc(800); blue_elixir = (uint16_t )ps_malloc(800);

//人物 people_up = (uint16_t )ps_malloc(800); people_down = (uint16_t )ps_malloc(800); people_right = (uint16_t )ps_malloc(800); people_left = (uint16_t )ps_malloc(800); //2020 background = (uint16_t )ps_malloc(800); //1020 backgroundd = (uint16_t )ps_malloc(800);

//buffer = (uint16_t )heap_caps_malloc(80000, MALLOC_CAP_SPIRAM); //Serial.printf("@@@@@@ %d %f\n", sizeof(uint16_t), sizeof(byte)); //big_bat = (uint16_t )ps_malloc(400); logMemory();

// loadpsarm(SHOP_M, shop_m); //loadpsarm(SHOP_L,shop_l); //loadpsarm(SHOP_R,shop_r);

/ //@@@@@@@@@@ 敌人 //1 loadpsarm(gate_keeper_a,gate_keeper_c; //绿史莱姆 uint16_t green_slime; //红史莱姆 uint16_t red_slime; //蝙蝠 uint16_t bat; //法师 uint16_t priest; //骷髅队长 uint16_t skeleton_a; //骷髅士兵 uint16_t skeleton_b; //骷髅人 uint16_t skeleton_c; */ loadpsarm(SHOP_M, shop_m); loadpsarm(SHOP_L, shop_l); loadpsarm(SHOP_R, shop_r);

//1 loadpsarm(GATE_KEEPER_C, gate_keeper_c); loadpsarm(GREEN_SLIME, green_slime); loadpsarm(RED_SLIME, red_slime); loadpsarm(BAT, bat); loadpsarm(PRIEST, priest); loadpsarm(SKELETON_A, skeleton_a); loadpsarm(SKELETON_B, skeleton_b); loadpsarm(SKELETON_C, skeleton_c);

loadpsarm(ORBOFFLY, orbof_flying);

// loadpsarm(BIG_BAT, big_bat); loadpsarm(ROAD, road); loadpsarm(WALL, wall);

loadpsarm(YELLOWDOOR, yellow_door); loadpsarm(REDDOOR, red_door); loadpsarm(BLUEDOOR, blue_door);

loadpsarm(YELLOWKEY, yellow_key); loadpsarm(REDKEY, red_key); loadpsarm(BLUEKEY, blue_key);

loadpsarm(YELLOWKEYY, yellow_keyy); loadpsarm(REDKEYY, red_keyy); loadpsarm(BLUEKEYY, blue_keyy);

loadpsarm(ATTACK ,attack); loadpsarm( DEFEND ,defend); loadpsarm( LIFE ,life); loadpsarm( GOLD ,gold);

loadpsarm(REDCRYSTAL, red_crystal); loadpsarm(BLUECRYSTAL, blue_crystal); loadpsarm(REDELIXIR, red_elixir); loadpsarm(BLUEELIXIR, blue_elixir);

loadpsarm(PEOPLEUP, people_up); loadpsarm(PEOPLEDOWN, people_down); loadpsarm(PEOPLERIGHT, people_right); loadpsarm(PEOPLELEFT, people_left);

loadpsarm(BACKGROUND, background); loadpsarm(BACKGROUNDD, backgroundd);

loadpsarm(UPSTAIR, upstair);

//gfx->fillScreen(BLACK); unsigned long start = millis(); //gfx->fillScreen(RED); initfirstfloor(); information(); Serial.printf(" time used: %lu\n", millis() - start); / gfx->fillScreen(BLACK); for (int x = 0; x < 11; x += 20) { for (int y = 0; y < 1; y += 20) { display_picture(x, y, wall); } } //for (int i=0;i<30;i++) { // gfx->draw16bitRGBBitmap(30, i, buffer+(i30), 30, 1); // } Serial.printf(" time used: %lu\n", millis() - start); */ delay(100000000); }

void loadpsarm(char file, uint16_t buffer) { File bmpFile = SD_MMC.open(file, "r"); if (!bmpFile || bmpFile.isDirectory()) { Serial.println("ERROR: Failed to open file for reading"); } else { byte lo, hi; uint16_t tem; if (strcmp(BACKGROUNDD, file) == 0) { for (int y = 0; y < 20; y++) { bmpFile.seek(4 + (y 20)); //seek at start of line for (int x = 0; x < 10; x++) { lo = bmpFile.read(); hi = bmpFile.read(); tem = lo; tem = tem << 8; tem = tem | hi; //Serial.printf(" %d %d %x %x %x\n", y, x, lo, hi, tem); buffer[y 10 + x] = tem; } } } else { for (int y = 0; y < 20; y++) { bmpFile.seek(4 + (y 40)); //seek at start of line for (int x = 0; x < 20; x++) { lo = bmpFile.read(); hi = bmpFile.read(); tem = lo; tem = tem << 8; tem = tem | hi; //Serial.printf(" %d %d %x %x %x\n", y, x, lo, hi, tem); buffer[y 20 + x] = tem; } } } } bmpFile.close(); }

void drawmap(int floor) { for (int x = 1; x < 12; x++) { for (int y = 0; y < 13; y++) { int tem = mappp[floor][x][y]; switch (tem) { case 0: if (y == 0) { display_picture2((x - 1) 20, y 20, backgroundd); } else if (y == 12) { display_picture2((x - 1) 20, (y 20) - 10, backgroundd); } else { display_picture((x - 1) 20, (y 20) - 10, wall); } break; case 1: display_picture((x - 1) 20, (y 20) - 10, road); break; //暗墙 case 2: display_picture((x - 1) 20, (y 20) - 10, wall); break; //隐形墙 case 3: display_picture((x - 1) 20, (y 20) - 10, road); break; //岩浆 case 4: display_picture((x - 1) 20, (y 20) - 10, lava); break; //虚空 case 5: display_picture((x - 1) 20, (y 20) - 10, star); break; case 6: display_picture((x - 1) 20, (y 20) - 10, yellow_door); break; case 7: display_picture((x - 1) 20, (y 20) - 10, blue_door); break; case 8: display_picture((x - 1) 20, (y 20) - 10, red_door); break; case 9: display_picture((x - 1) 20, (y 20) - 10, iron_gate); break; case 10: display_picture((x - 1) 20, (y 20) - 10, steel_gate); break; case 11: display_picture((x - 1) 20, (y 20) - 10, upstair); break; case 12: display_picture((x - 1) 20, (y 20) - 10, downstair); break;

        case 16:
            display_picture((x - 1) * 20, (y * 20) - 10, people_up);
            break;
        case 17:
            display_picture((x - 1) * 20, (y * 20) - 10, people_down);
            break;
        case 18:
            display_picture((x - 1) * 20, (y * 20) - 10, people_left);
            break;
        case 19:
            display_picture((x - 1) * 20, (y * 20) - 10, people_right);
            break;

        case 21:
            display_picture((x - 1) * 20, (y * 20) - 10, yellow_key);
            break;
        case 22:
            display_picture((x - 1) * 20, (y * 20) - 10, blue_key);
        case 23:
            display_picture((x - 1) * 20, (y * 20) - 10, red_key);
            break;

        case 24:
            display_picture((x - 1) * 20, (y * 20) - 10, red_crystal);
            break;
        case 25:
            display_picture((x - 1) * 20, (y * 20) - 10, blue_crystal);
            break;
        case 26:
            display_picture((x - 1) * 20, (y * 20) - 10, red_elixir);
            break;
        case 27:
            display_picture((x - 1) * 20, (y * 20) - 10, blue_elixir);
            break;

        case 31:
            display_picture((x - 1) * 20, (y * 20) - 10, iron_sword);
            break;
        case 32:
            display_picture((x - 1) * 20, (y * 20) - 10, iron_shield);
            break;
        case 33:
            display_picture((x - 1) * 20, (y * 20) - 10, silver_sword);
            break;
        case 34:
            display_picture((x - 1) * 20, (y * 20) - 10, silver_shield);
            break;
        case 35:
            display_picture((x - 1) * 20, (y * 20) - 10, knight_sword);
            break;
        case 36:
            display_picture((x - 1) * 20, (y * 20) - 10, knight_shield);
            break;
        case 37:
            display_picture((x - 1) * 20, (y * 20) - 10, sacred_sword);
            break;
        case 38:
            display_picture((x - 1) * 20, (y * 20) - 10, sacred_shield);
            break;
        case 39:
            display_picture((x - 1) * 20, (y * 20) - 10, holy_sword);
            break;
        case 40:
            display_picture((x - 1) * 20, (y * 20) - 10, holy_shield);
            break;

        case 41:
            display_picture((x - 1) * 20, (y * 20) - 10, orbof_flying);
            break;
         //notebook
        case 42:
            display_picture((x - 1) * 20, (y * 20) - 10, orbof_flying);
            break;
        case 43:
            display_picture((x - 1) * 20, (y * 20) - 10, cross);
            break;
        case 44:
            display_picture((x - 1) * 20, (y * 20) - 10, mattock);
            break;
        case 45:
            display_picture((x - 1) * 20, (y * 20) - 10, bomb);
            break;
        case 46:
            display_picture((x - 1) * 20, (y * 20) - 10, warp_staff);
            break;
        case 47:
            display_picture((x - 1) * 20, (y * 20) - 10, lucky_gold);
            break;
        case 48:
            display_picture((x - 1) * 20, (y * 20) - 10, snow_crystal);
            break;
        case 49:
            display_picture((x - 1) * 20, (y * 20) - 10, wings_to_flydown);
            break;
        case 50:
            display_picture((x - 1) * 20, (y * 20) - 10, wings_to_flyup);
            break;
        case 51:
            display_picture((x - 1) * 20, (y * 20) - 10, magic_key);
            break;
        case 52:
            display_picture((x - 1) * 20, (y * 20) - 10, dragon_slayer);
            break;

        case 92:
        case 93:
        case 94:
        case 95:
        case 96:
        case 97:
        case 98:
        case 99:
        case 100:
            display_picture((x - 1) * 20, (y * 20) - 10, thief);
            break;

        case 101:
        case 102:
        case 103:
        case 104:
        case 105:
        case 106:
        case 107:
        case 108:
        case 109:
        case 110:
        case 111:
        case 112:
        case 113:
        case 114:
        case 115:
        case 116:
        case 117:
        case 118:
        case 119:
        case 120:
            display_picture((x - 1) * 20, (y * 20) - 10, oldman);
            break;

        case 131:
        case 132:
        case 133:
        case 134:
        case 135:
        case 136:
        case 137:
        case 138:
        case 139:
        case 140:
        case 141:
        case 142:
            display_picture((x - 1) * 20, (y * 20) - 10, merchant);
            break;

        case 160:
            display_picture((x - 1) * 20, (y * 20) - 10, shop_l);
            break;
        case 161:
            display_picture((x - 1) * 20, (y * 20) - 10, shop_m);
            break;
        case 162:
            display_picture((x - 1) * 20, (y * 20) - 10, shop_r);
            break;
        case 163:
        case 164:
            display_picture((x - 1) * 20, (y * 20) - 10, princess);
            break;

        case 251:
            display_picture((x - 1) * 20, (y * 20) - 10, green_slime);
            break;
        case 252:
            display_picture((x - 1) * 20, (y * 20) - 10, red_slime);
            break;
        case 253:
            display_picture((x - 1) * 20, (y * 20) - 10, bat);
            break;
        case 254:
            display_picture((x - 1) * 20, (y * 20) - 10, priest);
            break;
        case 255:
            display_picture((x - 1) * 20, (y * 20) - 10, skeleton_c);
            break;
        case 256:
            display_picture((x - 1) * 20, (y * 20) - 10, skeleton_b);
            break;
        case 257:
            display_picture((x - 1) * 20, (y * 20) - 10, gate_keeper_c);
            break;
        case 258:
            display_picture((x - 1) * 20, (y * 20) - 10, skeleton_a);
            break;
        case 259:
            display_picture((x - 1) * 20, (y * 20) - 10, big_slime);
            break;
        case 260:
            display_picture((x - 1) * 20, (y * 20) - 10, big_bat);
            break;
        case 261:
            display_picture((x - 1) * 20, (y * 20) - 10, super_priest);
            break;
        case 262:
            display_picture((x - 1) * 20, (y * 20) - 10, zombine);
            break;
        case 263:
            display_picture((x - 1) * 20, (y * 20) - 10, zombine_knight);
            break;
        case 264:
            display_picture((x - 1) * 20, (y * 20) - 10, rock);
            break;
        case 265:
            display_picture((x - 1) * 20, (y * 20) - 10, vampire);
            break;
        case 266:
            display_picture((x - 1) * 20, (y * 20) - 10, ghost_solider);
            break;
        case 267:
            display_picture((x - 1) * 20, (y * 20) - 10, solider);
            break;
        case 268:
            display_picture((x - 1) * 20, (y * 20) - 10, slime_man);
            break;
        case 269:
            display_picture((x - 1) * 20, (y * 20) - 10, gate_keeper_b);
            break;
        case 270:
            display_picture((x - 1) * 20, (y * 20) - 10, swords_man);
            break;
        case 271:
            display_picture((x - 1) * 20, (y * 20) - 10, knight);
            break;
        case 272:
            display_picture((x - 1) * 20, (y * 20) - 10, gold_knight);
            break;
        case 282:
            display_picture((x - 1) * 20, (y * 20) - 10, great_magic_master);
            break;
        case 280:
        case 281:
        case 283:
            display_picture((x - 1) * 20, (y * 20) - 10, boss);
            break;
        case 284:
            display_picture((x - 1) * 20, (y * 20) - 10, octopus_wn);
            break;
        case 285:
            display_picture((x - 1) * 20, (y * 20) - 10, octopus_n);
            break;
        case 286:
            display_picture((x - 1) * 20, (y * 20) - 10, octopus_en);
            break;
        case 287:
            display_picture((x - 1) * 20, (y * 20) - 10, octopus_w);
            break;
        case 288:
            display_picture((x - 1) * 20, (y * 20) - 10, octopus_m);
            break;
        case 289:
            display_picture((x - 1) * 20, (y * 20) - 10, octopus_e);
            break;
        case 290:
            display_picture((x - 1) * 20, (y * 20) - 10, octopus_ws);
            break;
        case 291:
            display_picture((x - 1) * 20, (y * 20) - 10, octopus_s);
            break;
        case 292:
            display_picture((x - 1) * 20, (y * 20) - 10, octopus_es);
            break;
        case 293:
            display_picture((x - 1) * 20, (y * 20) - 10, dragon_wn);
            break;//魔龙左上
        case 294:
            display_picture((x - 1) * 20, (y * 20) - 10, dragon_n);
            break;//中上
        case 295:
            display_picture((x - 1) * 20, (y * 20) - 10,dragon_en);
            break;//右上
        case 296:
            display_picture((x - 1) * 20, (y * 20) - 10, dragon_w);
            break;
        case 297:
            display_picture((x - 1) * 20, (y * 20) - 10, dragon_m);
            break;
        case 298:
            display_picture((x - 1) * 20, (y * 20) - 10, dragon_e);
            break;
        case 299:
            display_picture((x - 1) * 20, (y * 20) - 10, dragon_ws);
            break;
        case 300:
            display_picture((x - 1) * 20, (y * 20) - 10, dragon_s);
            break;
        case 301:
            display_picture((x - 1) * 20, (y * 20) - 10, dragon_es);
            break;
        case 302:
            display_picture((x - 1) * 20, (y * 20) - 10, magician_b);
            break;
        case 303:
            display_picture((x - 1) * 20, (y * 20) - 10, magician_a);
            break;//高级巫师
        case 304:
            display_picture((x - 1) * 20, (y * 20) - 10, slime_lord);
            break;
        case 305:
            display_picture((x - 1) * 20, (y * 20) - 10, vampire_bat);
            break;//吸血蝙蝠
        case 306:
            display_picture((x - 1) * 20, (y * 20) - 10, dark_knight);
            break;//黑暗骑士
        case 307:
            display_picture((x - 1) * 20, (y * 20) - 10, magic_sergeant);
            break;//魔法警卫
        case 308:
            display_picture((x - 1) * 20, (y * 20) - 10, gate_keeper_a);
            break;//高级卫兵
        }
    }
}

}

void initfirstfloor() {

for (int x = 1; x < 12; x++) { for (int y = 0; y < 13; y++) { int tem = mappp[1][x][y]; switch (tem) { case 0: if (y == 0) { display_picture2((x - 1) 20, y 20, backgroundd); } else if (y == 12) { display_picture2((x - 1) 20, (y 20) - 10, backgroundd); } else { display_picture((x - 1) 20, (y 20) - 10, wall); } break; case 1: display_picture((x - 1) 20, (y 20) - 10, road); break; case 6: display_picture((x - 1) 20, (y 20) - 10, yellow_door); break; case 8: display_picture((x - 1) 20, (y 20) - 10, red_door); break; case 11: display_picture((x - 1) 20, (y 20) - 10, upstair); break; case 17: display_picture((x - 1) 20, (y 20) - 10, people_down); break; case 21: display_picture((x - 1) 20, (y 20) - 10, yellow_key); break; case 22: display_picture((x - 1) 20, (y 20) - 10, blue_key); case 23: display_picture((x - 1) 20, (y 20) - 10, red_key); break; case 24: display_picture((x - 1) 20, (y 20) - 10, red_crystal); break; case 25: display_picture((x - 1) 20, (y 20) - 10, blue_crystal); break; case 26: display_picture((x - 1) 20, (y 20) - 10, red_elixir); break; case 27: display_picture((x - 1) 20, (y 20) - 10, blue_elixir); break; case 41: display_picture((x - 1) 20, (y 20) - 10, orbof_flying); break; case 251: display_picture((x - 1) 20, (y 20) - 10, green_slime); break; case 252: display_picture((x - 1) 20, (y 20) - 10, red_slime); break; case 253: display_picture((x - 1) 20, (y 20) - 10, bat); break; case 254: display_picture((x - 1) 20, (y 20) - 10, priest); break; case 255: display_picture((x - 1) 20, (y 20) - 10, skeleton_c); break; case 256: display_picture((x - 1) 20, (y 20) - 10, skeleton_b); break; } } } }

void information() {

for (int x = 0; x < 240; x += 20) { display_picture(220, x, background);
} for (int x = 0; x < 130; x += 20) { display_picture(280, x, background); } display_picture(240, 0, life); display_picture(240, 70, gold); display_picture(260, 0, attack); display_picture(260, 70, defend);

display_picture(240, 135, yellow_keyy); display_picture(260, 135, blue_keyy); display_picture(280, 135, red_keyy);

displaymota(); displayzhuangbei(); }

void displaymota() { gfx->setFont(u8g2_font_unifont_t_chinese); gfx->setTextColor(WHITE); gfx->setCursor(188, 265); gfx->println("魔 塔"); gfx->setCursor(183, 290); gfx->println("第 层"); //displayfloor(); gfx->setFont(f); }

void displayzhuangbei() { gfx->setFont(u8g2_font_unifont_t_chinese); gfx->setTextColor(WHITE); gfx->setCursor(0, 315); gfx->println("装备"); gfx->setFont(f); }