Compare commits
3 Commits
9d5dbadc64
...
23add4aba3
Author | SHA1 | Date |
---|---|---|
DeathByDenim | 23add4aba3 | |
DeathByDenim | 07e9aefbaa | |
DeathByDenim | 92726a3290 |
42
World/Map.gd
42
World/Map.gd
|
@ -4,18 +4,18 @@ var base_positions: Array[Vector2i] = []
|
|||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
$Options.reset_to_defaults()
|
||||
MapConfig.reset_to_defaults()
|
||||
|
||||
|
||||
|
||||
func load_map(file_name: String):
|
||||
$Options.num_errors = 0
|
||||
$Options.reset_to_defaults()
|
||||
MapConfig.num_errors = 0
|
||||
MapConfig.reset_to_defaults()
|
||||
parse_map_file(file_name)
|
||||
apply_options()
|
||||
prints("Loaded", $Options.mapname, "by", $Options.mapauthor)
|
||||
if $Options.num_errors > 0:
|
||||
push_error("Map contains ", $Options.num_errors, " errors")
|
||||
prints("Loaded", MapConfig.mapname, "by", MapConfig.mapauthor)
|
||||
if MapConfig.num_errors > 0:
|
||||
push_error("Map contains ", MapConfig.num_errors, " errors")
|
||||
|
||||
|
||||
func parse_map_file(file_name):
|
||||
|
@ -47,7 +47,7 @@ func parse_map_file(file_name):
|
|||
line_number += 1
|
||||
if multi_line_mode_option:
|
||||
if line.contains(multi_line_terminator):
|
||||
$Options.set_option(multi_line_mode_option, multi_line_content)
|
||||
MapConfig.set_option(multi_line_mode_option, multi_line_content)
|
||||
multi_line_mode_option = ""
|
||||
else:
|
||||
multi_line_content += line
|
||||
|
@ -70,27 +70,27 @@ func parse_map_file(file_name):
|
|||
multi_line_mode_option = option[0].strip_edges().to_lower()
|
||||
multi_line_terminator = option[1].split("\\multiline:")[1].strip_edges()
|
||||
continue
|
||||
$Options.set_option(option[0].strip_edges(), option[1].strip_edges())
|
||||
MapConfig.set_option(option[0].strip_edges(), option[1].strip_edges())
|
||||
if multi_line_mode_option != "":
|
||||
print("EOF reached before end of multiline")
|
||||
|
||||
if $Options.mapdata.length() > 0 and $Options.mapwidth > 0 and $Options.mapheight > 0:
|
||||
for iy in range($Options.mapheight):
|
||||
for ix in range($Options.mapwidth):
|
||||
var letter_code = $Options.mapdata[iy * $Options.mapwidth + ix]
|
||||
if MapConfig.mapdata.length() > 0 and MapConfig.mapwidth > 0 and MapConfig.mapheight > 0:
|
||||
for iy in range(MapConfig.mapheight):
|
||||
for ix in range(MapConfig.mapwidth):
|
||||
var letter_code = MapConfig.mapdata[iy * MapConfig.mapwidth + ix]
|
||||
if tile_dictionary.has(letter_code):
|
||||
set_cell(0, Vector2i(ix, iy), 0, tile_dictionary[letter_code])
|
||||
if "_0123456789".contains(letter_code):
|
||||
base_positions.push_back(Vector2i(ix, iy))
|
||||
if $Options.edgewrap:
|
||||
if ix < $Options.mapwidth / 2:
|
||||
base_positions[-1].x += $Options.mapwidth
|
||||
if iy < $Options.mapheight / 2:
|
||||
base_positions[-1].y += $Options.mapheight
|
||||
if $Options.edgewrap:
|
||||
set_cell(0, Vector2i(ix + $Options.mapwidth, iy), 0, tile_dictionary[letter_code])
|
||||
set_cell(0, Vector2i(ix + $Options.mapwidth, iy + $Options.mapheight), 0, tile_dictionary[letter_code])
|
||||
set_cell(0, Vector2i(ix, iy + $Options.mapheight), 0, tile_dictionary[letter_code])
|
||||
if MapConfig.edgewrap:
|
||||
if ix < MapConfig.mapwidth / 2:
|
||||
base_positions[-1].x += MapConfig.mapwidth
|
||||
if iy < MapConfig.mapheight / 2:
|
||||
base_positions[-1].y += MapConfig.mapheight
|
||||
if MapConfig.edgewrap:
|
||||
set_cell(0, Vector2i(ix + MapConfig.mapwidth, iy), 0, tile_dictionary[letter_code])
|
||||
set_cell(0, Vector2i(ix + MapConfig.mapwidth, iy + MapConfig.mapheight), 0, tile_dictionary[letter_code])
|
||||
set_cell(0, Vector2i(ix, iy + MapConfig.mapheight), 0, tile_dictionary[letter_code])
|
||||
|
||||
else:
|
||||
print("Map data or dimensions missing")
|
||||
|
|
|
@ -2,6 +2,7 @@ extends MultiplayerSynchronizer
|
|||
|
||||
@export var rotate := 0.0
|
||||
@export var thrust := false
|
||||
@export var shoot := false
|
||||
|
||||
const ROTATION = 0.05
|
||||
|
||||
|
@ -18,3 +19,5 @@ func _process(delta):
|
|||
if Input.is_action_pressed("right"):
|
||||
rotate += ROTATION
|
||||
thrust = Input.is_action_pressed("thrust")
|
||||
shoot = Input.is_action_pressed("shoot")
|
||||
|
||||
|
|
|
@ -4,10 +4,11 @@ extends CharacterBody2D
|
|||
const ROTATION = 0.05
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||
var Bullet = preload("res://World/bullet.tscn")
|
||||
|
||||
var thrust = 6.0
|
||||
var gravity := Vector2.ZERO
|
||||
var last_shot_utime := 0
|
||||
|
||||
# Set by the authority, synchronized on spawn.
|
||||
@export var player := 1 :
|
||||
|
@ -27,24 +28,33 @@ func _ready():
|
|||
# Only process on server.
|
||||
# EDIT: Left the client simulate player movement too to compesate network latency.
|
||||
# set_physics_process(multiplayer.is_server())
|
||||
pass
|
||||
|
||||
gravity = 1000*MapConfig.gravity * Vector2.LEFT.rotated(deg_to_rad(MapConfig.gravityangle))
|
||||
|
||||
|
||||
func shoot():
|
||||
if Time.get_ticks_usec() < last_shot_utime + 1000000 * MapConfig.firerepeatrate / MapConfig.framespersecond:
|
||||
return
|
||||
|
||||
# "Muzzle" is a Marker2D placed at the barrel of the gun.
|
||||
var b = Bullet.instantiate()
|
||||
b.start($"Muzzle main".global_position, rotation)
|
||||
b.start($"Muzzle main".global_position, velocity, rotation)
|
||||
get_tree().root.add_child(b)
|
||||
last_shot_utime = Time.get_ticks_usec()
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
rotation += input.rotate
|
||||
|
||||
# Add the gravity.
|
||||
velocity.y += gravity * delta
|
||||
velocity += gravity * delta
|
||||
|
||||
if input.thrust:
|
||||
velocity += Vector2(thrust, 0).rotated(rotation)
|
||||
if input.shoot:
|
||||
shoot()
|
||||
|
||||
var collision = move_and_collide(velocity * delta)
|
||||
if collision:
|
||||
velocity = (1 - $"../../Map/Options".playerwallbouncebrakefactor) * velocity.bounce(collision.get_normal())
|
||||
velocity = (1 - MapConfig.playerwallbouncebrakefactor) * velocity.bounce(collision.get_normal())
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@ properties/0/sync = true
|
|||
properties/1/path = NodePath(".:thrust")
|
||||
properties/1/spawn = false
|
||||
properties/1/sync = true
|
||||
properties/2/path = NodePath(".:shoot")
|
||||
properties/2/spawn = false
|
||||
properties/2/sync = true
|
||||
|
||||
[node name="Player ship" type="CharacterBody2D"]
|
||||
script = ExtResource("1_tcnl2")
|
||||
|
|
|
@ -45,8 +45,8 @@ func _process(delta):
|
|||
|
||||
func _on_map_boundaries_body_exited(body):
|
||||
|
||||
var width = $Map/Options.mapwidth
|
||||
var height = $Map/Options.mapheight
|
||||
var width = MapConfig.mapwidth
|
||||
var height = MapConfig.mapheight
|
||||
|
||||
if body.position.x < $"Map boundaries".position.x - 32*width:
|
||||
body.position.x += 64 * width
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://ddr7q5f0xrfsm"]
|
||||
[gd_scene load_steps=7 format=3 uid="uid://ddr7q5f0xrfsm"]
|
||||
|
||||
[ext_resource type="Script" path="res://World/PlayingField.gd" id="1_ashcc"]
|
||||
[ext_resource type="Texture2D" uid="uid://d4hd1froa8gji" path="res://Images/tilemap.png" id="2_covyd"]
|
||||
[ext_resource type="Script" path="res://World/Map.gd" id="3_1prtd"]
|
||||
[ext_resource type="Script" path="res://World/Options.gd" id="4_36ml1"]
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_b2nj3"]
|
||||
texture = ExtResource("2_covyd")
|
||||
|
@ -172,9 +171,6 @@ cell_quadrant_size = 64
|
|||
format = 2
|
||||
script = ExtResource("3_1prtd")
|
||||
|
||||
[node name="Options" type="Node" parent="Map"]
|
||||
script = ExtResource("4_36ml1")
|
||||
|
||||
[node name="Map boundaries" type="Area2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Map boundaries"]
|
||||
|
|
|
@ -3,12 +3,12 @@ extends CharacterBody2D
|
|||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||
var speed = 750
|
||||
var life_time = 1.0
|
||||
@onready var life_time: float = MapConfig.shotlife
|
||||
|
||||
func start(_position, _direction):
|
||||
func start(_position, _velocity, _direction):
|
||||
rotation = _direction
|
||||
position = _position
|
||||
velocity = Vector2(speed, 0).rotated(rotation)
|
||||
velocity = _velocity + Vector2(speed, 0).rotated(rotation)
|
||||
|
||||
func _physics_process(delta):
|
||||
var collision = move_and_collide(velocity * delta)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=4 format=3]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://dc67u0fso8ivs"]
|
||||
|
||||
[ext_resource type="Script" path="res://World/bullet.gd" id="1_j3y75"]
|
||||
|
||||
|
|
|
@ -263,7 +263,10 @@ var maxroundtime: int
|
|||
var roundstoplay: int
|
||||
var maxpausetime: int
|
||||
|
||||
func reset_to_defaults():
|
||||
func _ready() -> void:
|
||||
reset_to_defaults()
|
||||
|
||||
func reset_to_defaults() -> void:
|
||||
gravity = -0.14
|
||||
shipmass = 20.0
|
||||
ballmass = 50.0
|
||||
|
@ -525,7 +528,7 @@ func reset_to_defaults():
|
|||
roundstoplay = 0
|
||||
maxpausetime = 3600
|
||||
|
||||
func set_option(option: String, value: String):
|
||||
func set_option(option: String, value: String) -> void:
|
||||
option = option.to_lower()
|
||||
match option:
|
||||
"gravity":
|
|
@ -0,0 +1,11 @@
|
|||
extends Node
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
|
@ -15,6 +15,11 @@ run/main_scene="res://Lobby/Lobby.tscn"
|
|||
config/features=PackedStringArray("4.0", "Mobile")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
PlayerConfig="*res://player_config.gd"
|
||||
MapConfig="*res://map_config.gd"
|
||||
|
||||
[input]
|
||||
|
||||
thrust={
|
||||
|
|
Loading…
Reference in New Issue