Bullets follow direction of camera, more multiplayer progress

This commit is contained in:
Paul Black 2023-02-14 11:40:02 -07:00
parent 923ed7a018
commit 6b0d3d1c68
7 changed files with 74 additions and 33 deletions

View file

@ -10,11 +10,13 @@ var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@export var Bullet = preload("res://objects/Bullet/Bullet.tscn")
@onready var neck := $CollisionShape3D/Neck
@onready var camera := $CollisionShape3D/Neck/Camera3D
@onready var selfTeddy = self.get_path()
var globalscene
func _ready():
Global.playingGame = true
Global.selfTeddy = selfTeddy
func _unhandled_input(event):
if event is InputEventMouseButton:
@ -90,7 +92,7 @@ func _physics_process(delta):
print("shoot")
var b = Bullet.instantiate()
owner.add_child(b)
b.transform = $CollisionShape3D/Neck/BulletGenerator.global_transform
b.transform = $CollisionShape3D/Neck/Camera3D/BulletGenerator.global_transform
b.velocity = -b.global_transform.basis.z * b.muzzle_velocity
if Input.is_action_just_pressed("console"):
var scene_trs = load("res://scenes/console.tscn")

View file

@ -17,11 +17,13 @@ func _physics_process(delta):
transform.origin += velocity * delta
for body in get_overlapping_bodies():
if body.is_in_group("human"):
if body.get_path() == Global.selfTeddy:
pass
elif body.is_in_group("human"):
print("Bullet hit a human player")
Global.playerHealth = Global.playerHealth - 10
self.queue_free()
if body.is_in_group("AI"):
elif body.is_in_group("AI"):
print("Bullet hit an AI player")
body.queue_free()
self.queue_free()

View file

@ -30,7 +30,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.859224, 0)
[node name="Camera3D" type="Camera3D" parent="CollisionShape3D/Neck"]
[node name="BulletGenerator" type="Marker3D" parent="CollisionShape3D/Neck"]
[node name="BulletGenerator" type="Marker3D" parent="CollisionShape3D/Neck/Camera3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.104801, -0.858231)
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]

View file

@ -32,6 +32,7 @@ grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_8vwth")
[node name="close" type="Button" parent="."]
layout_mode = 0
offset_left = 311.0
offset_top = 174.0
offset_right = 342.0
@ -40,18 +41,18 @@ text = "X"
[node name="Panel2" type="Panel" parent="."]
layout_mode = 0
offset_left = 386.0
offset_top = 217.0
offset_right = 586.0
offset_bottom = 417.0
offset_left = 355.0
offset_top = 215.0
offset_right = 555.0
offset_bottom = 415.0
theme_override_styles/panel = SubResource("StyleBoxFlat_xhmtq")
[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_left = 426.0
offset_top = 303.0
offset_right = 542.0
offset_bottom = 329.0
offset_left = 395.0
offset_top = 295.0
offset_right = 511.0
offset_bottom = 321.0
text = "IMAGE OF MAP"
[node name="mapLabel" type="Label" parent="."]
@ -72,35 +73,59 @@ text = "Playground"
[node name="portBox" type="LineEdit" parent="."]
layout_mode = 0
offset_left = 648.0
offset_top = 411.0
offset_right = 715.062
offset_bottom = 442.0
offset_left = 675.0
offset_top = 412.0
offset_right = 742.062
offset_bottom = 443.0
placeholder_text = "Port"
[node name="startButton" type="Button" parent="."]
layout_mode = 0
offset_left = 735.0
offset_top = 410.0
offset_right = 817.0
offset_bottom = 442.0
offset_left = 751.0
offset_top = 411.0
offset_right = 833.0
offset_bottom = 443.0
text = "START"
[node name="lowerMapLabel" type="Label" parent="."]
layout_mode = 0
offset_left = 386.0
offset_top = 425.0
offset_right = 426.0
offset_bottom = 448.0
offset_left = 359.0
offset_top = 423.0
offset_right = 402.0
offset_bottom = 449.0
text = "Map: "
[node name="mapSelected" type="Label" parent="."]
layout_mode = 0
offset_left = 433.0
offset_left = 406.0
offset_top = 425.0
offset_right = 473.0
offset_right = 446.0
offset_bottom = 448.0
[node name="playerBox" type="LineEdit" parent="."]
layout_mode = 0
offset_left = 674.0
offset_top = 377.0
offset_right = 741.062
offset_bottom = 408.0
placeholder_text = "Players"
[node name="maxPlayersLabel" type="Label" parent="."]
layout_mode = 0
offset_left = 564.0
offset_top = 381.0
offset_right = 662.0
offset_bottom = 407.0
text = "Max Players:"
[node name="portLabel" type="Label" parent="."]
layout_mode = 0
offset_left = 623.0
offset_top = 416.0
offset_right = 663.0
offset_bottom = 442.0
text = "Port:"
[connection signal="pressed" from="close" to="." method="_on_close_pressed"]
[connection signal="pressed" from="playground" to="." method="_on_playground_pressed"]
[connection signal="pressed" from="startButton" to="." method="_on_start_button_pressed"]

View file

@ -15,6 +15,7 @@ var consoleOpen = false # This specifies whether or not the console is open
var consoleCommand # Defined by console.gd
var consoleOutput # Defined by console.gd
var godMode = false # Defined by console.gd
var selfTeddy # Defined as soon as the player script is initalized
func _process(delta):
if godMode:

View file

@ -28,23 +28,34 @@ func _on_playground_pressed():
func _on_start_button_pressed():
var PORT = $portBox.text
var MAX_PLAYERS = $playerBox.text
var intPORT = int(PORT)
var intMAX = int(MAX_PLAYERS)
if PORT:
prints("Player chose port", intPORT)
prints("Player chose port:", intPORT)
if SCENE:
print("Player chose map ", SCENE)
load_map(SCENE, intPORT)
print("Player chose map: ", SCENE)
if MAX_PLAYERS:
if intMAX < 1:
$mapSelected.text = "MAX PLAYERS CANNOT BE NEGATIVE"
elif intMAX > 4095:
$mapSelected.text = "MAX PLAYERS CANNOT BE ABOVE 4095"
else:
print("Player chose player limit: ", intMAX)
load_map(SCENE, intPORT, intMAX)
else:
$mapSelected.text = "NO MAX PLAYERS SELECTED"
else:
$mapSelected.text = "NO MAP SELECTED"
else:
$mapSelected.text = "NO PORT SPECIFIED"
func load_map(map, port):
var result = peer.create_server(port, 4095)
func load_map(map, port, maxPlayers):
var result = peer.create_server(port, maxPlayers) # Second paramater specifies the player limit. Can be anything between 1 and 4095
peer.get_incoming_connections()
prints("Creating server result:", result)
if result == OK:
print("Server should be listening...")
print("Server should be listening on port: ", port)
elif result == ERR_ALREADY_IN_USE:
printerr("Port is being used by something else!")
else:

View file

@ -51,6 +51,6 @@ func _on_join_button_pressed():
printerr("Did NOT connect to server")
$errorLabel.text = "Did NOT connect to server"
if result == OK:
print("Connected to server!")
print("Connected to server at IP ", IPADD, ":", intPORT, "!")
$errorLabel.text = "Connected to server!"