diff --git a/client/levels/mainMenu/MainMenu.tscn b/client/levels/mainMenu/MainMenu.tscn index 7ac146a77bd6eaa97eb2c075c910070b2b56ef3c..ce811942cde9494cba6e108f4d39fd84cec24f59 100644 --- a/client/levels/mainMenu/MainMenu.tscn +++ b/client/levels/mainMenu/MainMenu.tscn @@ -6,13 +6,13 @@ [ext_resource path="res://levels/mainMenu/assets/mainMenuCharacters.png" type="Texture" id=4] [ext_resource path="res://levels/commons/assets/logotmp.png" type="Texture" id=5] [ext_resource path="res://levels/commons/fonts/montserrat/Montserrat-Bold.otf" type="DynamicFontData" id=6] -[ext_resource path="res://levels/mainMenu/assets/letsplay.png" type="Texture" id=8] -[ext_resource path="res://levels/commons/scripts/buttonHover.gd" type="Script" id=10] -[ext_resource path="res://levels/mainMenu/assets/profile.png" type="Texture" id=11] -[ext_resource path="res://levels/mainMenu/assets/settings.png" type="Texture" id=12] -[ext_resource path="res://levels/mainMenu/assets/credits.png" type="Texture" id=13] -[ext_resource path="res://levels/mainMenu/assets/exit.png" type="Texture" id=14] -[ext_resource path="res://levels/commons/fonts/montserrat/Montserrat-Regular.otf" type="DynamicFontData" id=15] +[ext_resource path="res://levels/mainMenu/assets/letsplay.png" type="Texture" id=7] +[ext_resource path="res://levels/commons/scripts/buttonHover.gd" type="Script" id=8] +[ext_resource path="res://levels/mainMenu/assets/profile.png" type="Texture" id=9] +[ext_resource path="res://levels/mainMenu/assets/settings.png" type="Texture" id=10] +[ext_resource path="res://levels/mainMenu/assets/credits.png" type="Texture" id=11] +[ext_resource path="res://levels/mainMenu/assets/exit.png" type="Texture" id=12] +[ext_resource path="res://levels/commons/fonts/montserrat/Montserrat-Regular.otf" type="DynamicFontData" id=13] [sub_resource type="Animation" id=1] resource_name = "anim" @@ -11653,7 +11653,7 @@ size = 20 extra_spacing_top = 5 extra_spacing_bottom = 5 extra_spacing_char = 1 -font_data = ExtResource( 15 ) +font_data = ExtResource( 13 ) [sub_resource type="Animation" id=1394] tracks/0/type = "value" @@ -11817,7 +11817,7 @@ margin_bottom = 100.0 rect_min_size = Vector2( 0, 100 ) size_flags_horizontal = 5 theme = SubResource( 1390 ) -texture_normal = ExtResource( 8 ) +texture_normal = ExtResource( 7 ) expand = true stretch_mode = 4 @@ -11829,10 +11829,10 @@ rect_pivot_offset = Vector2( 179.208, 47.8025 ) mouse_default_cursor_shape = 2 size_flags_horizontal = 5 size_flags_vertical = 0 -texture_normal = ExtResource( 8 ) +texture_normal = ExtResource( 7 ) expand = true stretch_mode = 5 -script = ExtResource( 10 ) +script = ExtResource( 8 ) [node name="Tween" type="Tween" parent="homePage/sdfg/MarginContainer/menu/liensMenu/Play"] @@ -11845,10 +11845,10 @@ rect_pivot_offset = Vector2( 171.841, 50.9325 ) mouse_default_cursor_shape = 2 size_flags_horizontal = 5 size_flags_vertical = 0 -texture_normal = ExtResource( 11 ) +texture_normal = ExtResource( 9 ) expand = true stretch_mode = 5 -script = ExtResource( 10 ) +script = ExtResource( 8 ) [node name="Tween" type="Tween" parent="homePage/sdfg/MarginContainer/menu/liensMenu/Profile"] @@ -11861,10 +11861,10 @@ rect_pivot_offset = Vector2( 181.663, 47.9238 ) mouse_default_cursor_shape = 2 size_flags_horizontal = 5 size_flags_vertical = 0 -texture_normal = ExtResource( 12 ) +texture_normal = ExtResource( 10 ) expand = true stretch_mode = 5 -script = ExtResource( 10 ) +script = ExtResource( 8 ) [node name="Tween" type="Tween" parent="homePage/sdfg/MarginContainer/menu/liensMenu/Settings"] @@ -11877,10 +11877,10 @@ rect_pivot_offset = Vector2( 177.98, 48.5983 ) mouse_default_cursor_shape = 2 size_flags_horizontal = 5 size_flags_vertical = 0 -texture_normal = ExtResource( 13 ) +texture_normal = ExtResource( 11 ) expand = true stretch_mode = 5 -script = ExtResource( 10 ) +script = ExtResource( 8 ) [node name="Tween" type="Tween" parent="homePage/sdfg/MarginContainer/menu/liensMenu/Credits"] @@ -11896,11 +11896,11 @@ rect_pivot_offset = Vector2( 180.436, 49.2728 ) mouse_default_cursor_shape = 2 size_flags_horizontal = 5 size_flags_vertical = 0 -texture_normal = ExtResource( 14 ) +texture_normal = ExtResource( 12 ) texture_pressed = SubResource( 1392 ) expand = true stretch_mode = 5 -script = ExtResource( 10 ) +script = ExtResource( 8 ) [node name="Tween" type="Tween" parent="homePage/sdfg/MarginContainer/menu/liensMenu/Exit"] diff --git a/client/levels/test/game.gd b/client/levels/test/game.gd index 68e7f5644be8ade24069f647929dd9d72d493f07..917d3e4d58e884d85017ac243f940ca3a78bcda8 100644 --- a/client/levels/test/game.gd +++ b/client/levels/test/game.gd @@ -5,6 +5,7 @@ var movementInput:int = 0 var jumpId:int = 0 # Distinguish 2 different jumps var mouseX:int = 0 # Mouse X percentage var mouseY:int = 0 # Mouse Y percentage +var itemInput:bool = false # Attacks enum { @@ -19,6 +20,7 @@ func _physics_process(_delta): func getPlayerInput(): movementInput = 0 + itemInput = false var attackStateInput:int = NONE var vpSize:Vector2 = get_viewport().size var mousePosition:Vector2 = get_viewport().get_mouse_position() @@ -30,7 +32,11 @@ func getPlayerInput(): if Input.is_action_just_pressed("movementJump"): jumpId += 1 - + + if Input.is_action_just_pressed("itemInput"): + itemInput = true + + if Input.is_action_pressed("primaryAttack"): attackStateInput = PUNCH mouseX = int(mousePosition.x/vpSize.x * 100) - 50 @@ -42,7 +48,7 @@ func getPlayerInput(): # Sent without safety resend rpc_unreliable_id(1, "sendPlayerInputs", movementInput, jumpId, - attackStateInput, mouseX, mouseY) + attackStateInput, mouseX, mouseY, itemInput) puppet func backToLobby(): diff --git a/client/project.godot b/client/project.godot index f0278d74875887868bd3cb3068414dbee48872f9..2b624cca981ca8071f399b7fa6cc60b004f4c268 100644 --- a/client/project.godot +++ b/client/project.godot @@ -61,6 +61,11 @@ secondaryAttack={ "events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":2,"pressed":false,"doubleclick":false,"script":null) ] } +itemInput={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":69,"unicode":0,"echo":false,"script":null) + ] +} [rendering] diff --git a/server/autoloads/gamestate.gd b/server/autoloads/gamestate.gd index f4d18aec7bebbc224eba62e07c7d00c2cee07c93..29548939fe137518171b084ae3c6df67ce7f411e 100644 --- a/server/autoloads/gamestate.gd +++ b/server/autoloads/gamestate.gd @@ -11,11 +11,11 @@ const ENVIRONMENT_LAYER = 0 const PLAYER_LAYER = 1 const MAX_SPAWN_POINT = 70 -const MAX_ITEMS = 20 -var nbItemTotal = 0 +const MAX_ITEMS = 5 +var nbItemTotal:int = 0 var timer = null -var item_delay = 15 +var item_delay = 30 signal deleteItem var rng = RandomNumberGenerator.new() @@ -23,6 +23,9 @@ var rng = RandomNumberGenerator.new() var typeItems = ["beer","trumpet"] + + + func _ready(): # When a client connects to the server get_tree().connect("network_peer_connected", self, "_playerConnected") @@ -115,14 +118,14 @@ func spawnInitItem(): for item_counter in range(MAX_ITEMS): nbItemTotal+=1 var typeItem = rng.randi_range(0,len(typeItems)-1) - var itemScene = load("res://entities/items/"+typeItems[typeItem]+".tscn") - var item = itemScene.instance() + var itemScene = load("res://entities/items/"+typeItems[typeItem]+".gd") var i=rng.randi_range(0,len(listAvailableItem)-1) - item.set_name("item"+str(nbItemTotal)) - get_node(GAMEPATH+"itemCollection").add_child(item) - self.connect("deleteItem",item,"on_timeout_complete") var position = get_node(GAMEPATH+"spawnCollection/spawn"+str(listAvailableItem[i]+1)).get_translation() - item.translate(position) + var newitemScene:Object = itemScene.new(nbItemTotal,typeItem,position) + newitemScene.set_name("item"+str(newitemScene.get_instance_id())) + get_node(GAMEPATH+"itemCollection").add_child(newitemScene) + self.connect("deleteItem",newitemScene,"on_timeout_complete") + newitemScene.translate(position) listAvailableItem.remove(i) rpc("registerItem",nbItemTotal,typeItem,position) timer.start() diff --git a/server/entities/characters/player.gd b/server/entities/characters/player.gd index ea5cbcd42680ccffed09b91d190b61ee9ff04523..786c22d7f33fdf72b4dddda6ccb150659879aa0a 100644 --- a/server/entities/characters/player.gd +++ b/server/entities/characters/player.gd @@ -1,5 +1,7 @@ extends KinematicBody +const GAMEPATH = "/root/game/" + onready var ownId:int = int(name) ######## MOVEMENT AND POSITION VARS ######## @@ -136,6 +138,11 @@ enum { ANIM_BIG_IMPACT = 15 } +######## ITEMS ######## + +var typeItem = null +var nbShot = null + ######## FUNCTIONS ######## # called by the engine @@ -146,7 +153,7 @@ func _physics_process(delta:float): # Called from the game script to update the vars func getPlayerInputs(movementInput:int, jumpId:int, attackTypeInput:int, -mouseX:int, mouseY:int): +mouseX:int, mouseY:int, itemInput:bool): # Prevent the player from moving when attacking if (isAttacking): if (is_on_floor()): @@ -181,6 +188,14 @@ mouseX:int, mouseY:int): && 1.5*mouseX > -mouseY): attackDirection = MOUSE_DOWN processAttack(attackTypeInput) + + # Pick and Drop Item + if itemInput : + print("input") + for node in get_node(GAMEPATH+"spawnCollection/"): + print("node :"+node.name()) +# node.nearItem() + pass func processMovement(delta:float): diff --git a/server/entities/items/beer.gd b/server/entities/items/beer.gd index 8bbdc3b9f3e6afe1ad059adc508b6f83e1ccaf96..735be7efdb42392a7cf56f1eb43af8296672f035 100644 --- a/server/entities/items/beer.gd +++ b/server/entities/items/beer.gd @@ -4,6 +4,22 @@ const GAMEPATH = "/root/game/" const player: = preload("res://entities/characters/player.gd") +var id:int +var typeItem: int +var position: Vector3 + + +func _init(id: int, typeItem: int, position:Vector3): + self.id = id + self.typeItem = typeItem + self.position = position + + + +func nearItem(): + var listBody = self.get_overlapping_bodies() + print(listBody) + #var timer = null #var beer_delay = 15 # diff --git a/server/entities/items/trumpet.gd b/server/entities/items/trumpet.gd index 2006681a5cac66bea1153391bc25ba1ecf93323d..22becae876a507b9b36b696f96f9f479665a34f5 100644 --- a/server/entities/items/trumpet.gd +++ b/server/entities/items/trumpet.gd @@ -4,6 +4,21 @@ const player: = preload("res://entities/characters/player.gd") const GAMEPATH = "/root/game/" + +var id:int +var typeItem:int +var position:Vector3 + + +func _init(id: int, typeItem: int, position:Vector3): + self.id = id + self.typeItem = typeItem + self.position = position + + +func nearItem(): + var listBody = self.get_overlapping_bodies() + print(listBody) #var timer = null #var beer_delay = 15 # diff --git a/server/levels/test/game.gd b/server/levels/test/game.gd index 17b8eab57d7770de7bad6cb7a79e17e5aa864c21..b9db2b66879442bc5ceef3a353eba486864afcf6 100644 --- a/server/levels/test/game.gd +++ b/server/levels/test/game.gd @@ -1,11 +1,11 @@ extends Node -master func sendPlayerInputs(movementInput:int, jumpId:int, attackStateInput:int, mouseX:int, mouseY:int): +master func sendPlayerInputs(movementInput:int, jumpId:int, attackStateInput:int, mouseX:int, mouseY:int, itemInput:bool): # Get the input from a client and send it to the matching remote player var senderId:int = get_tree().get_rpc_sender_id() if gamestate.players.has(senderId): gamestate.get_node("/root/game/"+str(senderId)).getPlayerInputs(movementInput, - jumpId, attackStateInput, mouseX, mouseY) + jumpId, attackStateInput, mouseX, mouseY, itemInput) # When the player exits the game area