Rocks
The goal of the game is to destroy the floating space rocks, so, now that you can shoot, it's time to add them. Like the ship, the rocks will also be RigidBody2D
, which will make them travel in a straight line at a steady speed unless disturbed. They'll also bounce off each other in a realistic fashion. To make things more interesting, rocks will start out large and, when you shoot them, break into multiple smaller rocks.
Scene setup
Start a new scene by making a RigidBody2D
, naming it Rock
, and adding a Sprite
using the res://assets/rock.png
texture. Add a CollisionShape2D
, but don't add a shape to it yet. Because you'll be spawning different-sized rocks, the collision shape will need to be set in the code and adjusted to the correct size.
Set the Bounce
property of the Rock
to 1
and both Linear
/Damp
and Angular
/Damp
to 0
.
Variable size
Attach a script and define the member variables:
extends RigidBody2D var screensize = Vector2() var size var radius var scale_factor = 0.2
The Main
script...