void aiInput_think(aiComp *ai) { aiInput *this = (aiInput *) ai; sfVector2i d = (sfVector2i) {0, 0}; switch(*this->action) { case(ACTION_MOVE_NE): d.x += 1; case(ACTION_MOVE_N): d.y += -1; break; case(ACTION_MOVE_SE): d.y += 1; case(ACTION_MOVE_E): d.x += 1; break; case(ACTION_MOVE_SW): d.x += -1; case(ACTION_MOVE_S): d.y += 1; break; case(ACTION_MOVE_NW): d.y += -1; case(ACTION_MOVE_W): d.x += -1; case(ACTION_NONE): break; } entity_move(this->parent, d); }
// This is the kitten's callback, // all its actions take place here void kitten_move(gpointer kittyp) { Kitten * kitty; Entity * player; Level world; TimeTracker * time; EntitySet * others; float x, y; float px, py; float dx, dy; unsigned int dir; Entity * body; Player * dude; kitty = (Kitten *) kittyp; player = kitty->player; world = kitty->world; time = kitty->time; others = kitty->others; body = kitty->body; entity_position(body, &x, &y); entity_position(player, &px, &py); dir = look(x, y, px, py); dx = px - x; dy = py - y; entity_set_direction(body, dx, dy); entity_move(body, world, time, others); entity_get_direction(body, &dx, &dy); if (collision(body, x + dx, y + dy, others) == player) { if (expired(kitty->claw_timer)) { play_wav(kitty->claw); } if (expired(kitty->attack_timer)) { dude = entity_user_data(player); player_hurt(dude); } if (dir == LEFT) { set_animation(body, "attack_left"); } else if (dir == RIGHT) { set_animation(body, "attack_right"); } else if (dir == UP) { set_animation(body, "attack_up"); } else if (dir == DOWN) { set_animation(body, "attack_down"); } } else if (dir == LEFT) { set_animation(body, "left"); } else if (dir == RIGHT) { set_animation(body, "right"); } else if (dir == UP) { set_animation(body, "up"); } else if (dir == DOWN) { set_animation(body, "down"); } }
void ennemie_move(ennemie* p_ennemie, struct t_map* p_map, struct t_unit* p_unit) { entity_move((entity*)p_ennemie, p_map); }
static void input() { SDL_PumpEvents(); vec3_t inputvec = {0,0,0}; const uint8_t *keyboard = SDL_GetKeyboardState(0); if(takeinput) { if(state_has_controller() && usecontroller) { inputvec.x = leftstick.x; inputvec.z = leftstick.y; rotx += JOYSTICK_SENSITIVITY_LOOK*rightstick.x*dt/1000.0; roty -= JOYSTICK_SENSITIVITY_LOOK*rightstick.y*dt/1000.0; } else { if(keyboard[SDL_SCANCODE_W]) inputvec.z -= 1; if(keyboard[SDL_SCANCODE_A]) inputvec.x -= 1; if(keyboard[SDL_SCANCODE_S]) inputvec.z += 1; if(keyboard[SDL_SCANCODE_D]) inputvec.x += 1; if(keyboard[SDL_SCANCODE_LSHIFT]) inputvec.y -= 1; if(keyboard[SDL_SCANCODE_SPACE]) inputvec.y += 1; int mousex, mousey; SDL_GetMouseState(&mousex, &mousey); state_mouse_center(); double deltamousex = mousex - windoww/2; double deltamousey = mousey - windowh/2; rotx += MOUSE_SENSITIVITY*deltamousex; roty -= MOUSE_SENSITIVITY*deltamousey; roty = roty > M_PI/2-.005 ? M_PI/2-.005 : roty; roty = roty < -M_PI/2+.005 ? -M_PI/2+.005 : roty; rotx = rotx > M_PI*2 ? rotx - M_PI*2: rotx; rotx = rotx < -M_PI*2 ? rotx + M_PI*2: rotx; } } forwardcamera.x = sin(rotx) * cos(roty); forwardcamera.y = sin(roty); forwardcamera.z = -cos(rotx) * cos(roty); vec3_t rotatevec; rotatevec.x = cos(rotx)*inputvec.x - sin(rotx)*inputvec.z; rotatevec.z = sin(rotx)*inputvec.x + cos(rotx)*inputvec.z; rotatevec.y = inputvec.y; if(dt < 500) { if(flying) { rotatevec.x *= PLAYER_FLY_SPEED * dt / 1000.0; rotatevec.y *= PLAYER_FLY_SPEED * dt / 1000.0; rotatevec.z *= PLAYER_FLY_SPEED * dt / 1000.0; entity_move(pos, &rotatevec); } else { rotatevec.x *= PLAYER_WALK_MAX_FORCE; rotatevec.y = 0; rotatevec.z *= PLAYER_WALK_MAX_FORCE; entity_update(pos, &rotatevec, dt/1000.0); } } if(keyboard[SDL_SCANCODE_R]) { block_t b; b.id = SAND; b.metadata.number = SIM_WATER_LEVELS; world_ray_set(&headpos, &forwardcamera, b, 1, 1, 1000); } if(keyboard[SDL_SCANCODE_E]) { world_ray_del(&headpos, &forwardcamera, 1, 1000); } if(keyboard[SDL_SCANCODE_X]) { vec3_t dir; for(dir.x = -1; dir.x < 1; dir.x += .3) for(dir.y = -1; dir.y < 0; dir.y += .3) for(dir.z = -1; dir.z < 1; dir.z += .3) world_ray_del(&headpos, &dir, 1, 50); } headpos = *posptr; headpos.y += PLAYER_EYEHEIGHT; }