0 votes

As a learning exercise, I am trying to recreate "Asteroids". I've managed to get to the point with a moving ship, that fires bullets, at ever decreasing sizes of 'roids. Large, Medium and Small. Large when hit, splits into 2 new instances of med; med when hit splits into 2 new instances of small; and small when hit is the end of the chain.
I notice the code for each asteroid is very similar, so I would like some help building a parent class for the general asteroid. The problem is that I'm not sure what, and what not to include in the parent.

Each asteroid is an Area2D with coll2D, Timer, Sprite, and a Particle emitter.

I'll leave it there for now and expand with code if anyone can help.

Thanks :)

asked Jan 25 in Engine by GodotBadger (22 points)

How are these asteroids different? Is it only the size that differs? If so, you could create a conditional statement that checks the size of the asteroid and act accordingly.

1 Answer

+1 vote

I assume you are writing your project in GDScript. If you want to create a class that inherits some other class, use the

extends [name of the other class]

keyword. For example, if you have an Asteroid node, create a new node and put this in it :

extends Asteroid

Then, redefine the functions that you want to override there.

After a quick google search, I found this : https://kidscancode.org/blog/2018/01/godot3_inheritance/

answered Jan 25 by Teln0 (76 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.