Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI-Nspire => Topic started by: gameblabla on August 03, 2013, 03:12:54 pm

Title: [C] Rainbow Dash Cloud Attack
Post by: gameblabla on August 03, 2013, 03:12:54 pm
(http://img95.xooimage.com/files/e/1/e/scr3_rd-3ffeb15.png)
Hi !
You asked for it , there it is !
You play as Rainbow Dash and you need to grab all the white clouds and kick the storm clouds !
You score 100 pts for each cloud you grab and score 300 pts if you kick a storm cloud.
The maximum score you can get is 99999 , i dare you to reach that !
Hope you'll enjoy it !

Download : (You need Ndless installed on your TI-nspire)
Version 1.05 (http://goo.gl/xJyaqb)

Screenshots :
(http://img99.xooimage.com/files/2/c/1/scr1_rd-3ffeaec.png)
(http://img99.xooimage.com/files/f/4/8/scr2_rd-3ffeb11.png)
Title: Re: [C] Rainbow Dash Cloud Attack
Post by: Lionel Debroux on August 03, 2013, 03:37:09 pm
Quote
That's because i need to write a integer to a file but fscanf() is not available in Ndless...
fgetc() works but only writes a char...
Just choose an endianness for your serialization of integers, and use fgetc on the integer shifted by 8, 16 and 24 then and'ed with 0xFF :)
Title: Re: [C] Rainbow Dash Cloud Attack
Post by: Sorunome on August 03, 2013, 03:51:33 pm
yaaaaaaaaay :D
Also, can you still kill the black clouds if you hit 'em right at the end? (and giving more points)
Title: Re: [C] Rainbow Dash Cloud Attack
Post by: gameblabla on August 03, 2013, 05:51:38 pm
Quote
That's because i need to write a integer to a file but fscanf() is not available in Ndless...
fgetc() works but only writes a char...
Just choose an endianness for your serialization of integers, and use fgetc on the integer shifted by 8, 16 and 24 then and'ed with 0xFF :)
^^' Sorry , i don't understand...
But i found a way to get the save working. It is not precise at all but it works well with my game.

yaaaaaaaaay :D
Also, can you still kill the black clouds if you hit 'em right at the end? (and giving more points)
No , you can't do that. This will probably be in the next update.

EDIT : A new update is available , you can now save your highscore ! http://goo.gl/ZCY4yz (http://goo.gl/ZCY4yz)
Title: Re: [C] Rainbow Dash Cloud Attack
Post by: Sorunome on August 03, 2013, 06:49:49 pm
You code fast O.O
Title: Re: [C] Rainbow Dash Cloud Attack
Post by: gameblabla on August 04, 2013, 12:20:05 am
You code fast O.O
Indeed.
I have released a new version (i think this will be the last one) , you can now kick clouds !
(http://img96.xooimage.com/files/a/3/5/scr4_rd-3ffffbd.png)
Download link : http://goo.gl/i3DWR6 (http://goo.gl/i3DWR6)
Title: Re: [C] Rainbow Dash Cloud Attack
Post by: Sorunome on August 04, 2013, 04:33:55 am
ok, now i /really/ need a cx, great job!
Title: Re: [C] Rainbow Dash Cloud Attack
Post by: Jonius7 on August 04, 2013, 10:05:17 am
That looks like some nice animations with the kicking. Will definitely appeal to MLP Fans :).
Also why is the max points 25500?
Title: Re: [C] Rainbow Dash Cloud Attack
Post by: gameblabla on August 04, 2013, 01:44:57 pm
Thanks everybody !
I have released a new version (again) , it fixes some bugs.
http://goo.gl/OIwqpV (http://goo.gl/OIwqpV)

Also why is the max points 25500?
For each (white) cloud you touch , you get 100 pts and if you kick a black one , you get 200 pts.
I can only store a char , what can i do ? (the max value for an unsigned char is 255)
Easy , i divide the highscore by 100 and then the program saves the highscore.
When the game will read the savefile , it will multiply the highscore stored in the file by 100.
I know, Lionel would not be proud of me...
Title: Re: [C] Rainbow Dash Cloud Attack
Post by: Sorunome on August 04, 2013, 01:47:42 pm
Can't you somehow do 2-byte vars?
Title: Re: [C] Rainbow Dash Cloud Attack
Post by: gameblabla on August 04, 2013, 02:54:46 pm
Code: [Select]
               
sc = (highscore / 10000) % 10;
dscore[0]=sc;
sc = (highscore / 1000) % 10;
dscore[1]=sc;
sc = (highscore / 100) % 10;
dscore[2]=sc;
sc = (highscore / 10) % 10;
dscore[3]=sc;
sc = highscore % 10;
dscore[4]=sc;

file = fopen("/documents/rdsave.save.tns", "w+");
                        fputc( dscore[0], file);
fputc( dscore[1], file);
                        fputc( dscore[2], file);
fputc( dscore[3], file);
fputc( dscore[4], file);
fclose(file);

I'm really stupid , i should have done this done before. Thanks Lionel...
You can download the new update here : http://goo.gl/xJyaqb (http://goo.gl/xJyaqb)
The max pts is now 99999.
Title: Re: [C] Rainbow Dash Cloud Attack
Post by: Lionel Debroux on August 04, 2013, 03:04:57 pm
What I meant was really shifts and ands, not division and modulo on a processor without a divide instruction :)
Code: [Select]
uint32_t ReadLongBigEndian (void) {
    uint32_t temp_long;
    temp_long  = fgetc(output) << 24;
    temp_long |= fgetc(output) << 16;
    temp_long |= fgetc(output) << 8;
    temp_long |= fgetc(output);
    return temp_long;
}

uint32_t ReadLongLittleEndian (void) {
    uint32_t temp_long;
    temp_long  = fgetc(output);
    temp_long |= fgetc(output) << 8;
    temp_long |= fgetc(output) << 16;
    temp_long |= fgetc(output) << 24;
    return temp_long;
}

void WriteIntBigEndian (uint32_t long_in) {
    fputc (((int)(long_in >> 24)) & 0xFF, output);
    fputc (((int)(long_in >> 16)) & 0xFF, output);
    fputc (((int)(long_in >>  8)) & 0xFF, output);
    fputc (((int)(long_in      )) & 0xFF, output);
    fflush(output);
}

void WriteIntLittleEndian (uint32_t long_in) {
    fputc (((int)(long_in      )) & 0xFF, output);
    fputc (((int)(long_in >>  8)) & 0xFF, output);
    fputc (((int)(long_in >> 16)) & 0xFF, output);
    fputc (((int)(long_in >> 24)) & 0xFF, output);
    fflush(output);
}

Also, another piece of general advice: don't put .tns files at the root of /documents, because TILP cannot cope with them, which means that users couldn't backup such files once your program has created them.
Title: Re: [C] Rainbow Dash Cloud Attack
Post by: Adriweb on August 04, 2013, 08:18:45 pm
Also, another piece of general advice: don't put .tns files at the root of /documents, because TILP cannot cope with them, which means that users couldn't backup such files once your program has created them.
Eh, that's quite annoying, can't it be fixed ? (I'm among probably many of users for who the root is just a mess :D)
Title: Re: [C] Rainbow Dash Cloud Attack
Post by: gameblabla on August 04, 2013, 09:47:55 pm
What I meant was really shifts and ands, not division and modulo on a processor without a divide instruction :)
Code: [Select]
uint32_t ReadLongBigEndian (void) {
    uint32_t temp_long;
    temp_long  = fgetc(output) << 24;
    temp_long |= fgetc(output) << 16;
    temp_long |= fgetc(output) << 8;
    temp_long |= fgetc(output);
    return temp_long;
}

uint32_t ReadLongLittleEndian (void) {
    uint32_t temp_long;
    temp_long  = fgetc(output);
    temp_long |= fgetc(output) << 8;
    temp_long |= fgetc(output) << 16;
    temp_long |= fgetc(output) << 24;
    return temp_long;
}

void WriteIntBigEndian (uint32_t long_in) {
    fputc (((int)(long_in >> 24)) & 0xFF, output);
    fputc (((int)(long_in >> 16)) & 0xFF, output);
    fputc (((int)(long_in >>  8)) & 0xFF, output);
    fputc (((int)(long_in      )) & 0xFF, output);
    fflush(output);
}

void WriteIntLittleEndian (uint32_t long_in) {
    fputc (((int)(long_in      )) & 0xFF, output);
    fputc (((int)(long_in >>  8)) & 0xFF, output);
    fputc (((int)(long_in >> 16)) & 0xFF, output);
    fputc (((int)(long_in >> 24)) & 0xFF, output);
    fflush(output);
}

Hehe , thank you Lionel ! I will certainly use it for my future projects !

Also, another piece of general advice: don't put .tns files at the root of /documents, because TILP cannot cope with them, which means that users couldn't backup such files once your program has created them.
Thanks for the advice , i did a small update to fix that. (Go download it in my first post)
The savefile is now stored in ndless's folder.

I think that will be the last update for my game , i guess it's time to work on another game...
Thank you guys for your support !