diff --git a/project.godot b/project.godot index b373694..7b17d93 100644 --- a/project.godot +++ b/project.godot @@ -75,6 +75,12 @@ 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":0,"physical_scancode":16777234,"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":0,"physical_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) + ] +} [physics] diff --git a/src/models/bullet/Bullet.gd b/src/models/bullet/Bullet.gd new file mode 100644 index 0000000..1239bb3 --- /dev/null +++ b/src/models/bullet/Bullet.gd @@ -0,0 +1,8 @@ +extends KinematicBody2D + +var speed = 128 +var velocity = Vector2.ZERO + +func _physics_process(_delta): + velocity.x = speed + move_and_slide(velocity) diff --git a/src/models/bullet/Bullet.tscn b/src/models/bullet/Bullet.tscn new file mode 100644 index 0000000..ea59ef4 --- /dev/null +++ b/src/models/bullet/Bullet.tscn @@ -0,0 +1,16 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://src/models/bullet/bullet.png" type="Texture" id=1] +[ext_resource path="res://src/models/bullet/Bullet.gd" type="Script" id=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 3.5, 3.5 ) + +[node name="Bullet" type="KinematicBody2D"] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) diff --git a/src/models/bullet/bullet.png b/src/models/bullet/bullet.png new file mode 100644 index 0000000..48433ff Binary files /dev/null and b/src/models/bullet/bullet.png differ diff --git a/src/models/bullet/bullet.png.import b/src/models/bullet/bullet.png.import new file mode 100644 index 0000000..c9aa360 --- /dev/null +++ b/src/models/bullet/bullet.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/bullet.png-7146bc96edc61364c883e6ea6db4f1ea.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://src/models/bullet/bullet.png" +dest_files=[ "res://.import/bullet.png-7146bc96edc61364c883e6ea6db4f1ea.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 +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/src/models/enemies/bat/bat.gd b/src/models/enemies/bat/bat.gd index 12114e8..9c7fbb3 100644 --- a/src/models/enemies/bat/bat.gd +++ b/src/models/enemies/bat/bat.gd @@ -9,7 +9,7 @@ func _ready(): hp = 15 func _physics_process(_delta): - var player_position = player.global_position + Vector2(8, 8) + var player_position = player.global_position + Vector2(12, 12) var angle = get_angle_to(player_position) if position.distance_to(player_position) > 64: velocity.x = cos(angle) diff --git a/src/models/player/player.gd b/src/models/player/player.gd index ad57e33..503f55d 100644 --- a/src/models/player/player.gd +++ b/src/models/player/player.gd @@ -5,6 +5,14 @@ var speed_multiplier: float = 1.0 var slowed = false var target var speed = 100 + +onready var bullet = preload("res://src/models/bullet/Bullet.tscn") +var bullet_instance + +func _process(_delta): + if Input.is_action_just_pressed("shoot"): + _shoot() + func get_input(): var input_direction = Input.get_vector("left", "right", "up", "down") velocity = input_direction * speed @@ -29,7 +37,6 @@ func _physics_process(_delta): const SHADER = preload("res://res/shaders/outline.tres") - func choose_target(): var least_dist = 4000 var enemy_dist @@ -40,3 +47,9 @@ func choose_target(): least_dist = enemy_dist target = enemy #enemy.set_shader_param("width", 0) + +func _shoot(): + bullet_instance = bullet.instance() + get_parent().add_child(bullet_instance) + bullet_instance.global_position.x = get_node("../Player").global_position.x + 12 + bullet_instance.global_position.y = get_node("../Player").global_position.y - 4