Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI-Nspire => Topic started by: Spenceboy98 on May 20, 2013, 12:40:51 am

Title: [Nspire C] Zombie Chase
Post by: Spenceboy98 on May 20, 2013, 12:40:51 am
This is a port of my Prizm game Zombie Chase.

Here is some screenies:
(http://oi42.tinypic.com/e99cpd.jpg)

(http://oi41.tinypic.com/n4vzpc.jpg)

The problem is, is that it reboots the calc every time you exit.
This is the code it does when the while loop breaks:
Code: [Select]
free(screen);
return 0;

The screen variable is:
Code: [Select]
screen = (char*)malloc(SCREEN_BYTES_SIZE * sizeof(char));
I hope you can help so that I can get this uploaded for you to enjoy(or dislike :P).
Title: Re: [Nspire C] Zombie Chase
Post by: excale on May 20, 2013, 05:29:50 am
I think it reboots after the return, possibly because you wrote data out of the malloc-ed memory somewhere earlier in the program, thus overwriting some informations needed by the OS.
Title: Re: [Nspire C] Zombie Chase
Post by: ajorians on May 20, 2013, 08:09:47 am
Hi Spenceboy98,

A couple of tips I've learned that may be able to help:
1. After free; you can set your pointer to NULL:
free(screen);
screen = NULL;
return 0;
And so I suggest for every free to set the pointer to NULL.  Because should you call free again on the same pointer, free(NULL) won't crash!  See the C standard 7.20.3.2: http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1124.pdf
But that may be an indication that you are freeing the same memory twice.

2. Are you using an emulator or only transferring to your calculator?  I only say because if you use an emulator; besides being faster you can add printf (amongst other things) to see the values of variables:
printf("Screen pointer is at address %p\n", screen);

3. Are you using anything for the graphics?  That is entirely your choice; but nRGBLib (http://ourl.ca/14731) is really helpful!  In there is a macro:
#define GetNewScreenBuffer() malloc(SCREEN_BYTES_SIZE)
(https://bitbucket.org/totorigolo/nrgblib/src/9a736d6ff9e432e7e1df2122c03d8b39c05d6dd2/src/include/nCOMMON.h?at=default)
And I am thinking you could use that instead of writing it yourself.

If you post your source code I'll take a look to see why the calculator reboots on exit.  I've chased down a few of these now! :)

Have a great day!
Title: Re: [Nspire C] Zombie Chase
Post by: Spenceboy98 on May 20, 2013, 05:12:48 pm
Hi Spenceboy98,

A couple of tips I've learned that may be able to help:
1. After free; you can set your pointer to NULL:
free(screen);
screen = NULL;
return 0;
And so I suggest for every free to set the pointer to NULL.  Because should you call free again on the same pointer, free(NULL) won't crash!  See the C standard 7.20.3.2: http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1124.pdf
But that may be an indication that you are freeing the same memory twice.

2. Are you using an emulator or only transferring to your calculator?  I only say because if you use an emulator; besides being faster you can add printf (amongst other things) to see the values of variables:
printf("Screen pointer is at address %p\n", screen);

3. Are you using anything for the graphics?  That is entirely your choice; but nRGBLib (http://ourl.ca/14731) is really helpful!  In there is a macro:
#define GetNewScreenBuffer() malloc(SCREEN_BYTES_SIZE)
(https://bitbucket.org/totorigolo/nrgblib/src/9a736d6ff9e432e7e1df2122c03d8b39c05d6dd2/src/include/nCOMMON.h?at=default)
And I am thinking you could use that instead of writing it yourself.

If you post your source code I'll take a look to see why the calculator reboots on exit.  I've chased down a few of these now! :)

Have a great day!


I've tested it on both emulator and calc. I don't really want to post my source, but I'll pm you it, so that you can help.
Title: Re: [Nspire C] Zombie Chase
Post by: Spenceboy98 on May 21, 2013, 11:11:23 pm
*BUMP*

Working version thanks to ajorians(I had the background filling routine filling too much :P).

Screenies:
(http://i40.tinypic.com/ngvteg.png)

(http://i43.tinypic.com/1znwqyd.png)

Could someone test this on a CX and post some screenshots of those?

Download is attached.
Title: Re: [Nspire C] Zombie Chase
Post by: Spenceboy98 on May 22, 2013, 05:58:07 pm
*BUMP*

Could someone please test this on a CX? I'd like to see what it looks like. :P

Also, opinions are appreciated. :)
Title: Re: [Nspire C] Zombie Chase
Post by: ajorians on May 24, 2013, 01:29:08 pm
Hi Spenceboy98,

I just tested your program and I hit troubles with my CX :(

The first 2 screenshots are what it looked like to me.

Which is strange because I compiled your code and it looked fine (3rd screenshot).  I still have the code and can send it.  I am thinking that when I compiled and ran your code compared to this version it seems like the filesize increased a lot (4th screenshot; the version I got working is the smaller filesize).

Hope that helps.  Holler if I can be of any more help.  And have a great day!
Title: Re: [Nspire C] Zombie Chase
Post by: Levak on May 24, 2013, 03:06:42 pm
You need either to use lcd_ingray or lcd_incolor according to is_cx :
http://hackspire.unsads.com/wiki/index.php/Libndls#Screen
Title: Re: [Nspire C] Zombie Chase
Post by: Spenceboy98 on May 24, 2013, 04:45:06 pm
How about now(attached)?

The reason it is bigger than what I showed is because I made it have the color FAIL, which made it a lot bigger. :P
Title: Re: [Nspire C] Zombie Chase
Post by: Spenceboy98 on May 25, 2013, 03:44:51 pm
*BUMP*

I needs some CX testers please. ;) :P
Title: Re: [Nspire C] Zombie Chase
Post by: Lionel Debroux on May 25, 2013, 03:57:38 pm
I've tipped people at TI-Planet about it ( http://tiplanet.org/forum/viewtopic.php?f=17&t=11982 ), hopefully this will provide more beta-testers :)
Title: Re: [Nspire C] Zombie Chase
Post by: Spenceboy98 on May 25, 2013, 05:48:07 pm
I've tipped people at TI-Planet about it ( http://tiplanet.org/forum/viewtopic.php?f=17&t=11982 ), hopefully this will provide more beta-testers :)


Thanks. I hope it will. :)
Title: Re: [Nspire C] Zombie Chase
Post by: AlexisVieira on May 27, 2013, 09:58:22 am
well, it works good on my nspire touchpad but the "points" of the "zombies" are too small
Title: Re: [Nspire C] Zombie Chase
Post by: DJ Omnimaga on May 27, 2013, 01:31:52 pm
Looks nice, is it like Scipi/HOMER-16's computer zombie game? And yeah maybe the points could be a bit larger and there should be a bit of color.
Title: Re: [Nspire C] Zombie Chase
Post by: Spenceboy98 on May 27, 2013, 04:14:33 pm
Looks nice, is it like Scipi/HOMER-16's computer zombie game? And yeah maybe the points could be a bit larger and there should be a bit of color.

It should work on a CX, but no one has tested my most recent upload.

About the points, do you mean the amount taken off of the health when you get touched by a zombie?
Title: Re: [Nspire C] Zombie Chase
Post by: Matrefeytontias on May 28, 2013, 08:31:42 am
I think DJ and Alexis meant that the dots that represents the zombies are a bit too small.
Title: Re: [Nspire C] Zombie Chase
Post by: ajorians on May 28, 2013, 08:49:12 am
Hi Spenceboy98,

I just tested your build from May 24th on my Nspire CX and sadly I still see the 4 screens at the top with white the rest of the way down.  I tested it also on my Nspire Touchpad where it looked alright.  I hope somebody else is able to help you verify the problem I am seeing on the CX.  Since you don't want to share the source code; I can post the graphic3.c/.h, utils.c/.h and the Makefile I used when testing your code.  Maybe your version of those files differs than mine.  I think this game is great and I'd like to see it working.

Levak: I used lcd_ingray before on a CX.  I didn't see on http://hackspire.unsads.com/wiki/index.php/Libndls#Screen saying only when is_cx.

Well have a great day!
Title: Re: [Nspire C] Zombie Chase
Post by: AlexisVieira on May 28, 2013, 09:36:35 am
I think DJ and Alexis meant that the dots that represents the zombies are a bit too small.

yes is that
Title: Re: [Nspire C] Zombie Chase
Post by: DJ Omnimaga on June 11, 2013, 12:01:03 am
Yeah I meant the zombie sprites.
Title: Re: [Nspire C] Zombie Chase
Post by: Spenceboy98 on November 07, 2015, 06:07:24 pm
*necrobump*
I finally got around to getting it to work on the CX! :D (after over two years :P)
Made movements faster too! I eventually plan on adding coins to collect and some sort of score system. Enjoy! :D

https://www.cemetech.net/scripts/countdown.php?/nspire/games/ZombieChase.zip