generated from sigonasr2/CPlusPlusProjectTemplate
Hex texturing test
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
efaceb4fa4
commit
cfc22af487
Binary file not shown.
BIN
hexTex.png
Normal file
BIN
hexTex.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 540 B |
67
main.cpp
67
main.cpp
@ -3,58 +3,51 @@
|
||||
|
||||
using namespace olc;
|
||||
|
||||
class Circles : public olc::PixelGameEngine
|
||||
class Hexes : public olc::PixelGameEngine
|
||||
{
|
||||
public:
|
||||
Circles()
|
||||
Hexes()
|
||||
{
|
||||
sAppName = "Circles";
|
||||
sAppName = "Hexes";
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
int CIRCLE_PRECISION=32;
|
||||
|
||||
void DrawCircleDecal(vf2d pos,float radius,Pixel col=WHITE) {
|
||||
std::vector<vf2d> poly;
|
||||
std::vector<vf2d> uvs;
|
||||
for (int i=0;i<CIRCLE_PRECISION;i++) {
|
||||
poly.push_back({pos.x+sinf(2*M_PI/CIRCLE_PRECISION*i)*radius,pos.y+cosf(2*M_PI/CIRCLE_PRECISION*i)*radius});
|
||||
uvs.push_back({0,0});
|
||||
}
|
||||
poly.push_back(poly[0]);
|
||||
uvs.push_back({0,0});
|
||||
SetDecalStructure(DecalStructure::LINE);
|
||||
SetDecalMode(DecalMode::WIREFRAME);
|
||||
DrawPolygonDecal(nullptr,poly,uvs,col);
|
||||
SetDecalMode(DecalMode::NORMAL);
|
||||
SetDecalStructure(DecalStructure::FAN);
|
||||
}
|
||||
void FillCircleDecal(vf2d pos,float radius,Pixel col=WHITE) {
|
||||
std::vector<vf2d> poly;
|
||||
std::vector<vf2d> uvs;
|
||||
poly.push_back(pos);
|
||||
uvs.push_back({0,0});
|
||||
for (int i=0;i<CIRCLE_PRECISION;i++) {
|
||||
poly.push_back({pos.x+sinf(2*M_PI/CIRCLE_PRECISION*i)*radius,pos.y+cosf(2*M_PI/CIRCLE_PRECISION*i)*radius});
|
||||
uvs.push_back({0,0});
|
||||
}
|
||||
poly.push_back(poly[1]);
|
||||
uvs.push_back({0,0});
|
||||
DrawPolygonDecal(nullptr,poly,uvs,col);
|
||||
}
|
||||
Decal*hexImg;
|
||||
vf2d offset={100,100};
|
||||
|
||||
bool OnUserCreate() override
|
||||
{
|
||||
// Called once at the start, so create things here
|
||||
hexImg = new Decal(new Sprite("hexTex.png"));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnUserUpdate(float fElapsedTime) override
|
||||
{
|
||||
if (GetKey(UP).bHeld) {
|
||||
offset.y+=fElapsedTime*200;
|
||||
}
|
||||
if (GetKey(DOWN).bHeld) {
|
||||
offset.y-=fElapsedTime*200;
|
||||
}
|
||||
if (GetKey(LEFT).bHeld) {
|
||||
offset.x+=fElapsedTime*200;
|
||||
}
|
||||
if (GetKey(RIGHT).bHeld) {
|
||||
offset.x-=fElapsedTime*200;
|
||||
}
|
||||
// called once per frame
|
||||
DrawCircleDecal({50,50},10,BLUE);
|
||||
FillCircleDecal({100,100},20,GREEN);
|
||||
float scale=20;
|
||||
for (int x=0;x<20;x++) {
|
||||
for (int y=0;y<20;y++) {
|
||||
vf2d offset2={(y&1?-0.45F*scale:0)+offset.x+x*0.9F*scale,y*scale*0.7F+offset.y};
|
||||
DrawPolygonDecal(hexImg,{
|
||||
{0+offset2.x,0.5F*scale+offset2.y},{-0.45F*scale+offset2.x,0.25F*scale+offset2.y},{0+offset2.x,0+offset2.y},{0.45F*scale+offset2.x,0.25F*scale+offset2.y},{0.45F*scale+offset2.x,0.75F*scale+offset2.y},{0+offset2.x,1*scale+offset2.y},{-0.45F*scale+offset2.x,0.75F*scale+offset2.y},{-0.45F*scale+offset2.x,0.25F*scale+offset2.y}
|
||||
},{
|
||||
{1,1},{0,1},{0,0},{0,1},{0,0},{0,1},{0,0},{0,1}
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -62,7 +55,7 @@ public:
|
||||
|
||||
int main()
|
||||
{
|
||||
Circles demo;
|
||||
Hexes demo;
|
||||
if (demo.Construct(256, 240, 4, 4))
|
||||
demo.Start();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user