123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- #include "player.hpp"
- player::player() : game_object(C/2, R-1, 1)
- {
- length=8;
- weaponclass=0;
- weaponclassrkt=0;
- rocketlauncher=FALSE;
- commands[0]='a'; //left
- commands[1]='d'; //right
- commands[2]='w'; //up
- commands[3]='s'; //down
- godmode=false;
- }
- player::player(int Length) : game_object(C/2, R, 1)
- {
- length=(Length<2?2:(Length>20?20:Length));
- weaponclass=0;
- weaponclassrkt=0;
- rocketlauncher=FALSE;
- commands[0]='a'; //left
- commands[1]='d'; //right
- commands[2]='w'; //up
- commands[3]='s'; //down
- godmode=false;
- }
- void player::set_commands(int* _commands){
- for(int i=0;i<4;i++)
- commands[i]=_commands[i];
- }
- void player::next_pos(int command)
- {
- if((command==commands[0] || command==KEY_LEFT) && x>0) x-=2;
- if((command==commands[1] || command==KEY_RIGHT) && x<C-length) x+=2;
- if((command==commands[2] || command==KEY_UP) && y>0) y--;
- if((command==commands[3] || command==KEY_DOWN) && y<R-1) y++;
- }
- void player::shoot(std::list<bullet> & bullets)
- {
- static int thiscannon=0;
-
- if(weaponclass==0){
- if(thiscannon)
- {
- bullet new_bullet(x+(int)(length/2.),y,2);
- bullets.push_back(new_bullet);
- }
- else
- {
- bullet new_bullet(x+(int)(length/2.)-1,y,2);
- bullets.push_back(new_bullet);
- }
- thiscannon= ~thiscannon;
- }
-
- else if(weaponclass==1){
- bullet new_bullet1(x+(int)(length/2.),y,2);
- bullets.push_back(new_bullet1);
- bullet new_bullet2(x+(int)(length/2.)-1,y,2);
- bullets.push_back(new_bullet2);
- }
-
- else if(weaponclass==2){
- if(thiscannon)
- {
- bullet new_bullet(x+(int)(length/2.),y,2);
- bullets.push_back(new_bullet);
- }
- else
- {
- bullet new_bullet(x+(int)(length/2.)-1,y,2);
- bullets.push_back(new_bullet);
- }
- thiscannon= ~thiscannon;
- if(length>2){
- bullet new_bullet1(x+1,y,2);
- bullets.push_back(new_bullet1);
- bullet new_bullet3(x+(length-2>(int)(length/2.)?length-2:((int)(length/2.)+1>length?length-1:(int)(length/2.)+1)),y,2);
- bullets.push_back(new_bullet3);
- }
- }
-
- else if(weaponclass==3){
- bullet new_bullet(x+(int)(length/2.),y,2);
- bullets.push_back(new_bullet);
- bullet new_bullet2(x+(int)(length/2.)-1,y,2);
- bullets.push_back(new_bullet2);
- if(length>2){
- bullet new_bullet1(x+1,y,2);
- bullets.push_back(new_bullet1);
- bullet new_bullet3(x+(length-2>(int)(length/2.)?length-2:((int)(length/2.)+1>length?length-1:(int)(length/2.)+1)),y,2);
- bullets.push_back(new_bullet3);
- }
- }
-
- else if(weaponclass==4){
- bullet new_bullet4(x+(int)(length/2.)-1,y,2);
- bullets.push_back(new_bullet4);
- bullet new_bullet5(x+(int)(length/2.),y,2);
- bullets.push_back(new_bullet5);
- if(length>2){
- bullet new_bullet6(x+(int)(length/2.)+1,y,2);
- bullets.push_back(new_bullet6);
- bullet new_bullet2(x+(length-2>(int)(length/2.)+1?length-2:length-1),y,2);
- bullets.push_back(new_bullet2);
- bullet new_bullet3(x+(1<(int)(length/2.)-2?1:0),y,2);
- bullets.push_back(new_bullet3);
- }
- if(length>4){
- bullet new_bullet7(x+(int)(length/2.)-2,y,2);
- bullets.push_back(new_bullet7);
- }
- }
-
- else if(weaponclass==5){
- for(int i=0;i<length;i++){
- bullet new_bullet(x+i,y,2);
- bullets.push_back(new_bullet);
- }
- }
- }
- void player::shootrkt(std::list<rocket>& rockets)
- {
- static int thiscannon=0;
-
- if(weaponclassrkt==0){
- if(thiscannon)
- {
- rocket new_rocket(x+(int)(length/2.),y,1);
- rockets.push_back(new_rocket);
- }
- else
- {
- rocket new_rocket(x+(int)(length/2.)-1,y,-1);
- rockets.push_back(new_rocket);
- }
- thiscannon= ~thiscannon;
- }
-
- else if(weaponclassrkt==1){
- rocket new_rocket1(x+(int)(length/2.),y,1);
- rockets.push_back(new_rocket1);
- rocket new_rocket2(x+(int)(length/2.)-1,y,-1);
- rockets.push_back(new_rocket2);
- }
-
- else if(weaponclassrkt==2){
- if(thiscannon)
- {
- rocket new_rocket(x+(int)(length/2.),y,1);
- rockets.push_back(new_rocket);
- }
- else
- {
- rocket new_rocket(x+(int)(length/2.)-1,y,-1);
- rockets.push_back(new_rocket);
- }
- thiscannon= ~thiscannon;
- if(length>2){
- rocket new_rocket1(x+1,y,1);
- rockets.push_back(new_rocket1);
- rocket new_rocket3(x+(length-2>(int)(length/2.)?length-2:((int)(length/2.)+1>length?length-1:(int)(length/2.)+1)),y,-1);
- rockets.push_back(new_rocket3);
- }
- }
-
- else if(weaponclassrkt==3){
- rocket new_rocket(x+(int)(length/2.),y,1);
- rockets.push_back(new_rocket);
- rocket new_rocket2(x+(int)(length/2.)-1,y,-1);
- rockets.push_back(new_rocket2);
- if(length>2){
- rocket new_rocket1(x+1,y,1);
- rockets.push_back(new_rocket1);
- rocket new_rocket3(x+(length-2>(int)(length/2.)?length-2:((int)(length/2.)+1>length?length-1:(int)(length/2.)+1)),y,-1);
- rockets.push_back(new_rocket3);
- }
- }
-
- else if(weaponclassrkt==4){
- rocket new_rocket4(x+(int)(length/2.)-1,y,1);
- rockets.push_back(new_rocket4);
- rocket new_rocket5(x+(int)(length/2.),y,-1);
- rockets.push_back(new_rocket5);
- if(length>2){
- rocket new_rocket6(x+(int)(length/2.)+1,y,1);
- rockets.push_back(new_rocket6);
- rocket new_rocket2(x+(length-2>(int)(length/2.)+1?length-2:length-1),y,-1);
- rockets.push_back(new_rocket2);
- rocket new_rocket3(x+(1<(int)(length/2.)-2?1:0),y,1);
- rockets.push_back(new_rocket3);
- }
- if(length>4){
- rocket new_rocket7(x+(int)(length/2.)-2,y,-1);
- rockets.push_back(new_rocket7);
- }
- }
-
- else if(weaponclassrkt==5){
- for(int i=0;i<length;i++){
- rocket new_rocket(x+i,y,pow(-1.,(double)i));
- rockets.push_back(new_rocket);
- }
- }
- }
|