#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;
}
标签:20,img,raylib,int,U1S03,40,WINDOW,playerimg,反弹球
From: https://www.cnblogs.com/evencai/p/18637518