// WORK IN PROGRESS CONVERSION.... // #include "raylib.h" #include static int tempmap[32][32] = {0}; // start setup static int weasel=0; static int startsetuppalettemode; // '0=c64 1=db32 static bool startsetupdone; static int startsetupx; static int startsetupy; static int startsetupwidth; static int startsetupheight; static RenderTexture2D startsetupim[5]; //5=numstartsetup //Field startsetupcan:Canvas[] static int startsetupselected; static int startsetup8x8id; static int startsetup16x16id = 1; static int startsetup32x32id = 2; static int startsetupc64id = 3; static int startsetupdb32id = 4; static int numstartsetup = 5; //' //'tool view static int toolx; static int tooly; static int toolwidth; static int toolheight; static RenderTexture2D toolim[16]; //16 = numtools //Field toolcan:Canvas[] static bool toolgridtoggle = true; static int toolselected = 0; static int toolpencilid = 0; static int tooleraserid = 1; static int toolfillid = 2; static int toollineid = 3; static int toolselectionid = 4; static int toolcopyid = 5; static int toolpasteid = 6; static int toolcutid = 7; static int toolflipverticalid = 8; static int toolfliphorizontalid = 9; static int toolcolorpickerid = 10; static int toolgridid = 11; static int toolfilledrectid = 12; static int tooloutlinerectid = 13; static int toolfilledcircleid = 14; static int tooloutlinecircleid = 15; static int numtools = 16; static int delay; static int delaydefault = 20; //' //' sprite library static int spritelibx; static int spriteliby; static int spritelibwidth; static int spritelibheight; static int numspritelib; static RenderTexture2D spritelibim[80*4]; // 80*4 = numspritelib //Field spritelibcan:Canvas[] static int spritelibmap[80*4][32][32]; // numspritelib, static int spritelibselected = 0; static float spritelibscale; //' //'preview static RenderTexture2D previewim; //Field previewcan:Canvas static int previewx; static int previewy; static int previewwidth; static int previewheight; static int previewcellwidth; static int previewcellheight; // tile map view static int tilemapx; static int tilemapy; static int tilemapwidth; static int tilemapheight; static int tilemaptileshorizontal; static int tilemaptilesvertical; static int tilemaptilesscreenhorizontal=100; static int tilemaptilesscreenvertical=100; static int tilemap[100][100]; //' //'sprite view static int map[32][32]; // 8 = edit canvas width static int canvasx; static int canvasy; //'canvas x and y position on the scrern static float canvaswidth=256; static float canvasheight=256; //'width and height of our canvas static float gridwidth; static float gridheight;// ' grids width and height static int spritewidth; static int spriteheight;// ' our main sprite width and height //' line tool fields static bool linepressed=false; static bool lineactive=false; static int linestartx; static int linestarty; static int lineendx; static int lineendy; //' Selection fields static bool selectionpressed = false ; static bool selectionactive = false; static int selectionstartx; static int selectionstarty; static int selectionendx; static int selectionendy; static int selectionbuffer[32][32]; //'our copy paste buffer static int selectionbufferstartx; static int selectionbufferstarty; static int selectionbufferendx; static int selectionbufferendy; static bool selectionnegativeswitchx = false;// ' switch if negative selection static bool selectionnegativeswitchy = false; //' filled/outlined rectsangles and circles fields static bool bcselectionpressed = false; static bool bcselectionactive = false; static int bcselectionstartx; static int bcselectionstarty; static int bcselectionendx; static int bcselectionendy; static int bcselectionbuffer[32][32];// 'our copy paste buffer static int bcselectionbufferstartx; static int bcselectionbufferstarty; static int bcselectionbufferendx; static int bcselectionbufferendy; static bool bcselectionnegativeswitchx = false; // ' switch if negative selection static bool bcselectionnegativeswitchy = false; //' //' palette static Color c64color[16]; //' our colors static Color db32color[32];// ' our colors static int paletteselected;// ' our selected color from palette static int paletteeraser; static int palettex; static int palettey; //'screen x and y static float palettewidth; static float paletteheight;// ' our palette screen w and h static float palettecellwidth; static float palettecellheight; //'cell width and height of color static int numpalette;// 'number of colors //' //' Top Bar static int topbarx; static int topbary; static int topbarwidth; static int topbarheight; static Color topbarcolor; static RenderTexture2D topbarim[3]; //Field topbarcan:Canvas[] static int topbarspriteeditid = 0; static int topbarmapeditid = 1; static int numtopbaricons = 2; static int topbarcurrentid = 0; //' //' Middle bar static int middlebarx; static int middlebary; static int middlebarwidth; static int middlebarheight; static Color middlebarcolor; static RenderTexture2D middlebarim[4]; //nummiddlebaricons //Field middlebarcan:Canvas[] static int middlebar0id = 0; static int middlebar1id = 1; static int middlebar2id = 2; static int middlebar3id = 3; static int nummiddlebaricons = 4; static int middlebarcurrentid = 0; //' //' Bottom Bar static int bottombarx; static int bottombary; static int bottombarwidth; static int bottombarheight; static Color bottombarcolor; static void inic64colors(void); static void inidb32colors(void); static bool rectsoverlap(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); static bool circlerectcollide(int cx,int cy,int cr,int rx,int ry,int rw,int rh); static float Clamp(float value, float min, float max); static void startsetupsetup(void); static void startsetupview(void); static void bottombarview(void); static void middlebarview(); static void setupmiddlebar(void); static void setuptopbar(void); static void paletteview(void); static void spritegrid(void); static void toolview(void); static void spritelibview(void); static void spriteview(void); static void updatespritelib(void); static void updatepreview(void); static void spritelibcopytocanvas(void); int main(void) { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 640; const int screenHeight = 480; InitWindow(screenWidth, screenHeight, "raylib example."); //'start setup setup //' be sure to start the editor with the selection startsetupdone=false; startsetupx = 320-80; startsetupy = 150; startsetupwidth = 150; startsetupheight = 200-35; //startsetupim = New Image[numstartsetup]; //startsetupcan = New Canvas[numstartsetup] for(int i=0;i0)DrawRectangle(x*2,y*2,2,2,c64color[eightxeight[y][x]]); EndTextureMode(); }} //startsetupcan[startsetup8x8id].Flush() //the 16x16 selection button int sixteenxsixteen[16][16] = { {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {1,12,1,1,1,12,12,12,12,12,1,12,1,1,1,12}, {1,12,1,12,12,12,1,12,1,12,1,12,1,12,12,12}, {1,12,1,1,1,12,12,1,12,12,1,12,1,1,1,12}, {1,12,1,12,1,12,1,12,1,12,1,12,1,12,1,12}, {1,12,1,1,1,12,12,12,12,12,1,12,1,1,1,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}}; for(int y=0;y<16;y++){ for(int x=0;x<16;x++){ BeginTextureMode(startsetupim[startsetup16x16id]); //startsetupcan[startsetup16x16id].Color = c64color[sixteenxsixteen[y][x]] //If sixteenxsixteen[y][x] = 0 Then startsetupcan[startsetup16x16id].Alpha=0 Else startsetupcan[startsetup16x16id].Alpha=1 if(sixteenxsixteen[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[sixteenxsixteen[15-y][x]]); //startsetupcan[startsetup16x16id].DrawRect(x*2,y*2,2,2) EndTextureMode(); }} //startsetupcan[startsetup16x16id].Flush() // the 32x32 selection button int thirtytwoxthirtytwo[16][16] = { {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {1,1,12,1,1,12,12,12,12,12,1,1,12,1,1,12}, {12,1,12,12,1,12,1,12,1,12,12,1,12,12,1,12}, {1,1,12,1,1,12,12,1,12,12,1,1,12,1,1,12}, {12,1,12,1,12,12,1,12,1,12,12,1,12,1,12,12}, {1,1,12,1,1,12,12,12,12,12,1,1,12,1,1,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}}; for(int y=0;y<16;y++){ for(int x=0;x<16;x++){ BeginTextureMode(startsetupim[startsetup32x32id]); //startsetupcan[startsetup32x32id].Color = c64color[thirtytwoxthirtytwo[y][x]] //If thirtytwoxthirtytwo[y][x] = 0 Then startsetupcan[startsetup32x32id].Alpha=0 Else startsetupcan[startsetup32x32id].Alpha=1 //startsetupcan[startsetup32x32id].DrawRect(x*2,y*2,2,2) if(thirtytwoxthirtytwo[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[thirtytwoxthirtytwo[15-y][x]]); EndTextureMode(); }} //startsetupcan[startsetup32x32id].Flush() // the c64 palette selection button int c641616[16][16] = { {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,1,1,12,12,12,1,1,12,12,1,12,12,12,12}, {12,1,12,12,12,12,1,12,12,12,12,1,12,12,12,12}, {12,1,12,12,12,12,1,12,12,12,12,1,12,12,1,12}, {12,1,12,12,12,12,1,1,1,12,12,1,1,1,1,12}, {12,1,12,12,12,12,1,12,12,1,12,12,12,12,1,12}, {12,1,12,12,12,12,1,12,12,1,12,12,12,12,1,12}, {12,12,1,1,12,12,12,1,1,12,12,12,12,12,1,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}}; for(int y=0;y<16;y++){ for(int x=0;x<16;x++){ BeginTextureMode(startsetupim[startsetupc64id]); //startsetupcan[startsetupc64id].Color = c64color[c641616[y][x]] //If c641616[y][x] = 0 Then startsetupcan[startsetupc64id].Alpha=0 Else startsetupcan[startsetupc64id].Alpha=1 //startsetupcan[startsetupc64id].DrawRect(x*2,y*2,2,2) if(c641616[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[c641616[15-y][x]]); EndTextureMode(); }} //startsetupcan[startsetupc64id].Flush() // the db32 palette selection button int db321616[16][16] = { {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,1,12,1,12,12,12,1,1,12,12,1,1,1,12}, {12,12,1,12,1,12,12,12,12,12,1,12,12,12,1,12}, {12,12,1,12,1,12,12,12,12,12,1,12,12,12,1,12}, {12,1,1,12,1,1,12,12,1,1,12,12,1,1,1,12}, {1,12,1,12,1,12,1,12,12,12,1,12,1,12,12,12}, {1,12,1,12,1,12,1,12,12,12,1,12,1,12,12,12}, {1,1,1,12,1,1,1,12,1,1,12,12,1,1,1,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12}}; for(int y=0;y<16;y++){ for(int x=0;x<16;x++){ BeginTextureMode(startsetupim[startsetupdb32id]); //startsetupcan[startsetupdb32id].Color = c64color[db321616[y][x]] //If db321616[y][x] = 0 Then startsetupcan[startsetupdb32id].Alpha=0 Else startsetupcan[startsetupdb32id].Alpha=1 //startsetupcan[startsetupdb32id].DrawRect(x*2,y*2,2,2) if(db321616[15-y][x]>0)DrawRectangle(x*2,y*2,2,2,c64color[db321616[15-y][x]]); EndTextureMode(); }} //startsetupcan[startsetupdb32id].Flush() } void startsetupview(){ //canvas.Color = Color.Black DrawRectangle(startsetupx-1,startsetupy-1,startsetupwidth+2,startsetupheight+2,BLACK); //canvas.Color = c64color[12] DrawRectangle(startsetupx,startsetupy,startsetupwidth,startsetupheight,c64color[12]); //Local selected:Bool=False bool selected = false; for(int i=0;i<3;i++){ //canvas.Color = Color.Grey.Blend(Color.Black,.5) //DrawRectangle(startsetupx+8+20,startsetupy+8+i*48,32,32,GRAY); //canvas.Color = Color.White DrawTexture(startsetupim[i].texture,startsetupx+9+20,startsetupy+9+i*48,WHITE); //' draw the palette buttons //canvas.Color = Color.Black //DrawRectangle(startsetupx+8+50,startsetupy+8+i*48,32,32,BLACK); //canvas.Color = Color.White //DrawTexture(startsetupim[3],startsetupx+9+50,startsetupy+9+i*48,0,.9,.9) DrawTexture(startsetupim[3].texture,startsetupx+9+60,startsetupy+9+i*48,WHITE); //canvas.Color = Color.Black //DrawRectangle(startsetupx+8+80,startsetupy+8+i*48,32,32,BLACK); //canvas.Color = Color.White DrawTexture(startsetupim[4].texture,startsetupx+9+100,startsetupy+9+i*48,WHITE); if(IsMouseButtonDown(0)){ if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,startsetupx+9+60,startsetupy+9+i*48,32,32)){ startsetupselected = i; startsetuppalettemode = 0; selected = true; } if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,startsetupx+9+100,startsetupy+9+i*48,32,32)){ startsetupselected = i; startsetuppalettemode = 1; selected = true; } } } if(selected == true){ if(startsetuppalettemode == 1){// ' if the db32 palette was selected paletteeraser = 0; palettex = 640-150; palettey = 32; palettewidth = 32*4; paletteheight = 32*4; numpalette = 32; palettecellwidth = 32*4/4; palettecellheight = 32*4/8; } switch (startsetupselected){ case 0: spritelibscale = 4; spritewidth = 8; spriteheight = 8; //map = New Int[spritewidth,spriteheight] //selectionbuffer = New Int[spritewidth,spriteheight]; gridwidth = canvaswidth/spritewidth; gridheight = canvasheight/spriteheight; //spritelibmap = New Int[numspritelib,spritewidth,spriteheight]; break; case 1: spritelibscale = 2; spritewidth = 16; spriteheight = 16; //map = New Int[spritewidth,spriteheight]; //selectionbuffer = New Int[spritewidth,spriteheight]; gridwidth = canvaswidth/spritewidth; gridheight = canvasheight/spriteheight; //spritelibmap = New Int[numspritelib,spritewidth,spriteheight]; break; case 2: spritelibscale = 1; spritewidth = 32; spriteheight = 32; //map = New Int[spritewidth,spriteheight]; //selectionbuffer = New Int[spritewidth,spriteheight]; gridwidth = canvaswidth/spritewidth; gridheight = canvasheight/spriteheight; //spritelibmap = New Int[numspritelib,spritewidth,spriteheight]; break; } startsetupdone = true; } } void bottombarview(){ //canvas.Color = bottombarcolor DrawRectangle(bottombarx,bottombary,bottombarwidth,bottombarheight,bottombarcolor); //canvas.Color = bottombarcolor/2 DrawRectangle(bottombarx,bottombary+bottombarheight/2,bottombarwidth,bottombarheight/2,(Color){50,5,2,255}); } void middlebarview(){ //canvas.Color = middlebarcolor DrawRectangle(middlebarx,middlebary,middlebarwidth,middlebarheight,middlebarcolor); //canvas.Color = middlebarcolor/2 DrawRectangle(middlebarx,middlebary+middlebarheight/2,middlebarwidth,middlebarheight/2,DARKGRAY); //' Draw the icons .. int num = 0; for(int x = 640-128;x<640;x+=32){ if(num>=nummiddlebaricons)continue; int pointx=x+middlebarx; int pointy=middlebary; if(middlebarcurrentid == num){ //canvas.Color=Color.White DrawTexture(middlebarim[num].texture,pointx,pointy,WHITE); }else{ DrawTexture(middlebarim[num].texture,pointx,pointy,DARKGRAY); //canvas.Color=Color.DarkGrey } //canvas.DrawImage(middlebarim[num],pointx,pointy) //' //' Selection of the sprite editor or the map editor if(IsMouseButtonDown(0)){ if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){ middlebarcurrentid = num; } } num+=1; } } void setupmiddlebar(){ int zero[8][8]={ {0,12,12,12,12,12,12,0}, {12,12,12,1,1,1,12,12}, {12,12,12,1,12,1,12,12}, {12,12,12,1,12,1,12,12}, {12,12,12,1,12,1,12,12}, {12,12,12,1,1,1,12,12}, {12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12}}; for(int y=0;y<8;y++){ for(int x=0;x<8;x++){ //middlebarcan[middlebar0id].Color = c64color[zero[y][x]] //If zero[y][x] = 0 Then middlebarcan[middlebar0id].Alpha=0 Else middlebarcan[middlebar0id].Alpha=1 BeginTextureMode(middlebarim[middlebar0id]); DrawRectangle(x*4,y*4,4,4,c64color[zero[7-y][x]]); EndTextureMode(); }} //middlebarcan[middlebar0id].Flush() int one[8][8]={ {0,12,12,12,12,12,12,0}, {12,12,12,1,1,12,12,12}, {12,12,12,12,1,12,12,12}, {12,12,12,12,1,12,12,12}, {12,12,12,12,1,12,12,12}, {12,12,12,1,1,1,12,12}, {12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12}}; for(int y=0;y<8;y++){ for(int x=0;x<8;x++){ //middlebarcan[middlebar1id].Color = c64color[one[y][x]] //If one[y][x] = 0 Then middlebarcan[middlebar1id].Alpha=0 Else middlebarcan[middlebar1id].Alpha=1 BeginTextureMode(middlebarim[middlebar1id]); DrawRectangle(x*4,y*4,4,4,c64color[one[7-y][x]]); EndTextureMode(); }} //middlebarcan[middlebar1id].Flush() int two[8][8]={ {0,12,12,12,12,12,12,0}, {12,12,12,1,1,1,12,12}, {12,12,12,12,12,1,12,12}, {12,12,12,12,1,12,12,12}, {12,12,12,1,12,12,12,12}, {12,12,12,1,1,1,12,12}, {12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12}}; for(int y=0;y<8;y++){ for(int x=0;x<8;x++){ //middlebarcan[middlebar2id].Color = c64color[two[y][x]] //If two[y][x] = 0 Then middlebarcan[middlebar2id].Alpha=0 Else middlebarcan[middlebar2id].Alpha=1 BeginTextureMode(middlebarim[middlebar2id]); DrawRectangle(x*4,y*4,4,4,c64color[two[7-y][x]]); EndTextureMode(); }} //middlebarcan[middlebar2id].Flush() int three[8][8]={ {0,12,12,12,12,12,12,0}, {12,12,12,1,1,1,12,12}, {12,12,12,12,12,1,12,12}, {12,12,12,12,1,1,12,12}, {12,12,12,12,12,1,12,12}, {12,12,12,1,1,1,12,12}, {12,12,12,12,12,12,12,12}, {12,12,12,12,12,12,12,12}}; for(int y=0;y<8;y++){ for(int x=0;x<8;x++){ //middlebarcan[middlebar3id].Color = c64color[three[y][x]] //If three[y][x] = 0 Then middlebarcan[middlebar3id].Alpha=0 Else middlebarcan[middlebar3id].Alpha=1 BeginTextureMode(middlebarim[middlebar3id]); DrawRectangle(x*4,y*4,4,4,c64color[three[7-y][x]]); EndTextureMode(); }} //middlebarcan[middlebar3id].Flush() } void setuptopbar(){ int mapedit[8][8] = { {1,1,1,0,0,1,1,0}, {1,1,1,0,0,1,1,0}, {1,1,1,0,0,0,0,0}, {0,0,0,1,1,1,1,1}, {1,1,0,1,1,1,1,1}, {1,1,0,1,1,1,1,1}, {0,0,0,1,1,1,1,1}, {0,0,0,1,1,1,1,1}}; for(int y=0;y<8;y++){ for(int x=0;x<8;x++){ //topbarcan[topbarmapeditid].Color = c64color[mapedit[y][x]] //If mapedit[y][x] = 0 Then topbarcan[topbarmapeditid].Alpha=0 Else topbarcan[topbarmapeditid].Alpha=1 BeginTextureMode(topbarim[topbarmapeditid]); if(mapedit[7-y][x]>0)DrawRectangle(x*4,y*4,4,4,c64color[mapedit[7-y][x]]); EndTextureMode(); }} //topbarcan[topbarmapeditid].Flush() int spriteedit[8][8] = { {1,0,0,0,0,0,0,1}, {0,1,0,0,0,0,1,0}, {0,1,0,1,1,0,1,0}, {0,0,1,1,1,1,0,0}, {0,1,1,0,0,1,1,0}, {0,1,1,1,1,1,1,0}, {0,0,1,1,1,1,0,0}, {0,1,0,1,1,0,1,0}}; for(int y=0;y<8;y++){ for(int x=0;x<8;x++){ //topbarcan[topbarspriteeditid].Color = c64color[spriteedit[y][x]] //If spriteedit[y][x] = 0 Then topbarcan[topbarspriteeditid].Alpha=0 Else topbarcan[topbarspriteeditid].Alpha=1 BeginTextureMode(topbarim[topbarspriteeditid]); if(spriteedit[7-y][x]>0)DrawRectangle(x*4,y*4,4,4,c64color[spriteedit[7-y][x]]); EndTextureMode(); }} //topbarcan[topbarspriteeditid].Flush() } void topbarview(){ //canvas.Color = topbarcolor DrawRectangle(topbarx,topbary,topbarwidth,topbarheight,topbarcolor); //canvas.Color = topbarcolor/2 DrawRectangle(topbarx,topbary+topbarheight/2,topbarwidth,topbarheight/2,(Color){50,5,2,255}); //' //' Draw the icons .. int num = 0; for(int x=640-200;x<640;x+=32){ if(num>=numtopbaricons) continue; int pointx=x+topbarx; int pointy=topbary+3; if(topbarcurrentid == num){ //canvas.Color=Color.White DrawTextureEx(topbarim[num].texture,(Vector2){pointx,pointy},0,0.6f,WHITE); }else{ DrawTextureEx(topbarim[num].texture,(Vector2){pointx,pointy},0,0.6f,DARKGRAY); //canvas.Color=Color.DarkGrey } //canvas.DrawImage(topbarim[num],pointx,pointy,0,.6,.6) //' //' Selection of the sprite editor or the map editor if(IsMouseButtonDown(0)){ if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){ topbarcurrentid = num; } } num+=1; } } void paletteview(){ //canvas.Color = Color.Black DrawRectangle(palettex,palettey,palettewidth,paletteheight,BLACK); //canvas.Scissor = New Recti(palettex+2,palettey+2,palettex+2+palettewidth-4,palettey+2+paletteheight-4) //canvas.Color = Color.White int cc=0; for(int y=0;y=numpalette)break; float pointx=x+palettex; float pointy=y+palettey; //' //' Draw our color if(startsetuppalettemode == 0){ //canvas.Color = c64color[cc] DrawRectangle(pointx,pointy,palettecellwidth,palettecellheight,c64color[cc]); }else{ //canvas.Color = db32color[cc] DrawRectangle(pointx,pointy,palettecellwidth,palettecellheight,db32color[cc]); } //canvas.DrawRect(pointx,pointy,palettecellwidth,palettecellheight) //' //' Draw a white bar around the currently selected color if(paletteselected == cc){ //canvas.OutlineMode = OutlineMode.Solid //canvas.OutlineWidth = 3 //canvas.OutlineColor = Color.Black //canvas.DrawRect(pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4) DrawRectangleLinesEx((Rectangle){pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4}, 3, BLACK); //canvas.OutlineMode = OutlineMode.Solid //canvas.OutlineWidth = 1 //canvas.OutlineColor = Color.Yellow //canvas.DrawRect(pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4) DrawRectangleLinesEx((Rectangle){pointx+2,pointy+2,palettecellwidth-4,palettecellheight-4}, 1, YELLOW); //canvas.OutlineMode = OutlineMode.None } //' //' Select our color if(IsMouseButtonDown(0)){ if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,palettecellwidth,palettecellheight)){ paletteselected = cc; } } //' cc+=1; }} //canvas.Scissor = New Recti(0,0,640,480) //'canvas.Color = c64color[2] } void spritegrid(){ //' If grid noview then exit this method if(toolgridtoggle == false)return; //' draw our grid //canvas.Color = Color.Grey for(int y=0;y0)delay-=1; int num=0; for(int y=tooly;y=numtools)continue; int pointx=x; int pointy=y; if(toolselected == num){ //canvas.Color = Color.Yellow DrawRectangle(pointx,pointy,32,32,YELLOW); //canvas.Color = Color.White //canvas.Scissor = New Recti(pointx+2,pointy+2,pointx+30,pointy+30) DrawTexture(toolim[num].texture,pointx,pointy,WHITE); //canvas.Scissor = New Recti(0,0,640,480) }else{ DrawTexture(toolim[num].texture,pointx,pointy,WHITE); } //' //'/ Interaction with the tool area //' if(IsMouseButtonDown(0)){ if(rectsoverlap(GetMouseX(),GetMouseY(),1,1,pointx,pointy,32,32)){ toolselected = num; //' Pastethe selected area if(toolselected == toolpasteid){ if(selectionstartx == selectionendx && selectionstarty == selectionendy){ }else{ for(int y1=selectionbufferstarty; y1=32 || y1>=32) continue; if(destx<0 || desty<0 || destx>=32 || desty>=32)continue; if(destx>selectionendx || desty>selectionendy)continue; map[destx][desty] = selectionbuffer[x1][y1]; } } toolselected = toolpencilid; } } //' Copy the selected area if(toolselected == toolcopyid){ if(selectionstartx == selectionendx && selectionstarty == selectionendy){ }else{ selectionbufferstartx = selectionstartx; selectionbufferstarty = selectionstarty; selectionbufferendx = selectionendx; selectionbufferendy = selectionendy; for(int y1=selectionstarty;y1=numspritelib)break; } if(num>=numspritelib)break; } } void spriteview(){ //canvas.Color = Color.Grey for(int y=0;y Color.Black map[x,y] = paletteselected End If Next Next End If End If ' bcselectionendy=0 bcselectionendx=0 bcselectionstarty=0 bcselectionstartx=0 End If End If End if ' Copy to clipboard If Keyboard.KeyReleased(Key.C) copytoclipboard() End if */ } } updatepreview(); updatespritelib(); } void updatepreview(){ /* previewcan.Clear(Color.Black) For Local y:Int=0 Until map.GetSize(1) For Local x:Int=0 Until map.GetSize(0) Local pointx:Int=x*previewcellwidth Local pointy:Int=y*previewcellheight If startsetuppalettemode = 0 previewcan.Color = c64color[map[x,y]] Else previewcan.Color = db32color[map[x,y]] End If previewcan.DrawRect(pointx,pointy,previewcellwidth,previewcellheight) Next Next previewcan.Flush() */ } void updatespritelib(){ for(int y=0;y = New List ' Add the start position on the list ol.AddLast(New pathnode(x,y)) ' set the cloes map at the start position to distance 1 Local colorundermouse:Int=map[x,y] map[x,y] = paletteselected ' some helper arrays. We can determine the top,right,and bottom ' and left position cells with these numbers. Local dx:Int[] = New Int[](0,1,0,-1) Local dy:Int[] = New Int[](-1,0,1,0) ' While there is contents in the list While ol.Count() <> 0 ' Get the current location Local x1:Int=ol.First.x Local y1:Int=ol.First.y ' Remove the current location from the list ol.RemoveFirst() ' Get 4 new positions around the current positions For Local i:=0 Until 4 ' Set new x and y Local nx:Int=x1+dx[i] Local ny:Int=y1+dy[i] ' If the coordinates are inside the map If nx>=0 And ny>=0 And nx paletteselected ' Set the new distance based on the current distance map[nx,ny] = paletteselected ' Add new position to the list ol.AddLast(New pathnode(nx,ny)) End If End If Next Wend */ } void spritelibcopytocanvas(){ for(int y=0;y= (x2 + w2) || (x1 + w1) <= x2))return false; if((y1 >= (y2 + h2) || (y1 + h1) <= y2))return false; return true; } bool circlerectcollide(int cx,int cy,int cr,int rx,int ry,int rw,int rh){ float closestx = Clamp(cx, rx, rx+rw); float closesty = Clamp(cy, ry, ry+rh); float distancex = cx - closestx; float distancey = cy - closesty; float distancesquared = (distancex * distancex) + (distancey * distancey); return distancesquared < (cr * cr); } // Clamp float value float Clamp(float value, float min, float max) { const float res = value < min ? min : value; return res > max ? max : res; }