Now we can call it from wherever we want, but instead of just writing “score”, we need to write “game.score”. Let's try it out!
score = 0
Now we add 1 point to our score whenever we destroy an asteroid. Test it out!
if collision_check(self, 'obj_projectile'): projectile = collision_check(self, 'obj_projectile') destroy(projectile) game.score = game.score + 1 destroy(self)
We only want to add score when they are destroyed, and since they have health, we'll put the line here instead of with the collision code.
if health ‹= 0: game.score = game.score + 5 destroy(self)
We can combine regular text inside the quotation marks with variables outside of them! Hit reload and test it out!
if key_was_pressed('S'): print("Score: " + game.score)
Now when we get 50 points, it should load the victory room with our trophy object!
if game.score >= 50: print("You win!") room_set('rm_victory')
Test it out and make sure that it works!
if health ‹= 0: room_set('rm_game_over') destroy(self)
Want to make another game? Try another tutorial!
PixelPAD is loading...