author | saiam |
Wed, 03 Dec 2008 16:47:17 +0000 | |
changeset 183 | e31ff2152774 |
parent 182 | 84675387ca74 |
permissions | -rw-r--r-- |
26 | 1 |
|
2 |
#include "GameState.hh" |
|
94 | 3 |
#include "Engine.hh" |
182
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
4 |
#include "Config.hh" |
26 | 5 |
|
182
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
6 |
/** |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
7 |
* shoots the selected weapon. |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
8 |
* TODO: selection and weapon information |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
9 |
*/ |
180 | 10 |
void Player::shoot (void) { |
182
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
11 |
// here should be somehow considered which projectile it is |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
12 |
if(!canShoot()) |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
13 |
return; |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
14 |
reloadTimer += 0; |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
15 |
Vector unitVectorAim = facingRight ? Vector(std::cos(aim), -std::sin(aim)) : |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
16 |
Vector(-std::cos(aim), -std::sin(aim)); |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
17 |
float shotspeed = 100*PHYSICS_TICK_MS; |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
18 |
Vector shotRelativeVelocity = unitVectorAim * shotspeed; |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
19 |
Vector shotVelocity = this->velocity + shotRelativeVelocity; |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
20 |
this->state.addProjectile(new Shot(this->state, this->position, shotVelocity, true)); |
180 | 21 |
} |
22 |
||
96
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
94
diff
changeset
|
23 |
void Player::handleMove (PlayerInput_Move input) { |
108 | 24 |
float fx = 0; // Force in x-direction |
25 |
float da = 0; // Crosshair angle |
|
26 | 26 |
|
96
4a801210096c
fix movement physics+network code to some degree, jumping is now buggy?
terom
parents:
94
diff
changeset
|
27 |
// handle left/right |
160 | 28 |
if ((input & INPUT_MOVE_LEFT) && (velocity.x > -PLAYER_MAX_SPEED)) |
108 | 29 |
fx -= PLAYER_MOVE_FORCE; |
50
9e1a6506f5a1
some rough-handed code modifications towards a newer, better, working Physics
terom
parents:
26
diff
changeset
|
30 |
|
160 | 31 |
if ((input & INPUT_MOVE_RIGHT) && (velocity.x < PLAYER_MAX_SPEED)) |
108 | 32 |
fx += PLAYER_MOVE_FORCE; |
94 | 33 |
|
108 | 34 |
if (input & INPUT_MOVE_UP) |
35 |
da += CROSSHAIR_ANGLE_SPEED; |
|
36 |
||
37 |
if (input & INPUT_MOVE_DOWN) |
|
38 |
da -= CROSSHAIR_ANGLE_SPEED; |
|
39 |
||
170 | 40 |
if (input & INPUT_MOVE_JUMP) { |
41 |
if ((input & INPUT_MOVE_LEFT)) |
|
42 |
jump(-1); |
|
43 |
else if ((input & INPUT_MOVE_RIGHT)) |
|
44 |
jump(1); |
|
45 |
else |
|
46 |
jump(0); |
|
47 |
} |
|
114
71f7e9d3d052
V?h?n siistin tota walkkia, viel? on kyll? tekemist?.
saiam
parents:
108
diff
changeset
|
48 |
|
117 | 49 |
if (input & INPUT_MOVE_DIG) { |
50 |
// Should create Shot which destroys ground, but also should be destroyed then, |
|
51 |
// but it doesn't. |
|
52 |
// But this now just segfaults |
|
53 |
// world.addObject(new Shot(state, position, true)); |
|
54 |
||
153
73402d5b778e
Lots of small fixe. Moved drawing PhysicsObjects away from Graphics.cc.
saiam
parents:
122
diff
changeset
|
55 |
world.removeGround(position, 15); |
117 | 56 |
} |
182
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
57 |
|
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
58 |
if (input & INPUT_SHOOT) { |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
59 |
this->shoot(); |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
60 |
} |
183
e31ff2152774
Now we use different lists for players and projectiles
saiam
parents:
182
diff
changeset
|
61 |
|
e31ff2152774
Now we use different lists for players and projectiles
saiam
parents:
182
diff
changeset
|
62 |
|
e31ff2152774
Now we use different lists for players and projectiles
saiam
parents:
182
diff
changeset
|
63 |
|
e31ff2152774
Now we use different lists for players and projectiles
saiam
parents:
182
diff
changeset
|
64 |
// Player facing |
e31ff2152774
Now we use different lists for players and projectiles
saiam
parents:
182
diff
changeset
|
65 |
if (fx < 0) setFacing(false); |
e31ff2152774
Now we use different lists for players and projectiles
saiam
parents:
182
diff
changeset
|
66 |
else if (fx > 0) setFacing(true); |
e31ff2152774
Now we use different lists for players and projectiles
saiam
parents:
182
diff
changeset
|
67 |
|
e31ff2152774
Now we use different lists for players and projectiles
saiam
parents:
182
diff
changeset
|
68 |
|
e31ff2152774
Now we use different lists for players and projectiles
saiam
parents:
182
diff
changeset
|
69 |
this->changeAim(da); // Move crosshair |
e31ff2152774
Now we use different lists for players and projectiles
saiam
parents:
182
diff
changeset
|
70 |
|
e31ff2152774
Now we use different lists for players and projectiles
saiam
parents:
182
diff
changeset
|
71 |
// Apply force |
e31ff2152774
Now we use different lists for players and projectiles
saiam
parents:
182
diff
changeset
|
72 |
applyForce(Vector(fx, 0)); |
e31ff2152774
Now we use different lists for players and projectiles
saiam
parents:
182
diff
changeset
|
73 |
|
26 | 74 |
} |
94 | 75 |
|
76 |
void Player::debugInfo (void) { |
|
108 | 77 |
Engine::log(DEBUG, "Player.debugInfo") << "In air: " << this->inAir; |
94 | 78 |
} |
116 | 79 |
|
80 |
void Shot::onCollision() { |
|
182
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
81 |
world.removeGround(position, 20); |
116 | 82 |
} |
182
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
83 |
|
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
84 |
void Shot::draw(CL_GraphicContext *gc) { |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
85 |
|
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
86 |
|
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
87 |
CL_Quad player( |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
88 |
(position).x+1, (position).y+1, |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
89 |
(position).x-1, (position).y+1, |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
90 |
(position).x+1, (position).y-1, |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
91 |
(position).x-1, (position).y-1 |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
92 |
); |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
93 |
|
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
94 |
gc->fill_quad(player, CL_Color::green); |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
95 |
|
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
96 |
const uint16_t chlen = 10; |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
97 |
uint16_t x = player.center().x; |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
98 |
uint16_t y = player.center().y; |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
99 |
if(target_visible) { |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
100 |
if (facingRight) { |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
101 |
gc->draw_line(x, y, |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
102 |
x + std::cos(aim)*chlen, |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
103 |
y - std::sin(aim)*chlen, |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
104 |
CL_Color::black); |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
105 |
} else { |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
106 |
gc->draw_line(x, y, |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
107 |
x - std::cos(aim)*chlen, |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
108 |
y - std::sin(aim)*chlen, |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
109 |
CL_Color::black); |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
110 |
} |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
111 |
} |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
112 |
} |
84675387ca74
PhyWo draw, Shot speed, Shot.show_target, Shot is now drawn with const shape...
nireco
parents:
180
diff
changeset
|
113 |