static void Parse(lua_State* L, void* userData) { // We currently can't run the GC while parsing because some objects used by // the parser are not properly stored in a root location. ParseArgs* args = static_cast<ParseArgs*>(userData); Input input; Input_Initialize(L, &input, args->reader, args->userdata); Prototype* prototype = NULL; if (Input_PeekByte(&input) == '\033') { // The data is a pre-compiled binary. prototype = LoadBinary(L, &input, args->name); } else { prototype = Parse(L, &input, args->name); } ASSERT(prototype != NULL); PushPrototype(L, prototype); Table* env = L->globals.table; Closure* closure = Closure_Create(L, prototype, env); PushClosure(L, closure); // Initialize the up values. Typically a top level check won't have any up // values, but if the chunk was created using string.dump or a similar method // it may. These up values will cease to function once the chunk is loaded. for (int i = 0; i < closure->lclosure.numUpValues; ++i) { closure->lclosure.upValue[i] = UpValue_Create(L); } // Remove the prototype from the stack. ASSERT( (L->stackTop - 2)->object == prototype ); State_Remove(L, L->stackTop - 2); }
void UpdateMenu(void) { // 签到 //fprintf(fp, "Level1:Update\n"); // 状态切换 if (KeyPressed[KeyR]) Next = GS_Restart; if (KeyPressed[KeyESC] || (KeyPressed[KeyLeftBottom] && (posX<-160) && (posX>-270) && (posY>-135) && (posY<-85))) Next = GS_Quit; if (KeyPressed[KeyLeftBottom] && (posX<-70) && (posX>-320) && (posY>60) && (posY<110)) Next = GS_L1; if (KeyPressed[Key2]) Next = GS_L2; if (KeyPressed[KeyLeftBottom] && (posX<-160) && (posX>-270) && (posY > -40) && (posY < 10)) Next = GS_L3; // 对象移动 //不需要运动 /* if (KeyPressed[KeyUp]) obj1Y += 0.5f; else if (KeyPressed[KeyDown]) obj1Y -= 0.5f; if (KeyPressed[KeyLeft]) obj1X -= 0.5f; else if (KeyPressed[KeyRight]) obj1X += 0.5f; */ // 输入重置 Input_Initialize(); // 签到 fprintf(fp, "Level1:Update\n"); }
void Update2(void) { //unsigned long i; float winMaxX, winMaxY, winMinX, winMinY; double frameTime; // ========================================================================================== // 获取窗口四条边的坐标,当窗口发生移动或缩放,以下值会发生变化 // ========================================================================================== winMaxX = AEGfxGetWinMaxX(); winMaxY = AEGfxGetWinMaxY(); winMinX = AEGfxGetWinMinX(); winMinY = AEGfxGetWinMinY(); // ====================== // 帧时间:相当于zero中的dt // ====================== frameTime = AEFrameRateControllerGetFrameTime(); // ========================= // 游戏逻辑响应输入 // ========================= // 状态切换 if (KeyPressed[KeyR]) Next = GS_Restart; if (KeyPressed[KeyESC]) Next = GS_Quit; if (KeyPressed[Key1]) Next = GS_L1; if (KeyPressed[KeyMenu]) Next = GS_MENU; // 主角的移动 if (KeyPressed[KeyUp]) { obj1Y += 20.0f; } else if (KeyPressed[KeyDown]) { obj1Y -= 20.0f; } if (KeyPressed[KeyLeft]) { obj1X -= 20.0f; } else if (KeyPressed[KeyRight]) { obj1X += 20.0f; } //鼠标左键控制石头生成 if ((KeyPressed[KeyLeftBottom]) && (Burglar->flag& FLAG_ACTIVE))//&& (StoneCount>0)) { pStone = gameObjCreate(TYPE_STONE, 3.0f, 0, 0, 0.0f);; AE_ASSERT(pStone); // 实例化 // 初始化: 坐标位置 朝向和尺寸大小 //在主角位置产生,射向鼠标位置 pStone->posCurr.x = Burglar->posCurr.x; pStone->posCurr.y = Burglar->posCurr.y; //石头减一 StoneCount -= 1; } //随机产生水果,每隔3秒产生一个,一个界面最多产生10个水果 TimeTot++; if (TimeTot == 180 && Fruit_NUM<10) { Fruit_NUM++; int Xx, Yy; Xx = rand(); Yy = rand(); //控制水果在界面内产生 while (Xx > 800.0f) //控制水果在界面宽度内产生 { Xx = (int)rand(); } while (Yy > 600.0f)//控制水果在界面高度度内产生 { Yy = (int)rand(); } Xx = Xx - 400; Yy = Yy - 300; TimeTot = 0; GameObj* pFruit = gameObjCreate(TYPE_WATERMELON, 3.0f, 0, 0, 0.0f);; AE_ASSERT(pFruit); // 实例化 // 初始化: 坐标位置 朝向和尺寸大小 pFruit->posCurr.x = Xx; pFruit->posCurr.y = Yy; pFruit->scale = 5.0f; } else if (TimeTot == 200) TimeTot = 0; //遍历所有对象以决定操作 for (int i = 1; i < GAME_OBJ_NUM_MAX; i++) { GameObj* pObj = sGameObjList + i; //石头的发射 if (pObj->flag && pObj->pObject->type == TYPE_STONE) { //石头朝着鼠标位置运动 pStone->velCurr.x = (posX - Burglar->posCurr.x) / 10.0f; pStone->velCurr.y = (posY - Burglar->posCurr.y) / 10.0f; pObj->posCurr.x += pObj->velCurr.x; pObj->posCurr.y += pObj->velCurr.y; //碰撞到狗或者boss for (int j = 1; j < GAME_OBJ_NUM_MAX; j++) { GameObj* pObj0 = sGameObjList + j; if (pObj0->flag && (pObj0->pObject->type == TYPE_DOG || pObj0->pObject->type == TYPE_BOSS)) { if (StaticPointToStaticCircle(&pObj->posCurr, &pObj0->posCurr, 10.0)) { gameObjDestroy(pObj0); gameObjDestroy(pObj); } } } } //捡石头 if (pObj->flag&&pObj->pObject->type == TYPE_STONE_STATIC) { if (StaticRectToStaticRect(&Burglar->posCurr, 33, 30, &pObj->posCurr, 15, 15)) { gameObjDestroy(pObj); StoneCount += 1; } } //离陷阱距离近时 if (pObj->flag && pObj->pObject->type == TYPE_TRAP_IN) { if (Burglar->flag&FLAG_ACTIVE) { if (((pObj->posCurr.x - Burglar->posCurr.x)*(pObj->posCurr.x - Burglar->posCurr.x) + (pObj->posCurr.y - Burglar->posCurr.y) *(pObj->posCurr.y - Burglar->posCurr.y)) < 4000) { pTrap = gameObjCreate(TYPE_TRAP_OUT, 10.0f, 0, 0, 0.0f); pTrap->posCurr.x = pObj->posCurr.x; pTrap->posCurr.y = pObj->posCurr.y; pTrap->scale = 10.0; if (StaticRectToStaticRect(&Burglar->posCurr, 30, 30, &pObj->posCurr, 40, 40) && pObj->flag) { Burglar->scale -= 0.5; } if (Burglar->scale < 1.0f) { gameObjDestroy(Burglar);//碰撞了,减少scale,并销毁对象 } } } } //远离陷阱时 if (pObj->flag && pObj->pObject->type == TYPE_TRAP_OUT) { if (((pObj->posCurr.x - Burglar->posCurr.x)*(pObj->posCurr.x - Burglar->posCurr.x) + (pObj->posCurr.y - Burglar->posCurr.y) *(pObj->posCurr.y - Burglar->posCurr.y))>40000) gameObjDestroy(pObj); } //Boss 的运动跟碰撞 if (pObj->flag && pObj->pObject->type == TYPE_BOSS) { //发生碰撞,主角死亡 if (StaticRectToStaticRect(&Burglar->posCurr, 15.0f, 15.0f, &pObj->posCurr, 15.0f, 15.0f)) { gameObjDestroy(Burglar); } } //狗的边界控制 if (pObj->flag&&pObj->pObject->type == TYPE_DOG) { if (pObj->posCurr.x >= winMaxX || pObj->posCurr.x <= winMinX) { pObj->posCurr.x = -pObj->posCurr.x; } if (pObj->posCurr.y <= winMinY || pObj->posCurr.y >= winMaxY) { pObj->posCurr.y = -pObj->posCurr.y; } //是否与狗发生碰撞 if (StaticRectToStaticRect(&Burglar->posCurr, 30, 30, &pObj->posCurr, 30, 30) && pObj->flag) { Burglar->scale -= 0.5; } if (Burglar->scale < 1.0f) { gameObjDestroy(Burglar);//碰撞了,减少scale,并销毁对象 } } //捡西瓜 if (pObj->flag&&pObj->pObject->type == TYPE_WATERMELON) { if (StaticPointToStaticCircle(&Burglar->posCurr, &pObj->posCurr, 10.0)) { gameObjDestroy(pObj); Fruit_NUM -= 1; sScore += 10; } } if (pObj->flag && pObj->pObject->type == TYPE_BURGLARBLOOD) { //更新血量位置 pObj->posCurr.x = Burglar->posCurr.x; pObj->posCurr.y = Burglar->posCurr.y + 35.0f; if (!Burglar->flag&FLAG_ACTIVE) { gameObjDestroy(pObj); //销毁主角的同时,销毁主角的血量 } } }//for //狗运动 for (int a = 0; a < 5; a++) { srand(time()); int PosDogX = (pDog[a]->posCurr.x + 400) / 40; int PosDogY = (pDog[a]->posCurr.y + 300) / 15; if (mapinfo[PosDogX - 1][PosDogY]) { pDog[a]->posCurr.x += 1; } else if (mapinfo[PosDogX + 1][PosDogY]) { pDog[a]->posCurr.x -= 1; } else if (mapinfo[PosDogX][PosDogY + 1]) { pDog[a]->posCurr.y -= 1; } else if (mapinfo[PosDogX][PosDogY - 1]) { pDog[a]->posCurr.y += 1; } //else //{ // pDog[a]->posCurr.x += 2; //} } //狗的运动 TimeTot1++; int x; if (TimeTot1 < 300) { pDog[0]->posCurr.x += 1; pDog[1]->posCurr.x -= 1; pDog[2]->posCurr.y += 1; pDog[3]->posCurr.y -= 1; pDog[4]->posCurr.x += 1; } if (TimeTot1 >= 300 && TimeTot1 < 600) { pDog[0]->posCurr.x -= 1; pDog[1]->posCurr.x += 1; pDog[2]->posCurr.y -= 1; pDog[3]->posCurr.y += 1; pDog[4]->posCurr.y -= 1; } if (TimeTot1 >= 600 && TimeTot1 < 900) { pDog[0]->posCurr.y += 1; pDog[1]->posCurr.y -= 1; pDog[2]->posCurr.x += 1; pDog[3]->posCurr.x -= 1; pDog[4]->posCurr.y += 1; } if (TimeTot1 >= 900 && TimeTot1 < 1200) { pDog[0]->posCurr.y -= 1; pDog[1]->posCurr.y += 1; pDog[2]->posCurr.x -= 1; pDog[3]->posCurr.x += 1; pDog[4]->posCurr.y -= 1; } if (TimeTot1 == 1200) { TimeTot1 = 0; } //按空格键 if (KeyPressed[KeySpace]) { } // 输入重置 Input_Initialize(); // 签到 fprintf(fp, "Level2:Update\n"); }