|
Re: Saving and Loading Problem January 29, 2009 11:59AM | Registered: 17 years ago Posts: 265 |
|
Re: Saving and Loading Problem January 29, 2009 12:02PM | Registered: 17 years ago Posts: 25 |
|
Re: Saving and Loading Problem January 29, 2009 04:38PM | Registered: 17 years ago Posts: 265 |
|
Re: Saving and Loading Problem January 29, 2009 08:19PM | Admin Registered: 17 years ago Posts: 5,132 |
FILE *pattern;
void SavePattern(){
pattern = fopen("sd:/apps/Wiibreaker/data/pattern1.pattern","wb");
fwrite(brickx, 1, sizeof(brickx)*30, pattern);
fwrite(bricky, 1, sizeof(bricky)*30, pattern);
fclose(pattern);
}
void LoadPattern(){
pattern = fopen("sd:/apps/Wiibreaker/data/pattern1.pattern","rb");
fread(brickx, 1, sizeof(brickx)*30, pattern);
fread(bricky, 1, sizeof(bricky)*30, pattern);
fclose(pattern);
}|
Re: Saving and Loading Problem January 30, 2009 12:16AM | Admin Registered: 17 years ago Posts: 5,132 |
int brickx[30]; //X values for the bricks
int bricky[30]; //Y values for the bricks
int brickweareon = 0;
GameWindow gwd;
ftImage print(640, 480);
Sprite Text;
FILE *pattern;
void LoadPattern();//Load Pattern into level editor
void LoadPattern(){
pattern = fopen("sd:/apps/Wiibreaker/data/pattern1.pattern","rb");
fread(brickx, 1, sizeof(brickx)*30, pattern);
fread(bricky, 1, sizeof(bricky)*30, pattern);
fclose(pattern);
}
int main(int argc, char **argv){
fatInitDefault();//Initialize the front SD for loading images
gwd.InitVideo();
WPAD_Init(); //Initialize the Wiimote
WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);//Allows us to use the Wiimote pointer
print.setFont(font_ttf, font_ttf_size);
print.setSize(32);
Text.SetPosition(100, 50);
Text.SetImage(&print);
print.setColor(Color::Color(0,255,255));
LoadPattern();
for(;;)
{
WPAD_ScanPads();
print.printf("Brick: %d\n", brickweareon);
print.printf("X: %d\n", brickx[brickweareon]);
print.printf("Y: %d\n", bricky[brickweareon]);
print.flush();
Text.Draw();
print.clear();
print.reset();
if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_A)
brickweareon++;
if((WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_HOME) || (WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_CLASSIC_BUTTON_HOME))
break;
if(brickweareon > 29)
brickweareon = 0;
gwd.Flush();
}
return 0;
}|
Re: Saving and Loading Problem January 30, 2009 07:46AM | Registered: 17 years ago Posts: 109 |
|
Re: Saving and Loading Problem January 30, 2009 11:52AM | Registered: 17 years ago Posts: 25 |
|
Re: Saving and Loading Problem January 30, 2009 02:20PM | Admin Registered: 17 years ago Posts: 5,132 |
|
Re: Saving and Loading Problem January 30, 2009 03:11PM | Registered: 17 years ago Posts: 276 |
Quote
http://www.cplusplus.com/reference/clibrary/cstdio/fread.html
Parameters
size_t fread ( void * ptr, size_t size, size_t count, FILE * stream );
ptr
Pointer to a block of memory with a minimum size of (size*count) bytes.
size
Size in bytes of each element to be read.
count
Number of elements, each one with a size of size bytes.
stream
Pointer to a FILE object that specifies an input stream.
FILE *pattern = fopen("sd:/apps/Wiibreaker/data/pattern1.pattern","rb");
if (pattern)
{
fread(&brickx[0], sizeof(brickx), 1, pattern);
fread(&bricky[0], sizeof(bricky), 1, pattern);
fclose(pattern);
}FILE *pattern = fopen("sd:/apps/Wiibreaker/data/pattern1.pattern","wb");
if (pattern)
{
fwrite(&brickx[0], sizeof(brickx), 1, pattern);
fwrite(&bricky[0], sizeof(bricky), 1, pattern);
fclose(pattern);
}|
Re: Saving and Loading Problem January 30, 2009 03:16PM | Admin Registered: 17 years ago Posts: 5,132 |
|
Re: Saving and Loading Problem January 30, 2009 03:23PM | Registered: 17 years ago Posts: 276 |
|
Re: Saving and Loading Problem January 30, 2009 03:32PM | Admin Registered: 17 years ago Posts: 5,132 |
void SavePattern(){
FILE *pattern = fopen("sd:/apps/Wiibreaker/data/pattern1.pattern","wb");
if (pattern){
for(int i = 0; i < 30; i++){
fwrite(&brickx, sizeof(brickx), 1, pattern);
fwrite(&bricky, sizeof(bricky), 1, pattern);
}
fclose(pattern);
}
}
void LoadPattern(){
FILE *pattern = fopen("sd:/apps/Wiibreaker/data/pattern1.pattern","rb");
if (pattern) {
for(int i = 0; i < 30; i++){
fread(&brickx, sizeof(brickx), 1, pattern);
fread(&bricky, sizeof(bricky), 1, pattern);
}
fclose(pattern);
}
}
EDIT: However it did fix my pattern tool.|
Re: Saving and Loading Problem January 30, 2009 03:41PM | Registered: 17 years ago Posts: 25 |
void SavePattern(){
FILE *pattern = fopen("sd:/apps/Wiibreaker/data/pattern1.pattern","wb");
if (pattern){
for(int i = 0; i < 30; i++){
fwrite(&brickx, sizeof(int), 1, pattern);
fwrite(&bricky, sizeof(int), 1, pattern);
}
fclose(pattern);
}
}
void LoadPattern(){
FILE *pattern = fopen("sd:/apps/Wiibreaker/data/pattern1.pattern","rb");
if (pattern) {
for(int i = 0; i < 30; i++){
fread(&brickx, sizeof(int), 1, pattern);
fread(&bricky, sizeof(int), 1, pattern);
}
fclose(pattern);
}
}
void SavePattern(){
FILE *pattern = fopen("sd:/apps/Wiibreaker/data/pattern1.pattern","wb");
if (pattern){
fwrite(&brickx[0], sizeof(brickx), 1, pattern);
fwrite(&bricky[0], sizeof(bricky), 1, pattern);
fclose(pattern);
}
}
void LoadPattern(){
FILE *pattern = fopen("sd:/apps/Wiibreaker/data/pattern1.pattern","rb");
if (pattern) {
fread(&brickx[0], sizeof(brickx), 1, pattern);
fread(&bricky[0], sizeof(bricky), 1, pattern);
fclose(pattern);
}
}
|
Re: Saving and Loading Problem January 30, 2009 03:50PM | Admin Registered: 17 years ago Posts: 5,132 |
|
Re: Saving and Loading Problem January 30, 2009 04:03PM | Registered: 17 years ago Posts: 276 |
|
Re: Saving and Loading Problem January 30, 2009 04:54PM | Admin Registered: 17 years ago Posts: 5,132 |
|
Re: Saving and Loading Problem January 30, 2009 06:25PM | Registered: 17 years ago Posts: 703 |
unsigned long swap2 (unsigned long number)
{
return (((number&0x000000FF)<<24)+((number&0x0000FF00)<<8) + ((number&0x00FF0000)>>8)+((number&0xFF000000)>>24));
}
for(int i = 0; i < 30; i++){
brickx = swap2 (brickx);
bricky = swap2 (bricky);
}
|
Re: Saving and Loading Problem January 30, 2009 07:02PM | Registered: 17 years ago Posts: 109 |
|
Re: Saving and Loading Problem January 30, 2009 11:36PM | Registered: 17 years ago Posts: 78 |
/* NOT a working example, just a hint to get you started */
/* This will save each integer on a new line */
/* FILE *f is a stream you have opened elsewhere */
void write_int_to_file(int value, FILE *f) {
char buffer[12]; /* You will need some memory to hold the string */
sprintf(buffer, "%d\n", value); /* print the numerical representation of the int into the buffer */
fputs(buffer, f); /* Write the buffer to the file stream */
}
/* This will return the integer value in the array */
int read_int_from_array(char *array) {
return atoi(array);
}
void load_file() {
/* Open the file stream here - I'll call it inFile */
char buffer[12]; /* buffer to read each line of the file to */
while (fgets(buffer, 12, inFile) != NULL) {
int value = read_int_from_array(buffer);
/* Do something with value */
}
}|
Re: Saving and Loading Problem January 31, 2009 11:49AM | Registered: 17 years ago Posts: 265 |