help to program an idea for a game

Godot Version

Godot 4

Question

Hello everyone :wink:

I have a school project where I need to make a shmup, and we also have to create something called a “special feature” (something unique to my shmup that the others in my class don’t have).

For example, my special feature is that when you press “M”, you can change the shape of the spaceship.

Phase 1 is the default one (you don’t need to press anything; it appears when the game starts).
It’s a triangle, it shoots a single projectile, it’s accurate, the ship moves at a medium speed, and it has 3 lives.

Phase 2 (activated when you press “M”) is a circle.
It shoots 3 projectiles, has 2 lives, and moves a little faster.

Phase 3 is a square.
It moves much faster than the previous forms, but it cannot shoot.

So now that you have some context, here’s my question:
How can I make it so that when I press “M”, Phase 2 appears and Phase 1 disappears from the screen, and Phase 2 uses its own speed, its own Marker2D for projectiles, etc.? And if I press “M” again, Phase 3 appears, replacing Phase 2, and so on?

I know you might say I could have chosen a much simpler special feature to implement…

Make each phase a scene, when “M” is pressed, delete the old one, instantiate next one, and place it at the position of the old one.

The alternative approach would be to put all phases into one scene and just enable/disable visibility and processing for each pahse node(s), depending on which phase is currently active.

1 Like

This would be an easier approach, considering the scope of your game.

Just make a main ‘player’ node and add all three different shapes (as Sprite2D nodes). Then enable disable them according to which phase you are in.

And for choosing phase, you can make a simple enum that has the phases, and a variable that holds the current phase value. And each time you press M, you switch to the next phase on the enum.

I think this project sounds like a good way of learning basics of game design but also godot. So kudos to the teacher :slight_smile:

okay I understand pretty but How I cant tell phase 1 : Triangle, phase 2 : circle, phase 3 : square ?.

you just create an enum. You can write whatever you want there.

Then make it behave however you want according to the current phase that has a value from the enum

Maintain an integer variable that stores the current state/phase. Increment by one when switching to next state. You can then use this variable as an array index or a dictionary key for any state-specific data stored in an array or a dictionary. You can also branch your code depending on the value of this variable.

1 Like

Can I just make 3 [Export] ? Like
[Export] Player_Phase_1
[Export] Player_Phase_2
[Export] Player_Phase_3
is it more easy ? or later I will not be able to change the sprite in the game ?

You can but that doesn’t really solve the problem of tracking which phase is the current. You still need some kind of variable that determines the currently active phase.

Try to approach this problem as if instead of 3 phases you have a big arbitrary number of phases - for example 99. How would you solve this?

Thinking about the problem like that will make your solution generalized and easily expandable should you decide to add couple more phases in some future version of the game. Also, if you approach it like that - your teacher will love it.

2 Likes