Spinal's Mode13 (256 color buffered mode) demo. Palette rotation is still not working

Dependencies:   PokittoLib

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "Pokitto.h"
00002 
00003 Pokitto::Core game;
00004 
00005 unsigned short pal[256]; // assign a 256 entry array to hold the palette
00006 
00007 int PntClr(int x, int y){
00008     return game.display.getPixel(x,y);
00009 }
00010 void Dot (int x, int y, int c){
00011     game.display.drawPixel(x,y,c);
00012 }
00013 int RandMinMax(int min, int max){
00014     return rand() % max + min;
00015 }
00016 int Adjust (int xa, int ya, int x, int y, int xb, int yb){
00017     if(PntClr(x, y) != 0) return 0;
00018     int q = abs(xa - xb) + abs(ya - yb);
00019     int v = (PntClr(xa, ya) + PntClr(xb, yb)) / 2 + (RandMinMax(0,q*10)) / 10;
00020     if (v < 1) v = 1;
00021     if (v > 255) v = 255;
00022     Dot(x, y, v);
00023     return 1;
00024 }
00025 void SubDivide (int x1, int y1, int x2, int y2){
00026     if ((x2 - x1 < 2) && (y2 - y1 < 2)) return;
00027     int x = (x1 + x2) / 2;
00028     int y = (y1 + y2) / 2;
00029     Adjust(x1, y1, x, y1, x2, y1);
00030     Adjust(x1, y2, x, y2, x2, y2);
00031     Adjust(x2, y1, x2, y, x2, y2);
00032     Adjust(x1, y1, x1, y, x1, y2);
00033     if(PntClr(x, y) == 0)   {
00034         int v = PntClr(x1, y1) + PntClr(x2, y1) + PntClr(x2, y2);
00035         v = v + PntClr(x1, y2) + PntClr(x1, y) + PntClr(x, y1);
00036         v = v + PntClr(x2, y) + PntClr(x, y2);
00037         v = v / 8;
00038         Dot(x, y, v);
00039     }
00040     SubDivide(x1, y1, x, y);
00041     SubDivide(x, y, x2, y2);
00042     SubDivide(x, y1, x2, y);
00043     SubDivide(x1, y, x, y2);
00044 }
00045 void make_plasma(int x1=0,int y1=0,int x2=game.display.width-1,int y2=game.display.height-1){
00046     game.display.clear();
00047     if(x1<0)x1=0;
00048     if(y1<0)y1=0;
00049     if(x2>game.display.width-1)x2=game.display.width-1;
00050     if(y2>game.display.height-1)y2=game.display.height-1;
00051     Dot(x1, y1, RandMinMax(0,255) + 1);
00052 Dot(x2, y1, RandMinMax(0,255) + 1);
00053 Dot(x2, y2, RandMinMax(0,255) + 1);
00054 Dot(x1, y2, RandMinMax(0,255) + 1);
00055 SubDivide(x1, y1, x2, y2);
00056 }
00057 void make_pal(void){
00058     int a,s,r,g,b;
00059     for(a=0; a<=63; a++){
00060         s = 0;  r = a;      g = 63-a;   b = 0;      pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
00061         s = 64; r = 63-a;   g = 0;      b = a;      pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
00062         s = 128; r = 0;     g = 0;      b = 63-a;   pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
00063         s = 192; r = 0;     g = a;      b = 0;      pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
00064     }
00065     game.display.load565Palette(&pal[0]); // load a palette the same way as any other palette in any other screen mode
00066 }
00067 int main(){
00068     char col=0;
00069     game.begin();
00070     game.display.persistence=1;
00071     srand(game.getTime());
00072 make_pal(); // create 256 colour palette for this demo
00073 make_plasma(0,0,game.display.width-1,game.display.height-1); // create a nice plasma cloud
00074 
00075 while (game.isRunning()) {
00076     if(game.update()){
00077     // mode 13 has a palette offset, so instead of rotating your palette, you just tell it which colour should be first.
00078         game.display.palOffset = col++;
00079     }
00080 }
00081 
00082 return 1;
00083 }