Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 16, 2019, 1:13:58 PM (5 years ago)
Author:
pomselj
Message:

BallProjectiles fly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.cc

    r12368 r12371  
    3434#include "BallProjectile.h"
    3535#include "../OrxoBlox/OrxoBlox.h"
     36#include "../OrxoBlox/OrxoBloxStones.h"
    3637#include "gametypes/Gametype.h"
    3738
     
    5758        this->maxTextureIndex_ = 8;
    5859        this->setDestroyAfterCollision(false); //I want the ball to bounce, not to be destroyed
     60        this->fieldWidth_ = 46;
     61        this->fieldHeight_ =  49;
    5962        //this->orxoblox_ = this->getOrxoBlox();
    6063
     
    6467    void BallProjectile::registerVariables()
    6568    {
    66         registerVariable( this->fieldWidth_ );
    67         registerVariable( this->fieldHeight_ );
    6869        registerVariable(this->materialBase_);
    6970        registerVariable( this->speed_ );
     
    145146        orxout() << "wanna bounce..." << endl;
    146147        bool result = BasicProjectile::processCollision(otherObject, contactPoint, cs);
    147         Bounce(otherObject, contactPoint, cs);
     148        if (result == true) {
     149            if (otherObject->isA(Class(OrxoBloxStones))) {
     150                Bounce(otherObject, contactPoint, cs);
     151            }
     152        }
    148153        orxout() << "BOUNCED!" << endl;
    149154
     
    175180        Vector3 acceleration = this->getAcceleration();
    176181
     182        velocity.y = 0;
     183        position.y = 0;
     184
    177185        // If the ball has gone over the top or bottom boundary of the playing field (i.e. the ball has hit the top or bottom delimiters).
    178         if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
     186        if (position.z > this->fieldHeight_ || position.z < -this->fieldHeight_)
    179187        {
    180188
    181189            velocity.z = -velocity.z;
    182190            // And its position is set as to not overstep the boundary it has just crossed. Remember z axis is reverted!!!
    183             if (position.z > this->fieldHeight_ / 2){
     191            if (position.z > this->fieldHeight_){
    184192                // Set the ball to be exactly at the boundary.
    185                 position.z = this-> fieldHeight_ / 2;
     193                position.z = this-> fieldHeight_;
    186194               
    187195                //orxoblox_->LevelUp();
     
    218226
    219227            }
    220             if (position.z < -this->fieldHeight_ / 2){
    221                 position.z = -this->fieldHeight_ / 2 ;
     228            if (position.z < -this->fieldHeight_){
     229                position.z = -this->fieldHeight_;
    222230               
    223231            }
     
    228236        //Ball hits the right or left wall and should bounce back.
    229237        // If the ball has crossed the left or right boundary of the playing field.
    230         if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
     238        if (position.x > this->fieldWidth_ || position.x < -this->fieldWidth_)
    231239        {
    232240            //Ball hits the right Wall
    233             if (position.x > this->fieldWidth_ / 2)
     241            if (position.x > this->fieldWidth_)
    234242                {
    235243                    // Set the ball to be exactly at the boundary.
    236                     position.x = this->fieldWidth_ / 2;
     244                    position.x = this->fieldWidth_;
    237245                    // Invert its velocity in x-direction (i.e. it bounces off).
    238246                    velocity.x = -velocity.x;
     
    241249
    242250            //Ball hits the left wall
    243             else if (position.x < -this->fieldWidth_ / 2)
     251            else if (position.x < -this->fieldWidth_)
    244252                {
    245253                        // Set the ball to be exactly at the boundary.
    246                         position.x = -this->fieldWidth_ / 2;
     254                        position.x = -this->fieldWidth_;
    247255                        // Invert its velocity in x-direction (i.e. it bounces off).
    248256                        velocity.x = -velocity.x;
Note: See TracChangeset for help on using the changeset viewer.