Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 30, 2017, 3:52:23 PM (7 years ago)
Author:
jkindle
Message:

Added movement of camera.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/SuperOrxoBros_FS17/src/modules/superorxobros/SOBFigure.cc

    r11381 r11383  
    3737#include "core/XMLPort.h"
    3838#include "graphics/Model.h"
     39#include "graphics/Camera.h"
    3940
    4041
     
    4849
    4950        // initialize variables
    50      
     51
    5152        moveUpPressed_ = false;
    5253        moveDownPressed_ = false;
     
    5556        firePressed_ = false;
    5657        timeSinceLastFire_ = 0.0;
    57  
     58        lastSpeed_z = 0.0;
     59
    5860        gravityAcceleration_ = 250.0;//8.0
    59        
     61
    6062        dead_ = false;
    6163        setAngularFactor(0.0);
     
    6567    {
    6668        SUPER(SOBFigure, XMLPort, xmlelement, mode);
    67  
     69
    6870    }
    6971
     
    7476        if (hasLocalController())
    7577        {
    76             timeSinceLastFire_ += dt;
    77 
    78             // Move up/down
    79             Vector3 velocity = getVelocity();
    80          
    81            
    82            
    83 
    84            
    85 
    86        
    87 
    88             // Move left/right
    89             if (dead_ == false)
    90             {
    91 
    92                 if (firePressed_ && std::abs(velocity.z) < 0.1) {
    93                     velocity.z = 200;
    94                 } else {
    95 
    96                 }
    97 
    98 
    99 
    100 
    101                 if (moveRightPressed_)
    102                     velocity.x = 75;
    103                 else if (moveLeftPressed_)
    104                     velocity.x = -75;
    105                 else
    106                     velocity.x = 0;
     78          Vector3 velocity = getVelocity();
     79          Vector3 position = getPosition();
     80
     81          if (dead_) {
     82            velocity.x = 0;
     83            velocity.z = 0;
     84            setVelocity(velocity);
     85            return;
     86        }
     87
     88
     89        int maxvelocity_x = 100;
     90        int speedAddedPerTick = 5;
     91        int camMaxOffset = 25;
     92
     93        timeSinceLastFire_ += dt;
     94        lastSpeed_z = velocity.z;
     95
     96
     97
     98        //If player hits space and does not move in z-dir
     99        if (firePressed_ && std::abs(velocity.z) < 0.07 && std::abs(lastSpeed_z) < 0.07) {
     100            velocity.z = 150;
     101        }
     102
     103        //Left-right movement with acceleration
     104        if (moveRightPressed_) {
     105            if (std::abs(velocity.x) < maxvelocity_x) {
     106                velocity.x += speedAddedPerTick;
    107107            }
    108             else
    109             {
    110                 velocity.x = 0.0;
     108        } else if (moveLeftPressed_) {
     109            if (std::abs(velocity.x) < maxvelocity_x) {
     110                velocity.x -= speedAddedPerTick;
    111111            }
    112                         velocity.z -= gravityAcceleration_*dt;
    113 
    114            
    115 
    116             setVelocity(velocity);
    117 
    118 
     112        } else {
     113            velocity.x /= 1.1;
     114        }
    119115       
    120         }
     116
     117        velocity.z -= gravityAcceleration_*dt;
     118        setVelocity(velocity);
     119
     120
     121        //Camera operation
     122        Camera* cam = getCamera();
     123        Vector3 campos = cam->getPosition();
     124
     125        if (campos.x + camMaxOffset < position.x) {
     126            campos.x = position.x - camMaxOffset;
     127            cam->setPosition(campos);
     128        }
     129           if (campos.x - camMaxOffset > position.x) {
     130            campos.x = position.x + camMaxOffset;
     131            cam->setPosition(campos);
     132        }
     133
     134
     135
     136    }
    121137
    122138        // Move through the left and right screen boundaries
    123        
     139
    124140        //setPosition(position);
    125141
    126142        // Reset key variables
    127         moveUpPressed_ = false;
    128         moveDownPressed_ = false;
    129         moveLeftPressed_ = false;
    130         moveRightPressed_ = false;
    131         moveDownPressed_ = false;
    132         firePressed_ = false;
    133      
    134     }
    135 
    136    
    137 
    138    
     143    moveUpPressed_ = false;
     144    moveDownPressed_ = false;
     145    moveLeftPressed_ = false;
     146    moveRightPressed_ = false;
     147    moveDownPressed_ = false;
     148    firePressed_ = false;
     149
     150}
     151
     152
     153
     154
    139155
    140156   /* void SOBFigure::CollisionWithEnemy(SOBEnemy* enemy)
     
    146162    }*/
    147163
    148    
    149 
    150 
    151    
    152 
    153     void SOBFigure::moveFrontBack(const Vector2& value)
    154     {
    155         if (value.x > 0)
    156         {
    157             moveUpPressed_ = true;
    158             moveDownPressed_ = false;
    159         }
    160         else
    161         {
    162             moveUpPressed_ = false;
    163             moveDownPressed_ = true;
    164         }
    165     }
    166 
    167     void SOBFigure::moveRightLeft(const Vector2& value)
    168     {
    169         if (value.x > 0)
    170         {
    171             moveLeftPressed_ = false;
    172             moveRightPressed_ = true;
    173         }
    174         else
    175         {
    176             moveLeftPressed_ = true;
    177             moveRightPressed_ = false;
    178         }
    179     }
    180 
    181    
    182 
    183  
    184 
    185     void SOBFigure::boost(bool boost)
    186         {
    187         firePressed_ = true;
    188     }
    189 }
     164
     165
     166
     167
     168
     169void SOBFigure::moveFrontBack(const Vector2& value)
     170{
     171    if (value.x > 0)
     172    {
     173        moveUpPressed_ = true;
     174        moveDownPressed_ = false;
     175    }
     176    else
     177    {
     178        moveUpPressed_ = false;
     179        moveDownPressed_ = true;
     180    }
     181}
     182
     183void SOBFigure::moveRightLeft(const Vector2& value)
     184{
     185    if (value.x > 0)
     186    {
     187        moveLeftPressed_ = false;
     188        moveRightPressed_ = true;
     189    }
     190    else
     191    {
     192        moveLeftPressed_ = true;
     193        moveRightPressed_ = false;
     194    }
     195}
     196
     197
     198
     199
     200
     201void SOBFigure::boost(bool boost)
     202{
     203    firePressed_ = true;
     204}
     205}
Note: See TracChangeset for help on using the changeset viewer.