-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from sinproject-iwasaki/56-add-a-first-event
Add a first event #56
- Loading branch information
Showing
4 changed files
with
50 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use bevy::prelude::*; | ||
|
||
use crate::{block_pattern::BlockPatterns, sprite}; | ||
|
||
#[derive(Resource)] | ||
pub struct EventTriggerState { | ||
event_timer: Timer, | ||
} | ||
|
||
impl Default for EventTriggerState { | ||
fn default() -> Self { | ||
Self { | ||
event_timer: Timer::from_seconds(1.0, TimerMode::Repeating), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Event, Default)] | ||
pub struct NewBlockEvent; | ||
|
||
pub fn event_trigger( | ||
time: Res<Time>, | ||
mut state: ResMut<EventTriggerState>, | ||
mut new_block_events: EventWriter<NewBlockEvent>, | ||
) { | ||
if state.event_timer.tick(time.delta()).finished() { | ||
new_block_events.send_default(); | ||
} | ||
} | ||
|
||
pub fn event_listener( | ||
mut commands: Commands, | ||
mut new_block_events: EventReader<NewBlockEvent>, | ||
mut block_patterns: Res<BlockPatterns>, | ||
) { | ||
for _ in new_block_events.read() { | ||
println!("New block event received!"); | ||
sprite::spawn_block(&mut commands, &mut block_patterns) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters