diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2025-01-08 10:08:03 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2025-01-08 10:08:03 +0100 |
commit | 7f7c5c56dce30d47c32fb57fad6d839d0990b054 (patch) | |
tree | eebc8d3f4c332d969f4a66a566edd844bd43387c /game/player/PlayerScript.cpp | |
parent | ceb41b7ae7e2734af954364b319fc0b6f2a86c2f (diff) |
enemy spawn working + enemy shooting
Diffstat (limited to 'game/player/PlayerScript.cpp')
-rw-r--r-- | game/player/PlayerScript.cpp | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index 472d7c8..8372080 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -1,10 +1,12 @@ +#include <iostream> #include "PlayerScript.h" #include "../Config.h" - +#include "../enemy/BattleScript.h" #include <crepe/api/Animator.h> #include <crepe/api/ParticleEmitter.h> #include <crepe/api/Rigidbody.h> +#include <crepe/api/BoxCollider.h> #include <crepe/api/Transform.h> #include <crepe/types.h> @@ -16,7 +18,6 @@ void PlayerScript::init() { return this->on_collision(ev); }); } - bool PlayerScript::on_collision(const CollisionEvent & ev) { BehaviorScript & play_scr = this->get_components_by_name<BehaviorScript>("player").front(); BehaviorScript & end_scr = this->get_components_by_name<BehaviorScript>("player").back(); @@ -77,8 +78,16 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { for (ParticleEmitter & emitter : emitters) { emitter.data.boundary.offset = vec2(0, -transform.position.y); } - + Rigidbody & rb = this->get_components_by_name<Rigidbody>("player").front(); + if (this->get_key_state(Keycode::P)) { + this->trigger_event<BattleStartEvent>(BattleStartEvent{ + .num_enemies = 5, + }); + } + if(this->get_key_state(Keycode::ENTER)){ + this->shoot(transform.position,0); + } if (this->get_key_state(Keycode::SPACE)) { rb.add_force_linear(vec2(0, -PLAYER_GRAVITY_SCALE / 2.5) * dt.count() / 0.02); if (prev_anim != 1) { @@ -117,3 +126,25 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { } } } + +void PlayerScript::shoot(const vec2& location,float angle){ + cout << "player shot" << endl; + RefVector<Transform> bullet_transforms = this->get_components_by_tag<Transform>("PlayerBullet"); + + for(Transform& bullet_pos : bullet_transforms){ + //cout << "bullet pos x: " << bullet_pos.position.x << " y: " << bullet_pos.position.y << endl; + if(bullet_pos.position.x == 0 && bullet_pos.position.y == -850){ + + cout << "bullet found\n"; + bullet_pos.position = location; + bullet_pos.position.x += 20; + cout << "bullet pos x: " << bullet_pos.position.x << " y: " << bullet_pos.position.y << endl; + Rigidbody& bullet_body = this->get_components_by_id<Rigidbody>(bullet_pos.game_object_id).front(); + BoxCollider bullet_collider = this->get_components_by_id<BoxCollider>(bullet_pos.game_object_id).front(); + //bullet_collider.active = true; + bullet_body.active = true; + return; + } + } + cout << "bullet not found\n"; +} |