diff --git a/assets/misc/SimpleGunShot.png b/assets/misc/SimpleGunShot.png new file mode 100644 index 0000000..1642d92 --- /dev/null +++ b/assets/misc/SimpleGunShot.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ff0bee32a80e3f8c4bea146508113f56f50266d1db5dcd54532d8cbeabbc5f46 +size 550 diff --git a/assets/misc/SimpleGunShot.png.import b/assets/misc/SimpleGunShot.png.import new file mode 100644 index 0000000..18d9b90 --- /dev/null +++ b/assets/misc/SimpleGunShot.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/SimpleGunShot.png-9f4751826e09c42069e0e43d2842bcdb.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/misc/SimpleGunShot.png" +dest_files=[ "res://.import/SimpleGunShot.png-9f4751826e09c42069e0e43d2842bcdb.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/assets/misc/SimpleGunShot.tscn b/assets/misc/SimpleGunShot.tscn new file mode 100644 index 0000000..7277969 --- /dev/null +++ b/assets/misc/SimpleGunShot.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://assets/misc/SimpleGunShot.png" type="Texture" id=1] +[ext_resource path="res://assets/misc/Hitbox.tscn" type="PackedScene" id=2] +[ext_resource path="res://src/misc/SimpleGunShot.gd" type="Script" id=3] +[ext_resource path="res://src/misc/SimpleGunShotHitbox.gd" type="Script" id=4] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 1.00781, 1.99957 ) + +[node name="SimpleGunShot" type="KinematicBody2D"] +visible = false +collision_layer = 0 +collision_mask = 20 +script = ExtResource( 3 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) + +[node name="GunShotHitbox" parent="." instance=ExtResource( 2 )] +script = ExtResource( 4 ) + +[node name="CollisionShape2D" parent="GunShotHitbox" index="0"] +shape = SubResource( 1 ) +[connection signal="area_entered" from="GunShotHitbox" to="GunShotHitbox" method="_on_Hitbox_area_entered"] + +[editable path="GunShotHitbox"] diff --git a/assets/players/Soldier.tscn b/assets/players/Soldier.tscn index 825f608..e04685b 100644 --- a/assets/players/Soldier.tscn +++ b/assets/players/Soldier.tscn @@ -19,3 +19,6 @@ texture = ExtResource( 1 ) position = Vector2( 0, 3 ) rotation = 1.5708 shape = SubResource( 1 ) + +[node name="GunShot" type="Node2D" parent="."] +position = Vector2( 5, -20 ) diff --git a/assets/worlds/BasicWorld.tscn b/assets/worlds/BasicWorld.tscn index 060cbee..6d3eb6f 100644 --- a/assets/worlds/BasicWorld.tscn +++ b/assets/worlds/BasicWorld.tscn @@ -6,7 +6,7 @@ [ext_resource path="res://assets/worlds/backgrounds/default-background.png" type="Texture" id=4] [ext_resource path="res://assets/worlds/backgrounds/buildings-bg.png" type="Texture" id=7] -[sub_resource type="TileSet" id=22] +[sub_resource type="TileSet" id=1] 0/name = "default-background.png 0" 0/texture = ExtResource( 4 ) 0/tex_offset = Vector2( 0, 0 ) @@ -35,7 +35,7 @@ [node name="BackgroundTile" type="TileMap" parent="."] position = Vector2( 280, 216 ) -tile_set = SubResource( 22 ) +tile_set = SubResource( 1 ) cell_size = Vector2( 16, 16 ) format = 1 tile_data = PoolIntArray( -851984, 0, 0, -851983, 0, 0, -851982, 0, 0, -851981, 0, 0, -851980, 0, 0, -851979, 0, 0, -851978, 0, 0, -851977, 0, 0, -851976, 0, 0, -851975, 0, 0, -851974, 0, 0, -851973, 0, 0, -851972, 0, 0, -851971, 0, 0, -851970, 0, 0, -851969, 0, 0, -917504, 0, 0, -917503, 0, 0, -917502, 0, 0, -786448, 0, 0, -786447, 0, 0, -786446, 0, 0, -786445, 0, 0, -786444, 0, 0, -786443, 0, 0, -786442, 0, 0, -786441, 0, 0, -786440, 0, 0, -786439, 0, 0, -786438, 0, 0, -786437, 0, 0, -786436, 0, 0, -786435, 0, 0, -786434, 0, 0, -786433, 0, 0, -851968, 0, 0, -851967, 0, 0, -851966, 0, 0, -720913, 0, 0, -720912, 0, 0, -720911, 0, 0, -720910, 0, 0, -720909, 0, 0, -720908, 0, 0, -720907, 0, 0, -720906, 0, 0, -720905, 0, 0, -720904, 0, 0, -720903, 0, 0, -720902, 0, 0, -720901, 0, 0, -720900, 0, 0, -720899, 0, 0, -720898, 0, 0, -720897, 0, 0, -786432, 0, 0, -786431, 0, 0, -786430, 0, 0, -655377, 0, 0, -655376, 0, 0, -655375, 0, 0, -655374, 0, 0, -655373, 0, 0, -655372, 0, 0, -655371, 0, 0, -655370, 0, 0, -655369, 0, 0, -655368, 0, 0, -655367, 0, 0, -655366, 0, 0, -655365, 0, 0, -655364, 0, 0, -655363, 0, 0, -655362, 0, 0, -655361, 0, 0, -720896, 0, 0, -720895, 0, 0, -720894, 0, 0, -589840, 0, 0, -589839, 0, 0, -589838, 0, 0, -589837, 0, 0, -589836, 0, 0, -589835, 0, 0, -589834, 0, 0, -589833, 0, 0, -589832, 0, 0, -589831, 0, 0, -589830, 0, 0, -589829, 0, 0, -589828, 0, 0, -589827, 0, 0, -589826, 0, 0, -589825, 0, 0, -655360, 0, 0, -655359, 0, 0, -655358, 0, 0, -524304, 0, 0, -524303, 0, 0, -524302, 0, 0, -524301, 0, 0, -524300, 0, 0, -524299, 0, 0, -524298, 0, 0, -524297, 0, 0, -524296, 0, 0, -524295, 0, 0, -524294, 0, 0, -524293, 0, 0, -524292, 0, 0, -524291, 0, 0, -524290, 0, 0, -524289, 0, 0, -589824, 0, 0, -589823, 0, 0, -589822, 0, 0, -458768, 0, 0, -458767, 0, 0, -458766, 0, 0, -458765, 0, 0, -458764, 0, 0, -458763, 0, 0, -458762, 0, 0, -458761, 0, 0, -458760, 0, 0, -458759, 0, 0, -458758, 0, 0, -458757, 0, 0, -458756, 0, 0, -458755, 0, 0, -458754, 0, 0, -458753, 0, 0, -524288, 0, 0, -524287, 0, 0, -524286, 0, 0, -393232, 0, 0, -393231, 0, 0, -393230, 0, 0, -393229, 0, 0, -393228, 0, 0, -393227, 0, 0, -393226, 0, 0, -393225, 0, 0, -393224, 0, 0, -393223, 0, 0, -393222, 0, 0, -393221, 0, 0, -393220, 0, 0, -393219, 0, 0, -393218, 0, 0, -393217, 0, 0, -458752, 0, 0, -458751, 0, 0, -458750, 0, 0, -327696, 0, 0, -327695, 0, 0, -327694, 0, 0, -327693, 0, 0, -327692, 0, 0, -327691, 0, 0, -327690, 0, 0, -327689, 0, 0, -327688, 0, 0, -327687, 0, 0, -327686, 0, 0, -327685, 0, 0, -327684, 0, 0, -327683, 0, 0, -327682, 0, 0, -327681, 0, 0, -393216, 0, 0, -393215, 0, 0, -393214, 0, 0, -262160, 0, 0, -262159, 0, 0, -262158, 0, 0, -262157, 0, 0, -262156, 0, 0, -262155, 0, 0, -262154, 0, 0, -262153, 0, 0, -262152, 0, 0, -262151, 0, 0, -262150, 0, 0, -262149, 0, 0, -262148, 0, 0, -262147, 0, 0, -262146, 0, 0, -262145, 0, 0, -327680, 0, 0, -327679, 0, 0, -327678, 0, 0, -196624, 0, 0, -196623, 0, 0, -196622, 0, 0, -196621, 0, 0, -196620, 0, 0, -196619, 0, 0, -196618, 0, 0, -196617, 0, 0, -196616, 0, 0, -196615, 0, 0, -196614, 0, 0, -196613, 0, 0, -196612, 0, 0, -196611, 0, 0, -196610, 0, 0, -196609, 0, 0, -262144, 0, 0, -262143, 0, 0, -262142, 0, 0, -131088, 0, 0, -131087, 0, 0, -131086, 0, 0, -131085, 0, 0, -131084, 0, 0, -131083, 0, 0, -131082, 0, 0, -131081, 0, 0, -131080, 0, 0, -131079, 0, 0, -131078, 0, 0, -131077, 0, 0, -131076, 0, 0, -131075, 0, 0, -131074, 0, 0, -131073, 0, 0, -196608, 0, 0, -196607, 0, 0, -196606, 0, 0, -65552, 0, 0, -65551, 0, 0, -65550, 0, 0, -65549, 0, 0, -65548, 0, 0, -65547, 0, 0, -65546, 0, 0, -65545, 0, 0, -65544, 0, 0, -65543, 0, 0, -65542, 0, 0, -65541, 0, 0, -65540, 0, 0, -65539, 0, 0, -65538, 0, 0, -65537, 0, 0, -131072, 0, 0, -131071, 0, 0, -131070, 0, 0, -16, 0, 0, -15, 0, 0, -14, 0, 0, -13, 0, 0, -12, 0, 0, -11, 0, 0, -10, 0, 0, -9, 0, 0, -8, 0, 0, -7, 0, 0, -6, 0, 0, -5, 0, 0, -4, 0, 0, -3, 0, 0, -2, 0, 0, -1, 0, 0, -65536, 0, 0, -65535, 0, 0, -65534, 0, 0, 65520, 0, 0, 65521, 0, 0, 65522, 0, 0, 65523, 0, 0, 65524, 0, 0, 65525, 0, 0, 65526, 0, 0, 65527, 0, 0, 65528, 0, 0, 65529, 0, 0, 65530, 0, 0, 65531, 0, 0, 65532, 0, 0, 65533, 0, 0, 65534, 0, 0, 65535, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 131056, 0, 0, 131057, 0, 0, 131058, 0, 0, 131059, 0, 0, 131060, 0, 0, 131061, 0, 0, 131062, 0, 0, 131063, 0, 0, 131064, 0, 0, 131065, 0, 0, 131066, 0, 0, 131067, 0, 0, 131068, 0, 0, 131069, 0, 0, 131070, 0, 0, 131071, 0, 0, 65536, 0, 0, 65537, 0, 0, 65538, 0, 0, 196592, 0, 0, 196593, 0, 0, 196594, 0, 0, 196595, 0, 0, 196596, 0, 0, 196597, 0, 0, 196598, 0, 0, 196599, 0, 0, 196600, 0, 0, 196601, 0, 0, 196602, 0, 0, 196603, 0, 0, 196604, 0, 0, 196605, 0, 0, 196606, 0, 0, 196607, 0, 0, 131072, 0, 0, 131073, 0, 0, 131074, 0, 0, 262128, 0, 0, 262129, 0, 0, 262130, 0, 0, 262131, 0, 0, 262132, 0, 0, 262133, 0, 0, 262134, 0, 0, 262135, 0, 0, 262136, 0, 0, 262137, 0, 0, 262138, 0, 0, 262139, 0, 0, 262140, 0, 0, 262141, 0, 0, 262142, 0, 0, 262143, 0, 0, 196608, 0, 0, 196609, 0, 0, 196610, 0, 0, 327664, 0, 0, 327665, 0, 0, 327666, 0, 0, 327667, 0, 0, 327668, 0, 0, 327669, 0, 0, 327670, 0, 0, 327671, 0, 0, 327672, 0, 0, 327673, 0, 0, 327674, 0, 0, 327675, 0, 0, 327676, 0, 0, 327677, 0, 0, 327678, 0, 0, 327679, 0, 0, 262144, 0, 0, 262145, 0, 0, 262146, 0, 0, 393200, 0, 0, 393201, 0, 0, 393202, 0, 0, 393203, 0, 0, 393204, 0, 0, 393205, 0, 0, 393206, 0, 0, 393207, 0, 0, 393208, 0, 0, 393209, 0, 0, 393210, 0, 0, 393211, 0, 0, 393212, 0, 0, 393213, 0, 0, 393214, 0, 0, 393215, 0, 0, 327680, 0, 0, 327681, 0, 0, 327682, 0, 0, 458736, 0, 0, 458737, 0, 0, 458738, 0, 0, 458739, 0, 0, 458740, 0, 0, 458741, 0, 0, 458742, 0, 0, 458743, 0, 0, 458744, 0, 0, 458745, 0, 0, 458746, 0, 0, 458747, 0, 0, 458748, 0, 0, 458749, 0, 0, 458750, 0, 0, 458751, 0, 0, 393216, 0, 0, 393217, 0, 0, 393218, 0, 0 ) @@ -57,4 +57,4 @@ region_rect = Rect2( 0, 0, 300, 200 ) [node name="ExternalFrame" parent="." instance=ExtResource( 2 )] [node name="Soldier" parent="." instance=ExtResource( 1 )] -position = Vector2( 160.164, 152.523 ) +position = Vector2( 160, 296 ) diff --git a/project.godot b/project.godot index 3ed05cb..d50f7f3 100644 --- a/project.godot +++ b/project.godot @@ -57,9 +57,12 @@ ui_accept={ "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":16777221,"unicode":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777222,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null) ] } +ui_select={ +"deadzone": 0.5, +"events": [ ] +} ui_left={ "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":16777231,"unicode":0,"echo":false,"script":null) @@ -88,6 +91,12 @@ ui_down={ , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null) ] } +shoot={ +"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":32,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null) + ] +} [layer_names] diff --git a/src/misc/SimpleGunShot.gd b/src/misc/SimpleGunShot.gd new file mode 100644 index 0000000..acccfac --- /dev/null +++ b/src/misc/SimpleGunShot.gd @@ -0,0 +1,11 @@ +extends KinematicBody2D + +export var SPEED = 5 + +var _velocity = Vector2.ZERO + +func _ready(): + visible = true + +func _physics_process(delta): + move_and_collide(Vector2(0, SPEED * -1)) diff --git a/src/misc/SimpleGunShotHitbox.gd b/src/misc/SimpleGunShotHitbox.gd new file mode 100644 index 0000000..7133596 --- /dev/null +++ b/src/misc/SimpleGunShotHitbox.gd @@ -0,0 +1,4 @@ +extends Area2D + +func _on_Hitbox_area_entered(area): + queue_free() diff --git a/src/players/Soldier.gd b/src/players/Soldier.gd index 45fd471..a633ea3 100644 --- a/src/players/Soldier.gd +++ b/src/players/Soldier.gd @@ -1,21 +1,34 @@ extends KinematicBody2D +const SimpleGunShot = preload("res://assets/misc/SimpleGunShot.tscn") + export var ACCELERATION: int = 700 export var MAX_SPEED: int = 150 export var ROLL_SPEED: int = 120 export var FRICTION: int = 550 -var velocity: Vector2 = Vector2.ZERO +var _velocity: Vector2 = Vector2.ZERO func _physics_process(delta: float) -> void: + if Input.is_action_just_pressed("shoot"): + shoot() + move(delta) + +func shoot() -> void: + var simpleGunShot := SimpleGunShot.instance() + var gunShot := get_node("GunShot") + simpleGunShot.position = gunShot.get_global_position() + get_tree().current_scene.add_child(simpleGunShot) + +func move(delta: float) -> void: var input_vector := Vector2.ZERO input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left") input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up") input_vector = input_vector.normalized() if input_vector != Vector2.ZERO: - input_vector = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta) + input_vector = _velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta) else: - input_vector = velocity.move_toward(Vector2.ZERO, FRICTION * delta) + input_vector = _velocity.move_toward(Vector2.ZERO, FRICTION * delta) - velocity = move_and_slide(input_vector) + _velocity = move_and_slide(input_vector)