Try it out!
self.y = self.y - 2
Almost the exact same code! See how with these basics we can expand into new things?
if collision_check(self, 'obj_enemy_projectile'): enemyProjectile = collision_check(self, 'obj_enemy_projectile') destroy(enemyProjectile) health = health - 1
Again, remember that you can change these numbers as long as they still make sense in the end. (For example, the enemies shouldn’t move faster than the enemy projectiles.)
self.y = self.y - 1
timer = 0
Don't forget to set the timer back to 0! Otherwise it will only shoot once and never again.
timer = timer + 1 if timer == 120: enemyProjectile = object_new('obj_enemy_projectile') enemyProjectile.x = self.x enemyProjectile.y = self.y timer = 0
And now we want them to lose health when the collide with our projectiles. Just like how our player loses health from enemy projectiles!
health = 3
This won’t do anything just yet… We also need to destroy them if their health is 0! Still in obj_enemy / Loop:
if collision_check(self, 'obj_projectile'): projectile = collision_check(self, 'obj_projectile') destroy(projectile) health = health - 1
This should look familiar too. It's just like the code we used for our player's health!
if health ‹= 0: destroy(self)
enemyTimer = 0
Again, this is just like the code we used for spawning asteroids or shields, only replacing some words with “enemy”.
enemyTimer = enemyTimer + 1 if enemyTimer == 300: enemyOffset = random.randint(-200, 200) enemy = object_new('obj_enemy') enemy.x = self.x + enemyOffset enemy.y = self.y + enemyOffset enemyTimer = 0
Ready for more? Try the next lesson!
PixelPAD is loading...