Chara pixelcroft in the shrine of dusty artifacts

need some help with collision + physics
for platfrormer
code so far works on hardware

#include "Pokitto.h"
#include "sprites.h"
Pokitto::Core game;
bool checkcheck(short x, short y,short w, short h){
    short t =((short)(-y+w)/16)*8 +(short)((short)((-x+h)/16)/2);
    if(((short)((-x+h)/16))%2 ==1){
        if(level[t+3]>>4 == 15) return 0;
    }
    else{
       if(((uint8_t)(level[t+2]<<4))>>4 == 15)  return 0;
    }
    return 1;
}
bool collcheck(short x, short y){
    if(checkcheck(-x,-y,55,59)){
        return 0;
    }
    if(checkcheck(-x,-y,55,49)){
        return 0;
    }
    if(checkcheck(-x,-y,39,59)){
        return 0;
    }
    if(checkcheck(-x,-y,39,49)){
        return 0;
    }
    if(checkcheck(-x,-y,33,59)){
        return 0;
    }
    if(checkcheck(-x,-y,33,49)){
        return 0;
    }
    return 1;
}
void DrawLevel(short x, short y){
   game.display.drawRectangle((short)((-x+59)/16)*16+x,((short)(-y+55)/16)*16+y,16,16);
   game.display.drawRectangle((short)((-x+49)/16)*16+x,((short)(-y+55)/16)*16+y,16,16);
   game.display.drawRectangle((short)((-x+59)/16)*16+x,((short)(-y+39)/16)*16+y,16,16);
   game.display.drawRectangle((short)((-x+49)/16)*16+x,((short)(-y+39)/16)*16+y,16,16);
   game.display.drawRectangle((short)((-x+59)/16)*16+x,((short)(-y+33)/16)*16+y,16,16);
   game.display.drawRectangle((short)((-x+49)/16)*16+x,((short)(-y+33)/16)*16+y,16,16);
    char width = level[0];
    char w2 = width/2;
    char tileSize = 16;
    char ts2 = tileSize*2;
    for(int i = 0; i < width*(level[1]/2); i++){
        if ((level[i+2]>>4) <2){
            game.display.drawBitmap(((i%w2)*ts2)-tileSize+x,(((int)i/w2)*tileSize)+y,rock[(level[i+2]>>4)]);
        }
        if (((uint8_t)(level[i+2]<<4))>>4 <2){
            game.display.drawBitmap(((i%w2)*ts2)+x,(((int)i/w2)*tileSize)+y,rock[((uint8_t)(level[i+2]<<4))>>4]);
        }
    }
}

int main () {
game.begin();
game.display.bgcolor=11;
short x = 50;
short y = 184;
float vy = 0;
char frame = 0;
short speed = 4;
float maxspeed = 6;

short gravity = 0;
bool floor = true;

bool derection = false;
game.display.load565Palette(pallet);
while (game.isRunning()) {

     if (game.buttons.pressed(BTN_A) && collcheck(x,y-(30/5))==1 && floor){
            vy=30;
            floor = false;
    }

    if (game.update()) {

        if(vy > 0){
            if (collcheck(x,y-(vy/5))==1){
                y-=vy/5;
                vy-=2;
            }else vy=0;
        }
        else if(y < 184){
            bool looptest = true;
            while(looptest){
                if (collcheck(x,y+gravity)==1){
                    y+=gravity;
                    gravity++;
                    looptest = false;
                }
                else if(gravity>1){
                    gravity-=1;
                }
                else{
                    floor = true;
                    looptest = false;
                }
            }
        }
        if(collcheck(x,y+gravity)==0){floor = true;}

         if (game.buttons.repeat(BTN_LEFT,0)){
            bool looptest = true;
            while(looptest){
                if (collcheck(x-speed,y)==1){
                    x-=speed;
                    looptest = false;
                }else{
                    speed --;
                }
            }
            speed = 4;
            derection = false;
            //if(x%4==0){
            frame++;
            frame=frame%6;
            //}
        }
        else if (game.buttons.repeat(BTN_RIGHT,0)){
            bool looptest = true;
            while(looptest){
                if (collcheck(x+speed,y)==1){
                    x+=speed;

                 looptest = false;
                }else{
                    speed --;
                }
            }
            derection = true;
            //if(x%4==0){
            frame++;
            frame=frame%6;
           // }
        } else frame = 0;


        DrawLevel(-x,-y);
        game.display.setInvisibleColor(14);
        game.display.drawBitmap(55-7,44-13,sprite[frame],0,derection);
        game.display.bgcolor =2;
        game.display.print("hi");
    }

}

return 1;
}


sprites.h

//sprite
const unsigned short pallet[]={
0xb07,
0x44a,
0x6506,
0x8668,
0x0,
0x210,
0x4439,
0x7ddf,
0x72c7,
0xcc68,
0xfeb2,
0xfd42,
0xf720,
0xacd0,
0xca30,
0xffff,
};

//sprite
const uint8_t sprite[][366]={{14, 26, /*width, height*/
0xee,0xee,0xe8,0x88,0x88,0xee,0xee,
0xee,0xee,0x8d,0xd8,0xdd,0x8e,0xee,
0xee,0xe8,0x88,0x88,0x88,0xd8,0xee,
0xee,0x8d,0xcc,0xbb,0x8d,0xc8,0xee,
0xee,0xd8,0xaa,0xa9,0x8d,0x88,0xee,
0xee,0x84,0x4a,0x44,0x88,0xd8,0xee,
0xee,0xd8,0x5a,0x5f,0x88,0xd8,0xee,
0xee,0xe8,0x4a,0x4f,0xa8,0x88,0xee,
0xee,0xe8,0xaa,0xaa,0x98,0x8e,0x8e,
0xee,0x8e,0xe1,0xa9,0x1e,0x8e,0xee,
0xee,0xea,0xa1,0x31,0x3a,0xa8,0xee,
0xee,0xe9,0x33,0x33,0x39,0xae,0xee,
0xee,0xee,0x33,0x33,0x10,0xaa,0xee,
0xee,0xee,0xa3,0x31,0x0e,0x9a,0xee,
0xee,0xea,0x91,0x11,0x0e,0xea,0xae,
0xee,0xe9,0xac,0xb4,0x4e,0xe9,0xae,
0xee,0xee,0x48,0x48,0x84,0x9a,0xae,
0xee,0xee,0x48,0x44,0x84,0xea,0x9e,
0xee,0xee,0x88,0x84,0x88,0xee,0xee,
0xee,0xee,0xaa,0x9a,0xaa,0xee,0xee,
0xee,0xee,0xaa,0x9a,0xaa,0xee,0xee,
0xee,0xee,0x99,0xae,0xa9,0x9e,0xee,
0xee,0xee,0xaa,0xae,0xaa,0xae,0xee,
0xee,0xee,0x44,0xae,0xa4,0x4e,0xee,
0xee,0xee,0x44,0x4e,0x44,0x4e,0xee,
0xee,0xe8,0x88,0x4e,0x48,0x8e,0xee,
},
{14, 26, /*width, height*/
0xee,0xee,0xe8,0x88,0x88,0xee,0xee,
0xee,0xee,0x8d,0xd8,0xdd,0x8e,0xee,
0xee,0xe8,0x88,0x88,0x88,0xd8,0xee,
0xee,0x8d,0xcc,0xbb,0x8d,0xc8,0xee,
0xee,0xd8,0xaa,0xa9,0x8d,0x88,0xee,
0xee,0x84,0x4a,0x44,0x88,0xd8,0xee,
0xee,0xd8,0x5a,0x5f,0x88,0xd8,0xee,
0xee,0xe8,0x4a,0x4f,0xa8,0x88,0xee,
0xee,0xe8,0xaa,0xaa,0x98,0x8e,0x8e,
0xee,0x8e,0xe1,0xa9,0x1e,0x8e,0xee,
0xee,0xea,0xa1,0x33,0x1e,0xe8,0xee,
0xae,0xea,0x93,0x33,0x31,0xee,0xee,
0x9a,0xe9,0x33,0x33,0x3a,0xae,0xee,
0xaa,0xaa,0x33,0x33,0x19,0xaa,0xee,
0xe9,0xaa,0xe1,0x11,0x0e,0x9a,0xae,
0xee,0xee,0xe1,0x11,0x0e,0xe9,0x9a,
0xee,0xee,0xec,0xb4,0x44,0xee,0x9a,
0xee,0xee,0x44,0x88,0x84,0xee,0xee,
0xee,0xee,0x48,0xaa,0x84,0xee,0xee,
0xee,0xee,0x8a,0xaa,0x98,0xee,0xee,
0xee,0xee,0x9a,0xa9,0xee,0xee,0xee,
0xee,0xee,0xea,0xa9,0xae,0xee,0xee,
0xee,0xee,0xe4,0x44,0xae,0xee,0xee,
0xee,0xee,0xe4,0x44,0x44,0xee,0xee,
0xee,0xee,0xe8,0x84,0x44,0xee,0xee,
0xee,0xee,0xee,0xe8,0x88,0xee,0xee,
},
{14, 26, /*width, height*/
0xee,0xee,0xee,0xee,0xee,0xee,0xee,
0xee,0xee,0xe8,0x88,0x88,0xee,0xee,
0xee,0xee,0x8d,0xd8,0xdd,0x8e,0xee,
0xee,0xe8,0x88,0x88,0x88,0xd8,0xee,
0xee,0x8d,0xcc,0xbb,0x8d,0xc8,0xee,
0xee,0xd8,0xaa,0xa9,0x8d,0x88,0xee,
0xee,0x84,0x4a,0x44,0x88,0xd8,0xee,
0xee,0xd8,0x5a,0x5f,0x88,0xd8,0xee,
0xee,0xe8,0x4a,0x4f,0xa8,0x88,0x8e,
0xee,0x88,0xaa,0xaa,0x98,0x8e,0xee,
0xee,0xee,0xe1,0xa9,0x1e,0x88,0xee,
0xea,0xa9,0x91,0x31,0x3a,0xaa,0xee,
0xea,0x9a,0x33,0x33,0x39,0xaa,0xae,
0xea,0x9a,0x33,0x33,0x10,0xe9,0xae,
0xe9,0xa9,0xe3,0x31,0x0e,0xee,0xaa,
0xee,0xee,0xe1,0x11,0x0e,0xee,0x9a,
0xee,0xee,0xec,0xb4,0x4e,0xee,0xee,
0xee,0xee,0x48,0x48,0x84,0xee,0xee,
0xee,0xee,0x48,0x8a,0x84,0xee,0xee,
0xee,0xee,0x49,0x9a,0x94,0xee,0xee,
0xee,0xee,0xe9,0xaa,0x9e,0xee,0xee,
0xee,0xee,0xea,0xa9,0xaa,0xee,0xee,
0xee,0xee,0x4a,0x9e,0x9a,0xae,0xee,
0xee,0xe4,0x44,0xee,0xe4,0x44,0xee,
0xee,0x84,0x44,0xee,0xee,0x44,0x4e,
0xee,0xe8,0x8e,0xee,0xee,0x88,0x8e,
},
{14, 26, /*width, height*/
0xee,0xee,0xee,0xee,0xee,0xee,0xee,
0xee,0xee,0xe8,0x88,0x88,0xee,0xee,
0xee,0xee,0x8d,0xd8,0xdd,0x8e,0xee,
0xee,0xe8,0x88,0x88,0x88,0xd8,0xee,
0xee,0x8d,0xcc,0xbb,0x8d,0xc8,0xee,
0xee,0xd8,0xaa,0xa9,0x8d,0x88,0xee,
0xee,0x84,0x4a,0x44,0x88,0xd8,0xee,
0xee,0xd8,0x5a,0x5f,0x88,0xd8,0xee,
0xee,0xe8,0x4a,0x4f,0xa8,0x88,0xee,
0xee,0xe8,0xaa,0xaa,0x98,0x8e,0x8e,
0xee,0x8a,0x91,0xa9,0x1a,0x8e,0xee,
0xee,0xe9,0x33,0x33,0x39,0xa8,0xee,
0xee,0xee,0x33,0x33,0x10,0xaa,0xee,
0xee,0xee,0xa3,0x31,0x0e,0x9a,0xee,
0xee,0xea,0x91,0x11,0x0e,0xea,0xae,
0xee,0xe9,0xac,0xb4,0x4e,0xe9,0xae,
0xee,0xee,0x48,0x48,0x84,0x9a,0xae,
0xee,0xee,0x48,0x44,0x84,0xea,0x9e,
0xee,0xee,0x88,0x84,0x88,0xee,0xee,
0xee,0xee,0xaa,0x9a,0xaa,0xee,0xee,
0xee,0xee,0xaa,0x9a,0xaa,0xee,0xee,
0xee,0xee,0xaa,0x99,0x9a,0xee,0xee,
0xee,0xee,0xe9,0x9a,0xaa,0x8e,0xee,
0xee,0xee,0xee,0x94,0x4a,0x8e,0xee,
0xee,0xee,0xee,0xe4,0x44,0x8e,0xee,
0xee,0xee,0xee,0x88,0x88,0xee,0xee,
},
{14, 26, /*width, height*/
0xee,0xee,0xe8,0x88,0x88,0xee,0xee,
0xee,0xee,0x8d,0xd8,0xdd,0x8e,0xee,
0xee,0xe8,0x88,0x88,0x88,0xd8,0xee,
0xee,0x8d,0xcc,0xbb,0x8d,0xc8,0xee,
0xee,0xd8,0xaa,0xa9,0x8d,0x88,0xee,
0xee,0x84,0x4a,0x44,0x88,0xd8,0xee,
0xee,0xd8,0x5a,0x5f,0x88,0xd8,0xee,
0xee,0xe8,0x4a,0x4f,0xa8,0x88,0xee,
0xee,0xe8,0xaa,0xaa,0x98,0x8e,0x8e,
0xee,0x8e,0xe1,0xa9,0x1e,0x8e,0xee,
0xee,0xea,0xa1,0x31,0x3a,0xa8,0xee,
0xee,0xe9,0x33,0x33,0x39,0xae,0xee,
0xee,0xee,0x33,0x33,0x1a,0xae,0xee,
0xee,0xee,0x93,0x31,0x0a,0xae,0xee,
0xee,0xee,0xe1,0x19,0xaa,0x9e,0xee,
0xee,0xee,0xec,0x9a,0xa9,0xee,0xee,
0xee,0xee,0x48,0x49,0x94,0xee,0xee,
0xee,0xee,0x48,0x84,0x84,0xee,0xee,
0xee,0xee,0x99,0x84,0x88,0xee,0xee,
0xee,0xee,0xaa,0x9a,0xaa,0xee,0xee,
0xee,0xea,0xaa,0x99,0xaa,0xee,0xee,
0xee,0xea,0xa9,0xee,0x9a,0xae,0xee,
0xee,0x44,0x9e,0xee,0x9a,0xae,0xee,
0xee,0x84,0x4e,0xee,0x94,0x4e,0xee,
0xee,0xe8,0x8e,0xee,0x44,0x4e,0xee,
0xee,0xee,0xee,0xee,0x88,0x8e,0xee,
},
{14, 26, /*width, height*/
0xee,0xee,0xee,0xee,0xee,0xee,0xee,
0xee,0xee,0xe8,0x88,0x88,0xee,0xee,
0xee,0xee,0x8d,0xd8,0xdd,0x8e,0xee,
0xee,0xe8,0x88,0x88,0x88,0xd8,0xee,
0xee,0x8d,0xcc,0xbb,0x8d,0xc8,0xee,
0xee,0xd8,0xaa,0xa9,0x8d,0x88,0xee,
0xee,0x84,0x4a,0x44,0x88,0xd8,0xee,
0xee,0xd8,0x5a,0x5f,0x88,0xd8,0xee,
0xee,0xe8,0x4a,0x4f,0xa8,0x88,0x8e,
0xee,0x88,0xaa,0xaa,0x98,0x8e,0xee,
0xee,0xee,0xe1,0xa9,0x1e,0x88,0xee,
0xee,0xee,0x93,0x33,0x39,0xae,0xee,
0xee,0xee,0x39,0xa3,0x9a,0xae,0xee,
0xee,0xee,0x3a,0x9a,0xaa,0xee,0xee,
0xee,0xee,0x91,0xa9,0x9a,0xee,0xee,
0xee,0xee,0xe1,0x11,0x0e,0xee,0xee,
0xee,0xee,0xec,0xb4,0x4e,0xee,0xee,
0xee,0xee,0x48,0x48,0x84,0xee,0xee,
0xee,0xee,0x48,0x84,0x84,0xee,0xee,
0xee,0xee,0x49,0x4a,0x94,0xee,0xee,
0xee,0xee,0xaa,0x8a,0xae,0xee,0xee,
0xee,0xee,0xaa,0x99,0xaa,0xee,0xee,
0xee,0xe4,0xa9,0xee,0x99,0xae,0xee,
0xee,0x44,0x4e,0xee,0xe4,0x44,0xee,
0xe8,0x44,0x4e,0xee,0xee,0x44,0x4e,
0xee,0x88,0xee,0xee,0xee,0x88,0x8e,
}
};
const uint8_t rock[][146]={{16, 16, //18/*width, height*/
0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,
0x77,0x77,0x65,0x67,0x77,0x77,0x77,0x64,
0x77,0x77,0x76,0x77,0x77,0x77,0x77,0x75,
0x67,0x77,0x76,0x77,0x77,0x67,0x77,0x75,
0x66,0x67,0x66,0x77,0x76,0x76,0x77,0x65,
0x56,0x66,0x66,0x67,0x77,0x77,0x66,0x65,
0x55,0x66,0x65,0x66,0x66,0x66,0x66,0x65,
0x55,0x55,0x55,0x66,0x66,0x66,0x66,0x54,
0x66,0x66,0x54,0x56,0x66,0x66,0x54,0x66,
0x56,0x66,0x65,0x45,0x66,0x64,0x46,0x66,
0x65,0x66,0x55,0x54,0x54,0x45,0x55,0x65,
0x66,0x55,0x55,0x54,0x44,0x55,0x55,0x56,
0x55,0x55,0x55,0x45,0x54,0x45,0x55,0x55,
0x55,0x55,0x44,0x55,0x55,0x44,0x45,0x55,
0x44,0x44,0x44,0x55,0x55,0x54,0x44,0x44,
0x56,0x44,0x44,0x45,0x55,0x54,0x44,0x44,
0x55,0x54,0x44,0x44,0x44,0x44,0x44,0x44,
0x44,0x44,0x44,0x44,0x44,0x44,0x45,0x44,
},{16, 18, /*width, height*/
0xee,0x11,0xee,0xee,0xee,0xee,0xee,0x11,
0x1e,0xe1,0x11,0xee,0xee,0xee,0x11,0x11,
0x1e,0xe1,0x00,0x11,0xee,0x11,0x11,0x01,
0x11,0xee,0x10,0x00,0x11,0xe1,0x10,0x1e,
0x01,0x11,0x10,0x10,0x00,0x11,0x01,0x1e,
0x10,0x11,0xe1,0x00,0x00,0x01,0x11,0xee,
0xee,0x01,0x10,0x10,0x10,0x00,0x01,0x11,
0x11,0x10,0x00,0x00,0x11,0x01,0x10,0x00,
0x10,0x01,0x10,0x01,0x11,0x10,0x01,0x00,
0x00,0x00,0x0e,0x01,0x11,0x10,0x00,0x11,
0x01,0x00,0x00,0xe0,0x01,0x11,0x00,0x00,
0x00,0x11,0x10,0xee,0x00,0x01,0x10,0x00,
0x00,0x00,0x01,0x01,0xe0,0x00,0x01,0x00,
0x10,0x00,0x10,0x00,0x11,0x10,0x00,0x11,
0x01,0x01,0x10,0x00,0x00,0x01,0x00,0x00,
0x00,0x01,0xe1,0x11,0x11,0x00,0x00,0x00,
0x10,0x01,0xee,0xee,0xe1,0x00,0x10,0x10,
0xe1,0x1e,0xee,0xee,0xe1,0x11,0xe1,0xe1,
}};
const uint8_t level[]={16, 16, /*width, height*/
0xf1,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
0xf1,0xf1,0xf1,0xf1,0xf1,0xf1,0xf1,0xf1,
0xf1,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,
0xf1,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,
0xf1,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,
0xf1,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,
0xf1,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,
0xf1,0xff,0xff,0xff,0xf1,0xff,0xff,0xf0,
0xf1,0xff,0xff,0xff,0xff,0x1f,0xff,0xf0,
0xf0,0x11,0x1f,0xff,0xff,0xff,0xff,0xf0,
0xf0,0xff,0xff,0xff,0xff,0xff,0xf0,0x00,
0xf0,0xff,0xff,0xff,0xff,0xff,0x11,0xf0,
0xf0,0xff,0xff,0x11,0x11,0xff,0xff,0xf0,
0xf1,0xff,0xff,0xff,0xff,0x1f,0xff,0xf0,
0xf0,0x00,0xff,0xff,0xff,0xf1,0xff,0xf0,
0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};


3 Likes

Are you making binaries already?

yea it work alright
platfrom-test.bin (28.0 KB)

have a couple iseus with the lagecy code of the other games, would like to see if theres any new generated documentation

Can you make little introduction to physics library? It can be really useful.

pretty sure there is no physics library atm

I think there is a physics lib

1 Like

here this might be helpfull, though the way im doing is specific for platformers

I hope this doesn’t sound rude, but are you new-ish to programming and/or C++?

uhm i wrote 4BS sprite/pallet converter for png, tga, bmp, psd
and the tutorials so far
have like 5 years in lua and seen 10 other languages
i have a only a year of education c/c++ in school but my main problem is mathematics and algebra
@Pharap why you ask?

1 Like

I have no educational background for programming and I am using C for nearly 1 year. I am still beginner in programming and English. Sometimes it’s hard to understand English for me. Because we have one of the worst educational system in the world. I’m trying to improve my skills :slight_smile:

2 Likes

yea tell me about it, second language is french in my education system.
wow we are getting of topic here.

2 Likes

Partly a lack of structs/classes, partly because your code is a bit hard to follow
e.g. one or two really long lines, several long/complex expressions, various bits of repetition, using (-x + 59 instead of the equivalent 59 - x, returning 0 and 1 instead of false and true several other things.

Might just be because it’s a draft or because of stylistic difference/preference. If Lua is the only language you have significant experience with that would sort of explain the lack of classes, as would being new to C and C++.

Lua’s a nice language, I learnt Lua to use with ComputerCraft (a Minecraft mod) a few years back. It’s still my favourite scripting language (unless you count C#, but I’ve only seen that used for scripting once).

I meant @adekto :P.
That’s good to know though.

I’m a pretty strong believer in self-education (i.e. learning from internet tutorials and articles), so do not worry about not learning programming at school.

Most of my programming knowledge comes from the internet and practise, my college wasn’t the best for teaching programming.

I had to learn both French and German despite telling them I only wanted to learn French. I don’t know either well enough to hold a conversation but still got a ‘C’ in both.


While we’re at it I may as well say what my background is.

I’ve been programming for about 4-5 years now.
I have varying levels of experience with roughly 10 different languages.
(C# and C++ are my main two, the ones I like most as well as the ones I use most.)

85% to 95% of my programming knowledge has been learned from the internet, lots of practise and occaisionally a book or two.

My college didn’t really teach me that much about programming, the internet was a much better teacher.

1 Like

Oh yea im getting the hang off classes, though my lua natior I usualy put it in a struct (i know i know there basically the same just reverse priorities)

And yes its cuz im live coding it till something works fast fixes add a - here ad a constant value there

I don’t really plan qnd witout knowing what has to happen i dont think about semantics or clean code or even optimized code

Speaking of heavy use of classes I wonder how that compiles and inpacts speed. I was looking at parts of the library and some functions just call another function in another class

natior?

Fair enough.

Personally I try to avoid doing that, I prefer working on the problem first (often on paper) and then writing code afterwards.

C++ is very good for size and speed.

E.g. something like:

struct Vector
{
    int x, y;

    Vector(void) = default;
    Vector(const int & x, const int & y) : x(x), y(y) {}
};
Vector operator +(const Vector & left, const Vector & right)
{
    return Vector(left.x + right.x, left.y + right.y);
}

void main(void)
{
  Vector a = Vector(5, 6);
  Vector b = Vector(6, 7);
  Vector c = a + b;
}

Usually* compiles to the same code as

void main(void)
{
  int ax = 5; int ay = 6;
  int bx = 6; int by = 7;
  int cx = ax + bx; int cy = ay + by;
}

C++ being heavier/slower than C is a myth that was once true when C++'s compilers were young and inexperienced and C’s compilers had a few years of experience behind them, but nowadays two equivalent pieces of code in C and C++ are equal.

Generally C++ does produce small, fast code. There are features that will increase code size and make things run slower (e.g. using virtual functions, using exceptions, using dynamic memory) but those are generally easy to avoid or reduce, and doing the equivalent in C would have the same impact.

In modern C++ it’s even easier because you can do things like specify the size of enums and mark functions as constexpr which indicates to the compiler that it should try to evaluate the variable/function at compile time if possible (failing that there’s the template meta-programming approach which isn’t particularly friendly but gets the job done).

In C++ things are usually* very vigorously inlined, so that would usually compile as if the inner function was being called itself.


* I say “usually” because there are arcane reasons why these might not happen in some circumstances, but with the Pokitto they’re unlikely. Such circumstances include badly made compilers that don’t do thorough optimisations or certain circumstances where it can’t be optimised for some reason, e.g. a call to a function in a .dll (or .so if you’re on Linux) can’t usually be inlined.

1 Like

I have a question about the ledge climbing mentioned a few posts back. One thing that’s not clear to me is how the ledge climbing might look from an animation perspective. I feel like that might influence how it would be implemented. For example, perhaps she would put her arms on the ledge when you are at a certain height, and then clamber on, or perhaps vault herself up so you would sort of leap onto the ledge. Would you lock on to it or sort of bounce up on it?

I am interested in collaborating on making a platforming engine, but I’m not sure my personal preferences would be the best for designing the overall framework. I have been using mostly the C subset of C++ for my personal projects on the Gamebuino and Pokitto. I have plenty of experience with objects, but I think I have been enjoying writing things closer to how they actually assemble among other reasons. Anyway, I think that most people here would prefer to use classes.

1 Like

The easiest way would definitely be the old fashioned ‘jump above the platform and land on it on the way back down’.
In that case you could get away with a simple raycast downwards to detect a platform below the character.

I found a few examples online (but I didn’t like them because they were for Unity :P).
Here’s a nice image pair that summarises the idea:


Taken from this blog.

A proper gripping animation would be possible but more difficult because then you have to consider being under and close to the platform as well. You could probably get away with another raycast, but then the logic for holding the character in place while the ‘pull up’ animation plays would be a bit fiddly because it means interrupting/suspending all the other physics stuff.


Personally I do prefer C++ style with classes that knit together well.

I’ve used high level languages like C# and Lua, and I’ve gone as low as inline assembly.
Higher level stuff might not seem as ‘hackerish’ or ‘old school’, but in my opinion it’s better for productivity and understanding (assuming you understand the features of course).

For example, in C++ you can define your own operators.
I find it much nicer when adding two things to be able to write a + b instead of the C-style thingAdd(a, b).
Also I find that list.add(object) is much easier to read/understand than the C-style listAdd(list, object) - in the former it’s clear that the object is being added to the list because of the syntax, in the latter it’s a matter of convention.

i asume you meant this[quote=“wuuff, post:64, topic:164”]
I have a question about the ledge climbing mentioned a few posts back
[/quote]

i think its mostly an in animation to climb it an then at some frame jump up tiles to keep sprite size to a minimum

@Pharap if your interested in writing this or helping out, your very much welcome to try
@wuuff please by all means join up i prefer the none classes style aswel since its easer to explain, this game is just a sample for the engine wich can and should be used for more then one game, main thing is loading more levels and sprites from sd card still

I’d gladly offer advice here and there (especially about C++ features, error messages, theory or problem solving), but I wouldn’t be ready to go full time just yet, I’m still recovering from my last project (which took 2-3 months on and off).
I also haven’t got round to collecting my Pokitto from the recipient yet, and I’m waiting on a tutorial on how to use the offline IDE.

@Pharap Does you Fixed Point library work on Pokitto? That would be essential in games as floats are too slow.

1 Like

I am planning to release it for Pokitto (sort of).

In fact I’m intending to release a ‘general’ version (which was originally slated to be released alongside the Arduino version) which should compile for all systems.

At the moment the biggest issue that’s stopping me from releasing it is the random function which I need to decide to either solve or to remove it completely.

I’ve been on hiatus from working on the library for the last week or so because 2-3 months of on and off working on it was tiring and I was worried I’d start to hate looking at it if I didn’t take a break :P.
I’ll probably pick it up again in a week or so.

If you’re interested and want to know more about the library (how it works, the history of it, decisions made, the issue with random numbers etc) don’t hesitate to ask, I’d be more than happy to bore you with the details.

One small note:
As the issue on Github notes, there aren’t any benchmarks at the moment.
That’s something I need to get round to.
It’s a hard thing to test because of the nature of fixed points - they have a limited range of values.