Compare commits
3 Commits
eac8f75da8
...
5b2c7e729d
Author | SHA1 | Date |
---|---|---|
|
5b2c7e729d | |
|
c642aff92f | |
|
aeb2cf2b23 |
9
keys.c
9
keys.c
|
@ -27,6 +27,15 @@ int key_pressed(KeyControl key)
|
|||
return IsKeyPressed(keys[key]);
|
||||
}
|
||||
|
||||
int key_released(KeyControl key)
|
||||
{
|
||||
// NOTE: mouse button id's are less than 6, keyboard id's are over 32
|
||||
if (keys[key] <= 6)
|
||||
return IsMouseButtonReleased(keys[key]);
|
||||
else
|
||||
return IsKeyReleased(keys[key]);
|
||||
}
|
||||
|
||||
void change_layout_azerty()
|
||||
{
|
||||
keys[KC_UP] = KEY_S;
|
||||
|
|
2
keys.h
2
keys.h
|
@ -24,4 +24,6 @@ int key_down(KeyControl key);
|
|||
|
||||
int key_pressed(KeyControl key);
|
||||
|
||||
int key_released(KeyControl key);
|
||||
|
||||
#endif // KEYS_H
|
||||
|
|
2
main.c
2
main.c
|
@ -125,6 +125,8 @@ int main(void)
|
|||
|
||||
Camera2D effect_camera = camera;
|
||||
effect_camera.offset = Vector2Add(effect_camera.offset, cam_shake);
|
||||
if (player_type == PLAYER_MINIGUN)
|
||||
process_minigun(Vector2Add(SCREEN_MIDDLE, cam_shake), &camera, &effect_camera);
|
||||
BeginMode2D(effect_camera);
|
||||
{
|
||||
DrawTexture(map.texture, map.box.x, map.box.y, WHITE);
|
||||
|
|
41
minigun.c
41
minigun.c
|
@ -6,6 +6,9 @@
|
|||
|
||||
Texture minigun_texture;
|
||||
|
||||
#define DEFAULT_BACK_SPEED 5
|
||||
float back_speed = DEFAULT_BACK_SPEED;
|
||||
|
||||
void load_minigun()
|
||||
{
|
||||
minigun_texture = LoadTexture("data/minigun.png");
|
||||
|
@ -16,9 +19,34 @@ float minigun_radius()
|
|||
return fmax(minigun_texture.width, minigun_texture.height)/2;
|
||||
}
|
||||
|
||||
void process_minigun(Vector2 pos, Camera2D *real_cam, Camera2D *effect_cam)
|
||||
{
|
||||
if (key_down(KC_SPECIAL)) {
|
||||
int force = 5;
|
||||
effect_cam->offset.x += GetRandomValue(-force/2, force/2);
|
||||
effect_cam->offset.y += GetRandomValue(-force/2, force/2);
|
||||
}
|
||||
else if (key_down(KC_SHOOT)) {
|
||||
back_speed += GetFrameTime() * 1.2;
|
||||
if (back_speed >= 25)
|
||||
back_speed = 25;
|
||||
float angle = -Vector2LineAngle(pos, GetMousePosition());
|
||||
angle *= 180/PI;
|
||||
Vector2 world = GetScreenToWorld2D(pos, *real_cam);
|
||||
Vector2 toward = Vector2Normalize((Vector2) {cos(angle * PI/180), sin(angle * PI/180)});
|
||||
real_cam->target = Vector2Subtract(world, Vector2Scale(toward, back_speed));
|
||||
|
||||
bullet_spawn(BULLET_MINIGUN, Vector2Subtract(world, Vector2Scale(toward, 5*1.0)), angle);
|
||||
bullet_spawn(BULLET_MINIGUN, Vector2Subtract(world, Vector2Scale(toward, 5*6.0)), angle);
|
||||
}
|
||||
if (key_down(KC_SPECIAL) || !key_down(KC_SHOOT)) {
|
||||
back_speed = DEFAULT_BACK_SPEED;
|
||||
}
|
||||
}
|
||||
|
||||
void draw_minigun(Vector2 pos, Camera2D *cam)
|
||||
{
|
||||
|
||||
(void) cam;
|
||||
Texture m = minigun_texture;
|
||||
Rectangle source = {0, 0, m.width, m.height};
|
||||
Rectangle dest = {pos.x, pos.y, m.width, m.height};
|
||||
|
@ -26,15 +54,8 @@ void draw_minigun(Vector2 pos, Camera2D *cam)
|
|||
float angle = -Vector2LineAngle(pos, GetMousePosition());
|
||||
angle *= 180/PI;
|
||||
|
||||
if (key_down(KC_SHOOT)) {
|
||||
int speed = 5;
|
||||
Vector2 world = GetScreenToWorld2D(pos, *cam);
|
||||
Vector2 toward = Vector2Normalize((Vector2) {cos(angle * PI/180), sin(angle * PI/180)});
|
||||
cam->target = Vector2Subtract(world, Vector2Scale(toward, speed));
|
||||
|
||||
bullet_spawn(BULLET_MINIGUN, Vector2Subtract(world, Vector2Scale(toward, speed*1.0)), angle);
|
||||
bullet_spawn(BULLET_MINIGUN, Vector2Subtract(world, Vector2Scale(toward, speed*6.0)), angle);
|
||||
}
|
||||
if (key_down(KC_SPECIAL))
|
||||
DrawLineEx(pos, GetMousePosition(), 10, RED);
|
||||
|
||||
DrawTexturePro(m, source, dest, origin, angle + 90, WHITE);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue