Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * PrimeScroll.cpp
- *
- * Created on: Dec 7, 2012
- * Author: duenez
- */
- #define __SCROLL_IMPL__
- #include "PrimeScroll.h"
- #undef __SCROLL_IMPL__
- #include <vector>
- #include "orx.h"
- #include "CCharacter.h"
- #include <sys/time.h>
- #include <time.h>
- CPlayer *Player;
- orxFLOAT Speed;
- orxCLOCK *Clock;
- int gameState;
- void movePlayer();
- void showMenu();
- enum game_state
- {
- GAME_MENU, GAME_OVER, GAME_PLAY
- };
- void PrimeScroll::Update( const orxCLOCK_INFO *_pstClockInfo )
- {
- orxLOG("\nUpdate" );
- //Process all pending callbacks
- CTimer::getInstance()->update( _pstClockInfo->fDT );
- //TODO: Fix prob. of appearance from this exponential!
- // A new NumberBall appears
- if( rand() % 100 == 0 )
- {
- //TODO: Recycle from a pool for efficiency.
- CreateObject( "NumberBall" );
- }
- //TODO: Infinite enemies!!
- if( rand() % 100 == 0 ) //int( orxConfig_GetS32( "NumBugs" )))
- {
- CreateObject( "Bug" );
- }
- }
- void moveCamera()
- {
- //TODO: Don't use hard-coded constants
- orxFLOAT dX = 200, dY = 150;
- orxVECTOR c, p;
- orxCAMERA *cam = orxCamera_Get( "Camera" );
- orxObject_GetPosition( Player->GetOrxObject(), &p );
- //TODO: Find out why the position is offset
- //p.fY -= 300;
- orxCamera_GetPosition( cam, &c );
- //Clip X coordinate
- if( p.fX > c.fX + dX )
- c.fX = p.fX - dX;
- if( p.fX < c.fX - dX )
- c.fX = p.fX + dX;
- //Clip Y coordinate
- if( p.fY > c.fY + dY )
- c.fY = p.fY - dY;
- if( p.fY < c.fY - dY )
- c.fY = p.fY + dY;
- orxCamera_SetPosition( cam, &c );
- }
- /** Input update callback
- */
- void orxFASTCALL InputUpdate(const orxCLOCK_INFO *_pstClockInfo, void *_pstContext)
- {
- if (gameState == GAME_PLAY)
- {
- Player->move();
- moveCamera();
- }
- else if (gameState == GAME_OVER)
- {
- orxOBJECT *text = orxObject_CreateFromConfig( "Te" );
- char str[10];
- sprintf( str, "%s", "GAME OVER" );
- orxSTRING orxStr = str;
- orxObject_SetTextString( text, orxStr );
- gameState = GAME_MENU;
- }
- //else
- // showMenu();
- }
- /*
- void PrimeScroll::showMenu()
- {
- if(orxInput_IsActive("Start"))
- {
- gameState = GAME_PLAY;
- Player = dynamic_cast<CPlayer*>( CreateObject( "Player" ) );
- }
- }
- */
- void setupInput()
- {
- /* Reloads inputs */
- // orxInput_Load(orxSTRING_EMPTY);
- /* Gets main clock */
- orxCLOCK *pstMainClock = orxClock_FindFirst(orx2F(-1.0f), orxCLOCK_TYPE_CORE);
- /* Registers our input update callback to it
- * !!IMPORTANT!! *DO NOT* handle inputs in clock callbacks that are *NOT* registered to the main clock
- * you might miss input status updates if the user clock runs slower than the main one
- */
- orxClock_Register(pstMainClock, InputUpdate, orxNULL, orxMODULE_ID_MAIN, orxCLOCK_PRIORITY_NORMAL);
- }
- void PrimeScroll::BindObjects()
- {
- ScrollBindObject<CEnemy> ("Bug");
- ScrollBindObject<CPlayerBullet> ("Bubble");
- ScrollBindObject<CEnemyBullet> ("EnemyBullet");
- ScrollBindObject<CShrapnel> ("Shrapnel");
- ScrollBindObject<CPlayer> ("Player");
- ScrollBindObject<CNumberBall> ("NumberBall");
- }
- orxSTATUS PrimeScroll::Init()
- {
- //orxS32 i;
- /* Displays a small hint in console */
- orxLOG("\nInit" );
- //Initialize the static variables needed for the Health bars
- CCharacter::Init();
- setupInput();
- orxViewport_CreateFromConfig( "Viewport" );
- Player = CreateObject<CPlayer>( "Player" );
- orxLOG( "\nPlayer %lx", Player->GetOrxObject() );
- Clock = orxClock_CreateFromConfig( "Clock" );
- orxConfig_PushSection( "Constants" );
- Speed = orxConfig_GetFloat( "Speed" );
- orxConfig_PopSection();
- //orxClock_Register( Clock, update, orxNULL, orxMODULE_ID_MAIN, orxCLOCK_PRIORITY_NORMAL );
- //orxEvent_AddHandler( orxEVENT_TYPE_PHYSICS, PhysicsEventHandler );
- //orxEvent_AddHandler( orxEVENT_TYPE_OBJECT, ObjectEventHandler );
- gameState = GAME_PLAY;
- return orxSTATUS_SUCCESS;
- }
- orxSTATUS PrimeScroll::Run()
- {
- return orxSTATUS_SUCCESS;
- }
- void PrimeScroll::Exit()
- {
- //TODO: Save the state! User might want to resume.
- return;
- }
- int main( int argc, char **argv )
- {
- srand( time(NULL) );
- PrimeScroll::GetInstance().Execute( argc, argv );
- PrimeScroll::GetInstance().StartGame();
- //orx_Execute( argc, argv, Init, Run, Exit );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement