Author Topic: [Lua] Bobby Carrot  (Read 33800 times)

0 Members and 1 Guest are viewing this topic.

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
[Lua] Bobby Carrot
« on: June 18, 2011, 09:20:50 am »
Hi everybody !
I introduce here my second project in Lua (after my space invaders) : Bobby Carrot.
It's a mobile game which I try to port to the Nspire.
It's a puzzle game about a little rabbit who has to eat all the carrots of each level.
I made the menu, the sprites, the level displaying and the scrolling. It remains the tiles actions and 48 levels :)
(I'm going to do a level creator in C)

First, it was going to be my contest entry. But my free version of Nspire student software expires in 18 days, so I give up (I'll have to ask someone to make the .tns for me, and I can't share the code if it's a contest entry)...  :'(

The level creator is attached, if you know the game, try it. There's a readme in the ZIP file.
« Last Edit: June 18, 2011, 01:02:57 pm by Chockosta »

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: [Lua] Bobby Carrot
« Reply #1 on: June 18, 2011, 09:24:35 am »
sweet bunny   ;)
Is he animated?
I hope so.
*insert supercool signature*

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Bobby Carrot
« Reply #2 on: June 18, 2011, 09:26:51 am »
He's not animated yet, but I hope I'll can do it.

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: [Lua] Bobby Carrot
« Reply #3 on: June 18, 2011, 09:29:13 am »
Hope you'll make it.

little hint:
try to make a better change betwen the Plants and the grey place (on the screenshot)
« Last Edit: June 18, 2011, 12:23:43 pm by p2 »
*insert supercool signature*

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Bobby Carrot
« Reply #4 on: June 18, 2011, 09:36:32 am »
Well this could be a good idea, but if I did that, the sprites won't be "mappable" (I really don't know the word)
I'll try that.

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: [Lua] Bobby Carrot
« Reply #5 on: June 18, 2011, 09:37:18 am »
Looks very nice indeed! :)

Very sad to hear that progress may halt because of the loss of student software. :'(


Offline pianoman

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 426
  • Rating: +24/-0
  • ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫
    • View Profile
Re: [Lua] Bobby Carrot
« Reply #6 on: June 18, 2011, 12:21:14 pm »
There are other tools you can use to convert the files... they just won't be compatible with OS 3.0.2 until you load it onto your calculator and send it back to the computer.

Looks great!

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Bobby Carrot
« Reply #7 on: June 18, 2011, 01:01:47 pm »
Yeah, but I have OS 2.0.1 on my calc. (I love oslauncher !)

I finished the level creator (beta).
I attach it in the first post. You can try it if you already know the game...
There's a readme in the ZIP file
For the ones who like C code, I post the code here :
Code: [Select]
#include <SDL.h>
#include <SDL_image.h>
#include <stdio.h>
#include <stdlib.h>

typedef struct
{
    uint8_t quit;
    uint8_t clic;
    uint8_t key[SDLK_LAST];
    SDL_Rect mouse;
} eventsManager;

void updateEvents(eventsManager *evts)
{
    SDL_Event event;
    while (SDL_PollEvent(&event))
    {
        switch (event.type)
        {
            case SDL_KEYDOWN:
                evts->key [event.key.keysym.sym] = 1;
                break;
            case SDL_KEYUP:
                evts->key [event.key.keysym.sym] = 0;
                break;
            case SDL_QUIT:
                evts->quit=1;
                break;
            case SDL_MOUSEBUTTONDOWN:
                evts->clic=1;
                break;
            case SDL_MOUSEBUTTONUP:
                evts->clic=0;
                break;
            case SDL_MOUSEMOTION:
                evts->mouse.x=event.motion.x;
                evts->mouse.y=event.motion.y;
                break;
            default:
                break;
        }
    }
}

int main(int argc, char **argv)
{
    int width,height,startx,starty,i;
    int current=2;
    char title[100];
    char str[100];

    FILE *filein = fopen("in.txt","r");
    fscanf(filein,"%d %d %d %d",&width,&height,&startx,&starty);
    fclose(filein);

    if (width>40)
        width=40;
    if (width<10)
        width=10;
    if (height>20)
        height=20;
    if (height<7)
        height=7;

    sprintf(title, "Bobby Carrot Level Creator - %d x %d - start : %d;%d",width,height,startx,starty);
    uint8_t *array=malloc(width*height*sizeof(uint8_t));
    memset(array,2,width*height*sizeof(uint8_t));


    //vars
    SDL_Surface *window = NULL;
    SDL_Surface *toolbar = NULL;
    SDL_Surface* sprites[14];
    SDL_Rect postb = {0,0};
    SDL_Rect posblit;
    uint8_t end=0;
    unsigned int ellapsed, time;

    //SDL routines
    eventsManager events;
    memset(&events, 0, sizeof(eventsManager));
    SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER);
    window=SDL_SetVideoMode(width*30,height*30+30,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
    SDL_WM_SetCaption(title,NULL);

    toolbar=IMG_Load("toolbar.jpg");
    for (i=0;i<14;i++)
    {
        sprintf(str,"Sprites/Bobby-%d.gif",i+1);
        sprites[i]=IMG_Load(str);
    }

    //render loop
    while (!end)
    {
        //FPS management
        time=SDL_GetTicks();
        //Events management
        updateEvents(&events);

        if (events.quit||events.key[SDLK_ESCAPE])
            end=1;
        if (events.key[SDLK_a])
            current=1;
        if (events.key[SDLK_z])
            current=2;
        if (events.key[SDLK_e])
            current=3;
        if (events.key[SDLK_r])
            current=4;
        if (events.key[SDLK_t])
            current=5;
        if (events.key[SDLK_y])
            current=6;
        if (events.key[SDLK_u])
            current=7;
        if (events.key[SDLK_i])
            current=8;
        if (events.key[SDLK_o])
            current=9;
        if (events.key[SDLK_p])
            current=10;
        if (events.key[SDLK_q])
            current=11;
        if (events.key[SDLK_s])
            current=12;
        if (events.key[SDLK_d])
            current=13;
        if (events.key[SDLK_f])
            current=14;

        if (events.mouse.y>30 && events.clic)
        {
            if (current==14)
                array[(events.mouse.y-30)/30*width+events.mouse.x/30]=0;
            else
                array[(events.mouse.y-30)/30*width+events.mouse.x/30]=current;
        }

        SDL_FillRect(window, NULL, SDL_MapRGB(window->format, 180, 115, 53));
        for(i=0;i<width*height;i++)
        {
            if (array[i]!=0)
            {
                posblit.x=(i%width)*30;
                posblit.y=(i/width)*30+30;
                SDL_BlitSurface(sprites[array[i]-1],NULL,window,&posblit);
            }
        }

        SDL_BlitSurface(sprites[current-1],NULL,window,&events.mouse);
        SDL_BlitSurface(toolbar,NULL,window,&postb);
        SDL_Flip(window);

        //50 FPS
        ellapsed = SDL_GetTicks() - time;
if (ellapsed < 20)
SDL_Delay (20 - ellapsed);
    }

    filein=fopen("out.txt","w+");
    fprintf(filein,"{%d,%d,%d,%d",width,height,startx,starty);
    for (i=0;i<width*height;i++)
    {
        fprintf(filein,",%d",array[i]);
    }
    fprintf(filein,"}");
    fclose(filein);

    //Free
    free(array);
    SDL_FreeSurface(window);
    SDL_FreeSurface(toolbar);
    for (i=0;i<14;i++)
    {
        SDL_FreeSurface(sprites[i]);
    }
    SDL_Quit();
    return 0;
}

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Bobby Carrot
« Reply #8 on: June 19, 2011, 10:44:25 am »
Beta version of the game !
You can try the 10 first levels (good luck for level 10).

I didn't add a readme, so here are the controls :
arrows : control Bobby / select the level
escape : quit the current level
enter : select the level.
There are  6 kinds of blocks :
-bush : it blocks you.
-rotating pipes : they rotate 90° clockwise each time you go on them.
-buttons : if you push them, all the pipes rotate.
-spikes : you can walk on them only once.
-carrots : eat them all !
-target : when you have eaten all the carrots, go on the target in order to complete the level.

You can see a video of the level 8 here

If someone could make some maps, It would be very nice :). It's pretty hard to do a good level...

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: [Lua] Bobby Carrot
« Reply #9 on: June 19, 2011, 10:49:52 am »
looks great.  ;)
but can you try to modify the walking?
It needn't to be animated, but It would look better if the steps aren't like beaming.

Or that the rabbit looks into the direction where he's walking. (Bad english... :-\ )
*insert supercool signature*

Offline mrmprog

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 559
  • Rating: +35/-1
    • View Profile
Re: [Lua] Bobby Carrot
« Reply #10 on: June 19, 2011, 12:07:58 pm »
The graphics look really nice. This is why I wish I had an nspire...

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: [Lua] Bobby Carrot
« Reply #11 on: June 19, 2011, 12:12:56 pm »
The graphics look really nice. This is why I wish I had an nspire...

Yap, he's taking full advantage of greyscale, like Hoffa did in Pixel Escape. This is getting awesome, nice job :)

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Bobby Carrot
« Reply #12 on: June 19, 2011, 01:21:21 pm »
Thanks for the comments !
For the rabbit, I can't make his movement "smooth". It would become too slow.
I could make him looking into the direction where he's walking (I don't know how to say it better :D ), but I'd have to add 3 sprites. The tns file is already 34 KB heavy. Adding these 3 big sprites would make it ~50 KB heavy. Is it too much or not ?

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: [Lua] Bobby Carrot
« Reply #13 on: June 20, 2011, 04:54:00 am »
Good games are large and very good games are very large. That's normal  ;)
If it's not too large fot the TI, it's ok.
« Last Edit: June 20, 2011, 04:56:38 am by p2 »
*insert supercool signature*

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: [Lua] Bobby Carrot
« Reply #14 on: June 20, 2011, 07:41:25 am »
I've just added these sprites, and it's only 40 KB large :)
And, nice picture ! Bobby is gonna eat you all !