#include <raylib.h>
#include<bits/stdc++.h>
using namespace std;
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
int main() {//初始化窗口InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT,"Test");SetTargetFPS(60);//创建一个40*40,透明背景的图片Image img=GenImageColor(40,40,BLANK);//在图片中绘制一个以(20,20)为圆心,半径为20的红色圆ImageDrawCircle(&img,20,20,19,RED);//注意texture才是最终被画到窗口上的东西,Texture texture = LoadTextureFromImage(img);UnloadImage(img); //不再需要使用img,释放掉//创建一个玩家的金色传说Image playerimg=GenImageColor(40,40,BLANK);ImageDrawCircle(&playerimg,20,20,19,GOLD);Texture playertexture = LoadTextureFromImage(playerimg);UnloadImage(playerimg);int x=0,y=0;int speedx=8,speedy=3;//开启程序的主循环while (!WindowShouldClose()) {if(x+speedx>=WINDOW_WIDTH-40 || x+speedx<=0){speedx*=-1;}if(y+speedy>=WINDOW_HEIGHT-40 || y+speedy<=0){speedy*=-1;}x+=speedx;y+=speedy;int px=GetMouseX();int py=GetMouseY();//绘制帧,这一Part都是放在循环的最后的BeginDrawing();//开始绘制ClearBackground(WHITE);//重新绘制一些背景。DrawTexture(texture,x,y,WHITE);//把咱们的小球元素画上去DrawTexture(playertexture,px-20,py-20,WHITE);EndDrawing();//结束绘制}//释放texture对象UnloadTexture(texture); UnloadTexture(playertexture);//关闭窗口CloseWindow();return 0;
}