void check_powerup_col(struct Snake snake[], struct Snake other_snake[], int dir_arg, int player, struct SnakeInfo * info){ checkFood(snake, other_snake, dir_arg, player, info); checkSpeed(snake, other_snake, player, info); checkFreeze(snake,other_snake, player, info); recalc_freeze_times(snake, player,info); checkEdwards(snake, other_snake, player, info); }
void Player::update(bool aim, int xMouse, int yMouse, const Uint8 *keyState, Food *food) { float xHead = 0; float yHead = 0; _head.getPos(&xHead, &yHead); updateBody(xHead, yHead); _head.update(aim, xMouse, yMouse, keyState); int eat = checkFood(food); if(eat){ BodyPart bodyPart(xHead, yHead); _bodyParts.push_back(bodyPart); } }
PlayerAI_Actions PlayerAI::takeAction() { int px, py; PlayerAI_Actions action; /* player coodinates */ px = cd->xpos; py = cd->ypos; /* set map for pathfinding algorithm */ pathfind_alg.setMatrix(cd->mapx, cd->mapy, cd->terrain); pathfind_alg.setSecondMatrix(CLIENT_MATRIX_SIZE, CLIENT_MATRIX_SIZE, cd->dynamic_objects, cd->xpos - MAX_CLIENT_VIEW, cd->ypos - MAX_CLIENT_VIEW); /* if node update was received wait some more */ /* if no update is received for a long time take another action */ if (purpose != BASIC) if (sbx != px || sby != py) { sb_wait_count++; if (sb_wait_count == AI_RETRY_COUNT) { if (debug_AI) printf("[AI]Wait limit reached " "(now:%d,%d -> sb: %d,%d) \n", px, py, sbx, sby); purpose = BASIC; path->clear(); } else return NO_ACTION; } if (debug_AI) printf("[AI][%d,%d]Purpose: %s\n", px, py, AI_state_names[purpose]); cd->purpose = purpose; /* select a new action */ switch (purpose) { case BASIC: checkFood(10) || checkQuest() || checkStrongPlayer() || checkWeakPlayer() || tryToExplore(); break; case SEEKING_QUEST: if (!questExists()) purpose = BASIC; checkFood(20); break; case CHASING_PLAYER: checkFood(40) || checkQuest() || checkWeakPlayer(); break; case EXPLORING: checkFood(90) || checkQuest() || checkStrongPlayer() || checkWeakPlayer(); break; default: break; } /* move player */ action = moveAlongThePath(); if (action != NO_ACTION) return action; if (path->size() <= 1 && purpose == CHASING_PLAYER) { if (debug_AI) printf("[AI]Attack\n"); purpose = BASIC; if (path->size() == 1) { int opponent_x = path->getX(); int opponent_y = path->getY(); if (opponent_x == px + 1) return ATTACK_RIGHT; if (opponent_x == px - 1) return ATTACK_LEFT; if (opponent_y == py + 1) return ATTACK_DOWN; if (opponent_y == py - 1) return ATTACK_UP; } return ATTACK_UP; } /* check if last purpose is over */ if (path->empty() && purpose != BASIC) { if (purpose == SEEKING_FOOD && cd->map[MAX_CLIENT_VIEW][MAX_CLIENT_VIEW].type == CELL_OBJECT && cd->map[MAX_CLIENT_VIEW][MAX_CLIENT_VIEW].quantity > 0) { if (debug_AI) printf("[AI]Eat\n"); purpose = BASIC; return USE; } purpose = BASIC; } return NO_ACTION; }