- Timestamp:
- Nov 13, 2017, 4:05:34 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc
r11541 r11555 19 19 RegisterObject(AsteroidsShip); 20 20 21 angle= 0.0f; 22 23 21 direction= 0.0f; 24 22 25 23 isFireing = false; … … 30 28 lastTime = 0; 31 29 32 height = this->getGame()->center_->getFieldHeight(); 33 width = this->getGame()->center_->getFieldWidth(); 34 35 force.x =0; 36 force.y =0; 37 38 velocity.x = 0; 39 velocity.y = 0; 40 30 height = 600; 31 width = 1000; 41 32 } 42 43 //Destructor44 AsteroidsShip::~AsteroidsShip()45 {46 if (this->isInitialized())47 this->cleanup();48 }49 50 33 51 34 … … 53 36 void AsteroidsShip::tick(float dt) 54 37 { 38 orxout() << "ich ticke!"<< endl; 39 SUPER(AsteroidsShip, tick, dt); 40 55 41 //Movement computation beachte Beschleunigung? 56 42 Vector3 pos = getPosition(); 43 Vector3 vel = getVelocity(); 57 44 58 float speed = sqrt(velocity.x*velocity.x+ velocity.y*velocity.y); 45 float speed = sqrt(vel.x*vel.x+ vel.z*velo.z); 46 47 48 //Daempfung falls das spaceship zu schnell wird 59 49 if(speed > maxspeed) 60 50 { 61 vel ocity.x *= maxspeed/speed;62 vel ocity.y*= mayspeed/speed;51 vel.x *= maxspeed/speed; 52 vel.z *= mayspeed/speed; 63 53 } 64 54 65 pos.x += velocity.x*dt; 66 pos.y += velocity.y*dt; 55 if(moveUpPressed_) 56 { 57 //Gas geben 58 vel.x += 1; 59 vel.z += 1; 60 61 }else if(moveDownPressed_){ 62 //Bremsen 63 vel.x += 1; 64 vel.z += 1; 65 }else if(moveLeftPressed_){ 66 //rotate left 67 }else if (moveRightPressed_){ 68 //rotateright 69 } 70 71 setVelocity(vel); 72 73 pos.x += vel.x*dt; 74 pos.z += vel.z*dt; 67 75 68 76 69 //haelt ship innerhalb des Kamerafensters 70 if(x>width) x=0; 71 if(x<0) x=width; 72 if(y>height) y=0; 73 if(y<0) y=height); 77 78 //haelt ship innerhalb des Kamerafensters, kommt oben bzw seitlich wieder raus. Man spawnt in (0,0) 79 if(pos.x > width/2) pos.x = -width/2; 80 if(pos.x < -width/2) pos.x = width/2; 81 if(pos.z > height/2) pos.z = -height/2; 82 if(pos.z < -height/2) pos.z = height/2; 74 83 75 84 76 85 //Schiessen wenn geschossen wurde 77 86 // shoot! 78 /* 87 79 88 if (isFireing) 80 89 ControllableEntity::fire(0); 81 */ 82 83 //Execute movement 84 if (this->hasLocalController()) 85 { 86 force.x += 1; 87 force.y += 1; 88 89 } 90 91 92 93 //Camera ticken? Bleibt eigentlich am selben Ort...irgendwo initialisieren 94 Camera* camera = this->getCamera(); 95 if (camera != nullptr) 96 { 97 camera->setPosition(Vector3(0,cameradistance, 0)); 98 camera->setOrientation(Vector3::UNIT_Z, Degree(90)); 99 } 100 101 90 102 91 103 92 // bring back on track! … … 107 96 } 108 97 109 velocity.x *= damping; 110 velocity.y *= damping; 98 //Reibung? 99 vel.x *= damping; 100 vel.y *= damping; 101 111 102 112 103 setPosition(pos); 113 setOrientation(Vector3::UNIT_Y, Degree( 270));104 setOrientation(Vector3::UNIT_Y, Degree(direction)); 114 105 115 SUPER(AsteroidsShip, tick, dt); 106 // Reset key variables 107 moveUpPressed_ = false; 108 moveDownPressed_ = false; 109 moveLeftPressed_ = false; 110 moveDownPressed_ = false; 111 116 112 117 113 } … … 119 115 void AsteroidsShip::moveFrontBack(const Vector2& value) 120 116 { 121 velocity.x += 1; 122 } 117 if (value.x > 0) 118 { 119 moveUpPressed_ = true; 120 moveDownPressed_ = false 121 if(moveUpPressed_) 122 { 123 orxout() << "up" << endl; 124 } 125 } 126 else 127 { 128 moveUpPressed_ = false; 129 moveDownPressed_ = true; 130 if(moveDownPressed_) 131 { 132 orxout() << "down" << endl; 133 } 134 } 135 } 123 136 124 void AsteroidsShip::move UpDown(const Vector2& value)137 void AsteroidsShip::moveRightLeft(const Vector2& value) 125 138 { 126 velocity.y +=1; 139 if (value.x > 0) 140 { 141 moveLeftPressed_ = false; 142 moveRightPressed_ = true; 143 } 144 if(moveRightPressed_) 145 { 146 orxout() << "right" << endl; 147 } 127 148 149 else 150 { 151 moveLeftPressed_ = true; 152 moveRightPressed_ = false; 153 if(moveLeftPressed_) 154 { 155 orxout() << "left" << endl; 156 } 157 } 128 158 } 129 void AsteroidsShip::moveFrontLeftRight(const Vector2& value) 130 { 131 132 } 159 133 160 134 161 Asteroids* AsteroidsShip::getGame()
Note: See TracChangeset
for help on using the changeset viewer.