// // When a mouse is clicked on the container /// @param x a int /// @param y a int /// @param button a int /// void cWindow::MouseClicked(int x, int y, int button) { //if content was clicked if((x >= m_X) && (x <= (m_X + m_Width))) { if((y >= m_Y) && (y <= (m_Y + m_Height))) { Logic(); //send click events to child m_Content->MouseClicked(x - m_X, y - m_Y, button); } } //if titlebar was clicked if((x >= m_X) && (x <= (m_X + m_Width))) { if((y >= (m_Y + m_Height)) && (y <= (m_Y + m_Height + m_TitleHeight))) { sPoint point; point.x = (GLfloat)(x - m_X); point.y = (GLfloat)(y - m_Y); m_ClickedPoint = point; m_Movable = true; m_Button = button; } } }
void cPlayer::doLogic(float const t, float const dt) { Logic(); for (std::size_t i = 0; i < mAttacks.size(); ++i) { mAttacks[i].doLogic(t,dt); } Vec3 const tilePos = mCoordChange.WorldToTile(posW); if(tilePos.y<0) mLife = 0; }
void Main_Loop() { while(running) { Logic(); Draw(); } }
/*** Loop ***/ void Loop( float elapsed ) { /* Input, Lógica, Sonido y Video */ Input( elapsed ); Logic( elapsed ); Sound( elapsed ); Video( elapsed ); }
void Enemy::Follow() { myAI = COMBAT; if( !pathSearched ) { std::cout<<"mob"<<myID<<": Searching for path...\n"; pathfinderPath.resize(0); iterator = 0; oldHeroPosition = sf::Vector2i( (int)Hero::myPosition.x,(int)Hero::myPosition.y ); pathStatus = GameEngine::getInstance()->pathfinder->FindPath( myID, myPosition , oldHeroPosition ); pathfinderPath = GameEngine::getInstance()->pathfinder->GetPath( myID ); pathSearched = true; } if( pathStatus == PathFinder::FOUND ) { if( iterator != pathfinderPath.size() ) { if( targetReached == true ) { pathFinderPoint = pathfinderPath[iterator]; pathFinderPoint.x = pathFinderPoint.x *32 +8 + rand()%24; pathFinderPoint.y = pathFinderPoint.y *32 +8 + rand()%24; iterator++; //std::cout<<"mob"<<myID<<": heading to : x = "<<pathFinderPoint.x /32<<" y = " << pathFinderPoint.y/32<<std::endl; if( iterator % 5 == 0 ) { if( ( oldHeroPosition.x/32 != (int)Hero::myPosition.x /32 ) && ( oldHeroPosition.y/32 != (int)Hero::myPosition.y /32 ) ) { pathSearched = false; } } } } else { std::cout<<"mob"<<myID<<": Target reached!\n"; myAI = FOLLOW; pathSearched = false; } Logic( pathFinderPoint ); } else { myAI = RETURN_TO_PATHWALK; pathSearched = false; myWeapon->active = false; std::cout<<"mob"<<myID<<": No path found\n"; } if( distanceFromHero > escapeRange ) { myAI = RETURN_TO_PATHWALK; pathSearched = false; std::cout<<"mob"<<myID<<": Returning to path...\n"; } }
void Enemy::Combat() { Logic( pathFinderPoint ); attacking = true; myWeapon->active = true; myWeapon->SetFiringPosition( sf::Vector2f( (float)myPosition.x, (float)myPosition.y) ); inMove = false; myAI = FOLLOW; }
void Splash_Screen::Start() { Setup(); //blank function call to be overridden by inheriting classes while (!m_close_splash && !m_game_over) //if the splash screen should be closed or the game should be ended { SDL_Flip(m_game->screen); //flip screen m_game->GetUserInput(); //get input from player Handle_Keys(); //blank function call to be overriden by inheriting classes, deals with input from previous step Logic(); //blank function call to be overriden by inheriting classes, handles the logic of each screen Render(); //each inheriting class uses Render in the same way so it makes sense to have it here } }
int main(){ EngineInit(); while(true){ Input(); Gui(); Logic(); Render(); } return 0; }
/** * Main. * @param Pointer to the UNIVERSE. * @return Success. */ int main(int argc, char *argv[]) { Initialize(); LoadData(); NewGame(); while(running) { Logic(); Drawing(); } Shutdown(); return 0; }
// // When a mouse is clicked on the container /// @param x a int /// @param y a int /// @param button a int /// void cContainer::MouseClicked(int x, int y, int button) { if((x >= m_X) && (x <= (m_X + m_Width))) { if((y >= m_Y) && (y <= (m_Y + m_Height))) { Logic(); //send click events to all childern for(std::list< cWidget* >::iterator itr = m_Widgets.begin(); itr != m_Widgets.end(); itr++) { (*itr)->MouseClicked(x - m_X, y - m_Y, button); } } } }
int main(int argc, char* argv[]) #endif { if( !Begin() ) return -1; DWORD time = 0; while(true) { #if !defined(_DEBUG) && defined(WIN32) __try { #endif if (MainServer.getServerState() == EStateStopping) { break; } Logic(); if( timeGetTime() - time > 2000 ) { time = timeGetTime(); Output(); } #if !defined(_DEBUG) && defined(WIN32) } __except (HandleException(GetExceptionInformation(), "CentralServers")) { // We don't actually do anything inside the handler. All of the // work is done by HandleException() } #endif #ifdef _WIN32 Sleep(1); #else #ifdef __linux__ usleep(1000); #endif #endif } End(); return 0; }
void Enemy::PathWalk() { attacking = false; if( frameCount == 50 ) { if( distanceFromHero < pullRange ) { if( GameEngine::getInstance()->pathfinder->IsInSight(myPosition,heroPosition) ) { myAI = FOLLOW; std::cout<<"mob"<<myID<<" Following...\n" ; } } }else { if(waitTimeCounter < waitTime && targetReached == true) { waitTimeCounter++; } else { waitTimeCounter = 0; // start chodzenia sciezka if( (unsigned)iterator < randomPatrolPath[pathNumber].size() ) { if( targetReached == true ) { pathFinderPoint = randomPatrolPath[pathNumber][iterator];//randomPatrolPath[pathNumber][iterator] pathFinderPoint.x = pathFinderPoint.x *32 +8 + rand()%24; pathFinderPoint.y = pathFinderPoint.y *32 +8 + rand()%24; iterator++; } } else { pathNumber++; iterator = 0; if( pathNumber >= numberOfRandomPathPoints ) pathNumber = 0; } Logic( pathFinderPoint ); // stop chodzenia sciezka } } }
bool CGame::Run() { m_gameLoop = true; m_pLogic->m_renderFlags.state = RS_renderMainMenu; double deltaTime = 0; double fps = 0; double currentTime = 0; m_pTimer->Start(); double vSyncLastTime = m_pTimer->GetTimeEx(); while (m_gameLoop) { currentTime = m_pTimer->GetTimeEx(); if (!Events()) break; m_pTimer->End(); deltaTime = m_pTimer->GetTime(); fps = m_pTimer->GetMicro(); m_pTimer->Start(); m_gameLoop = Logic(deltaTime); if (g_FPSLimit) { if (vSyncLastTime + 8333.333333 <= currentTime) { fps = (currentTime-vSyncLastTime); vSyncLastTime = currentTime; Render(1000000/fps); } } else { fps = (currentTime-vSyncLastTime); vSyncLastTime = currentTime; Render(1000000/fps); } } return true; }
// // Tells the widget where the mouse clicked /// @param x a int /// @param y a int /// void cTextbox::MouseClicked(int x, int y, int button) { bool clicked = false; if((x >= m_X) && (x <= (m_X + m_Width))) { if((y >= m_Y) && (y <= (m_Y + m_Height))) { clicked = true; Logic(); } } if(!clicked) { TextFocus( false ); } }
void Enemy::ReturnToPathWalk() { if( frameCount == 50 ) { if( distanceFromHero < pullRange ) { if( GameEngine::getInstance()->pathfinder->IsInSight(myPosition,heroPosition) ) { myAI = FOLLOW; std::cout<<"Following...\n" ; } } }else { if( FindPath( target ) == PathFinder::FOUND ) { if( iterator != pathfinderPath.size() ) { if( targetReached == true ) { pathFinderPoint = pathfinderPath[iterator]; pathFinderPoint.x = pathFinderPoint.x *32 + rand()%32; pathFinderPoint.y = pathFinderPoint.y *32 + rand()%32; iterator++; } } else { myAI = PATHWALK; pathSearched = false; } Logic( pathFinderPoint ); } } }
void luaV_execute (lua_State *L, int nexeccalls) { LClosure *cl; StkId base; TValue *k; const Instruction *pc; reentry: /* entry point */ lua_assert(isLua(L->ci)); pc = L->savedpc; cl = &clvalue(L->ci->func)->l; base = L->base; k = cl->p->k; /* main loop of interpreter */ for (;;) { const Instruction i = *pc++; StkId ra; if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) { traceexec(L, pc); if (L->status == LUA_YIELD) { /* did hook yield? */ L->savedpc = pc - 1; return; } base = L->base; } /* warning!! several calls may realloc the stack and invalidate `ra' */ ra = RA(i); lua_assert(base == L->base && L->base == L->ci->base); lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); switch (GET_OPCODE(i)) { case OP_MOVE: { setobjs2s(L, ra, RB(i)); continue; } case OP_LOADK: { setobj2s(L, ra, KBx(i)); continue; } case OP_LOADBOOL: { setbvalue(ra, GETARG_B(i)); if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ continue; } case OP_LOADNIL: { TValue *rb = RB(i); do { setnilvalue(rb--); } while (rb >= ra); continue; } case OP_GETUPVAL: { int b = GETARG_B(i); setobj2s(L, ra, cl->upvals[b]->v); continue; } case OP_GETGLOBAL: { TValue g; TValue *rb = KBx(i); sethvalue(L, &g, cl->env); lua_assert(ttisstring(rb)); Protect(luaV_gettable(L, &g, rb, ra)); continue; } case OP_GETTABLE: { Protect(luaV_gettable(L, RB(i), RKC(i), ra)); continue; } case OP_SETGLOBAL: { TValue g; sethvalue(L, &g, cl->env); lua_assert(ttisstring(KBx(i))); Protect(luaV_settable(L, &g, KBx(i), ra)); continue; } case OP_SETUPVAL: { UpVal *uv = cl->upvals[GETARG_B(i)]; setobj(L, uv->v, ra); luaC_barrier(L, uv, ra); continue; } case OP_SETTABLE: { Protect(luaV_settable(L, ra, RKB(i), RKC(i))); continue; } case OP_NEWTABLE: { int b = GETARG_B(i); int c = GETARG_C(i); sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c))); Protect(luaC_checkGC(L)); continue; } case OP_SELF: { StkId rb = RB(i); setobjs2s(L, ra+1, rb); Protect(luaV_gettable(L, rb, RKC(i), ra)); continue; } case OP_ADD: { arith_op(luai_numadd, TM_ADD); continue; } case OP_SUB: { arith_op(luai_numsub, TM_SUB); continue; } case OP_MUL: { arith_op(luai_nummul, TM_MUL); continue; } case OP_DIV: { arith_op(luai_numdiv, TM_DIV); continue; } case OP_MOD: { arith_op(luai_nummod, TM_MOD); continue; } case OP_POW: { arith_op(luai_numpow, TM_POW); continue; } case OP_UNM: { TValue *rb = RB(i); if (ttisnumber(rb)) { lua_Number nb = nvalue(rb); setnvalue(ra, luai_numunm(nb)); } else { Protect(Arith(L, ra, rb, rb, TM_UNM)); } continue; } #if defined(LUA_BITWISE_OPERATORS) case OP_BOR: { logic_op(luai_logor, TM_BOR); continue; } case OP_BAND: { logic_op(luai_logand, TM_BAND); continue; } case OP_BXOR: { logic_op(luai_logxor, TM_BXOR); continue; } case OP_BLSHFT: { logic_op(luai_loglshft, TM_BLSHFT); continue; } case OP_BRSHFT: { logic_op(luai_logrshft, TM_BRSHFT); continue; } case OP_BNOT: { TValue *rb = RB(i); if (ttisnumber(rb)) { lua_Integer r; lua_Number nb = nvalue(rb); luai_lognot(r, nb); setnvalue(ra, r); } else { Protect(Logic(L, ra, rb, rb, TM_BNOT)); } continue; } case OP_INTDIV: { arith_op(luai_numintdiv, TM_DIV); continue; } #endif case OP_NOT: { int res = l_isfalse(RB(i)); /* next assignment may change this value */ setbvalue(ra, res); continue; } case OP_LEN: { const TValue *rb = RB(i); switch (ttype(rb)) { case LUA_TTABLE: { setnvalue(ra, cast_num(luaH_getn(hvalue(rb)))); break; } case LUA_TSTRING: { setnvalue(ra, cast_num(tsvalue(rb)->len)); break; } default: { /* try metamethod */ Protect( if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN)) luaG_typeerror(L, rb, "get length of"); ) } } continue; } case OP_CONCAT: { int b = GETARG_B(i); int c = GETARG_C(i); Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L)); setobjs2s(L, RA(i), base+b); continue; } case OP_JMP: { dojump(L, pc, GETARG_sBx(i)); continue; } case OP_EQ: { TValue *rb = RKB(i); TValue *rc = RKC(i); Protect( if (equalobj(L, rb, rc) == GETARG_A(i)) dojump(L, pc, GETARG_sBx(*pc)); ) pc++; continue; } case OP_LT: { Protect( if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i)) dojump(L, pc, GETARG_sBx(*pc)); ) pc++; continue; } case OP_LE: { Protect( if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i)) dojump(L, pc, GETARG_sBx(*pc)); ) pc++; continue; }
// ============================================================================= // Nat Ryall 13-Apr-2008 // ============================================================================= void CPlayer::Update() { const static xfloat s_fMoveDir[PlayerDirection_Max] = {-1.f, -1.f, 1.f, 1.f}; static xfloat s_fBlockSize = 48.f; xfloat fAlpha = 1.f; switch (m_iState) { case PlayerState_Idle: { Logic(); // Idle is a logic state so if we have a state now, process it immediately. if (m_iState != PlayerState_Idle) Update(); } break; case PlayerState_Move: { // Move the player along their path. m_iTime = Math::Clamp<xint>(m_iTime + _TIMEDELTA, 0, m_iMoveTime); m_fTransition = Math::Clamp((xfloat)m_iTime / (xfloat)m_iMoveTime, 0.f, 1.f); m_pSprite->SetPosition(m_pCurrentBlock->GetScreenPosition() + (((m_pTargetBlock->GetScreenPosition() - m_pCurrentBlock->GetScreenPosition()) * m_iTime) / m_iMoveTime)); // See if we have arrived at the next block. if (m_pSprite->GetPosition() == m_pTargetBlock->GetScreenPosition()) { m_pCurrentBlock = m_pTargetBlock; m_pTargetBlock = NULL; SetState(PlayerState_Idle); } } break; case PlayerState_Warp: { if (m_bLeaving) { m_iTime = Math::Clamp<xint>(m_iTime + _TIMEDELTA, 0, m_iMoveTime); m_fTransition = Math::Clamp((xfloat)m_iTime / (xfloat)m_iMoveTime, 0.f, 1.f); if (m_iTime == m_iMoveTime) { m_fTransition = 1.f; m_pCurrentBlock = Global.m_pActiveMap->GetAdjacentBlock((t_AdjacentDirection)m_iTransitionDir, m_pCurrentBlock); m_iTransitionDir = (t_PlayerDirection)((m_iTransitionDir + 2) % PlayerDirection_Max); m_bLeaving = false; } } else { m_iTime = Math::Clamp<xint>(m_iTime - _TIMEDELTA, 0, m_iMoveTime); m_fTransition = Math::Clamp((xfloat)m_iTime / (xfloat)m_iMoveTime, 0.f, 1.f); if (m_iTime == 0) { m_fTransition = 0.f; SetState(PlayerState_Idle); } } xpoint xOffset; if (m_iTransitionDir % 2) xOffset.iY = (xint)(m_fTransition * s_fBlockSize * s_fMoveDir[m_iTransitionDir]); else xOffset.iX = (xint)(m_fTransition * s_fBlockSize * s_fMoveDir[m_iTransitionDir]); m_pSprite->SetPosition(m_pCurrentBlock->GetScreenPosition() + xOffset); if (Global.m_pLocalPlayer == this) Global.m_fScreenAlpha = Math::Clamp(1.f - m_fTransition, 0.f, 1.f); } break; case PlayerState_Die: { // Burst into particle dust, the ghost should keep moving. // Restart the round. } break; } if (this != Global.m_pLocalPlayer) { xfloat fVisibility = (m_pCurrentBlock->m_fPlayerVisibility * (1.f - m_fTransition)); if (m_pTargetBlock) fVisibility += m_pTargetBlock->m_fPlayerVisibility * m_fTransition; m_pSprite->SetAlpha(fVisibility * fAlpha); } else m_pSprite->SetAlpha(fAlpha); m_pSprite->Update(); }