Closed xoryouyou closed 3 years ago
Just following up. Are you interesting in finishing this up so it can be merged?
Same situation here as you've had it back in april. Somehow the notifications for this repo got lost.
Anyways I've commited the changes as requested and commented above about them. :smile:
I've had to rework the Invader.kill_invader_at
and Player.detect_hits
functions to return u16
.
Its not that clean since we now have to store the functions result like
before:
if(player.detect_hits(...))
{
do_stuff();
}
now:
let hit_result = player.detect_hits(...);
if(hit_result > 0)
{
do_stuff();
}
But that is the only way it works and we can later on move from a simple u16 which when positive
to a more meaningful struct like HitResult
which could feature detailed information and enable logic
based on the hit invader like combos,effect,etc.
But should do for now :smile:
I've added a simple score module in
score.rs
which implements theDrawable
trait to print the current score in the top left corner of theFrame
.The score is simply calculated by subtracting
Invaders.army.len()
from the newly introducedInvaders.total_count
which represents the total count of spawned invaders in the army.So each hit invader results in one point added on the score.
Note
To make rendering easier I've refactored
Frame
s data structure into a 2d char array in the form of[[char ; NUM_ROWS]; NUM_COLS]
.This allows for the same access
frame[x][y]
but only takeschar
instead of&str
.It was done to enable the dynamic use of
format!
inScore.update
which returns aString
. ThatString
is not easily convertable to&str
especially given the different lifetimes.This also gives the option to add more useful strings like "time played" or "level" onto the screen via a more complex module later on.
Would like to hear some feedback since it's my first contribution in rust :)