[OBSOLETE Tutorial][Advanced]3.Simultaneous development in PokittoLib & PokittoSim

Repository directory structure explained below:

Hello all

I have begun merging the PokittoLib and PokittoSim codebases.

PokittoLib git repository now has BOTH TOOLCHAINS (EmBitz and Code::Blocks) in the same repo

This means same Example/HelloWorld can be compiled to Windows target / Pokitto Binary

  • more examples, games, sound demos coming
  • Linux targets will be added

HARDWARE

Open EmBitz project file (.ebp) in EmBitz to generate Pokitto binary file

WINDOWS SIMULATION
Open Code::Blocks project file (Pokitto_sim.cbp) under Pokitto/POKITTO_SIM in Code::Blocks to make Windows Sim target

LINUX SIMULATION

Open Code::Blocks project file (Pokitto_sim_linux.cbp) under Pokitto/POKITTO_SIM in Code::Blocks to make Linux Sim target

… that’s it!

7 Likes

@jonne I´ve downloaded the new Sim/Lib but it seems there are many example sounds and so on in the POKITTO_SIM/bin/debug folder. I had expected a pokittosim.exe there, not so many other stuff. Is it still WIP or is this the final version?

2 Likes

I think i forgot to clean it. I will check

2 Likes

Some feedback:

  • SDL2 is missing from the repo
  • There’s a reference to CopyPageToFlash in PokittoCore.cpp that can’t be compiled

Question: Can I put a My_settings.h for each of my project? Is this the best way to share settings in both Embitz and Code::Blocks? No more #define tab in project build options form?

3 Likes

I will take a look. Basically you can comment out the code thats giving errors in the sim like this:

#ifndef POK_SIM
(Hardware related code)
#endif

As for the My_settings, the advantage vs. project build settings #defines is that the same system will work in the mbed online IDE

1 Like

Fixed

Fixed

3 Likes

Am I missing something or is SDL2 still not in the project?

1 Like

Augh.

I will fix that.

1 Like

@Zuzu36 Thanks! Its fixed now.

2 Likes

@jonne There´s still an error. Maybe it´s my fault?

1 Like

There was still 1 absolute search path defined. Fixed now. Try again please.

1 Like

It´s working now, but my Pong looks nicer before :stuck_out_tongue: Are there any changes in how the divice/simulator updates or how it loads the bitmaps & paletts?
(I could be really ANYTHING :fearful: )
EDIT:

Now nothing is working anymore. I just used the simulator.exe itself to start it and codeblocks has a problem now.
Please @jonne, help! :scream:

Please copy-paste your code here and i will help

use the </> (preformatted text) button in the forum text editor to insert code

Whhoooops. I will look at that

#include "pokitto.h"
#include "textures.h"

Pokitto::Core game;

void scorepoint(bool voidreset);
void endgame(bool voidreset2);

char status = 0;        //0=main-menu, 1=game, 2=settings, 3=about
char cursor = 0;
bool showdifficulty = 0;
bool showballmovement = 0;
char ballcolor = 0;         //0=default(changing), 1=orange, 2= yellow, 3= blue, 4=gray
char difficultysetting = 60;

float padplayer = 34;
float padcom = 34;
float ballx = 52;
float bally = 41;
float movex = 0;
float movey = 0;
short scoreplayer = 0;
short scorecom = 0;
char screenW = 110;
char screenH = 88;
char movecom = 0;
char moveplayer = 0;
short difficulty = 60;
bool gamestart = 0;
bool win = 0;

int main ()
{
    game.display.width = screenW;
    game.display.height = screenH;
    game.display.load565Palette(default36);
    game.setFrameRate(60);

    game.begin();

    while (game.isRunning())
    {
        if (game.update())
        {
            /*
            =====================MAINMENU======================
            */
            if (status == 0)
            {
                //______________LOGIC/CONTROL_______________
                if (cursor == 0)
                {
                    cursor = 30;
                }
                if (game.buttons.pressed(BTN_DOWN) && (cursor < 50))
                {
                    cursor += 10;
                }
                if (game.buttons.pressed(BTN_UP) && (cursor > 30))
                {
                    cursor -= 10;
                }
                if (game.buttons.released(BTN_A))
                {
                    status = ((cursor / 10) - 2);
                    cursor = 0;
                    endgame(1);
                }
                //_________________DISPLAY__________________
                game.display.drawBitmap(0,0,title);
                game.display.setCursor(20,30);
                game.display.print("Play");
                game.display.setCursor(20,40);
                game.display.print("Settings");
                game.display.setCursor(20,50);
                game.display.print("About");
                game.display.setCursor(90,80);
                game.display.print("1.0");

                game.display.setCursor(10,cursor);
                game.display.print(">");
            }
            /*
            =====================SETTINGS==========================
            */
            if (status == 2)
            {
                //__________________LOGIC/CONTROL____________________
                if (cursor == 0)
                {
                    cursor = 20;
                }
                if (game.buttons.pressed(BTN_DOWN) && (cursor < 60))
                {
                    if (cursor == 20) cursor += 20;
                    else cursor += 10;
                }
                if (game.buttons.pressed(BTN_UP) && (cursor > 20))
                {
                    if (cursor == 40) cursor -= 20;
                    else cursor -= 10;
                }
                if (game.buttons.pressed(BTN_B))
                {
                    status = 0;
                    cursor = 0;
                }
                if (game.buttons.pressed(BTN_LEFT))
                {
                    if (cursor == 20 && ballcolor > 0) ballcolor -= 1;
                    if (cursor == 40) showballmovement = 0;
                    if (cursor == 50) showdifficulty = 0;
                    if (cursor == 60 && difficultysetting < 80) difficultysetting += 10;
                }
                if (game.buttons.pressed(BTN_RIGHT))
                {
                    if (cursor == 20 && ballcolor < 4) ballcolor += 1;
                    if (cursor == 40) showballmovement = 1;
                    if (cursor == 50) showdifficulty = 1;
                    if (cursor == 60 && difficultysetting > 40) difficultysetting -= 10;
                }
                //_________________DISPLAY___________________
                game.display.setCursor(1,1);
                game.display.print("SETTINGS:");

                game.display.setCursor(15,20);
                game.display.print("Ball: ");
                if (ballcolor == 0)
                {
                    game.display.drawBitmap(50,21,ballgreen);
                    game.display.drawBitmap(58,21,ballred);
                }
                if (ballcolor == 1) game.display.drawBitmap(50,21,ballorange);
                if (ballcolor == 2) game.display.drawBitmap(50,21,ballyellow);
                if (ballcolor == 3) game.display.drawBitmap(50,21,ballblue);
                if (ballcolor == 4) game.display.drawBitmap(50,21,ballgray);
                game.display.setCursor(15,40);
                game.display.print("shwBllMvmnt: ");
                if (showballmovement == 0) game.display.print("off");
                if (showballmovement == 1) game.display.print("on");
                game.display.setCursor(15,50);
                game.display.print("shwDffclty: ");
                if (showdifficulty == 0) game.display.print("off");
                if (showdifficulty == 1) game.display.print("on");
                game.display.setCursor(15,60);
                game.display.print("strtDffclty: ");
                if (difficultysetting == 80) game.display.print("--");
                if (difficultysetting == 70) game.display.print("-");
                if (difficultysetting == 60) game.display.print("0");
                if (difficultysetting == 50) game.display.print("+");
                if (difficultysetting == 40) game.display.print("++");
                game.display.drawBitmap(2,76,backarrow);

                game.display.setCursor(5,cursor);
                game.display.print(">");
            }
            /*
            =========================ABOUT=========================
            */
            if (status == 3)
            {
                //________________LOGIC/CONTROL___________________
                if (game.buttons.pressed(BTN_B))
                {
                    status = 0;
                    cursor = 0;
                    endgame(1);
                }
                //____________________DISPLAY_____________________
                game.display.drawBitmap(2,2,paddlegreen);
                game.display.drawBitmap(13,2,paddlered);
                game.display.drawBitmap(24,2,ballgreen);
                game.display.drawBitmap(35,2,ballred);
                game.display.drawBitmap(46,2,ballorange);
                game.display.drawBitmap(57,2,ballyellow);
                game.display.drawBitmap(68,2,ballblue);
                game.display.drawBitmap(79,2,ballgray);

                game.display.setCursor(5,55);
                game.display.print("By: Zuzu36");
                game.display.setCursor(5,65);
                game.display.print("Made for Pokitto");
                game.display.drawBitmap(2,76,backarrow);
            }
            /*
            =========================GAME==========================
            */
            if (status == 1)
            {
                //_________________CONTROL___________________
                if (game.buttons.repeat(BTN_UP,0) && (padplayer > 0) && (gamestart == 1))
                {
                    padplayer -= 2;
                    moveplayer = -1;
                }
                else moveplayer = 0;
                if (game.buttons.repeat(BTN_DOWN,0) && (padplayer < 67) && (gamestart == 1))
                {
                    padplayer += 2;
                    moveplayer = 1;
                }
                else moveplayer = 0;
                if (game.buttons.pressed(BTN_A) && (gamestart == 0))
                {
                    if (win == 0)
                    {
                        movex = 3;
                    }
                    if (win == 1)
                    {
                        movex = -3;
                    }
                    gamestart = 1;
                }
                if (game.buttons.held(BTN_C,15))
                {
                    status = 0;
                    endgame(1);
                }
                //_________________LOGIC______________________
                if ((movecom > -2) && (movecom < 2))
                {
                    movecom = random(-2,2);
                }
                if ((difficulty == 10)||(difficulty == 100))
                {
                    endgame(1);
                }
                else difficulty = (difficultysetting - ((scoreplayer - scorecom)*2));
                //*******************GAMESTART****************
                if (gamestart == 1)
                {
                    ballx += movex;
                    bally += movey;
                    padcom += movecom;

                    if (movey == 0)
                    {
                        movey = random(-1,1);
                    }
                    //-----------------BALL------------------
                    if ((ballx - 1 <= 6) && ((bally + 6 >= padplayer) && (bally <= padplayer + 20)))
                    {
                        movex = 3;
                        movey += ((moveplayer / 2)+((bally - padplayer) / 20));
                    }
                    if ((ballx + 7 >= screenW - 6) && ((bally + 6>= padcom) && (bally <= padcom + 20)))
                    {
                        movex = -3;
                        movey += ((movecom / 4)+((bally -padcom) / 20));
                    }
                    if ((bally <= 0) || (bally + 6 >= 88))
                    {
                        movey *= -1;
                    }
                    //----------------SCORE-------------------
                    if (ballx <= 0)
                    {
                        scorecom += 1;
                        win = 0;
                        scorepoint(1);
                    }
                    if (ballx + 6 >= screenW)
                    {
                        scoreplayer += 1;
                        win = 1;
                        scorepoint(1);
                    }
                    if ((scoreplayer == 100) || (scorecom == 100))
                    {
                        endgame(1);
                    }
                    //-------------------COM------------------
                    if ((ballx > difficulty) && (movex > 0))
                    {
                        if (bally < padcom && padcom > 1)
                        {
                            movecom = -2;
                        }
                        if (bally + 6 > padcom + 20 && padcom + 20 < 86)
                        {
                            movecom = 2;
                        }
                    }
                    if (padcom - 1 <= 0)
                    {
                        movecom = 2;
                    }
                    if (padcom + 21 >= 86)
                    {
                        movecom = -2;
                    }
                }
                else
                {
                    game.display.setCursor(30,26);
                    game.display.print("Ready?");
                    game.display.drawBitmap(70,24,btna);
                }
                //_____________DRAW/PRINT/COLOR_______________
                if (showdifficulty == 1)
                {
                    game.display.setCursor(1,81);
                    game.display.print(difficulty);
                }
                if (showballmovement == 1)
                {
                    game.display.setCursor(1,1);
                    game.display.print(movey);
                }
                if (scoreplayer < 10) game.display.setCursor(43,5);
                else game.display.setCursor(37,5);
                game.display.print(scoreplayer);
                game.display.print(" - ");
                game.display.print(scorecom);
                game.display.drawBitmap(0,padplayer,paddlegreen);
                game.display.drawBitmap(screenW - 6,padcom,paddlered);

                if ((ballcolor == 0) && ((movex < 0) || ((win == 1) && (gamestart == 0)))) game.display.drawBitmap(ballx,bally,ballred);
                if ((ballcolor == 0) && ((movex > 0) || ((win == 0) && (gamestart == 0)))) game.display.drawBitmap(ballx,bally,ballgreen);
                if (ballcolor == 1) game.display.drawBitmap(ballx,bally,ballorange);
                if (ballcolor == 2) game.display.drawBitmap(ballx,bally,ballyellow);
                if (ballcolor == 3) game.display.drawBitmap(ballx,bally,ballblue);
                if (ballcolor == 4) game.display.drawBitmap(ballx,bally,ballgray);
            }
            game.display.bgcolor = 14;
            game.display.color = 15;
        }
        //game.update();
    }
    return 1;
}

void scorepoint(bool voidreset)
{
    padplayer = 34;
    padcom = 34;
    ballx = 52;
    bally = 44;
    movex = 0;
    movey = 0;
    gamestart = 0;
    movecom = 0;
    moveplayer = 0;
}

void endgame(bool voidreset2)
{
    padplayer = 34;
    padcom = 34;
    ballx = 52;
    bally = 44;
    movex = 0;
    movey = 0;
    scoreplayer = 0;
    scorecom = 0;
    gamestart = 0;
    win = 0;
    movecom = 0;
    moveplayer = 0;
    difficulty = 60;
}

I don’t know how main.cpp got added to the project, but it was an old file (Pokitto_sim first versions used SFML library)

I removed the file. It is not supposed to be included in the project. Repository has been updated.

Should work again.

remember to do a full rebuild

3 Likes

Works! But it don´t solve the problem with the “Red Pong :stuck_out_tongue:”
Do you need the “textures.h” too? Please find a way to fix it, in the old Sim it works.

I do not find “textures.h” on my hard drive. I don’t know where it has come from. Can you copy-paste from old sim and post the code here?

#ifndef TEXTURES_H_INCLUDED
#define TEXTURES_H_INCLUDED

#include <stdint.h>

//palette
const uint16_t default36[] = {
2016,1024,63488,32768,31,16,65504,46208,64352,45600,52224,31461,33808,25388,0,65535,
};
//paddles
const uint8_t paddlegreen[] =
{
6,20,
255,255,255,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
17,17,17,
};
const uint8_t paddlered[] =
{
6,20,
255,255,255,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
51,51,51,
};
//Balls
const uint8_t ballgreen[] =
{
6,6,
255,255,255,
16,0,15,
16,0,15,
16,0,15,
16,0,15,
17,17,17,
};
const uint8_t ballred[] =
{
6,6,
255,255,255,
242,34,35,
242,34,35,
242,34,35,
242,34,35,
51,51,51,
};
const uint8_t ballorange[] =
{
6,6,
255,255,255,
248,136,137,
248,136,137,
248,136,137,
248,136,137,
153,153,153,
};
const uint8_t ballyellow[] =
{
6,6,
255,255,255,
246,102,103,
246,102,103,
246,102,103,
246,102,103,
119,119,119,
};
const uint8_t ballblue[] =
{
6,6,
255,255,255,
244,68,69,
244,68,69,
244,68,69,
244,68,69,
85,85,85,
};
const uint8_t ballgray[] =
{
6,6,
255,255,255,
252,204,205,
252,204,205,
252,204,205,
252,204,205,
221,221,221,
};
//Other
const uint8_t title[] =
{
110,20,
238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,
238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,
238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,
238,238,238,238,238,15,255,255,238,238,224,255,255,254,238,224,254,238,238,238,239,238,238,224,255,255,255,254,238,238,238,238,238,238,238,255,255,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,
238,238,238,238,225,0,0,0,254,238,0,0,0,15,238,224,15,238,238,238,224,254,238,0,0,0,0,15,238,238,238,238,238,238,238,16,15,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,
238,238,238,238,16,238,238,15,238,225,14,238,224,254,238,16,15,238,238,238,15,238,225,14,238,238,238,238,238,238,238,238,238,238,238,16,15,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,
238,238,238,238,16,238,238,15,238,225,14,238,224,254,238,16,16,254,238,238,15,238,225,14,238,238,238,238,238,238,238,238,238,238,238,16,15,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,
238,238,238,225,14,238,224,14,238,16,238,238,0,238,225,14,16,254,238,224,14,238,16,238,238,238,238,238,238,238,238,238,238,238,238,16,15,238,238,238,238,239,255,238,238,238,238,238,238,238,238,238,238,238,238,
238,238,238,225,14,238,224,14,238,16,238,238,0,238,225,14,225,254,238,224,14,238,16,238,238,238,238,238,238,238,238,238,238,238,238,16,15,238,238,238,238,239,35,238,238,238,238,238,238,238,238,238,238,238,238,
238,238,238,16,0,0,0,238,225,14,238,224,14,238,16,238,225,254,238,0,238,225,14,238,0,15,238,238,238,238,238,238,238,238,238,16,15,238,238,238,238,227,51,238,238,238,255,255,238,238,238,238,238,238,238,
238,238,238,16,0,0,14,238,225,14,238,224,14,238,16,238,225,254,238,0,238,225,14,238,17,16,254,238,238,238,238,238,238,238,238,17,17,238,238,238,238,238,238,238,238,238,242,35,238,238,238,238,238,238,238,
238,238,225,14,238,238,238,238,16,238,238,0,238,225,14,238,225,254,224,14,238,16,238,238,238,15,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,242,35,238,238,238,238,238,238,238,
238,238,225,14,238,238,238,238,16,238,238,0,238,225,14,238,225,15,224,14,238,16,238,238,238,0,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,242,35,238,238,238,238,238,238,238,
238,238,16,238,238,238,238,225,14,238,224,14,238,16,238,238,225,15,0,238,225,14,238,238,224,14,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,242,35,238,238,238,238,238,238,238,
238,238,16,238,238,238,238,225,14,238,224,14,238,16,238,238,238,16,0,238,225,14,238,238,224,14,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,242,35,238,238,238,238,238,238,238,
238,225,14,238,238,238,238,16,0,0,0,238,225,14,238,238,238,16,14,238,17,0,0,0,0,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,242,35,238,238,238,238,238,238,238,
238,238,30,238,238,238,238,225,17,17,30,238,238,30,238,238,238,225,30,238,225,17,17,17,30,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,51,51,238,238,238,238,238,238,238,
238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,
238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,
238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,238,
};
const uint8_t btna[] =
{
10,10,
238,239,255,254,238,
239,254,238,239,254,
239,238,255,238,254,
254,239,238,254,239,
254,239,238,254,239,
254,239,255,254,239,
254,239,238,254,239,
239,238,238,238,254,
239,254,238,239,254,
238,239,255,254,238,
};
const uint8_t backarrow[] =
{
20,10,
238,238,238,238,238,238,239,255,254,238,
238,238,254,238,238,239,254,238,239,254,
238,239,254,238,238,239,239,255,238,254,
238,255,255,255,254,254,239,238,254,239,
239,255,255,255,254,254,239,255,238,239,
239,255,255,255,254,254,239,238,254,239,
238,255,255,255,254,254,239,238,254,239,
238,239,254,238,238,239,239,255,238,254,
238,238,254,238,238,239,254,238,239,254,
238,238,238,238,238,238,239,255,254,238,
};
#endif // TEXTURES_H_INCLUDED

I had explained it wrong, “textures.h” is part of my pong. The codes(main.cpp,textures.h) in the two sim versions are the same.

1 Like

@jonne I don´t see a mistake in my code. Is there something wrong with the simulator? Look at the picture above and what it looks like in the old sim: