Simulator experiments

Can you upload source ?

@jonne @krp Iā€™m going to work on it some more tonight after work then Iā€™ll share source. Iā€™d love to see it running on hardware!

Edit:
Also, Iā€™m not too sure on the tile sizes right now. These are 1212 currently, but my original game uses 88. Since the character is white he should pop on the screen. Iā€™ll try both. Only have to change the sprites and one variable.

1 Like

8x8 is very small indeed

https://drive.google.com/file/d/0B7qp81OkSLOOQ2hBNlBPYXh2ZjA/view?usp=sharing

Hereā€™s the new source. Iā€™m not very proud of it at all lol. It was a great learning experience to get me comfortable with c++ though. I planned on a complete port of my original game but I may start with a fresh idea instead :stuck_out_tongue:

2 Likes

Tried running game but no jetpack person view able output is like

You have to build it for the Hires target.
Catsfolly

1 Like

Looks great so far.

You might want to print ā€œgame overā€ in state 2 though - otherwise people might think the program crashedā€¦

else if (state==2){
game.display.color=1;
game.display.setCursor(90,80);
game.display.print(ā€œGame Overā€);

    }

Catsfolly

2 Likes

:+1: got it now !!!

very eager to play on device !!!

:heart_eyes:

Yeah by no means it is complete yet :stuck_out_tongue: Also not quite sure how to ā€œresetā€ the game after showing the game over screen. I planned on adding simple enemies and a score counter as well.

I will try this on the hardware later today

1 Like

I had another try at the plasma effect, this time using directPixel. However, it flickers a lot, is this the same on hardware?

#include "pokitto.h"
Pokitto::Core game;
unsigned short pal[256];
char buff[220*174];
int PntClr(int x, int y){
	return buff[x+game.display.width*y];
}
void Dot (int x, int y, int c){
    // create a buffer for the screen image
	buff[x+game.display.width*y]=c;
}
int RandMinMax(int min, int max){
    return rand() % max + min;
}
int Adjust (int xa, int ya, int x, int y, int xb, int yb){
	if(PntClr(x, y) != 0) return 0;
	int q = abs(xa - xb) + abs(ya - yb);
	int v = (PntClr(xa, ya) + PntClr(xb, yb)) / 2 + (RandMinMax(0,q*10)) / 10;
	if (v < 1) v = 1;
	if (v > 255) v = 255;
	Dot(x, y, v);
	return 1;
}
void SubDivide (int x1, int y1, int x2, int y2){
	if ((x2 - x1 < 2) && (y2 - y1 < 2)) return;
	int x = (x1 + x2) / 2;
	int y = (y1 + y2) / 2;
	Adjust(x1, y1, x, y1, x2, y1);
	Adjust(x1, y2, x, y2, x2, y2);
	Adjust(x2, y1, x2, y, x2, y2);
	Adjust(x1, y1, x1, y, x1, y2);
	if(PntClr(x, y) == 0)	{
		int v = PntClr(x1, y1) + PntClr(x2, y1) + PntClr(x2, y2);
		v = v + PntClr(x1, y2) + PntClr(x1, y) + PntClr(x, y1);
		v = v + PntClr(x2, y) + PntClr(x, y2);
		v = v / 8;
		Dot(x, y, v);
	}
	SubDivide(x1, y1, x, y);
	SubDivide(x, y, x2, y2);
	SubDivide(x, y1, x2, y);
	SubDivide(x1, y, x, y2);
}
void make_plasma(void){
	int i=0;
	for(i=0; i<game.display.width*game.display.height; i++)	{
		buff[i]=0;
	}
	srand(game.getTime());
	Dot(0, 0, RandMinMax(0,255) + 1);
	Dot(game.display.width-1, 0, RandMinMax(0,255) + 1);
	Dot(game.display.width-1, game.display.height-1, RandMinMax(0,255) + 1);
	Dot(0, game.display.height-1, RandMinMax(0,255) + 1);
	SubDivide(0, 0, game.display.width-1, game.display.height-1);
}
void make_pal(void){
	int a,s,r,g,b;
	for(a=0; a<=63; a++){
		s = 0; 	r = a; 		g = 63-a;	b = 0;		pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
		s = 64; r = 63-a;	g = 0;		b = a; 		pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
		s = 128; r = 0;	 	g = 0;		b = 63-a;	pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
		s = 192; r = 0;		g = a;		b = 0;	 	pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
	}
}

int main(){
	game.begin();
	game.display.persistence=1;
	game.display.width = 220; // full size
	game.display.height = 174;
	game.setFrameRate(20); // doesn't matter what this is, speed isn't an issue with this demo
	make_pal();
    make_plasma();

    int colNum = 0;

    while (game.isRunning()) {
        if (game.update()) {
            for(int y=0; y<game.display.height; y+=1){
                for(int x=0; x<game.display.width; x+=1){
                    game.display.directPixel(x,y,pal[(colNum+buff[x+220*y])&255]);
                }
            }
            colNum+=2;
            colNum&=255;
        }
    }
    return 1;
}
2 Likes

Flickering is simply caused by empty screen buffer being drawn on screen at each game.update

the following will give you correct behavior:

#include "Pokitto.h"


Pokitto::Core game;

unsigned short pal[256];
char buff[220*174];
int PntClr(int x, int y){
	return buff[x+game.display.width*y];
}
void Dot (int x, int y, int c){
    // create a buffer for the screen image
	buff[x+game.display.width*y]=c;
}
int RandMinMax(int min, int max){
    return rand() % max + min;
}
int Adjust (int xa, int ya, int x, int y, int xb, int yb){
	if(PntClr(x, y) != 0) return 0;
	int q = abs(xa - xb) + abs(ya - yb);
	int v = (PntClr(xa, ya) + PntClr(xb, yb)) / 2 + (RandMinMax(0,q*10)) / 10;
	if (v < 1) v = 1;
	if (v > 255) v = 255;
	Dot(x, y, v);
	return 1;
}
void SubDivide (int x1, int y1, int x2, int y2){
	if ((x2 - x1 < 2) && (y2 - y1 < 2)) return;
	int x = (x1 + x2) / 2;
	int y = (y1 + y2) / 2;
	Adjust(x1, y1, x, y1, x2, y1);
	Adjust(x1, y2, x, y2, x2, y2);
	Adjust(x2, y1, x2, y, x2, y2);
	Adjust(x1, y1, x1, y, x1, y2);
	if(PntClr(x, y) == 0)	{
		int v = PntClr(x1, y1) + PntClr(x2, y1) + PntClr(x2, y2);
		v = v + PntClr(x1, y2) + PntClr(x1, y) + PntClr(x, y1);
		v = v + PntClr(x2, y) + PntClr(x, y2);
		v = v / 8;
		Dot(x, y, v);
	}
	SubDivide(x1, y1, x, y);
	SubDivide(x, y, x2, y2);
	SubDivide(x, y1, x2, y);
	SubDivide(x1, y, x, y2);
}
void make_plasma(void){
	int i=0;
	for(i=0; i<game.display.width*game.display.height; i++)	{
		buff[i]=0;
	}
	srand(game.getTime());
	Dot(0, 0, RandMinMax(0,255) + 1);
	Dot(game.display.width-1, 0, RandMinMax(0,255) + 1);
	Dot(game.display.width-1, game.display.height-1, RandMinMax(0,255) + 1);
	Dot(0, game.display.height-1, RandMinMax(0,255) + 1);
	SubDivide(0, 0, game.display.width-1, game.display.height-1);
}
void make_pal(void){
	int a,s,r,g,b;
	for(a=0; a<=63; a++){
		s = 0; 	r = a; 		g = 63-a;	b = 0;		pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
		s = 64; r = 63-a;	g = 0;		b = a; 		pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
		s = 128; r = 0;	 	g = 0;		b = 63-a;	pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
		s = 192; r = 0;		g = a;		b = 0;	 	pal[a+s] = game.display.RGBto565(r*4,g*4,b*4);
	}
}
int main(){
	game.begin();
	game.display.persistence=1;
	game.display.width = 220; // full size
	game.display.height = 174;
	game.setFrameRate(20); // doesn't matter what this is, speed isn't an issue with this demo
	make_pal();
    make_plasma();
    int colNum = 0;

while (game.isRunning()) {
    //if (game.update()) {
        for(int y=0; y<game.display.height; y+=1){
            for(int x=0; x<game.display.width; x+=1){
                game.display.directPixel(x,y,pal[(colNum+buff[x+220*y])&255]);
            }

        }
        colNum+=2;
        colNum&=255;
        simulator.refreshDisplay();
    //}
 
}
return 1;
}

edit: lets put it here so others can see

ps. making Pokitto hardware so that you will not easily run out of things to try was one of my main goals. Yes, its more complicated to explain but I wanted to make something that allows you to discover new hardware tweaks for a long time.

2 Likes

Hereā€™s Jetpac by @trelemar

Does it compile? First try, zero change in code
Does it run? Smooth as butter

2 Likes

Way smoother than I ever expected. I will finish this eventually. Too many projects!

Thank you for showing on real hardware :smiley:

Time to go particle crazy like my original and really push the Pokitto :slight_smile:

@spinal here you go

had to decrease plasma buffer resolution (memory)

glitches you see are caused by me trying to optimize the addressing. laptop ran out of battery, so I am leaving it here for now.

but runs? full color? hell yeah

2 Likes

theres a decent bit of recursion going on there, impressive
anyone looking at porting this pico-8 3D library thing

and: its drawing pixel by pixel, each addressing is called separately. could be optimized much, much more

Does pokitto have some sort of ā€˜windowā€™ command for the screen, so that a stream of pixels would only take up a specific space?

The LCD does indeed have such a command on LCD driver level. However the window is not implemented in the Simulator.

What are you thinking about?

i can see a couple of neat tricks you can do with those screen sectors
like a minimap or lowres 16 color game with a hires text bar