Difference between revisions of "User talk:TPAINROXX/WiiMoveIt"

From WiiBrew
Jump to: navigation, search
(Help - added ...)
(Project on Hold)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
<!--
 
{{tmbox
 
{{tmbox
 
| type = notice
 
| type = notice
Line 16: Line 17:
 
...
 
...
  
<!-- Boy am I sure stupid... \/
+
==Source Code==
===Mini Game Ideas===
+
'''Code as of 7-16-09. ''' 
  
'''Games (and be detailed):'''
+
Yes, there's a lot of weird stuff going on, but I'm working on that. Also in '''settings.hpp''' part of the code is excerpted from teknecal's Tutorial 13 on saving and loading from XML files. I'll recode/fix it later. [[User:TPAINROXX|<font face="VINETA BT"><font color="black">-TPAINROXX</font>/<font color="green">BKW</font></font>]] 00:25, 17 July 2009 (UTC)
  
What about a puzzle game based on something like crate man, but from above instead of a side view with easily editable levels via a simple text document?--[[User:TPAINROXX|TPAINROXX/BKW]] 22:14, 28 June 2009 (UTC)
+
<div style="float: left;">
 +
{| class="wikitable collapsible collapsed"
 +
|-
 +
! main.cpp
 +
|-
 +
| ''' ''main.cpp'' '''
 +
|<source lang=cpp>
 +
/***********************************************/
 +
/*      WiiMoveIt - By Brandon Whitmire      */
 +
/*          Powered Using GRRLIB 4.0.0        */
 +
/*                  main.cpp                  */
 +
/***********************************************/
  
:Sure. I'll work on it if I can the program to work (again).--[[User:TPAINROXX|TPAINROXX/BKW]] 22:14, 28 June 2009 (UTC)
+
/************************************************
-->
+
TODO:
 +
 
 +
-Add Music/Sound Effects
 +
-Add Multiplayer
 +
-Add More Games
 +
-Add Better Games
 +
-Add Bosses
 +
-Add Storyline
 +
-Add Videos
 +
 
 +
~Fix screenshot destination
 +
~Use latest GRRLIB SVN
 +
 
 +
************************************************/
 +
#ifndef main_WiiMoveIt_cpp  //Not necessarily necessary, but...
 +
#define main_WiiMoveIt_cpp
 +
 
 +
#include "games.hpp"
 +
 
 +
#define __VER__ "1.0 DEMO"  //For version display
 +
 
 +
void game_version()
 +
{
 +
GRRLIB_texImg tex_font1 = GRRLIB_LoadTexture(font1);
 +
    GRRLIB_InitTileSet(&tex_font1, 32, 32, 32);
 +
 +
time(&start_time);
 +
 +
while(1)  //This displays the version and other version data.
 +
{
 +
clrscr();
 +
 +
GRRLIB_Printf(60, 60, tex_font1, WHITE, 2, "LOADING...");
 +
 +
GRRLIB_Printf(15, 150, tex_font1, LIME, 1, "VERSION v%s", __VER__);
 +
 +
GRRLIB_Printf(15, 230, tex_font1, LIME, 1, "DATE: %s", __DATE__);
 +
 +
GRRLIB_Printf(15, 310, tex_font1, LIME, 1, "TIME: %s", __TIME__);
 +
 +
GRRLIB_Printf(15, 400, tex_font1, GREEN, 2, "WIIMOVEIT");
 +
 +
GRRLIB_Render();
 +
 +
time(&cur_time);
 +
 +
if ( (cur_time - start_time) > 5)
 +
{break;}
 +
}
 +
 
 +
free(tex_font1.data);
 +
}
 +
 
 +
int main()
 +
{
 +
GRRLIB_texImg tex_font1 = GRRLIB_LoadTexture(font1);
 +
    GRRLIB_InitTileSet(&tex_font1, 32, 32, 32);
 +
 +
update_settings();
 +
 +
while(1)
 +
{
 +
clrscr();
 +
 +
load_settings() ? GRRLIB_Printf(60, 60, tex_font1, WHITE, 1, "SETTINGS LOADED!") : GRRLIB_Printf(60, 60, tex_font1, WHITE, 1, "ERROR LOADING SETTINGS!");
 +
 
 +
GRRLIB_Render();
 +
 +
WPAD_ScanPads();
 +
 +
if (WPAD_ButtonsHeld(0) && WPAD_BUTTON_HOME)
 +
{break;}
 +
}
 +
 
 +
free(tex_font1.data);
 +
 
 +
WLToggle();
 +
 
 +
GRRLIB_Init();
 +
 +
WPAD_Init();
 +
 +
WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
 +
 +
WPAD_SetVRes(0, 640, 480);
 +
 
 +
game_version(); //This displays the version and other version data.
 +
 +
intro();
 +
 +
exit_menu();
 +
 +
GRRLIB_Exit();
 +
 +
WLToggle();
 +
 +
return 0;
 +
}
 +
 
 +
//---------------------------------------------------------
 +
//    End of main.cpp
 +
//---------------------------------------------------------
  
==Code (for corrections and help)==
+
#endif //main_WiiMoveIt_cpp
'''Code as of 6-28-09.
 
  
Currently the program doesn't work: either a blank screen or code dump.'''
+
</source>
 +
|}
 +
</div>
  
<source lang=cpp>
 
  
/*=========================================================
+
<div style="float: left;">
WARNING: Working file; be carful with editing.
+
{| class="wikitable collapsible collapsed"
 +
|-
 +
! games.cpp
 +
|-
 +
| ''' '' games.hpp '' '''
 +
|<source lang=cpp>
 +
//---------------------------------------------------------
 +
//    games.cpp - Includes basic game engine.
 +
//---------------------------------------------------------
 +
/*********************************************************/
  
WiiMoveIt - By: Brandon Whitmire
+
#ifndef games_WiiMoveIt_hpp  //To prevent multiple inclusions.
 +
#define games_WiiMoveIt_hpp
  
Thanks for GRRLIB, and to NoNameNo and Crayon for GRRLIB help.
 
//=========================================================
 
GRRLIB Download and Help Forum : http://grrlib.santo.fr
 
*///=======================================================
 
//    START FILE INCLUSION
 
 
//---------------------------------------------------------
 
//---------------------------------------------------------
//    Important Files & Headers
+
//    GRRLIB - So Important it has its own spot....
///////////////////////////////////////////////////////////
+
//---------------------------------------------------------
//To switch between version because SVN doesn't always work.
+
 
//Or I don't know how to use it (mostly this is the problem).
+
#include "GRRLIB/GRRLIB/GRRLIB.h" //Version packed with GRRLIB 4.0.0
 +
 
 +
//---------------------------------------------------------
 +
//     Settings File
 +
//---------------------------------------------------------
  
// #include "GRRLIB/GRRLIB/GRRLIB.h" //Version packed with GRRLIB 4.0.0
+
#include "settings.hpp"
 +
 
 +
//---------------------------------------------------------
 +
//     Regular Headers and Such
 +
//---------------------------------------------------------
  
#include "GRRLIB/SVN/GRRLIB.h"    //SVN Version; rev101.
 
 
///////////////////////////////////////////////////////////
 
#include <cstdlib>
 
 
#include <time.h> //For time comparison.
 
#include <time.h> //For time comparison.
 
#include <unistd.h>  //For usleep();
 
#include <unistd.h>  //For usleep();
Line 61: Line 183:
 
using namespace std;
 
using namespace std;
  
//---------------------------------------------------------
+
//=========================================================
 
//    Start All File Inclusion
 
//    Start All File Inclusion
//---------------------------------------------------------
+
//=========================================================
  
#include "credits/intro.h"
+
#include "fonts/font1.h"
#include "fonts/font.h"
+
#include "fonts/font2.h"
 +
#include "fonts/font3.h"
  
 
//---------------------------------------------------------
 
//---------------------------------------------------------
//    For Regular Menu (aka "Lights Off")
+
//    Credits/Intro
 
//---------------------------------------------------------
 
//---------------------------------------------------------
  
#include "gfx/pointer1.h"
+
#include "credits/intro/swirl.h"
 +
#include "credits/intro/TPAINROXX.h"
  
#include "gfx/menu_pix/menu.h"
+
#include "credits/BKGD.h"
 
+
#include "credits/GRRLIB.h"
#include "gfx/menu_pix/button1.h"
+
#include "credits/Wilber.h"
#include "gfx/menu_pix/button2.h"
+
#include "credits/BKW2.h"
#include "gfx/menu_pix/button3.h"
+
#include "credits/Devkitlogo.h"
  
 
//---------------------------------------------------------
 
//---------------------------------------------------------
//    For Inverted Menu (aka "Lights On")
+
//    Menu
 
//---------------------------------------------------------
 
//---------------------------------------------------------
  
#include "gfx/pointer1_i.h"
+
#include "Menu/Pointer.h"
  
#include "gfx/menu_pix/menu_i/menu_i.h"
+
#include "Menu/WiiMoveIt.h"
  
#include "gfx/menu_pix/menu_i/button1_i.h"
+
#include "Menu/Exit.h"
#include "gfx/menu_pix/menu_i/button2_i.h"
 
#include "gfx/menu_pix/menu_i/button3_i.h"
 
  
//---------------------------------------------------------
+
#include "Menu/Buttons/BButton.h"
//     Options
+
#include "Menu/Buttons/WButton.h"
//---------------------------------------------------------
+
 
 +
#include "Menu/Buttons/Start.h"
 +
#include "Menu/Buttons/Options.h"
 +
#include "Menu/Buttons/Exit.h"
 +
 
 +
#include "Menu/Buttons/Button.h"
  
#include "gfx/menu_pix/options/options.h"
+
#include "Menu/Highlight.h"
#include "gfx/menu_pix/options/button.h"
+
#include "Menu/Highlight2.h"
  
 
//---------------------------------------------------------
 
//---------------------------------------------------------
Line 126: Line 253:
 
//Game 5 - The Square
 
//Game 5 - The Square
  
//---------------------------------------------------------
+
//Game 6 - Fix TV
 +
 
 +
//=========================================================
 +
//
 
//    END OF FILE INCLUSION
 
//    END OF FILE INCLUSION
//---------------------------------------------------------
+
//
///////////////////////////////////////////////////////////
+
//=========================================================
//---------------------------------------------------------
 
 
//    Important Variables and Functions
 
//    Important Variables and Functions
//---------------------------------------------------------
+
//=========================================================
 
 
void GRRLIB_FreeTexture(struct GRRLIB_texImg *tex)  //Declared here because of errors relating to not being declared.
 
{ //This is still part of GRRLIB, though.
 
    free(tex->data);
 
    free(tex);
 
    tex = NULL;
 
}
 
  
 
//Easy color codes from Crayon...
 
//Easy color codes from Crayon...
Line 160: Line 282:
 
#define WHITE  0xFFFFFFFF
 
#define WHITE  0xFFFFFFFF
  
void clrscr()
+
Mtx GXmodelView2D;  //Needed for GRRLIB
 +
 
 +
void clrscr()       //"Clears Screen"... for quick screen clearing...
 
{GRRLIB_FillScreen(BLACK);}
 
{GRRLIB_FillScreen(BLACK);}
  
Mtx GXmodelView2D;  //Needed for GRRLIB
+
time_t start_time, cur_time;  //Time delays/comparisons.
 +
 
 +
/*Wiimote 1 DATA*/
  
//Wiimote 1
+
ir_t ir1;  //IR Movement
ir_t ir1;  //IR Movement
 
 
 
orient_t or1;  //Orientation Movement
+
orient_t or1;  //Orientation Movement
 +
 
 +
/*Wii Light - Thanks to Crayon... again...*/
 +
 
 +
static vu32 *_wiilight_reg = (u32*)0xCD0000C0;
 +
/*
 +
void WiiLightOff()
 +
{*_wiilight_reg &= 0x20;}
  
time_t start_time, cur_time;  //Time delays/comparisons; may not be used.
+
void WiiLightOn()
 +
{*_wiilight_reg |= 0x20;}
 +
*/
 +
bool do_wiilight = true;  //For toggling on and off.
  
bool normal_menu = true; //If true then the it will be "Lights Off" for the menu.
+
void WLToggle()  //Toggles WiiLight on and off
 +
{
 +
if (wiilight) //From settings; if true then it does \/.
 +
{do_wiilight ? *_wiilight_reg |= 0x20 : *_wiilight_reg &= 0x20;}
 +
}
  
 
//---------------------------------------------------------
 
//---------------------------------------------------------
//    Rumble for IR Pointer Going Over a Button
+
//    Rumble Stuff
 
//---------------------------------------------------------
 
//---------------------------------------------------------
  
bool do_rumble = true; //This is so the Wiimote only rumbles one time if it's on a button.
+
#define P1 0  //For easy understanding.
 +
#define P2 1
 +
 
 +
bool do_rumble = true;
  
void rumble(u32 remote_channel)
+
void rumble(u32 _wiimote_channel_or_PLAYER_NUMBER_)
 
{
 
{
if (do_rumble == true)
+
if (rumbling)
 
{
 
{
WPAD_Rumble(remote_channel, 1);
+
if (do_rumble)
 +
{
 +
WPAD_Rumble( _wiimote_channel_or_PLAYER_NUMBER_, 1);
 +
 +
usleep(25000);
 +
 +
WPAD_Rumble( _wiimote_channel_or_PLAYER_NUMBER_, 0);
 
 
usleep(25000);
+
do_rumble = false;
+
}
WPAD_Rumble (remote_channel, 0);
 
 
do_rumble = false;
 
 
}
 
}
 
}
 
}
  
 
//---------------------------------------------------------
 
//---------------------------------------------------------
//    Game and Score Functions and Variables
+
//    Simple IR Comparison Function; Faster to Code
 
//---------------------------------------------------------
 
//---------------------------------------------------------
  
#define GAME_NUM  1 //Number of [WORKING] games.
+
bool IRposition (int IRx1, int IRy1, int IRx2, int IRy2, ir_t IR_T)
#define WIN      true   //A constant to help with "Win/Lose Game" instead of "True/False Game".
+
/*                Min X      Min Y    Max X    Max Y    IR Struct (i.e. ir1)
#define LOSE   false  // "ditto"
+
Returns true if a point lies within specified coodinates based off the IR.*/
 +
{return ((IRx1 <= IR_T.x) && (IRx2 >= IR_T.x) && (IRy1 <= IR_T.y) && (IRy2 >= IR_T.y));}
  
int  game_score = 0;  //Actual game score.
+
//---------------------------------------------------------
int  game_life  = 5;  //Make lives variable depending on difficulty/options.
+
//     Exit Function - GUI Version
bool game;   //This either increases your score or decreases your lives based on game performance.
+
//---------------------------------------------------------
bool game_easy = true;//The easy/hard difficulty variable.
 
  
void score()
+
void exit_menu()
{
+
{
/*
+
GRRLIB_texImg tex_Pointer = GRRLIB_LoadTexture(Pointer);
THIS IS GOOD IF YOU ARE NOT FAMILIAR WITH printf AND RELATED.
+
GRRLIB_texImg tex_Exit = GRRLIB_LoadTexture(Exit);
NORMALLY, I USE cout AND cin INSTEAD OF printf AND scanf.
+
GRRLIB_texImg tex_Highlight = GRRLIB_LoadTexture(Highlight);
 +
GRRLIB_texImg tex_Highlight2 = GRRLIB_LoadTexture(Highlight2);
  
EXCERPTED FROM DEV-CPP HELP ON INPUT/OUTPUT IN C.
+
while(1)
 
+
{
The % Format Specifiers:
+
GRRLIB_FillScreen(SILVER);
 
 
The % specifiers that you can use in ANSI C are:
 
 
 
      Usual variable type          Display
 
 
 
%c        char                    single character
 
%d (%i)   int                      signed integer
 
%e (%E)  float or double          exponential format
 
%f        float or double          signed decimal
 
%g (%G)  float or double          use %f or %e as required
 
%o        int                      unsigned octal value
 
 
 
%p        pointer                  address stored in pointer
 
%s        array of char            sequence of characters
 
%u        int                      unsigned decimal
 
%x (%X)  int                      unsigned hex value
 
*/
 
clrscr();
 
 
 
GRRLIB_texImg *tex_font = GRRLIB_LoadTexture(font);
+
GRRLIB_DrawImg(0, 0, tex_Exit, 0, 1, 1, SILVER);
GRRLIB_InitTileSet(tex_font, 16, 16, 32);
+
+
WPAD_ScanPads();
GRRLIB_Printf(100, 100, tex_font, BLACK, 2, "SCORE: %d", game_score );
+
 +
if ( IRposition (476, 61, 625, 210, ir1) )  //Cancel
 +
{
 +
rumble(P1);
 
 
GRRLIB_Printf(100, 175, tex_font, BLACK, 2, "LIVES: %d", game_life);
+
GRRLIB_DrawImg(476, 61, tex_Highlight, 0, 1, 1, SILVER);
 
GRRLIB_Printf(100, 250, tex_font, BLACK, 2, (game_easy == true ? "DIFFICULTY: EASY" : "DIFFICULTY: HARD") );
 
 
GRRLIB_Render();
 
 
usleep(3000000);
 
 
GRRLIB_FreeTexture(tex_font);
 
 
 
clrscr();
+
if (WPAD_ButtonsHeld(0) && WPAD_BUTTON_A)   
}
+
{break;}
 
+
}
//,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
 
//    Main Game Program
 
//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
 
 
void GAME()
 
{
 
clrscr();
 
 
//For All Games | Win & Lose |
 
GRRLIB_texImg *tex_Game_Win  = GRRLIB_LoadTexture(Game_Win);
 
GRRLIB_texImg *tex_Game_Lose = GRRLIB_LoadTexture(Game_Lose);
 
GRRLIB_texImg *tex_Game_Over  = GRRLIB_LoadTexture(Game_Over);
 
 
bool game_played[GAME_NUM];
 
 
 
for (int game_count = 1; game_count <= GAME_NUM; game_count++)  //This is to keep track of which games have been played
+
else if ( IRposition (16, 61, 165, 210, ir1) ) //To Wii Menu.
{game_played[game_count - 1] = false;}  //in a session.
 
 
 
while(1)
 
{
 
srand((unsigned)time(0));  //Generates a random number then starts a random game based off that number.
 
int random = ( (rand() % GAME_NUM)+1);
 
 
for (int game_count = 1; game_count <= GAME_NUM; game_count++)
 
 
{
 
{
if (game_played[game_count - 1] == true)
+
rumble(P1);
{continue;} //If game has been played then it will go back to the beginning of the loop.
+
 +
GRRLIB_DrawImg(16, 61, tex_Highlight, 0, 1, 1, SILVER);
 +
 +
if (WPAD_ButtonsHeld(0) && WPAD_BUTTON_A)
 +
{SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);}  
 
}
 
}
//.........................................................
+
if (random == 1)
+
else if ( IRposition (221, 61, 420, 260, ir1) ) //To Loader.
 
{
 
{
GRRLIB_texImg *tex_thing      = GRRLIB_LoadTexture(thing);
+
rumble(P1);
GRRLIB_texImg *tex_game1_start = GRRLIB_LoadTexture(game1_start);
+
GRRLIB_texImg *tex_game1_play  = GRRLIB_LoadTexture(game1_play);
+
GRRLIB_DrawImg(221, 61, tex_Highlight2, 0, 1, 1, SILVER); //Box is slightly bigger.
+
while(1)
+
if (WPAD_ButtonsHeld(0) && WPAD_BUTTON_A)
{
+
{exit(0);}
GRRLIB_DrawImg(0, 0, tex_game1_start, 0, 1, 1, BLACK);
 
 
GRRLIB_DrawImg(ir1.x - (32), ir1.y - (26), tex_thing, or1.roll, ir1.z, ir1.z, BLACK);
 
 
GRRLIB_Render();
 
 
clrscr();
 
/*
 
if () //These are conditionals for declaring whether or not the game is won.
 
{game = WIN;}
 
 
else if ()
 
{game = LOSE;}
 
*/
 
}
 
 
game_played[0] = true;  //Game has been played.
 
 
GRRLIB_FreeTexture (tex_thing);
 
GRRLIB_FreeTexture (tex_game1_start);
 
GRRLIB_FreeTexture (tex_game1_play);
 
 
}
 
}
//.........................................................
+
/* else if (random == 2)
+
else if ( IRposition (96, 271, 245, 420, ir1) ) //Turn off Wii.
{}
 
 
else if (random == 3)
 
{}
 
 
else if (random == 4)
 
{}
 
*/
 
if (game == WIN)
 
 
{
 
{
game_score++;
+
rumble(P1);
+
GRRLIB_DrawImg( 0, 0, tex_Game_Win, 0, 1, 1, BLACK);
+
GRRLIB_DrawImg(96, 271, tex_Highlight, 0, 1, 1, SILVER);
+
if ( (game_score % 10) == 0 ) //You get an extra life for every 10 pts attained.
+
if (WPAD_ButtonsHeld(0) && WPAD_BUTTON_A)
{game_life++;}
+
{SYS_ResetSystem(SYS_POWEROFF, 0, 0);}  
 
}
 
}
+
else if (game == LOSE)
+
else if ( IRposition (386, 271, 535, 420, ir1) ) //Reset Wii.
 
{
 
{
game_life--;
+
rumble(P1);
+
GRRLIB_DrawImg( 0, 0, tex_Game_Lose, 0, 1, 1, BLACK);
+
GRRLIB_DrawImg(386, 271, tex_Highlight, 0, 1, 1, SILVER);
 +
 +
if (WPAD_ButtonsHeld(0) && WPAD_BUTTON_A)
 +
{SYS_ResetSystem(SYS_RESTART, 0, 0);}
 
}
 
}
 +
 +
else
 +
{do_rumble = true;}
 +
 +
WPAD_IR(WPAD_CHAN_0, &ir1);
 +
WPAD_Orientation(WPAD_CHAN_0, &or1); 
 +
 +
GRRLIB_DrawImg( (ir1.x - tex_Pointer.w), (ir1.y - tex_Pointer.h), tex_Pointer, or1.roll, ir1.z, ir1.z, SILVER);
 
 
 
GRRLIB_Render();
 
GRRLIB_Render();
+
}
usleep(4000000);
+
 +
free(tex_Exit.data);
 +
free(tex_Pointer.data);
 +
free(tex_Highlight.data);
 +
free(tex_Highlight2.data);
 +
}
 +
 
 +
//---------------------------------------------------------
 +
//    Intro
 +
//---------------------------------------------------------
 +
 
 +
struct _intro_data
 +
{
 +
int x, y; //Positions
 +
 +
int deg;  //Degrees
 +
 +
float sx, sy;  //Scaling
 +
} dINTRO, dGRRLIB, dGIMP, dBKW2, dDEVKIT, dTPR_BKW; //d prefix added because of errors relating to texture loading.
 +
 
 +
#define MAX_PIXELATE 1
 +
 
 +
bool no_do_it = true;
 +
 
 +
void TPAINROXX_BKW()
 +
{
 +
GRRLIB_texImg tex_swirl = GRRLIB_LoadTexture(swirl);
 +
 +
GRRLIB_texImg tex_swirl2; // For effects.
 +
float pixelate = 0;
 +
 +
GRRLIB_texImg tex_TPR_BKW = GRRLIB_LoadTexture(TPAINROXX);
 +
 +
dTPR_BKW.deg = 0;
 
 
score(); //Displays score.
+
while(1)
 +
{
 +
clrscr();
 +
 +
GRRLIB_BMFX_Pixelate(tex_swirl, tex_swirl2, pixelate);
 +
 +
GRRLIB_DrawImg( (320 - tex_swirl2.w), (240 - tex_swirl2.h), tex_swirl2, dTPR_BKW.deg, 1, 1, BLACK);
 +
 +
if ( !(pixelate >= MAX_PIXELATE) )
 +
{
 +
pixelate += .02;
 +
dTPR_BKW.deg++;
 +
}
 
 
if (game_life <= 0)  //To be conbined with score later (break won't work if in score();).
+
else
 
{
 
{
GRRLIB_DrawImg( 0, 0, tex_Game_Over, 0, 1, 1, BLACK);
+
pixelate = 0;
 +
dTPR_BKW.deg = 0;
 
 
GRRLIB_Render();
+
GRRLIB_DrawImg( (320 - tex_TPR_BKW.w), ( (240 - tex_TPR_BKW.h) - tex_swirl2.h), tex_TPR_BKW, 0, 1, 1, BLACK);
 
 
usleep(4000000);
+
if (no_do_it)
 +
{
 +
time(&start_time);
 +
no_do_it = false;
 +
}
 
 
break;
+
time(&cur_time);
 +
 +
if ( (cur_time - start_time) > 5)
 +
{break;}
 
}
 
}
 
+
 +
GRRLIB_Render();
 
}
 
}
 +
 +
free(tex_TPR_BKW.data);
 +
free(tex_swirl.data);
 
}
 
}
  
//---------------------------------------------------------
+
void intro()
//    Options Function
 
//---------------------------------------------------------
 
 
 
void OPTIONS()
 
 
{
 
{
/* Locations
+
// TPAINROXX_BKW();
First Button: 
 
  
X 540-152 = 388
+
GRRLIB_texImg tex_BKGD = GRRLIB_LoadTexture(BKGD);
Y 280-76  = 204
+
GRRLIB_texImg tex_GRRLIB = GRRLIB_LoadTexture(GRRLIB);
 
+
GRRLIB_texImg tex_Wilber = GRRLIB_LoadTexture(Wilber);
Second Button:
+
GRRLIB_texImg tex_BKW2 = GRRLIB_LoadTexture(BKW2);
 
+
GRRLIB_texImg tex_Devkitlogo = GRRLIB_LoadTexture(Devkitlogo);
X 540-152 = 388
+
Y 380-76  = 304
+
dINTRO.sx = 0, dINTRO.sy = 0;
*/
 
  GRRLIB_texImg *tex_options = GRRLIB_LoadTexture(options);
 
  GRRLIB_texImg *tex_button  = GRRLIB_LoadTexture(button);
 
  GRRLIB_texImg *tex_pointer1  = GRRLIB_LoadTexture(pointer1);
 
 
 
  while(1)
 
  {
 
WPAD_ScanPads();
 
 
 
if (WPAD_ButtonsDown(0) && WPAD_BUTTON_PLUS)
+
while(1)
 
{
 
{
GRRLIB_FreeTexture(tex_options);
+
GRRLIB_FillScreen(SILVER);
GRRLIB_FreeTexture(tex_button);
+
 +
GRRLIB_DrawImg(0, 0, tex_BKGD, 0, dINTRO.sx, dINTRO.sy, SILVER);
 +
 +
GRRLIB_Render();
 
 
score();
+
if (dINTRO.sx >= 1) //Just to make sure...
 +
{break;}
 
 
break;
+
dINTRO.sx += .01;
 +
dINTRO.sy += .01;
 
}
 
}
 
 
clrscr();
 
 
 
GRRLIB_DrawImg( 0, 0, tex_options, 0, 1, 1, BLACK);
+
dGRRLIB.x = (0 - tex_GRRLIB.w);
 +
dGRRLIB.y = (0 - tex_GRRLIB.h);
 
 
if (normal_menu == true)  //Because the normal menu is "Lights Off"
+
dGRRLIB.deg = 0;
{GRRLIB_DrawImg( 388, 204, tex_button, 0, 1, 1, BLACK);}
 
 
 
if (game_easy == false)  //But easy is on and not easy is off.
+
dBKW2.x = (0 - tex_BKW2.w);
{GRRLIB_DrawImg( 388, 304, tex_button, 0, 1, 1, BLACK);}
+
dBKW2.y = ((tex_BKW2.h / 2) + 240); //240 is 1/2 of 480; the screen's height. This should center the image.
 
 
WPAD_IR(WPAD_CHAN_0, &ir1);          //For Wiimote 1 IR.
+
dBKW2.sx = 0, dBKW2.sy = 0;
WPAD_Orientation(WPAD_CHAN_0, &or1); //For Wiimote 1 orientation.
 
 
 
GRRLIB_DrawImg(ir1.x - 48, ir1.y - 45, tex_pointer1, or1.roll, ir1.z, ir1.z, BLACK);
+
bool BKW_switch = true;
 
 
GRRLIB_Render();
+
dGIMP.x = 0;
 +
dGIMP.y = 0;
 
 
if ( ((ir1.x >= 388) & (ir1.x <= 540)) & ((ir1.y >= 204) & (ir1.y <= 280)) )
+
unsigned int counter = 1;
{
 
rumble(0);
 
 
 
WPAD_ScanPads();
+
dDEVKIT.deg = 0;
 
if (WPAD_BUTTON_A & WPAD_ButtonsDown(0))
 
{
 
if (normal_menu == true)  //Lights off.
 
{normal_menu = false;}
 
 
else if (normal_menu == false)  //Lights on.
 
{normal_menu = true;}
 
}
 
 
 
}
+
time(&start_time);
 
 
else if ( ((ir1.x >= 388) & (ir1.x <= 540)) & ((ir1.y >= 304) & (ir1.y <= 380)) )
+
while(1)
 
{
 
{
rumble(0);
+
GRRLIB_FillScreen(SILVER);
 +
 +
GRRLIB_DrawImg(0, 0, tex_BKGD, 0, 1, 1, SILVER);
 +
 +
GRRLIB_DrawImg( 120, 350, tex_Devkitlogo, (dDEVKIT.deg += 1), 1, 1, SILVER);
 
 
WPAD_ScanPads();
+
GRRLIB_DrawImg(dGRRLIB.x, dGRRLIB.y, tex_GRRLIB, dGRRLIB.deg, 1, 1, SILVER);
+
if (WPAD_BUTTON_A & WPAD_ButtonsDown(0))
+
GRRLIB_DrawImg(0, 0, tex_BKW2, 0, dBKW2.sx, dBKW2.sy, SILVER);
{
+
if (game_easy == true)
+
if (BKW_switch)
 +
{
 +
dBKW2.sx += .05;
 +
dBKW2.sy += .05;
 +
 +
if (dBKW2.sx >= .75)
 +
{BKW_switch = false;}
 +
}
 +
 +
else
 +
{
 +
dBKW2.sx -= .05;
 +
dBKW2.sy -= .05;
 +
 +
if (dBKW2.sx <= 0)
 +
{BKW_switch = true;}
 +
}
 +
 +
GRRLIB_DrawImg(dGIMP.x, dGIMP.y, tex_Wilber, 0, 1, 1, SILVER);
 +
 +
if (counter == 1)
 
{
 
{
game_easy = false;
+
dGIMP.x += 5;
game_life = 3;
+
 +
if ( (dGIMP.x % 30) == 0)
 +
{counter++;}
 
}
 
}
 
 
else if (game_easy == false)
+
else if (counter == 2)
 
{
 
{
game_easy = true;
+
dGIMP.y += 5;
game_life = 5;
+
 +
if ( (dGIMP.y % 30) == 0)
 +
{counter--;}
 
}
 
}
}
+
 +
GRRLIB_Render();
 +
 +
dGRRLIB.x += 3;
 +
dGRRLIB.y += 2;
 +
 +
dGRRLIB.deg++;
 +
 +
time(&cur_time);
 +
 +
if ( (cur_time - start_time) >= 10 )
 +
{break;}
 +
 +
WPAD_ScanPads();
 +
 +
if (WPAD_ButtonsHeld(0) && WPAD_BUTTON_HOME)
 +
{break;}
 
}
 
}
 
 
else
+
free(tex_BKGD.data);
{do_rumble = true;}
+
free(tex_GRRLIB.data);
+
free(tex_Wilber.data);
  }
+
free(tex_BKW2.data);
+
free(tex_Devkitlogo.data);
 
}
 
}
  
 
//---------------------------------------------------------
 
//---------------------------------------------------------
//    Intro/Credits Function
+
//    End of games.cpp
 
//---------------------------------------------------------
 
//---------------------------------------------------------
  
void play_intro()
+
#endif //games_WiiMoveIt_hpp
{
+
</source>
clrscr();
+
|}
+
</div>
GRRLIB_texImg *tex_intro = GRRLIB_LoadTexture(intro);
+
 
+
 
GRRLIB_DrawImg( 0, 0, tex_intro, 0, 1, 1, BLACK);
+
<div style="float: left;">
+
{| class="wikitable collapsible collapsed"
GRRLIB_Render();
+
|-
+
! settings.cpp
usleep(400000);
+
|-
 +
| ''' '' settings.hpp '' '''
 +
|<source lang = cpp>
 +
//---------------------------------------------------------
 +
//    settings.hpp - Includes settings/options.
 +
//---------------------------------------------------------
 +
/*********************************************************/
 +
 
 +
#ifndef settings_WiiMoveIt_hpp  //To prevent multiple inclusions.
 +
#define settings_WiiMoveIt_hpp
 +
 
 +
//---------------------------------------------------------
 +
//    XML Library from Beardface, so thanks.
 +
//    -lmxml needs to be added to makefile
 +
//---------------------------------------------------------
 +
 
 +
#include "XML/mxml.h"
 +
 
 +
#include <cstdlib>
 +
 
 +
#include <zlib.h>
 +
 
 +
//=========================================================
 +
//    Settings Functions
 +
//=========================================================
 +
 
 +
/**********************************************************
 +
TODO:
 +
 
 +
-Convert to C++ or something (most of this code
 +
has been excerpted from Tutorial 13 of teknecal's
 +
codemii tutorials)
 +
 
 +
**********************************************************/
 +
 
 +
//---------------------------------------------------------
 +
//    Settings Variables
 +
//---------------------------------------------------------
 +
 
 +
const char set_dest[] = "sd:/apps/WiiMoveIt_V1.0/data/settings/WiiMoveIt.xml";
 +
 
 +
bool rumbling  = true;
 +
 
 +
#define EASY  0  
 +
#define NORMAL 1
 +
#define HARD  2
 +
 
 +
unsigned int difficulty = EASY;
 +
 
 +
bool menu = true;
  
GRRLIB_FreeTexture(tex_intro);
+
bool wiilight = true;
  
clrscr();
+
bool update_settings()  
}
 
//
 
///////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////
 
////-------------------------------------------------------////
 
////    Main Program                                      ////
 
////-------------------------------------------------------////
 
///////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////
 
//
 
int main()  
 
 
{
 
{
GRRLIB_texImg *tex_pointer1  = GRRLIB_LoadTexture(pointer1);
+
mxml_node_t *xml;
 +
mxml_node_t *data;
 +
xml = mxmlNewXML("1.0");
 
 
GRRLIB_texImg *tex_menu      = GRRLIB_LoadTexture(menu);
+
data = mxmlNewElement(xml, "settings");
 
 
GRRLIB_texImg *tex_button1    = GRRLIB_LoadTexture(button1);
+
char set1[1];
GRRLIB_texImg *tex_button2    = GRRLIB_LoadTexture(button2);
+
sprintf(set1, "%i", rumbling);
GRRLIB_texImg *tex_button3    = GRRLIB_LoadTexture(button3);
+
mxmlElementSetAttr(data, "rumble", set1);
+
char set2[1];
GRRLIB_texImg *tex_pointer1_i = GRRLIB_LoadTexture(pointer1_i);
+
sprintf(set2, "%i", difficulty);
 +
mxmlElementSetAttr(data, "difficulty", set2);
 +
char set3[1];
 +
sprintf(set3, "%i", menu);
 +
mxmlElementSetAttr(data, "menu", set3);
 +
char set4[1];
 +
sprintf(set4, "%i", wiilight);
 +
mxmlElementSetAttr(data, "wiilight", set4);
 
 
GRRLIB_texImg *tex_menu_i    = GRRLIB_LoadTexture(menu_i);
+
FILE *f;
 +
f = fopen( set_dest, "wb");
 
 
GRRLIB_texImg *tex_button1_i  = GRRLIB_LoadTexture(button1_i);
+
if (f == NULL) //Settings failed
GRRLIB_texImg *tex_button2_i  = GRRLIB_LoadTexture(button2_i);
+
{
GRRLIB_texImg *tex_button3_i  = GRRLIB_LoadTexture(button3_i);
+
fclose(f);
 +
 +
return false;
 +
}
 
 
    GRRLIB_Init(); //Starts GRRLIB
+
else //Settings saved
 +
{
 +
mxmlSaveFile(xml, f, MXML_NO_CALLBACK);
 +
fclose(f);
 +
mxmlDelete(data);
 +
mxmlDelete(xml);
 +
 +
return true;
 +
}
 +
}
 +
 
 +
bool load_settings()
 +
{
 +
mxml_node_t *tree;
 +
mxml_node_t *data;
 
 
WPAD_Init();   //Start WPAD-related Stuff
+
FILE *fp = fopen(set_dest, "rb");
 
 
WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
+
if (fp == NULL)
+
{
WPAD_SetVRes(WPAD_CHAN_0, 640, 480);
+
fclose(fp);
 +
return false;
 +
}
 
 
play_intro();  //Plays intro/credits
+
else
   
+
{
while(1)
+
fseek (fp , 0, SEEK_END);
{
+
long settings_size = ftell (fp);
//***********MENU START******************************************************************************
+
rewind (fp);
 
 
GRRLIB_DrawImg( 0, 0, (normal_menu == true ? tex_menu : tex_menu_i), 0, 1, 1, BLACK);
 
 
WPAD_ScanPads();
 
 
 
//***********START***********************************************************************************
+
if (settings_size > 0)  
if ( ( (ir1.x >= 20) & (ir1.x <= 212) & ( (ir1.y >= 364) & (ir1.y <= 620) ) ) )
 
 
{
 
{
rumble(0);
 
 
 
GRRLIB_DrawImg(20, 364, (normal_menu == true ? tex_button1 : tex_button1_i), 0, 1, 1, BLACK);
+
tree = mxmlLoadFile(NULL, fp, MXML_NO_CALLBACK);
 +
fclose(fp);
 +
 +
data = mxmlFindElement(tree, tree, "settings", NULL, NULL, MXML_DESCEND);
 +
 +
if (mxmlElementGetAttr(data,"rumble"))
 +
{
 +
rumbling = atoi(mxmlElementGetAttr(data,"rumble"));
 +
}
 +
 +
if (mxmlElementGetAttr(data,"difficulty"))
 +
{
 +
difficulty = atoi(mxmlElementGetAttr(data,"difficulty"));
 +
 +
if (difficulty > HARD)
 +
{difficulty = HARD;}
 +
}
 +
 +
if (mxmlElementGetAttr(data,"menu"))
 +
{
 +
menu = atoi(mxmlElementGetAttr(data,"menu"));
 +
}
 +
 +
if (mxmlElementGetAttr(data,"wiilight"))
 +
{
 +
wiilight = atoi(mxmlElementGetAttr(data,"wiilight"));
 +
}
 +
 +
mxmlDelete(data);
 +
mxmlDelete(tree);
 +
 +
return true;
 +
 +
}
 
 
if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_A)
+
else  
{GAME();}
 
 
//************OPTIONS********************************************************************************
 
else if ( ( (ir1.x >= 225) & (ir1.x <= 417) ) & ( (ir1.y >= 364) & (ir1.y <= 620) ) )
 
 
{
 
{
rumble(0);
+
fclose(fp);
+
unlink(set_dest);
GRRLIB_DrawImg(225, 364, (normal_menu == true ? tex_button2 : tex_button2_i), 0, 1, 1, BLACK);
 
 
 
if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_A)
+
return false;
{OPTIONS();}
+
}
}
+
}
 +
}
 +
 
 +
//=========================================================
 +
//    End of Settings Functions
 +
//=========================================================
 +
 
 +
//---------------------------------------------------------
 +
//    Options
 +
//---------------------------------------------------------
  
//************EXIT***********************************************************************************
+
void options()
else if ( ( (ir1.x >= 428) & (ir1.x <= 620) ) & ( (ir1.y >= 364) & (ir1.y <= 620) ) )
+
{
 +
/***
 +
  *
 +
  *
 +
  *
 +
  *TO BE ADDED LATER
 +
  *
 +
  *
 +
  *
 +
***/
 +
}
 +
 
 +
//---------------------------------------------------------
 +
//    Screenshot Function
 +
//---------------------------------------------------------
 +
 
 +
#define CONST_FILENAME 41
 +
 
 +
void SCRSHOT()
 +
{
 +
int scrshotfile = 1;
 +
 
 +
srand((unsigned)time(NULL))
 +
 
 +
const char def_filename[] = "sd:/apps/WiiMoveIt_v1.0/data/screenshots/";
 +
 +
char filename[scrshotfile];
 +
 +
while(1)
 +
{
 +
if ( (scrshotfile <= CONST_FILENAME))
 
{
 
{
rumble(0);
+
filename[scrshotfile - 1] = def_filename[scrshotfile-1];
 +
}
 
 
GRRLIB_DrawImg(428, 364, (normal_menu == true ? tex_button3 : tex_button3_i), 0, 1, 1, BLACK);
+
else
+
{
if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_A)
+
filename[scrshotfile - 1] = ((char) rand());
{goto exit;}
+
}
}
 
//************FOR RUMBLE*****************************************************************************
 
else
 
{do_rumble = true;}
 
//***********END LOOP }******************************************************************************
 
WPAD_IR(WPAD_CHAN_0, &ir1);          //For Wiimote 1 IR.
 
WPAD_Orientation(WPAD_CHAN_0, &or1);  //For Wiimote 1 orientation.
 
 
 
GRRLIB_DrawImg(ir1.x - 48, ir1.y - 45, (normal_menu == true ? tex_pointer1 : tex_pointer1_i), or1.roll, ir1.z, ir1.z, BLACK);
+
if (scrshotfile > 50) break;
 
 
GRRLIB_Render();
+
scrshotfile++;
+
}
clrscr();
 
}
 
//***********END*************************************************************************************
 
exit: //This is just in case I add anything after the loop, then it will exit correctly.
 
 
GRRLIB_FreeTexture(tex_pointer1);  //Not necessarily needed due to GRRLIB_Exit();, but here for future revision.
 
 
GRRLIB_FreeTexture(tex_menu);
 
 
 
GRRLIB_FreeTexture (tex_button1);
+
GRRLIB_ScrShot(filename);
GRRLIB_FreeTexture (tex_button2);
 
GRRLIB_FreeTexture (tex_button3);
 
 
GRRLIB_FreeTexture (tex_pointer1_i);
 
 
GRRLIB_FreeTexture (tex_menu_i);
 
 
GRRLIB_FreeTexture (tex_button1_i);
 
GRRLIB_FreeTexture (tex_button2_i);
 
GRRLIB_FreeTexture (tex_button3_i);
 
 
GRRLIB_Exit();  // Be a good boy, clear the memory allocated by GRRLIB
 
 
    return 0;
 
 
}
 
}
  
 
//---------------------------------------------------------
 
//---------------------------------------------------------
//    End of Program
+
//    End of settings.hpp
 
//---------------------------------------------------------
 
//---------------------------------------------------------
 +
 +
#endif //settings_WiiMoveIt_hpp
  
 
</source>
 
</source>
:Hi, did you see that post: http://grrlib.santo.fr/forum/viewtopic.php?pid=795#p795 from 2009-06-30 17:14:17? -[[User:Crayon|Crayon]] 03:05, 7 July 2009 (UTC)
+
|}
+
</div>
::Oh no, I didn't see that. I'll start implementing it tomorrow (as I've been on vacation a few days...), but thanks Crayon once again! --[[User:TPAINROXX|<font face="VINETA BT"><font color="black">-TPAINROXX</font>/<font color="green">BKW</font></font>]] 03:19, 7 July 2009 (UTC)
+
-->

Latest revision as of 03:44, 24 July 2009