-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduced fleets and enemy ship formations
- Loading branch information
1 parent
1e001f4
commit dd83faf
Showing
10 changed files
with
184 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"formations": [ | ||
{ | ||
"formation_name": "x", | ||
"odds": 1.0, | ||
"steps": { | ||
"0": [ | ||
1, | ||
2, | ||
5, | ||
7 | ||
], | ||
"1": [ | ||
3, | ||
4, | ||
5, | ||
7 | ||
], | ||
"2": [ | ||
7, | ||
8, | ||
5, | ||
7 | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[gd_scene load_steps=2 format=3 uid="uid://ri0gdlnfdj42"] | ||
|
||
[ext_resource type="Script" path="res://scripts/fleet.gd" id="1_eboqq"] | ||
|
||
[node name="Fleet" type="Area2D"] | ||
script = ExtResource("1_eboqq") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,5 @@ enum GameEvent { | |
enum EnemyType { | ||
SHIP, | ||
} | ||
|
||
enum Position { TOP, LEFT, RIGHT } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
extends Area2D | ||
class_name Fleet | ||
|
||
const ENEMY_SHIP: PackedScene = preload("res://scenes/enemy/Enemy.tscn") | ||
|
||
const NUM_SPAWN_COLUMNS := 5 | ||
const NUM_SPAWN_ROWS := 3 | ||
|
||
var long_side: float | ||
var short_side: float | ||
|
||
|
||
func _ready(): | ||
# Get viewport size | ||
var viewport = get_viewport().size | ||
|
||
long_side = viewport.x | ||
short_side = viewport.y / NUM_SPAWN_ROWS | ||
|
||
|
||
func init(steps): | ||
for index in range(0, steps.size()): | ||
var enemy_steps = steps[String.num(index)] | ||
var enemy = ENEMY_SHIP.instantiate() | ||
|
||
enemy.position = get_ship_position(enemy_steps[0]) | ||
# enemy.init(enemy_steps) | ||
add_child(enemy) | ||
|
||
|
||
func _physics_process(delta): | ||
position += Vector2.DOWN * 35 * delta | ||
|
||
|
||
func get_ship_position(piece_index: int) -> Vector2: | ||
var slot_size := Vector2(long_side / NUM_SPAWN_COLUMNS, short_side / NUM_SPAWN_ROWS) | ||
|
||
# Piece position coordinates | ||
var side_x := slot_size.x * (piece_index % NUM_SPAWN_COLUMNS) | ||
var side_y := slot_size.y * int(piece_index / float(NUM_SPAWN_COLUMNS)) | ||
|
||
var pos_x := side_x + slot_size.x / 2 | ||
var pos_y := side_y + slot_size.y / 2 | ||
return Vector2(pos_x, pos_y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.