Posts Tagged ‘c’

Fastforward!

MazeMania - NDS | Posted by Dean Carlson
Apr 27 2009

After a recent all nighter, I got a lot of stuff done for the NDS version of MazeMania.

Intro Screen
  • The Intro screen with a multitude of options
Level
  • Here is an example of a level. Special thanks to Kevin for helping me write all of them
  • The level is read in from a file and sprites are rendered accordingly (see previous post for my frustration with this)
  • Programed collision detection detects if you are hitting a wall and/or the finish and acts accordingly
Death areas and Walls
  • Added death area’s (skull and crossbones), where if the user comes in contact with it, they lose a life and have to start over
  • Also, added walls (red square in the middle of the maze), where if the user comes in contact with it, they will not be able to move until the wall moves
  • Both items “blink” so that the user can get by. I do that by moving the sprites off of the screen at different intervals then moving them back to their original positions.
Question round
  • Being that the corse is called “Educational Gaming,” there needed to be some educational element to the game. This is where the Question round comes in.
  • I chose to do grammar preparation for the SAT for a couple of reasons
    • First being that I struggled with this when I was taking the SATs. So, I figured I would help someone out
    • Second is that a lot of people don’t feel they can prepare for the SAT. This is untrue, and if they can have fun while doing it they might be more inclined to do it.
Game Over
  • Once the player runs out of lives, they will be shown this simple Game Over screen
  • They are given the option to restart or to view the credits. I may remove these options and force the user to view the credits in the future
Credits
  • After the user finishes the game, either by losing all of their lives or beating all of the levels, they will be brought to this credits screen
  • Share/Bookmark

Frustrations With Reading From a File on a DS

MazeMania - NDS | Posted by Dean Carlson
Apr 27 2009

According to the PAlib examples, reading from files via FAT is supposedly pretty easy, as depicted by this code (shortened for space):

#include "PA9.h"       // Include for PA_Lib
#include "fat.h"       // Include for FAT read/writes
int main(int argc, char ** argv)
{
...
fatInitDefault(); //Initialise fat library
FILE* testRead = fopen ("FATTest.txt", "rb"); //rb = read
char filetext[30];
fread(filetext, 30, 1, testRead);
fclose(testRead);

PA_OutputSimpleText(1, 1, 7, "FATTest.txt contains:");
PA_OutputText(1, 2, 8, "%s", filetext);
...
return 0;
} // End of main()

(Apologies that the code tags don’t seem to work in this theme…yet)

Well this code seems to appears to work on the emulator, and it’s really hit or miss on the actual DS. So I began to delve into this problem. After about 8-9 hours of trying to debug this problem by myself and with the assistance of Dr. Malloy trying many different things we didn’t really come to any finite conclusions.

Luckily, other students in my class are also reading from files and have found that FAT is no longer supported in this version in PAlib and have been using Embedded File System (EFS) Library to deal with file reading. So, that was a bunch of time wasted.

This is the EFS example that I found (shortened for space):

#include "PA9.h"        // Include for PA_Lib
#include "unistd.h"
#include "efs_lib.h"     // include EFS lib
int main(void) {
// init EFSlib & libfat
if(EFS_Init(EFS_AND_FAT | EFS_DEFAULT_DEVICE, NULL)) {
PA_OutputSimpleText(1, 0, 0, "EFS init ok");
PA_OutputText(1, 0, 1, "found NDS path: %s", efs_path);
struct stat st;
FILE* file;
u8* buffer;
int size;
// open a text file and read its contents
file = fopen("/test.txt", "rb");
if(file != NULL) {
stat("/test.txt", &st);// get file size using stat
size = st.st_size;
buffer = (u8*)malloc(size);
fread(buffer, 1, size, file);
buffer[size-1] = '\0';
PA_OutputText(1, 0, 4, "/test.txt content: '%s'", buffer);
PA_OutputText(1, 10, 5, "size: %d bytes", size);
free(buffer);
fclose(file);
}
} else {
PA_OutputSimpleText(1, 0, 0, "EFS init error!");
}
...
return 0;
}

(Again, apologies that the code tags don’t seem to work in this theme)

This works fine on both the emulator and the DS, except it only seems to work for doing it once, otherwise I get “EFS init error!”. So, at first I thought I would have to read each map and question into separate arrays at the beginning of the program. This, of course, is a horrible idea, not only would it increase load time by a significant amount but it would hog a ton of memory. So I began to try and figure out this problem. After a few more hours of investigation and debugging, I finally find out the problem. It turns out that the statement  “

if(EFS_Init(EFS_AND_FAT | EFS_DEFAULT_DEVICE, NULL))" 

will fail every time after the first call. It will fail because they have already been initialized. So that was a simple fix. I just modified it to this:

EFS_Init(EFS_AND_FAT | EFS_DEFAULT_DEVICE, NULL);
FILE* file = fopen (filename, "rb");
if ( file != NULL){

After more time being spent trying to figure out this new library, I think I finally have it figured out. EFS puts all of the files that you put into the “efsroot” folder in your program is loaded onto the NDS file and needs to be recompiled to have changes made to the file, be included in the NDS to be read. This kind of defeats the purpose of dynamic maps and questions on the files if they don’t have the source to recompile the NDS. Questions and maps will still be read from the files, in hope that reading and writing from files will become more dynamic in the future. Another thing is that EFS read works on the emulator but not EFS write. However, both work on the DS. So, after probably 12ish hours trying to trouble shoot the simple thing of file reading, it is finally solved and reading my maps into a 2d array to be rendered onto the screen.

  • Share/Bookmark

Contract, Storyboard, and Levels

MazeMania - NDS, MazeMania - Python | Posted by Dean Carlson
Apr 26 2009

There won’t be much text to this post, but there’s a lot of content! You can find my contract for the NDS version here. You can find my story board here (apologies for breaking the layout) or here (missing the awesome flow chart). All of the general level designs are screen shots from MazeFinger and can be seen here. At the end of the slides with the levels, there is my first screen shots of MazeMania on the DS! It may not look like much but it’s a step in the right direction.

Like I said, not a lot of text, but check out the links!

  • Share/Bookmark

MazeMania!!

MazeMania - NDS, MazeMania - Python | Posted by Dean Carlson
Apr 26 2009

I have chosen to do a maze game based off of the popular iPhone application, Maze Finger, with some new features. Included in those features are its new name (MazeMania), ecology related question rounds, new user input (the almighty mouse), and much more.

I have chosen to a similar game for the Nintendo DS, as I think there is a lot of potential in the touch screen and stylus. This game will be different in that the questions will be geared toward helping high school students prepare for the English part of the SAT by using old test questions.

I have also talked to my teacher, Dr. Malloy, and we are thinking of writing a paper to present at the Games+Learning+Society Conference based on the differences of the two very different platforms, education in games, and a future user study. The abstract can be found here. This played a pretty big role in why I am doing very similar games for each platform.

  • Share/Bookmark

Let it Begin…

MazeMania - NDS, MazeMania - Python | Posted by Dean Carlson
Apr 24 2009

In my CpSc 372 class, introduction to software development, taught by Dr. Malloy, we will be writing a game for the PC using Python and the PyGame library. Soon, 2 different clients will come in and present on what kind of general idea they would like in their games.

In my CpSc 481 class, educational gaming, also taught by Dr. Malloy, we will be writing a game for the Nintendo DS (dual screen) using C and a library that assists with the programming on the DS. In this area there are 2 main libraries, PAlib and libnds.  With regard to the 2 libraries it is said that PAlib is easier and faster to learn than libnds, but libnds has more capability. I will be using PAlib, so I can learn the language and program the game within the semester. This game is open ended, as far as the content, with the catch that it is educational in some way.

More on these 2 games coming soon.

  • Share/Bookmark