First game in PicoC - Sokoban

Started by a1ex, February 24, 2013, 10:47:55 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

a1ex

Since PicoC has now functions for simple graphics and can detect button presses, why not try to write a small game?

Source - sokoban.c

Don't expect fancy graphics; it's just a basic demo from which - I hope - you can learn some nice scripting tricks.



Feel free to add some new levels.

Marsu42

Quote from: a1ex on February 24, 2013, 10:47:55 PM
Since PicoC has now functions for simple graphics and can detect button presses, why not try to write a small game?

Could we please have Pong, complete mit "beep" sound and computer opponent :-) ? It's *the* classic and would really make a great ml demo, I saw you already have the more graphic routines added but not implemented. https://en.wikipedia.org/wiki/Pong


SDX

Properly the main reason for adding the drawing routines is, that some who had making a minigame in mind requested it - or am I wrong on that one? (I'm at least one of those).

Original pong isn't such a big deal once one has figured how to get smooth timing ;)


a1ex

Or, instead of smooth timing, one may assume variable timing for simulation, and sync with the DIGIC clock (which is very accurate).

For Pong, the API lacks a method to detect keys in a non-blocking way (currently get_key is blocking until you press something). Other than that, shouldn't be very hard.

wolf

Wow
...And I was always afraid of the day that a EOS offers the possibility to play a game. ;-)
The new picoc functions and picoc in generally are really great and I'm sure that some good and helpful scripts will follow.

Didn't heard of sokoban yet, but it's really nice...



a1ex

Timing for simple animations is not a problem at all :)


// Animation demo

void main()
{
    console_hide();
    set_gui_mode(1); // Play
   
    fill_rect(0, 0, 720, 480, COLOR_EMPTY);
   
    int x = 320;
    int y = 240;
    int r = 10;
   
    int dx = 0;
    int dy = 0;
   
    while(1)
    {
        int key = last_key();
       
        switch(key)
        {
            case LEFT:
                dx--;
                break;
            case RIGHT:
                dx++;
                break;
            case UP:
                dy--;
                break;
            case DOWN:
                dy++;
                break;
        }

        fill_circle(x, y, r, COLOR_EMPTY);
       
        x += dx;
        y += dy;
       
        // collisions are not exact
        if (x < r) { x = r; dx = -dx; }
        else if (x > 720-r) { x = 720-r; dx = -dx; }
        if (y < r) { y = r; dy = -dy; }
        else if (y > 480-r) { y = 480-r; dy = -dy; }
       
        fill_circle(x, y, r, COLOR_WHITE);
       
        sleep(0.01);
    }
}

main();


Alia5

Wonder how long it will take untill we can play tetris! :D
Great stuff here!

1%

Tetris seems like the game to have. Perfect for the arrow keys and wasting time.

Alia5

Only problem when thinking about Tetris is that get_key is currently blocking :(
Tetris makes no fun if you have to move Blocks down manually...

a1ex

F5, see the sticky post ;)

last_key() is not blocking

Alia5


obiyan19

sorry for old reply, but i discovered the sokoban game in the 600d audio built, and i dont have solution for the last (6) level !!!
600D + 7D + 5D2  // 24-105 L is ~ 100-400 L is ~ 18-200 is ~ 18-55 isII ~ sigma 50 f1.4 EX