Ben Evans University Second Year Project. Game Called Defender.
Embed:
(wiki syntax)
Show/hide line numbers
RandomMovement.cpp
00001 #include "RandomMovement.h" 00002 00003 void RandomMovement::move_direction() { 00004 switch (random_direction_) { 00005 case 0: set_sprite_direction(1, 0); break; 00006 case 1: set_sprite_direction(1, 1); break; 00007 case 2: set_sprite_direction(1, -1); break; 00008 case 3: set_sprite_direction(-1, 0); break; 00009 case 4: set_sprite_direction(-1, 1); break; 00010 case 5: set_sprite_direction(-1, -1); break; 00011 case 6: set_sprite_direction(0, -1); break; 00012 } 00013 } 00014 00015 void RandomMovement::set_sprite_direction(int x_change,int y_change) { 00016 position_x_ += x_change; 00017 position_y_ += y_change; 00018 } 00019 00020 void RandomMovement::set_random_move() { 00021 // Sprite only moves in one general direction 00022 if (direction_) { 00023 random_direction_ = rand() % 3; 00024 }else{ 00025 random_direction_ = rand() % 3 + 3; 00026 // printf("\random_direction_ = %d\n", random_direction_); 00027 } 00028 random_move_counter_ = rand() % 10 + 20; 00029 } 00030 00031 int RandomMovement::calc_sprite_movement(Direction d_) { 00032 // Moves the people in opposite direction to spaceship when it's position is 00033 // at min and max x positions and joystick has direction 00034 if (d_ == W || d_ == NW || d_ == SW) { 00035 return 2; 00036 }else if (d_ == E || d_ == NE || d_ == SE) { 00037 return -2; 00038 }else { 00039 return 0; 00040 } 00041 }
Generated on Fri Aug 5 2022 06:55:07 by
1.7.2