Pet

· · 休闲·娱乐

use Dev-c++ windows application to create a file called "pet.dev" to run this:

compile with -std=c++11 -DUNICODE -D_UNICODE

linker: -lwinmm -lmsimg32

The mean of "state" in the program:

static fall comfort grab jump sleep

main.cpp:

#include<windows.h>
#include<windowsx.h>
#include<wingdi.h>
#include<mmsystem.h>
#include<fstream>
#include<cmath>
#include<algorithm>
#include<random>
#include<chrono>
#include<vector>
#define TRANSPARENT_COLOR RGB(0,255,0)
#define Timer_Update 1
RECT WorkArea;
int state[10]={};
int SCX,SCY,BX=90,BY=71,EX=34,EY=13,HX=20,HY=20,HR=20,PX=40,PY=40,FX=30,FY=30,JT=80,JMA=300,TT=10,WT=50,SatyT=2000,EnerT=4500,EnerT_=3000,SaveT=1000;
double offsetEX,offsetEY,offsetLHX,offsetLHY,offsetRHX,offsetRHY;
POINT pos,mouse,mouse_;
HBITMAP back_ground=NULL,body=NULL,eyes=NULL,eyes_normol=NULL,eyes_comfort=NULL,eyes_fall=NULL,eyes_joy=NULL,eyes_sleep=NULL,eyes_surprise=NULL,eyes_hunger=NULL,hand=NULL,lhand=NULL,rhand=NULL,feedb=NULL,sleepb=NULL,food=NULL,food_=NULL;
std::vector<POINT>foods,foods_;int AvailIDX=-1;
bool PRESSED=false,PANEL=false,FEED=false,JumpStart=false;int WINK=0;int EndX,SuspendY;
int seed=std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();std::mt19937 rng(seed);
int satiety,energy;double Aj,Bj,Cj;int Sj;std::vector<int>FFallTimer;int FallTimer=0,SatietyTimer=0,EnergyTimer=0,EnergyTimer_=0,EatTimer=0,SaveTimer=0;bool hello=true;
static wchar_t savePath[MAX_PATH];static bool hasSavePath=false,first=true;
void HideFromTaskbar(HWND hwnd){
    LONG exStyle=GetWindowLongPtr(hwnd,GWL_EXSTYLE);
    SetWindowLongPtr(hwnd,GWL_EXSTYLE,(exStyle|WS_EX_TOOLWINDOW)&~WS_EX_APPWINDOW);
}
bool FileExists(const char* name){
    std::ifstream file(name);
    return !file.fail();
}
bool IsClickOnNonTransparent(HWND hwnd,int clickX,int clickY,HBITMAP hBmp,int btnX,int btnY,COLORREF transparentColor){
    if(clickX<btnX||clickX>btnX+PX||clickY<btnY||clickY>btnY+PX)return false;
    int localX=clickX-btnX;
    int localY=clickY-btnY;
    HDC hdc=GetDC(hwnd);
    HDC bmpDC=CreateCompatibleDC(hdc);
    HBITMAP oldBmp=(HBITMAP)SelectObject(bmpDC,hBmp);
    COLORREF pixelColor=GetPixel(bmpDC,localX,localY);
    SelectObject(bmpDC,oldBmp);
    DeleteDC(bmpDC);
    ReleaseDC(hwnd,hdc);
    return pixelColor!=transparentColor;
}
void LoadPetSave(HWND hwnd){
    if(!hasSavePath)return;
    pos.x=GetPrivateProfileIntW(L"Pet",L"PosX",pos.x,savePath);
    pos.y=GetPrivateProfileIntW(L"Pet",L"PosY",pos.y,savePath);
    satiety=GetPrivateProfileIntW(L"Pet",L"Satiety",satiety,savePath);
    energy=GetPrivateProfileIntW(L"Pet",L"Energy",energy,savePath);
    if(satiety<0)satiety=0;
    if(satiety>50)satiety=50;
    if(energy<0)energy=0;
    if(energy>50)energy=50;
    PANEL=GetPrivateProfileIntW(L"Pet",L"Panel",PANEL?1:0,savePath)!=0;
}
void SavePetSave(){
    if(!hasSavePath)return;
    wchar_t buf[32];
    swprintf(buf,32,L"%d",pos.x);
    WritePrivateProfileStringW(L"Pet",L"PosX",buf,savePath);
    swprintf(buf,32,L"%d",pos.y);
    WritePrivateProfileStringW(L"Pet",L"PosY",buf,savePath);
    swprintf(buf,32,L"%d",satiety);
    WritePrivateProfileStringW(L"Pet",L"Satiety",buf,savePath);
    swprintf(buf,32,L"%d",energy);
    WritePrivateProfileStringW(L"Pet",L"Energy",buf,savePath);
    swprintf(buf,32,L"%d",PANEL?1:0);
    WritePrivateProfileStringW(L"Pet",L"Panel",buf,savePath);
}
LRESULT CALLBACK WindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam){
    switch(uMsg){
        case WM_CREATE:{
            SCX=WorkArea.right-WorkArea.left,SCY=WorkArea.bottom-WorkArea.top;
            static std::uniform_int_distribution<int>disB(0,SCX-BX);
            pos.x=disB(rng),pos.y=-BY-500;
            SetTimer(hwnd,Timer_Update,TT,NULL);
            back_ground=(HBITMAP)LoadImage(NULL,L"image\\BackGround.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            body=(HBITMAP)LoadImage(NULL,L"image\\Body.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            eyes_normol=(HBITMAP)LoadImage(NULL,L"image\\Eyes_normol.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            eyes_comfort=(HBITMAP)LoadImage(NULL,L"image\\Eyes_comfort.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            eyes_fall=(HBITMAP)LoadImage(NULL,L"image\\Eyes_fall.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            eyes_joy=(HBITMAP)LoadImage(NULL,L"image\\Eyes_joy.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            eyes_sleep=(HBITMAP)LoadImage(NULL,L"image\\Eyes_sleep.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            eyes_surprise=(HBITMAP)LoadImage(NULL,L"image\\Eyes_surprise.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            eyes_hunger=(HBITMAP)LoadImage(NULL,L"image\\Eyes_hunger.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            eyes=eyes_normol;
            hand=(HBITMAP)LoadImage(NULL,L"image\\Hand.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            lhand=rhand=hand;
            feedb=(HBITMAP)LoadImage(NULL,L"image\\FeedButton.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            sleepb=(HBITMAP)LoadImage(NULL,L"image\\SleepButton.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            food=(HBITMAP)LoadImage(NULL,L"image\\Food.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            food_=(HBITMAP)LoadImage(NULL,L"image\\Food_.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            SetLayeredWindowAttributes(hwnd,TRANSPARENT_COLOR,0,LWA_COLORKEY);
            return 0;
        }case WM_SYSCOMMAND:{
            if(wParam==SC_CLOSE)MessageBox(hwnd,L"Why do you do that!!!\nDo not KILL me!!!!!",L"From Pet",MB_ICONINFORMATION);
            return 0;
        }case WM_KEYDOWN:{
            if(wParam==VK_F4&&(GetAsyncKeyState(VK_MENU)&0x8000))MessageBox(hwnd,L"Why do you do that!!!\nDo not KILL me!!!!!",L"From Pet",MB_ICONINFORMATION);
            return 0;
        }case WM_LBUTTONDOWN:{
            PRESSED=true;
            POINT clickPt={GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam)};
            if(PANEL){
                if(IsClickOnNonTransparent(hwnd,clickPt.x,clickPt.y,feedb,pos.x,pos.y-PY,TRANSPARENT_COLOR)){
                    FEED=true;
                    InvalidateRect(hwnd,NULL,FALSE);
                    return 0;
                }else if(IsClickOnNonTransparent(hwnd,clickPt.x,clickPt.y,sleepb,pos.x+BX-PX,pos.y-PY,TRANSPARENT_COLOR)&&satiety>10){
                    if(energy<=40)state[5]=!state[5];
                    InvalidateRect(hwnd,NULL,FALSE);
                    return 0;
                }else PANEL=false;
            }return 0;
        }case WM_LBUTTONUP:{
            PRESSED=false;
            return 0;
        }case WM_RBUTTONDOWN:{
            if(!PRESSED)PANEL=!PANEL;
            return 0;
        }case WM_TIMER:{
            if(wParam==Timer_Update){
                GetCursorPos(&mouse);ScreenToClient(hwnd,&mouse);
                SaveTimer++;if(SaveTimer==SaveT/TT){SavePetSave();SaveTimer=0;}
                if(!state[5])SatietyTimer++;if(SatietyTimer==SatyT/TT)satiety--,SatietyTimer=0;
                if(!state[5])EnergyTimer++;if(EnergyTimer==EnerT/TT)energy--,EnergyTimer=0;
                if(WINK)WINK++;if(WINK==WT/TT)WINK=0;
                static std::uniform_int_distribution<int>disW(0,99);
                if(!disW(rng)&&state[0]&&!WINK)eyes=eyes_sleep,WINK++;
                if(state[0]&&hello){
                    hello=false;
                    if(first)MessageBox(hwnd,L"Hello!\nNice to meet you!",L"From Pet",MB_ICONINFORMATION);
                    else MessageBox(hwnd,L"Hello!\nI am back!",L"From Pet",MB_ICONINFORMATION);
                }static std::uniform_int_distribution<int>disJ(0,159);
                if((state[5]||energy<=10)&&satiety>10&&energy<=50&&!state[3]&&!state[4]){
                    state[1]=0,state[2]=0,state[5]=1;
                    eyes=eyes_sleep;
                    double targetOEX=(BX-EX)/2;
                    double targetOEY=BY-25;
                    offsetEX=(int)(offsetEX*0.8+targetOEX*0.2);
                    offsetEY=(int)(offsetEY*0.8+targetOEY*0.2);
                    EnergyTimer_++;
                    if(EnergyTimer_==EnerT_/TT){
                        EnergyTimer_=0;
                        energy++;
                    }static std::uniform_int_distribution<int>disG(0,59);
                    if(energy>30&&!disG(rng))state[5]=0;
                }else state[5]=0,EnergyTimer_=0;
                if(!disJ(rng)&&state[0]&&!state[1]&&!state[2]&&!state[3]&&!state[4]&&!state[5]&&satiety>10&&!PANEL){
                    eyes=eyes_joy;state[0]=0;
                    std::uniform_int_distribution<int>disJPX(std::max((int)(pos.x-JMA),0),std::min((int)(pos.x+JMA),SCX-BX*2));
                    static std::uniform_int_distribution<int>disJPY(BY,SCY-BY);
                    while(true){
                        EndX=disJPX(rng);SuspendY=disJPY(rng);
                        if(EndX>=pos.x)EndX+=BX;Sj=EndX-pos.x;
                        Aj=4.0*(pos.y-SuspendY)/((pos.x-EndX)*(pos.x-EndX));
                        Bj=-(4.0*(pos.y-SuspendY)*(pos.x+EndX)/((pos.x-EndX)*(pos.x-EndX)));
                        Cj=(pos.y-SuspendY)*(pos.x+EndX)*(pos.x+EndX)/((pos.x-EndX)*(pos.x-EndX))+SuspendY;
                        double vx=-Bj/(2.0*Aj);
                        double vy=Aj*vx*vx+Bj*vx+Cj;
                        if(vy<0||vy>pos.y)continue;
                        int step=std::max((int)std::abs(Sj/JT),1);
                        int firstX=pos.x+(EndX>pos.x?step:-step);
                        double firstY=Aj*firstX*firstX+Bj*firstX+Cj;
                        if(firstY<0||firstY>SCY-BY)continue;
                        break;
                    }state[4]=1,JumpStart=false;
                }if(state[4]){
                    if(pos.y>=SCY-BY&&JumpStart||pos.x<0||pos.x+BX>SCX){
                        pos.y=SCY-BY;
                        if(pos.x<0)pos.x=0;
                        if(pos.x+BX>SCX)pos.x=SCX-BX;
                        state[4]=0;
                    }else{
                        JumpStart=true;
                        int dist=std::abs(EndX-pos.x);
                        if(dist<=1){
                            pos.x=EndX;
                            pos.y=SCY-BY;
                            state[4]=0;
                        }else{
                            int AddJ=std::max(std::min((int)std::abs(Sj/JT),dist),1)*(EndX>pos.x?1:-1);
                            pos.x+=AddJ;
                            int newY=(int)(Aj*pos.x*pos.x+Bj*pos.x+Cj);
                            if(newY<0)newY=0;
                            if(newY>SCY-BY)newY=SCY-BY;
                            pos.y=newY;
                        }
                    }double relEX=(double)(EndX-pos.x+BX/2)/BX;
                    double relEY=(double)(SCY-pos.y)/BY;
                    if(relEX<0.0)relEX=0.0;else if(relEX>1.0)relEX=1.0;
                    if(relEY<0.0)relEY=0.0;else if(relEY>1.0)relEY=1.0;
                    double targetOEX=15+relEX*(BX-EX-30);
                    double targetOEY=5+relEY*(BY-EY-10);
                    offsetEX=(int)(offsetEX*0.8+targetOEX*0.2);
                    offsetEY=(int)(offsetEY*0.8+targetOEY*0.2);
                    if(offsetEX<15)offsetEX=15;
                    if(offsetEX>BX-EX-15)offsetEX=BX-EX-15;
                    if(offsetEY<5)offsetEY=5;
                    if(offsetEY>BY-EY-10)offsetEY=BY-EY-10;
                }if(FEED){
                    FEED=false;
                    static std::uniform_int_distribution<int>disF(0,SCX-FX);
                    foods.push_back({disF(rng),-FY});
                    FFallTimer.push_back(0);
                }for(int Fi=0;Fi<foods.size();Fi++){
                    if(foods[Fi].y<SCY-FY&&(Fi!=AvailIDX||satiety<=45)){
                        FFallTimer[Fi]++;
                        foods[Fi].y+=std::min(FFallTimer[Fi]*10,(int)(SCY-FY-foods[Fi].y));
                    }
                }if(state[3]&&!state[5]){
                    if(pos.x+mouse.x-mouse_.x>=0&&pos.x+mouse.x-mouse_.x+BX<=SCX)pos.x+=mouse.x-mouse_.x;
                    if(pos.y+mouse.y-mouse_.y>=0&&pos.y+mouse.y-mouse_.y+BY<=SCY)pos.y+=mouse.y-mouse_.y;
                }if(state[4])state[0]=0,state[1]=0;
                else if(pos.y<SCY-BY)state[0]=0,state[1]=1;
                else state[0]=1,state[1]=0;
                if(!state[4]){
                    if(state[1]&&!state[3]){
                        eyes=eyes_fall;FallTimer++;
                        pos.y+=std::min(FallTimer*10,(int)(SCY-BY-pos.y));
                        double targetOEX=(BX-EX)/2,targetOEY=BY-25;
                        if(abs(offsetEX-targetOEX)<3)offsetEX=targetOEX;else offsetEX=(int)(offsetEX*0.8+targetOEX*0.2);
                        if(abs(offsetEY-targetOEY)<3)offsetEY=targetOEY;else offsetEY=(int)(offsetEY*0.8+targetOEY*0.2);
                    }else{if(!WINK&&!state[5])eyes=eyes_normol;FallTimer=0;}
                }if(mouse.x>=pos.x-HR&&mouse.x<=pos.x+BX+HR&&mouse.y>=pos.y-HR&&mouse.y<=pos.y+BY&&satiety>10&&!state[5]){
                    double targetOLHX=mouse.x-pos.x-HX,targetOLHY=mouse.y-pos.y-HY/2;
                    double targetORHX=mouse.x-pos.x,targetORHY=mouse.y-pos.y-HY/2;
                    if(abs(offsetLHX-targetOLHX)<3)offsetLHX=targetOLHX;else offsetLHX=(int)(offsetLHX*0.6+targetOLHX*0.4);
                    if(abs(offsetLHY-targetOLHY)<3)offsetLHY=targetOLHY;else offsetLHY=(int)(offsetLHY*0.6+targetOLHY*0.4);
                    if(abs(offsetRHX-targetORHX)<3)offsetRHX=targetORHX;else offsetRHX=(int)(offsetRHX*0.6+targetORHX*0.4);
                    if(abs(offsetRHY-targetORHY)<3)offsetRHY=targetORHY;else offsetRHY=(int)(offsetRHY*0.6+targetORHY*0.4);
                }else{
                    PRESSED=false;
                    double targetOLHX=0,targetOLHY=BY-HY;
                    double targetORHX=BX-HX,targetORHY=BY-HY;
                    if(abs(offsetLHX-targetOLHX)<3)offsetLHX=targetOLHX;else offsetLHX=(int)(offsetLHX*0.4+targetOLHX*0.6);
                    if(abs(offsetLHY-targetOLHY)<3)offsetLHY=targetOLHY;else offsetLHY=(int)(offsetLHY*0.4+targetOLHY*0.6);
                    if(abs(offsetRHX-targetORHX)<3)offsetRHX=targetORHX;else offsetRHX=(int)(offsetRHX*0.4+targetORHX*0.6);
                    if(abs(offsetRHY-targetORHY)<3)offsetRHY=targetORHY;else offsetRHY=(int)(offsetRHY*0.4+targetORHY*0.6);
                }if(mouse.x<pos.x-HR||mouse.x>pos.x+BX+HR||mouse.y<pos.y-PY||mouse.y>pos.y+BY)PANEL=false;
                if(state[0]&&!state[5]&&satiety>10){
                    if(mouse.x>pos.x&&mouse.x<pos.x+BX&&mouse.y>pos.y&&mouse.y<pos.y+BY){
                        state[2]=1;
                        if(!WINK)eyes=eyes_comfort;
                    }else{
                        state[2]=0;
                        if(!WINK)eyes=eyes_normol;
                    }double relEX=(double)(mouse.x-pos.x)/BX;
                    double relEY=(double)(mouse.y-pos.y)/BY;
                    if(relEX<0.0)relEX=0.0;else if(relEX>1.0)relEX=1.0;
                    if(relEY<0.0)relEY=0.0;else if(relEY>1.0)relEY=1.0;
                    double targetOEX=15+relEX*(BX-EX-30);
                    double targetOEY=5+relEY*(BY-EY-10);
                    offsetEX=(int)(offsetEX*0.8+targetOEX*0.2);
                    offsetEY=(int)(offsetEY*0.8+targetOEY*0.2);
                    if(offsetEX<15)offsetEX=15;
                    if(offsetEX>BX-EX-15)offsetEX=BX-EX-15;
                    if(offsetEY<5)offsetEY=5;
                    if(offsetEY>BY-EY-10)offsetEY=BY-EY-10;
                }if(offsetLHX==mouse.x-pos.x-HX&&offsetLHY==mouse.y-pos.y-HY/2&&offsetRHX==mouse.x-pos.x&&offsetRHY==mouse.y-pos.y-HY/2&&!state[5]&&PRESSED){state[1]=0,state[3]=1,state[4]=0;}
                else{state[3]=0;}
                static std::uniform_int_distribution<int>disE(0,299);
                if(satiety<=10||!disE(rng)&&satiety<=45){
                    if(foods.size()>0){
                        if(satiety<=10)eyes=eyes_surprise;else if(!PANEL)eyes=eyes_joy;
                        int MinIDX=-1,MinDIS=SCX+BX;
                        for(int Fi=0;Fi<foods.size();Fi++)if(abs((foods[Fi].x+FX/2)-(pos.x+BX/2))<=MinDIS&&foods[Fi].y==SCY-FY)MinDIS=abs((foods[Fi].x+FX/2)-(pos.x+BX/2)),MinIDX=Fi;
                        if(state[0]&&MinIDX!=-1){
                            if(MinDIS<=HR+BX/2){
                                AvailIDX=MinIDX;
                                foods[MinIDX].y=SCY-HY-FY/2;
                                double targetOLHX=pos.x-(foods[MinIDX].x-HX),targetOLHY=BY-HY;
                                double targetORHX=pos.x-(foods[MinIDX].x+HX+FX),targetORHY=BY-HY;
                                if(abs(offsetLHX-targetOLHX)<3)offsetLHX=targetOLHX;else offsetLHX=(int)(offsetLHX*0.9+targetOLHX*0.1);
                                if(abs(offsetLHY-targetOLHY)<3)offsetLHY=targetOLHY;else offsetLHY=(int)(offsetLHY*0.9+targetOLHY*0.1);
                                if(abs(offsetRHX-targetORHX)<3)offsetRHX=targetORHX;else offsetRHX=(int)(offsetRHX*0.9+targetORHX*0.1);
                                if(abs(offsetRHY-targetORHY)<3)offsetRHY=targetORHY;else offsetRHY=(int)(offsetRHY*0.9+targetORHY*0.1);
                                foods[MinIDX].x=pos.x-(offsetLHX-HX);
                            }else if(!state[1]&&!state[3]&&!state[4]&&!state[5]&&!PANEL){
                                state[0]=0;
                                static std::uniform_int_distribution<int>disJPY(BY,SCY-BY);
                                while(true){
                                    EndX=std::min(SCX-BX,std::max(0,(int)(foods[MinIDX].x)));SuspendY=disJPY(rng);Sj=EndX-pos.x;
                                    if(Sj==0)continue;
                                    Aj=4.0*(pos.y-SuspendY)/((pos.x-EndX)*(pos.x-EndX));
                                    Bj=-(4.0*(pos.y-SuspendY)*(pos.x+EndX)/((pos.x-EndX)*(pos.x-EndX)));
                                    Cj=(pos.y-SuspendY)*(pos.x+EndX)*(pos.x+EndX)/((pos.x-EndX)*(pos.x-EndX))+SuspendY;
                                    double vx=-Bj/(2.0*Aj);
                                    double vy=Aj*vx*vx+Bj*vx+Cj;
                                    if(vy<0||vy>pos.y)continue;
                                    int step=std::max((int)std::abs(Sj/JT),1);
                                    int firstX=pos.x+(EndX>pos.x?step:-step);
                                    double firstY=Aj*firstX*firstX+Bj*firstX+Cj;
                                    if(firstY<0||firstY>SCY-BY)continue;
                                    break;
                                }state[4]=1,JumpStart=false;
                            }
                        }
                    }else if(satiety<=10)eyes=eyes_hunger;
                }if(state[0]&&!state[5]&&satiety<=45){
                    if(AvailIDX!=-1)EatTimer++;
                    if(EatTimer==10){
                        EatTimer=0;
                        foods_.push_back({foods[AvailIDX].x,800});
                        foods.erase(foods.begin()+AvailIDX);
                        FFallTimer.erase(FFallTimer.begin()+AvailIDX);
                        satiety+=5;AvailIDX=-1;
                    }
                }for(int Fi=0;Fi<foods_.size();Fi++)foods_[Fi].y--;
                foods_.erase(std::remove_if(foods_.begin(),foods_.end(),[](const POINT& f){return f.y<=0;}),foods_.end());
                if(satiety>=50)satiety=50;if(energy>=50)energy=50;
                if(satiety<=0&&satiety%5==0&&SatietyTimer==0&&foods.size()==0)MessageBox(hwnd,L"I am so hungry...\ngive me some food...",L"From Pet",MB_ICONINFORMATION);
                mouse_=mouse;
                InvalidateRect(hwnd,NULL,FALSE);
            }return 0;
        }case WM_ERASEBKGND:{
            return TRUE;
        }case WM_NCHITTEST:{
            LRESULT hit=DefWindowProc(hwnd,uMsg,wParam,lParam);
            if(hit==HTCLIENT){
                POINT pt={GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam)};
                HDC hdc=GetDC(hwnd);
                COLORREF pixelColor=GetPixel(hdc,pt.x,pt.y);
                ReleaseDC(hwnd,hdc);
                if(pixelColor==TRANSPARENT_COLOR){
                    return HTTRANSPARENT;
                }
            }return hit;
        }case WM_PAINT:{
            PAINTSTRUCT ps;
            HDC hdc=BeginPaint(hwnd,&ps);
            RECT rc;
            GetClientRect(hwnd,&rc);
            int width=rc.right-rc.left,height=rc.bottom-rc.top;
            HDC memDC=CreateCompatibleDC(hdc);
            HBITMAP memBitmap=CreateCompatibleBitmap(hdc,width,height);
            HBITMAP oldBmp=(HBITMAP)SelectObject(memDC,memBitmap);
            if(back_ground){
                HDC back_groundDC=CreateCompatibleDC(hdc);
                HBITMAP back_ground_oldBmp=(HBITMAP)SelectObject(back_groundDC,back_ground);
                BITMAP bmp;
                GetObject(back_ground,sizeof(BITMAP),&bmp);
                StretchBlt(memDC,0,0,SCX,SCY,back_groundDC,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
                SelectObject(back_groundDC,back_ground_oldBmp);
                DeleteDC(back_groundDC);
            }if(body){
                HDC bodyDC=CreateCompatibleDC(hdc);
                HBITMAP body_oldBmp=(HBITMAP)SelectObject(bodyDC,body);
                BITMAP bmp;
                GetObject(body,sizeof(BITMAP),&bmp);
                TransparentBlt(memDC,pos.x,pos.y,bmp.bmWidth,bmp.bmHeight,bodyDC,0,0,bmp.bmWidth,bmp.bmHeight,TRANSPARENT_COLOR);
                SelectObject(bodyDC,body_oldBmp);
                DeleteDC(bodyDC);
            }if(eyes){
                HDC eyesDC=CreateCompatibleDC(hdc);
                HBITMAP eyes_oldBmp=(HBITMAP)SelectObject(eyesDC,eyes);
                BITMAP bmp;
                GetObject(eyes,sizeof(BITMAP),&bmp);
                TransparentBlt(memDC,pos.x+offsetEX,pos.y+offsetEY,bmp.bmWidth,bmp.bmHeight,eyesDC,0,0,bmp.bmWidth,bmp.bmHeight,TRANSPARENT_COLOR);
                SelectObject(eyesDC,eyes_oldBmp);
                DeleteDC(eyesDC);
            }if(lhand){
                HDC lhandDC=CreateCompatibleDC(hdc);
                HBITMAP lhand_oldBmp=(HBITMAP)SelectObject(lhandDC,lhand);
                BITMAP bmp;
                GetObject(lhand,sizeof(BITMAP),&bmp);
                TransparentBlt(memDC,pos.x+offsetLHX,pos.y+offsetLHY,bmp.bmWidth,bmp.bmHeight,lhandDC,0,0,bmp.bmWidth,bmp.bmHeight,TRANSPARENT_COLOR);
                SelectObject(lhandDC,lhand_oldBmp);
                DeleteDC(lhandDC);
            }if(rhand){
                HDC rhandDC=CreateCompatibleDC(hdc);
                HBITMAP rhand_oldBmp=(HBITMAP)SelectObject(rhandDC,rhand);
                BITMAP bmp;
                GetObject(rhand,sizeof(BITMAP),&bmp);
                TransparentBlt(memDC,pos.x+offsetRHX,pos.y+offsetRHY,bmp.bmWidth,bmp.bmHeight,rhandDC,0,0,bmp.bmWidth,bmp.bmHeight,TRANSPARENT_COLOR);
                SelectObject(rhandDC,rhand_oldBmp);
                DeleteDC(rhandDC);
            }if(feedb&&PANEL){
                HDC feedbDC=CreateCompatibleDC(hdc);
                HBITMAP feedb_oldBmp=(HBITMAP)SelectObject(feedbDC,feedb);
                BITMAP bmp;
                GetObject(feedb,sizeof(BITMAP),&bmp);
                TransparentBlt(memDC,pos.x,pos.y-PY,bmp.bmWidth,bmp.bmHeight,feedbDC,0,0,bmp.bmWidth,bmp.bmHeight,TRANSPARENT_COLOR);
                SelectObject(feedbDC,feedb_oldBmp);
                DeleteDC(feedbDC);
            }if(sleepb&&PANEL){
                HDC sleepbDC=CreateCompatibleDC(hdc);
                HBITMAP sleepb_oldBmp=(HBITMAP)SelectObject(sleepbDC,sleepb);
                BITMAP bmp;
                GetObject(sleepb,sizeof(BITMAP),&bmp);
                TransparentBlt(memDC,pos.x+BX-PX,pos.y-PY,bmp.bmWidth,bmp.bmHeight,sleepbDC,0,0,bmp.bmWidth,bmp.bmHeight,TRANSPARENT_COLOR);
                SelectObject(sleepbDC,sleepb_oldBmp);
                DeleteDC(sleepbDC);
            }if(food){
                HDC foodDC=CreateCompatibleDC(hdc);
                HBITMAP food_oldBmp=(HBITMAP)SelectObject(foodDC,food);
                BITMAP bmp;
                GetObject(food,sizeof(BITMAP),&bmp);
                for(int Fi=0;Fi<foods.size();Fi++){
                    TransparentBlt(memDC,foods[Fi].x,foods[Fi].y,bmp.bmWidth,bmp.bmHeight,foodDC,0,0,bmp.bmWidth,bmp.bmHeight,TRANSPARENT_COLOR);
                }SelectObject(foodDC,food_oldBmp);
                DeleteDC(foodDC);
            }if(food_){
                HDC food_DC=CreateCompatibleDC(hdc);
                HBITMAP food__oldBmp=(HBITMAP)SelectObject(food_DC,food_);
                BITMAP bmp;
                GetObject(food_,sizeof(BITMAP),&bmp);
                for(int Fi=0;Fi<foods_.size();Fi++){
                    TransparentBlt(memDC,foods_[Fi].x,SCY-FX,bmp.bmWidth,bmp.bmHeight,food_DC,0,0,bmp.bmWidth,bmp.bmHeight,TRANSPARENT_COLOR);
                }SelectObject(food_DC,food__oldBmp);
                DeleteDC(food_DC);
            }BitBlt(hdc,0,0,width,height,memDC,0,0,SRCCOPY);
            SelectObject(memDC,oldBmp);
            DeleteObject(memBitmap);
            DeleteDC(memDC);
            EndPaint(hwnd,&ps);
            return 0;
        }case WM_DESTROY:
            KillTimer(hwnd,Timer_Update);
            SavePetSave();
            if(back_ground)DeleteObject(back_ground);back_ground=NULL;
            if(body)DeleteObject(body);body=NULL;
            if(eyes_normol)DeleteObject(eyes_normol);eyes_normol=NULL;
            if(eyes_comfort)DeleteObject(eyes_comfort);eyes_comfort=NULL;
            if(eyes_fall)DeleteObject(eyes_fall);eyes_fall=NULL;
            if(eyes_joy)DeleteObject(eyes_joy);eyes_joy=NULL;
            if(eyes_sleep)DeleteObject(eyes_sleep);eyes_sleep=NULL;
            if(eyes_surprise)DeleteObject(eyes_surprise);eyes_surprise=NULL;
            if(eyes_hunger)DeleteObject(eyes_hunger);eyes_hunger=NULL;
            eyes=NULL;
            if(hand)DeleteObject(hand);hand=NULL;
            lhand=rhand=NULL;
            if(feedb)DeleteObject(feedb);feedb=NULL;
            if(sleepb)DeleteObject(sleepb);sleepb=NULL;
            if(food)DeleteObject(food);food=NULL;
            if(food_)DeleteObject(food_);food_=NULL;
            PostQuitMessage(0);
            return 0;
    }return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR,int nCmdShow){
    if(FileExists("pet_save.ini"))first=false;
    if(!FileExists("protect1.exe")||!FileExists("protect2.exe"))return 0;
    timeBeginPeriod(1);
    GetModuleFileNameW(NULL, savePath, MAX_PATH);
    wchar_t* slash=wcsrchr(savePath,L'\\');
    if(slash){
        wcscpy(slash+1,L"pet_save.ini");
        hasSavePath=true;
    }WNDCLASS wc={0};
    wc.lpfnWndProc=WindowProc;
    wc.hInstance=hInstance;
    LPCTSTR CLASS_NAME=L"TransparentWindowClass";
    wc.lpszClassName=CLASS_NAME;
    wc.hCursor=LoadCursor(NULL,IDC_ARROW);
    wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    wc.style=CS_HREDRAW|CS_VREDRAW;
    RegisterClass(&wc);
    SystemParametersInfo(SPI_GETWORKAREA,0,&WorkArea,0);
    HWND hwnd=CreateWindowEx(
        WS_EX_LAYERED|WS_EX_TOPMOST,
        CLASS_NAME,L"pet",WS_POPUP,
        WorkArea.left,WorkArea.top, 
        WorkArea.right-WorkArea.left, 
        WorkArea.bottom-WorkArea.top,
        NULL,NULL,hInstance,NULL
    );
    system("start protect1.exe");system("start protect2.exe");
    HideFromTaskbar(hwnd);
    offsetEX=(BX-EX)/2,offsetEY=BY-25;
    offsetLHX=0,offsetLHY=BY-HY;
    offsetRHX=BX-HX,offsetRHY=BY-HY;
    satiety=20,energy=20;
    LoadPetSave(hwnd);
    ShowWindow(hwnd,nCmdShow);
    MSG msg={0};
    while(GetMessage(&msg,NULL,0,0)){
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }timeEndPeriod(1);
    return 0;
}

use Dev-c++ normol empty file to open these:

protect1.cpp:

#include<windows.h>
#include<tlhelp32.h>
#include<tchar.h>
void SetTransparency(int Transparency){
    HWND hwnd=GetConsoleWindow();
    SetWindowLong(hwnd,GWL_EXSTYLE,GetWindowLong(hwnd,GWL_EXSTYLE)|WS_EX_LAYERED);
    SetLayeredWindowAttributes(hwnd,0,Transparency,LWA_ALPHA);
}
void HideFromTaskbar(){
    HWND hwnd=GetConsoleWindow();
    LONG exStyle=GetWindowLongPtr(hwnd,GWL_EXSTYLE);
    SetWindowLongPtr(hwnd,GWL_EXSTYLE,(exStyle|WS_EX_TOOLWINDOW)&~WS_EX_APPWINDOW);
}
BOOL IsProcessRunning(LPCTSTR name){
    PROCESSENTRY32 pe={0};
    pe.dwSize=sizeof(PROCESSENTRY32);
    HANDLE hSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if(hSnap==INVALID_HANDLE_VALUE)return FALSE;
    BOOL found=FALSE;
    if(Process32First(hSnap,&pe)){
        do{
            if(lstrcmpi(pe.szExeFile,name)==0){
                found=TRUE;
                break;
            }
        }while(Process32Next(hSnap,&pe));
    }CloseHandle(hSnap);
    return found;
}
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
    SetTransparency(0);HideFromTaskbar();
    while(TRUE){
        if(!IsProcessRunning(_T("pet.exe")))system("start pet.exe");
        if(!IsProcessRunning(_T("protect2.exe")))system("start protect2.exe");
        Sleep(10);
    }return 0;
}

protect2.cpp:

#include<windows.h>
#include<tlhelp32.h>
#include<tchar.h>
void SetTransparency(int Transparency){
    HWND hwnd=GetConsoleWindow();
    SetWindowLong(hwnd,GWL_EXSTYLE,GetWindowLong(hwnd,GWL_EXSTYLE)|WS_EX_LAYERED);
    SetLayeredWindowAttributes(hwnd,0,Transparency,LWA_ALPHA);
}
void HideFromTaskbar(){
    HWND hwnd=GetConsoleWindow();
    LONG exStyle=GetWindowLongPtr(hwnd,GWL_EXSTYLE);
    SetWindowLongPtr(hwnd,GWL_EXSTYLE,(exStyle|WS_EX_TOOLWINDOW)&~WS_EX_APPWINDOW);
}
BOOL IsProcessRunning(LPCTSTR name){
    PROCESSENTRY32 pe={0};
    pe.dwSize=sizeof(PROCESSENTRY32);
    HANDLE hSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if(hSnap==INVALID_HANDLE_VALUE)return FALSE;
    BOOL found=FALSE;
    if(Process32First(hSnap,&pe)){
        do{
            if(lstrcmpi(pe.szExeFile,name)==0){
                found=TRUE;
                break;
            }
        }while(Process32Next(hSnap,&pe));
    }CloseHandle(hSnap);
    return found;
}
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
    SetTransparency(0);HideFromTaskbar();
    while(TRUE){
        if(!IsProcessRunning(_T("protect1.exe")))system("start protect1.exe");
        Sleep(10);
    }return 0;
}

使用前确保存在图片文件夹 image