src/Player.cc
author terom
Sat, 06 Dec 2008 16:17:05 +0000
changeset 221 fbc5db6fce45
parent 220 1c92222af6d3
child 222 293ddf4c067d
permissions -rw-r--r--
reorganize the weapons code and input handling code
218
86d22fe82b30 add static Engine::graphicsEnabled function and disable player graphics loading when false
terom
parents: 217
diff changeset
     1
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
     2
#include "Engine.hh"
198
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
     3
#include "Player.hh" 
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
     4
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 208
diff changeset
     5
#include <cstdlib>
215
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
     6
#include <ClanLib/display.h>
216
a384bf0634f0 a bit better image_drawing
nireco
parents: 215
diff changeset
     7
#include <string>
218
86d22fe82b30 add static Engine::graphicsEnabled function and disable player graphics loading when false
terom
parents: 217
diff changeset
     8
#include <cassert>
215
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
     9
220
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    10
// player static state
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    11
bool Player::skin_loaded = false;
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    12
CL_Surface Player::skin_surface;
215
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
    13
220
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    14
// XXX: give these better names and move elsewhere
219
ec472f8ac482 fixed walkingspeed and improved drawing
nireco
parents: 218
diff changeset
    15
const int img_num_aim = 9;
ec472f8ac482 fixed walkingspeed and improved drawing
nireco
parents: 218
diff changeset
    16
const int img_num_step = 4;
ec472f8ac482 fixed walkingspeed and improved drawing
nireco
parents: 218
diff changeset
    17
const int img_height = 9;
ec472f8ac482 fixed walkingspeed and improved drawing
nireco
parents: 218
diff changeset
    18
const int img_width = 10;
216
a384bf0634f0 a bit better image_drawing
nireco
parents: 215
diff changeset
    19
198
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    20
Player::Player(GameState &state, Vector position, bool visible) : 
219
ec472f8ac482 fixed walkingspeed and improved drawing
nireco
parents: 218
diff changeset
    21
    PhysicsObject(state.world, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible), arsenal(), selectedWeapon(0), changing(false), animation_step(0) {
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents: 211
diff changeset
    22
    // TODO: arsenal's size should be affected by some value
4389c1e6b9b8 Weapon.cc&hh
nireco
parents: 211
diff changeset
    23
    // and weapons should be loaded from somewhere, not generated here
218
86d22fe82b30 add static Engine::graphicsEnabled function and disable player graphics loading when false
terom
parents: 217
diff changeset
    24
    for (int i = 0; i < 5; i++) {
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    25
        arsenal.push_back(Weapon(state, 10000, (5 - i) * 40 + 30, i * 6 + 5, i * 100 + 50, "asdf"));
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents: 211
diff changeset
    26
    }
218
86d22fe82b30 add static Engine::graphicsEnabled function and disable player graphics loading when false
terom
parents: 217
diff changeset
    27
    
220
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    28
    // build the player's shape
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    29
    // XXX: these dimensions are incorrect...
198
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    30
    std::vector<Vector> shape(4);
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    31
    shape[0] = Vector(0,-9);
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    32
    shape[1] = Vector(6,0);
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    33
    shape[2] = Vector(0,9); 
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    34
    shape[3] = Vector(-6,0);
220
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    35
198
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    36
    // Initialize the shape of the player (salmiakki shape)
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    37
    setShape(shape);
220
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    38
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    39
    // XXX: this should be a PhysicsObject constructor arg
198
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    40
    collision_elasticity = PLAYER_COLLISION_ELASTICITY;
220
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    41
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
    42
    // add to player-object list
198
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    43
    world.addPlayerObject(this);
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    44
}
8698cbb101df ja viel? lis??
ekku
parents:
diff changeset
    45
 
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 208
diff changeset
    46
void Player::handleDig (Vector position, float radius) {
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 208
diff changeset
    47
    Vector unitVectorAim = facingRight ? Vector(std::cos(aim), -std::sin(aim)) : 
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 208
diff changeset
    48
            Vector(-std::cos(aim), -std::sin(aim));
215
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
    49
    float shotspeed = 0*PHYSICS_TICK_MS;
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 208
diff changeset
    50
    Vector shotVelocity = unitVectorAim*shotspeed;
216
a384bf0634f0 a bit better image_drawing
nireco
parents: 215
diff changeset
    51
    new Projectile(this->state, this->position, shotVelocity, false, radius, 1);
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 208
diff changeset
    52
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 208
diff changeset
    53
}
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 208
diff changeset
    54
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    55
void Player::handleShoot (Weapon &weapon) {
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    56
    Vector unitVectorAim = (facingRight ? 
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    57
        Vector(std::cos(aim), -std::sin(aim)) : 
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    58
        Vector(-std::cos(aim), -std::sin(aim))
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    59
    );
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    60
    
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    61
    // XXX: what does the PHYSICS_TICK_MS stuff mean?
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    62
    float shotspeed = weapon.getVelocity() * PHYSICS_TICK_MS / 2;
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 208
diff changeset
    63
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
    64
    Vector shotRelativeVelocity = unitVectorAim * shotspeed;
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
    65
    Vector shotVelocity = this->velocity + shotRelativeVelocity;
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    66
    Vector shotPosition = this->position + unitVectorAim * 10;
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    67
    
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    68
    weapon.shoot(shotPosition, shotVelocity);
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
    69
}
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
    70
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    71
void Player::printDebugInfo (void) {
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    72
    Engine::log(DEBUG, "layer.debug") << "In air: " << this->inAir;
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    73
}
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    74
        
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    75
void Player::tick (TimeMS dt) {
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    76
    // let PhysicsObject execute
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    77
    PhysicsObject::tick(dt);
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    78
    
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    79
    // tick current weapon reload
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    80
    getWeapon().tickReload(dt);
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    81
}
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
    82
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    83
void LocalPlayer::handleInput (PlayerInput input) {
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    84
    // Movement force, vertical is always zero
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    85
    Vector move_force = Vector(0, 0); 
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
    86
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    87
    // Crosshair angle change
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    88
    float aim_delta = 0; 
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
    89
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    90
    // handle movement left/right by applying a horizontal force, but limit the player's speed
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    91
    if ((input & INPUT_MOVE_LEFT) && (velocity.x > -PLAYER_MAX_SPEED)) {
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    92
        setFacing(false);
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    93
        move_force.x -= PLAYER_MOVE_FORCE;
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    94
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    95
    }
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    96
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    97
    if ((input & INPUT_MOVE_RIGHT) && (velocity.x < PLAYER_MAX_SPEED)) {
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    98
        setFacing(true);
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
    99
        move_force.x += PLAYER_MOVE_FORCE;
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   100
    }
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   101
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   102
    // handle aim by creating a aim angle delta
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   103
    if (input & INPUT_AIM_UP)
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   104
        aim_delta += CROSSHAIR_ANGLE_SPEED;
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   105
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   106
    if (input & INPUT_AIM_DOWN)
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   107
        aim_delta -= CROSSHAIR_ANGLE_SPEED;
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   108
    
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   109
    // handle jumping by invoking the jump method
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   110
    // XXX: the direction should ideally be given using some other method
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   111
    if (input & INPUT_JUMP) {
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   112
        if (input & INPUT_MOVE_LEFT)
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
   113
            jump(-1);
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   114
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   115
        else if (input & INPUT_MOVE_RIGHT)
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
   116
            jump(1);
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   117
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
   118
        else
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
   119
            jump(0);
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
   120
    }
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   121
    
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   122
    // outsource digging to Player::handleDig, since this modifies the Terrain and Network needs to know
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   123
    if (input & INPUT_DIG) {
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   124
        handleDig(position, 15);
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
   125
201
135616467a0a rename Shot -> Projectile
terom
parents: 200
diff changeset
   126
        // Should create Projectile which destroys ground, but also should be destroyed then,
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
   127
        // but it doesn't.
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
   128
        // But this now just segfaults
201
135616467a0a rename Shot -> Projectile
terom
parents: 200
diff changeset
   129
//        world.addObject(new Projectile(state, position, true));
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
   130
    }
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   131
    
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   132
    // XXX: currently not network safe
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents: 211
diff changeset
   133
    if (input & INPUT_CHANGE) {
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   134
        if (changing) {
213
5bd5afab4673 some stuff to Weapon and shoot
nireco
parents: 212
diff changeset
   135
5bd5afab4673 some stuff to Weapon and shoot
nireco
parents: 212
diff changeset
   136
        } else {
5bd5afab4673 some stuff to Weapon and shoot
nireco
parents: 212
diff changeset
   137
            changing = true;
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   138
            selectedWeapon = (selectedWeapon + 1) % arsenal.size();
213
5bd5afab4673 some stuff to Weapon and shoot
nireco
parents: 212
diff changeset
   139
            Engine::log(DEBUG, "Player.cc:input ") << "changed weapon " << selectedWeapon;
5bd5afab4673 some stuff to Weapon and shoot
nireco
parents: 212
diff changeset
   140
        }
5bd5afab4673 some stuff to Weapon and shoot
nireco
parents: 212
diff changeset
   141
    } else {
5bd5afab4673 some stuff to Weapon and shoot
nireco
parents: 212
diff changeset
   142
        changing = false;
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents: 211
diff changeset
   143
    }
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   144
    
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   145
    // validate shoot events, and then outsource to handleShoot so Network can intercept it
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   146
    if (input & INPUT_SHOOT && getWeapon().canShoot()) {
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   147
        this->handleShoot(getWeapon());
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
   148
    }
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   149
    
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   150
    // XXX: how should this be written?
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   151
    if (move_force.x != 0) 
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   152
        animation_step = (animation_step + 1) % img_num_step;
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
   153
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   154
    // apply aim delta
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   155
    if (aim_delta)
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   156
        changeAim(aim_delta);
219
ec472f8ac482 fixed walkingspeed and improved drawing
nireco
parents: 218
diff changeset
   157
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   158
    // apply force
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   159
    if (!move_force.zero())
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   160
        applyForce(move_force);
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
   161
}
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 198
diff changeset
   162
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents: 211
diff changeset
   163
Weapon& Player::getWeapon() {
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   164
    return arsenal[selectedWeapon % arsenal.size()];
212
4389c1e6b9b8 Weapon.cc&hh
nireco
parents: 211
diff changeset
   165
}
215
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
   166
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   167
void Player::draw (CL_GraphicContext *gc) {
216
a384bf0634f0 a bit better image_drawing
nireco
parents: 215
diff changeset
   168
    int aim_img_idx = (int)((1 - (getAim()+KG_PI/2)/KG_PI)*img_num_aim);
219
ec472f8ac482 fixed walkingspeed and improved drawing
nireco
parents: 218
diff changeset
   169
    int step_img_idx = animation_step%img_num_step;
217
de56d9d16705 and yet better image drawing
nireco
parents: 216
diff changeset
   170
220
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
   171
    // load skin image if not yet loaded
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
   172
    if (!skin_loaded) {
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
   173
        skin_surface = CL_Surface(PLAYER_SKIN_PATH);
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
   174
        skin_loaded = true;
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
   175
    }
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   176
    
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   177
    // XXX: this logic looks weird
218
86d22fe82b30 add static Engine::graphicsEnabled function and disable player graphics loading when false
terom
parents: 217
diff changeset
   178
    CL_Rectf destination(position.x - 4, position.y - 4, position.x + 5, position.y + 4);
86d22fe82b30 add static Engine::graphicsEnabled function and disable player graphics loading when false
terom
parents: 217
diff changeset
   179
86d22fe82b30 add static Engine::graphicsEnabled function and disable player graphics loading when false
terom
parents: 217
diff changeset
   180
    if (!getFacing()) {
86d22fe82b30 add static Engine::graphicsEnabled function and disable player graphics loading when false
terom
parents: 217
diff changeset
   181
        destination = CL_Rect(position.x + 5, position.y - 4, position.x - 4, position.y + 4);
217
de56d9d16705 and yet better image drawing
nireco
parents: 216
diff changeset
   182
    }
de56d9d16705 and yet better image drawing
nireco
parents: 216
diff changeset
   183
220
1c92222af6d3 use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
terom
parents: 219
diff changeset
   184
    skin_surface.draw_subpixel(
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   185
            CL_Rectf(
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   186
                1 + step_img_idx * img_width, 
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   187
                aim_img_idx * img_height + 1, 
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   188
                1 + (1 + step_img_idx) * img_width, 
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   189
                (aim_img_idx + 1) * img_height + 1
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   190
            ), 
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   191
            destination, gc
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 220
diff changeset
   192
    );
217
de56d9d16705 and yet better image drawing
nireco
parents: 216
diff changeset
   193
    
215
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
   194
    const uint16_t chlen = 10;
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
   195
    uint16_t x = position.x;
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
   196
    uint16_t y = position.y;
218
86d22fe82b30 add static Engine::graphicsEnabled function and disable player graphics loading when false
terom
parents: 217
diff changeset
   197
    
86d22fe82b30 add static Engine::graphicsEnabled function and disable player graphics loading when false
terom
parents: 217
diff changeset
   198
    // draw "crosshair"
215
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
   199
    if (facingRight) {
216
a384bf0634f0 a bit better image_drawing
nireco
parents: 215
diff changeset
   200
        gc->draw_line(x + std::cos(aim)*chlen/2, 
a384bf0634f0 a bit better image_drawing
nireco
parents: 215
diff changeset
   201
                      y - std::sin(aim)*chlen/2,
215
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
   202
                      x + std::cos(aim)*chlen,
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
   203
                      y - std::sin(aim)*chlen,
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
   204
                      CL_Color::black);
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
   205
    } else {
216
a384bf0634f0 a bit better image_drawing
nireco
parents: 215
diff changeset
   206
        gc->draw_line(x - std::cos(aim)*chlen/2, 
a384bf0634f0 a bit better image_drawing
nireco
parents: 215
diff changeset
   207
                      y - std::sin(aim)*chlen/2,
215
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
   208
                      x - std::cos(aim)*chlen,
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
   209
                      y - std::sin(aim)*chlen,
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
   210
                      CL_Color::black);
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
   211
    }
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
   212
}
69de8d9fcc0a image is working.. well.. run it from build/src folder.
nireco
parents: 213
diff changeset
   213
219
ec472f8ac482 fixed walkingspeed and improved drawing
nireco
parents: 218
diff changeset
   214