Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11586


Ignore:
Timestamp:
Nov 21, 2017, 1:07:17 PM (6 years ago)
Author:
remartin
Message:

Major breakthrough: Variable Collision shape works, error in spawnChildren() found (health…). Smaller problems remain (Weird initial velocity, correct health setting).

Location:
code/branches/AsteroidMining_HS17/src/modules/asteroidmining
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc

    r11581 r11586  
    4444
    4545KNACKPUNKTE:
    46 o Collision Shape-Problem (Funktioniert nur, wenn im Konstruktor) -> Mit Factory-Methode oder so basteln.
    4746o Maximale Hitpunkte = 200?
    48 
    49 o Neue Asteroiden generieren -> Absturz
    50 --> Kollidiert sofort mit irgendetwas, death() wird mehrfach aufgerufen.
    51 --> Funktioniert der Test in den hit()-Methoden?
    52 --> Welcher Aufruf loest die death()-Methode auf?
    53 
    54 
     47o komische Startgeschwindigkeit der initialisierten Asteroiden. Fliegen davon.
    5548
    5649OFFEN:
     
    6154HANDBUCH:
    6255o im Level-File includes/pickups.oxi importieren.
     56o Bei der XML-Variante wird beim ersten Aufruf der Tick-Methode ein neuer Asteroid generiert,
     57  damit die Groesse der Collision Shape korrekt initialisiert wird.
    6358
    6459Anpassungen Pickup-Zeug:
     
    7368o Error-Nachricht: Einfach Argumente leer lassen.
    7469o Pickups: setMaxSpawned funktioniert nicht -> Bastelloesung: Auf 2 statt eins setzen, erstes wird wohl direkt zerstoert.
     70
     71o Groessenabhaengige Collison shape: Umweg ueber zweiten Konstruktor.
     72o Absturz beim Asteroidengenerieren: Health war auf 0 gesetzt! Wurde nur bei der xml-Variante definiert.
     73
    7574*/
    7675
     
    115114    RegisterClass(AsteroidMinable);
    116115
    117     AsteroidMinable::AsteroidMinable(Context* context) : Pawn(context)
    118     {
     116
     117    // This constructor is for XML access only.
     118    AsteroidMinable::AsteroidMinable(Context* context) : Pawn(context){
     119
     120        // Da auch noetig? Wegen set in XML-Code?
     121        RegisterObject(AsteroidMinable);
     122
     123        this->context = context;
     124        this->initialised = false;
     125
     126        //Noetig, damit nicht sofort zerstoert?
     127        this->setCollisionType(WorldEntity::CollisionType::Dynamic);
     128
     129        // Old from Pawn
     130        this->registerVariables();
     131
     132        orxout() << "AsteroidMining:: Pseudo-Konstruktor passiert!" << endl;
     133
     134    }
     135
     136    // Call this one from other C-files. Takes arguments.
     137    AsteroidMinable::AsteroidMinable(Context* c, float size, Vector3 position) : Pawn(c){
     138
    119139        RegisterObject(AsteroidMinable);
    120140
     
    123143        this->setRadarObjectShape(RadarViewable::Shape::Dot);
    124144        this->setCollisionType(WorldEntity::CollisionType::Dynamic);
    125         this->bAlive_ = true;
    126 
    127         this->bVulnerable_ = true;
     145
    128146        this->enableCollisionCallback();
    129147
     
    131149        this->generateSmaller = true;
    132150        //this->setHealth(50);
    133         this->size = 10; // customSize
    134         this->context = context;
    135         this->initialised = false;
     151        this->size = size; // customSize
     152        this->health_ = 5*size;// capped at 200 in pawn or smth?
     153        //this->setHealth(health_); // Confusing, delete one of these
     154        this->context = c;
    136155        //this->roll = rand()*5; //etwas Drehung. richtige Variable
    137 //this = new AsteroidMinable()
    138 
    139 
    140 
    141         // DELETE if other stuff works! (wrong size etc.)
    142         SphereCollisionShape* cs = new SphereCollisionShape(this->context);
    143         cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien
    144         this->attachCollisionShape(cs);
    145 
    146 
    147 
    148 
    149         // Old from Pawn
    150         this->registerVariables();
    151 
    152         orxout() << "AsteroidMining:: Konstruktor passiert!" << endl;
    153 
    154     }
    155 
    156     AsteroidMinable::~AsteroidMinable()
    157     {
    158 
    159     }
    160 
    161     void AsteroidMinable::putStuff(){
    162 
    163         // Add Model
    164         //<Model position="0,-40,40" yaw="90" pitch="-90" roll="0" scale="4" mesh="ast6.mesh" />
     156
     157        // Fliegt davon, irgendwieso. Dies scheint auch nicht zu nuetzen.
     158        this->setVelocity(0, 0, 0);
     159
     160
     161
     162        // Add Model    //<Model position="0,-40,40" yaw="90" pitch="-90" roll="0" scale="4" mesh="ast6.mesh" />
    165163        Model* hull = new Model(this->context);
    166164        // random one of the 6 shapes
     
    176174        this->attachCollisionShape(cs);
    177175
     176        // Old from Pawn
     177        this->registerVariables();
    178178
    179179        this->initialised=true;
    180180
    181         orxout() << "AsteroidMining:: Initialisierung abgeschlosssssen." << endl;
     181        orxout() << "AsteroidMining:: Initialisierung Zweitkonstruktor abgeschlosssssen." << endl;
     182
     183    }
     184
     185    AsteroidMinable::~AsteroidMinable(){
     186
     187    }
     188
     189    void AsteroidMinable::putStuff(){
     190
     191        // Just create a new asteroid to avoid Collision shape scale problems etc.
     192        AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition());
     193        reborn->toggleShattering(true); // mainly here to avoid 'unused' warning.
     194        this->~AsteroidMinable(); // seems dangerous. Necessary for efficiency?
    182195
    183196    }
     
    230243    void AsteroidMinable::setSize(float s){
    231244        this->size = s;
    232         this->health_ = 5*s;// capped at 200 in pawn or smth?
    233         this->setHealth(health_);
    234245    }
    235246
     
    237248        return this->size;
    238249    }
     250
     251    void AsteroidMinable::toggleShattering(bool b){
     252        this->generateSmaller = b;
     253    }
     254
    239255
    240256    void AsteroidMinable::death() //ueberschreiben
     
    335351
    336352        //Spawn this child  Game crashes!
    337         AsteroidMinable* child = new AsteroidMinable(this->context);
     353        //AsteroidMinable* child = new AsteroidMinable(this->context);
     354        AsteroidMinable* child = new AsteroidMinable(this->context, extra+1, this->getPosition() + Vector3(num*5, 0, 0));
    338355        // if(!(child == nullptr)){//Errorgebastel
    339356
    340357        // Position zu spaet gesetzt? Tick nicht atomar -> falsche Groesse evtl?
     358
     359        // child->setSize(extra + 1);
     360               
     361        //     //OFFEN:Kollision der Kinder verhindern
     362        //     //Relativ zu Elternteil automatisch?
     363        //     //Typ position:rand()*Vektoriwas?
     364        //     //pawn->getWorldPosition() + Vector3(30,0,-30);
     365        // child->setPosition(this->getPosition() + Vector3(num*5, 0, 0));
     366        // //child->setPosition(Vector3(0,0,0));
    341367
    342368        if(child == nullptr){
     
    344370        }
    345371
    346         child->setSize(extra + 1);
    347                
    348             //OFFEN:Kollision der Kinder verhindern
    349             //Relativ zu Elternteil automatisch?
    350             //Typ position:rand()*Vektoriwas?
    351             //pawn->getWorldPosition() + Vector3(30,0,-30);
    352         child->setPosition(this->getPosition() + Vector3(num*5, 0, 0));
    353         //child->setPosition(Vector3(0,0,0));
     372
    354373
    355374        //orxout() << "Done: Creating new Asteroid" << endl;
  • code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h

    r11581 r11586  
    5050
    5151        public:
    52             AsteroidMinable(Context* context);
     52            AsteroidMinable(Context* context);// This constructor is for XML access only!
     53            AsteroidMinable(Context* c, float size, Vector3 position);// Call this Constructor from other C-files.
     54
    5355            virtual ~AsteroidMinable();
    5456            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     
    6466            virtual void setSize(float f);
    6567            virtual float getSize();
     68
     69            virtual void toggleShattering(bool b);
    6670
    6771
Note: See TracChangeset for help on using the changeset viewer.