src/Rope.cc
author nireco
Sat, 31 Jan 2009 12:33:08 +0200
changeset 443 5d1119729f58
parent 428 712b943195a6
permissions -rw-r--r--
worm02 two pics to comment
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
     1
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
     2
// XXX: must include Player first, as it contains an instance of Rope
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
     3
#include "Player.hh"
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
     4
#include "Rope.hh"      
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
     5
#include "Engine.hh"
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
     6
#include "Error.hh"
412
721c60072091 new graphics code compiles... no, it doesn't work yet
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
     7
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
     8
#include <math.h>
252
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
     9
#include <stdexcept>
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    10
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    11
Rope::Rope(Player &player) : 
311
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 305
diff changeset
    12
    PhysicsObject(player.state.world, ROPE_MASS, Vector(0,0), Vector(0,0), ROPE, 0.00, false), 
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 305
diff changeset
    13
    player(player), 
440763821484 make Input have its own timer, and add key-repeat handling, and fix some warnings
terom
parents: 305
diff changeset
    14
    state(ROPE_FOLDED) 
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    15
{
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    16
    // XXX: better shape
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    17
    std::vector<Vector> shape(4);
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    18
    shape[0] = Vector(-1, -1);
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    19
    shape[1] = Vector(-1, 1);
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    20
    shape[2] = Vector(1, 1);
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    21
    shape[3] = Vector(1, -1);
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    22
    setShape(shape);
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    23
}
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    24
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    25
void Rope::throwRope (void) {
427
01e77fe8c040 fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    26
    if (state == ROPE_FIXED) {
01e77fe8c040 fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    27
        // unset pivot if we re-throw rope
01e77fe8c040 fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    28
        player.setPivot(NULL);
01e77fe8c040 fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    29
    }
01e77fe8c040 fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    30
01e77fe8c040 fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    31
    // update state
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    32
    state = ROPE_FLYING;
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    33
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    34
    // XXX: this should probably be more dynamic?
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    35
    length = ROPE_LENGTH;
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    36
    
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    37
    // copy position + velocity from player
427
01e77fe8c040 fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    38
    setPosition(player.getPosition());
01e77fe8c040 fix ticket:1 and make PhysicsObject setPosition/setVelocity protected
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    39
    setVelocity(player.getVelocity() + player.getDirection() * ROPE_VELOCITY);
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    40
    
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    41
    // we are FLYING
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    42
    inAir = true;
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    43
    
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    44
    // enable the physics object
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    45
    enable();
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    46
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    47
    // inform network
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    48
    player.handleRopeState(state);
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    49
}
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    50
273
eeb699e1d908 Made forceq to contain time again.
saiam
parents: 265
diff changeset
    51
void Rope::onCollision (Vector collisionPoint, PhysicsObject *other) {
322
f94a5c192097 Rope fixing
ekku
parents: 311
diff changeset
    52
    // Fix the rope to another player if collided with it
305
56799ec8d7be Weapon damage and some other stuff
ekku
parents: 296
diff changeset
    53
    if (other != NULL) {
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    54
        // we collided with another object
305
56799ec8d7be Weapon damage and some other stuff
ekku
parents: 296
diff changeset
    55
        if (other->getType() == PLAYER) {
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    56
            // set our player's pivot to the object that we collided with
305
56799ec8d7be Weapon damage and some other stuff
ekku
parents: 296
diff changeset
    57
            Player *target = dynamic_cast<Player*>(other);
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    58
            
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    59
            // ignore if the rope hits ourself
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    60
            if (target == &this->player)
305
56799ec8d7be Weapon damage and some other stuff
ekku
parents: 296
diff changeset
    61
                return;
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    62
            
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    63
            // set player's pivot to the other player
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    64
            player.setPivot(target);
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    65
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    66
            // disable ourselves as we're no longer relevant, don't keep colliding with the player
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    67
            disable();
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    68
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    69
        } else {
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    70
            // ignore other objects
305
56799ec8d7be Weapon damage and some other stuff
ekku
parents: 296
diff changeset
    71
            return;
56799ec8d7be Weapon damage and some other stuff
ekku
parents: 296
diff changeset
    72
        }
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    73
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    74
    } else { 
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    75
        // Collided with terrain, set player's pivot to ourselves
322
f94a5c192097 Rope fixing
ekku
parents: 311
diff changeset
    76
        player.setPivot(this);
305
56799ec8d7be Weapon damage and some other stuff
ekku
parents: 296
diff changeset
    77
    }
282
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 273
diff changeset
    78
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    79
    // attached to something!
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    80
    state = ROPE_FIXED;
428
712b943195a6 clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents: 427
diff changeset
    81
712b943195a6 clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents: 427
diff changeset
    82
    // XXX: reset, except we override tick() in ugly ways
712b943195a6 clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents: 427
diff changeset
    83
    setVelocity(Vector(0,0));
252
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
    84
        
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
    85
    // Ropes location will be used as the pivot point, so move the location to the collisionPoint.
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
    86
    // Currently the position is something like one pixel away from the collisionPoint where there isn't ground.
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
    87
    setPosition(collisionPoint);
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    88
    
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    89
    // inform network
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
    90
    player.handleRopeState(state);
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    91
}
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    92
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
    93
void Rope::release (void) {
252
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
    94
    // Remove the rope from the PhysicsWorld
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
    95
    disable();
229
355e46effa41 Rope works
ekku
parents: 228
diff changeset
    96
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    97
    state = ROPE_FOLDED;
228
dbc1bb7a98b5 Rope has forces
ekku
parents: 225
diff changeset
    98
    
dbc1bb7a98b5 Rope has forces
ekku
parents: 225
diff changeset
    99
    // player doesn't have a pivot anymore
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   100
    player.setPivot(NULL);
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   101
    
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   102
    // inform network
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   103
    player.handleRopeState(state);
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
   104
}
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
   105
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   106
void Rope::changeLength (float delta) {
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   107
    // change length
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   108
    length += delta;
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   109
    
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   110
    // minimum length
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   111
    if (length < 0)
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   112
        length = 0;
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   113
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   114
    // inform network
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   115
    player.handleRopeLength(length);
231
5085764e1dbb Rope length changing possible
ekku
parents: 229
diff changeset
   116
}
5085764e1dbb Rope length changing possible
ekku
parents: 229
diff changeset
   117
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
   118
RopeState Rope::getState (void) {
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
   119
    return state;
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
   120
}
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   121
        
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   122
float Rope::getLength (void) {
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   123
    return length;
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   124
}
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   125
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   126
Player *Rope::getPivotPlayer (void) {
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   127
    if (player.getPivot() == this)
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   128
        return NULL;
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   129
    else
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   130
        return dynamic_cast<Player*>(player.getPivot());
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   131
}
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   132
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   133
void Rope::updateState (RopeState new_state, Vector position, Vector velocity, float new_length, Player *pivot_player) {
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   134
    // update physics enabled/disabled state
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   135
    if (new_state == ROPE_FOLDED || new_state == ROPE_FIXED)
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   136
        disable();
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   137
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   138
    else // new_state == ROPE_FLYING
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   139
        enable();
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   140
    
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   141
    // update player.pivot to either the given pivot_player, or this rope
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   142
    if (new_state == ROPE_FIXED) {
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   143
        if (pivot_player)
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   144
            player.setPivot(pivot_player);
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   145
        else
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   146
            player.setPivot(this);
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   147
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   148
    } else if (this->state == ROPE_FIXED)
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   149
        player.setPivot(NULL);
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   150
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   151
    // update position stuff
264
215de3d4de60 change facingRight from a bool to an
terom
parents: 263
diff changeset
   152
    updatePhysics(position, velocity, true, FACING_RIGHT, 0);
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   153
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   154
    // update vars
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   155
    this->state = new_state;
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   156
    this->length = new_length;
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   157
}
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   158
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   159
void Rope::updateLength (float length) {
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   160
    // update length
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   161
    this->length = length;
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 235
diff changeset
   162
}
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
   163
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   164
#if GRAPHICS_ENABLED
412
721c60072091 new graphics code compiles... no, it doesn't work yet
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   165
void Rope::draw (graphics::Display &display, PixelCoordinate camera) {
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   166
    PixelCoordinate player_pos = player.getCoordinate() - camera;
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   167
    PixelCoordinate target_pos;
377
01d3c340b372 direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents: 328
diff changeset
   168
    
01d3c340b372 direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents: 328
diff changeset
   169
    // figure out what target is
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   170
    if (state == ROPE_FOLDED) {
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 231
diff changeset
   171
        return;
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 231
diff changeset
   172
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   173
    } else if (state == ROPE_FLYING) {
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   174
        // target is us
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   175
        target_pos = getCoordinate();
255
99431fdb0dc8 add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents: 254
diff changeset
   176
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   177
    } else {    // state == ROPE_FIXED
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   178
        // sanity-check
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   179
        if (player.getPivot() == NULL)
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   180
            throw Error("Rope::draw in state ROPE_FIXED, yet player.getPivot() is NULL");
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   181
        
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   182
        // target is our pivot
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   183
        target_pos = player.getPivot()->getCoordinate();
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   184
    }
377
01d3c340b372 direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents: 328
diff changeset
   185
 
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   186
    // align with camera
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   187
    target_pos -= camera;
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   188
    
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   189
    // draw a line from the player to the target chosen above
412
721c60072091 new graphics code compiles... no, it doesn't work yet
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   190
    display.get_gc()->draw_line(
257
549783d71e51 add a handful of consts to PhysicsObject and modify draw to use getCoordinate, and replace old skin.png with new skin.png
terom
parents: 256
diff changeset
   191
        player_pos.x, player_pos.y,
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   192
        target_pos.x, target_pos.y,
377
01d3c340b372 direction normalization functions in vector, change rope color, misc comments+whitespace
terom
parents: 328
diff changeset
   193
        ROPE_COLOR_DARK
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 231
diff changeset
   194
    );
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
   195
}
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   196
#endif
225
22ecb9cb9245 Rope can be drawn.
ekku
parents:
diff changeset
   197
252
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
   198
void Rope::tick (TimeMS dt) {
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   199
    if (state == ROPE_FLYING) {
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   200
        // let PhysicsObject handle the flying stage
252
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
   201
        PhysicsObject::tick(dt); 
322
f94a5c192097 Rope fixing
ekku
parents: 311
diff changeset
   202
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   203
    } else if (state == ROPE_FIXED) {
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   204
        // if player's pivot is some other player, then don't re-check the terrain
322
f94a5c192097 Rope fixing
ekku
parents: 311
diff changeset
   205
        if (player.getPivot() != this)
f94a5c192097 Rope fixing
ekku
parents: 311
diff changeset
   206
            return;
f94a5c192097 Rope fixing
ekku
parents: 311
diff changeset
   207
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   208
        // If there's no ground on the pivot point anymore, release the rope
428
712b943195a6 clean up PhysicsObject.hh a bit, make some things private
Tero Marttila <terom@fixme.fi>
parents: 427
diff changeset
   209
        if (!world.terrain.collides(getPosition())) { 
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   210
            // XXX: move to some new method
322
f94a5c192097 Rope fixing
ekku
parents: 311
diff changeset
   211
            state = ROPE_FLYING;
f94a5c192097 Rope fixing
ekku
parents: 311
diff changeset
   212
            length = ROPE_LENGTH;
f94a5c192097 Rope fixing
ekku
parents: 311
diff changeset
   213
            inAir = true;
f94a5c192097 Rope fixing
ekku
parents: 311
diff changeset
   214
            player.setPivot(NULL);
263
8c999cf4c182 weapon projectile radiuses and fix network play (local_player == NULL, Rope releasing upon being hit
terom
parents: 257
diff changeset
   215
            player.handleRopeState(state);
252
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
   216
        }
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   217
    } else { // state == ROPE_FOLDED
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   218
        // ignore ticks when folded
252
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
   219
    }
25054ce94d07 Rope is released if the ground on the pivot point is destroyed.
ekku
parents: 248
diff changeset
   220
}
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 322
diff changeset
   221