diff --git a/data/character/character.gd b/data/character/character.gd new file mode 100644 index 0000000..c3c5b0c --- /dev/null +++ b/data/character/character.gd @@ -0,0 +1,46 @@ +extends CharacterBody2D + + +var speed = 150 +var accel = 10 +var immobile = false + +var inventory = { + "stone": 0, + "wood": 0, + "food": 0 +} +var status = { + "health": 100, + "stamina": 100 +} + + +func _physics_process(delta): + var pre_velocity = Vector2(0, 0) + if !immobile: + pre_velocity = Input.get_vector("move_left", "move_right", "move_up", "move_down") + velocity = lerp(velocity, pre_velocity * speed, accel*delta) + move_and_slide() + +func _process(delta): + if Input.is_action_pressed("game_interact"): + if !$animation.is_playing(): + $animation.play("hit") + if $body_pivot/raycast.is_colliding(): + var hit_object = $body_pivot/raycast.get_collider() + if hit_object.type == "resource": + inventory[hit_object.resource_type] += 1 + + #update inventory HUD + $hud/inventory/stone_label.text = str(inventory.stone) + $hud/inventory/wood_label.text = str(inventory.wood) + + #update status HUD + $hud/bars/health.value = int(lerp($hud/bars/health.value, float(status.health), 20*delta)) + $hud/bars/stamina.value = int(lerp($hud/bars/stamina.value, float(status.stamina), 20*delta)) + +func _input(event): + if event is InputEventMouseMotion: + var mouse_pos = get_global_mouse_position() + $body_pivot.rotation = atan2((mouse_pos.y-position.y), (mouse_pos.x-position.x)) + (PI * 0.5) diff --git a/data/character/character.tscn b/data/character/character.tscn new file mode 100644 index 0000000..787f298 --- /dev/null +++ b/data/character/character.tscn @@ -0,0 +1,175 @@ +[gd_scene load_steps=12 format=3 uid="uid://4dsm0l7s6vki"] + +[ext_resource type="Texture2D" uid="uid://gfxfxkfu8uk4" path="res://textures/character/character.svg" id="1_f7cgp"] +[ext_resource type="Script" path="res://data/character/character.gd" id="1_qlitf"] +[ext_resource type="Script" path="res://data/character/hud.gd" id="3_eogh2"] +[ext_resource type="Texture2D" uid="uid://ttb1b3k07qu5" path="res://textures/world/biome/forest/boulder.svg" id="4_l3xyh"] +[ext_resource type="Texture2D" uid="uid://i7fjjduk8b0c" path="res://textures/world/biome/forest/tree.svg" id="5_j15j3"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_653al"] +radius = 36.0 + +[sub_resource type="Animation" id="Animation_gkjmi"] +resource_name = "hit" +length = 0.6 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("body_pivot/body:rotation") +tracks/0/interp = 2 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.25, 0.5), +"transitions": PackedFloat32Array(1, 1, 1), +"update": 0, +"values": [0.0, 1.13446, 0.0] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_se06j"] +_data = { +"hit": SubResource("Animation_gkjmi") +} + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_5s1x0"] +bg_color = Color(0.184314, 0.184314, 0.184314, 1) +corner_radius_top_left = 10 +corner_radius_top_right = 10 +corner_radius_bottom_right = 10 +corner_radius_bottom_left = 10 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_csph4"] +bg_color = Color(1, 0, 0, 1) +corner_radius_top_left = 10 +corner_radius_top_right = 10 +corner_radius_bottom_right = 10 +corner_radius_bottom_left = 10 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_31scb"] +bg_color = Color(0, 1, 0, 1) +corner_radius_top_left = 10 +corner_radius_top_right = 10 +corner_radius_bottom_right = 10 +corner_radius_bottom_left = 10 + +[node name="character" type="CharacterBody2D"] +script = ExtResource("1_qlitf") + +[node name="camera" type="Camera2D" parent="."] + +[node name="collision" type="CollisionShape2D" parent="."] +visible = false +shape = SubResource("CircleShape2D_653al") + +[node name="animation" type="AnimationPlayer" parent="."] +libraries = { +"": SubResource("AnimationLibrary_se06j") +} + +[node name="body_pivot" type="Node2D" parent="."] + +[node name="raycast" type="RayCast2D" parent="body_pivot"] +target_position = Vector2(0, -100) + +[node name="body" type="Sprite2D" parent="body_pivot"] +scale = Vector2(0.2, 0.2) +texture = ExtResource("1_f7cgp") + +[node name="hud" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 0 +offset_left = -432.0 +offset_top = -256.0 +offset_right = 464.0 +offset_bottom = 272.0 +script = ExtResource("3_eogh2") + +[node name="bars" type="Panel" parent="hud"] +layout_mode = 1 +offset_right = 368.0 +offset_bottom = 56.0 + +[node name="health" type="ProgressBar" parent="hud/bars"] +layout_mode = 0 +offset_left = 8.0 +offset_top = 8.0 +offset_right = 360.0 +offset_bottom = 16.0 +theme_override_styles/background = SubResource("StyleBoxFlat_5s1x0") +theme_override_styles/fill = SubResource("StyleBoxFlat_csph4") +value = 100.0 +show_percentage = false + +[node name="stamina" type="ProgressBar" parent="hud/bars"] +layout_mode = 0 +offset_left = 8.0 +offset_top = 40.0 +offset_right = 360.0 +offset_bottom = 48.0 +theme_override_styles/background = SubResource("StyleBoxFlat_5s1x0") +theme_override_styles/fill = SubResource("StyleBoxFlat_31scb") +value = 100.0 +show_percentage = false + +[node name="name" type="Panel" parent="hud"] +layout_mode = 1 +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -104.0 +offset_bottom = 32.0 +grow_horizontal = 0 + +[node name="username" type="Label" parent="hud/name"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +text = "Username" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="inventory" type="Panel" parent="hud"] +layout_mode = 1 +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -96.0 +offset_top = -88.0 +grow_horizontal = 0 +grow_vertical = 0 + +[node name="stone_image" type="Sprite2D" parent="hud/inventory"] +position = Vector2(24, 24) +scale = Vector2(0.0457143, 0.0457143) +texture = ExtResource("4_l3xyh") + +[node name="stone_label" type="Label" parent="hud/inventory"] +layout_mode = 0 +offset_left = 48.0 +offset_top = 8.0 +offset_right = 88.0 +offset_bottom = 40.0 +text = "0" +horizontal_alignment = 2 +vertical_alignment = 1 +clip_text = true + +[node name="wood_image" type="Sprite2D" parent="hud/inventory"] +position = Vector2(24, 64) +scale = Vector2(0.0457143, 0.0457143) +texture = ExtResource("5_j15j3") + +[node name="wood_label" type="Label" parent="hud/inventory"] +layout_mode = 0 +offset_left = 48.0 +offset_top = 48.0 +offset_right = 88.0 +offset_bottom = 80.0 +text = "0" +horizontal_alignment = 2 +vertical_alignment = 1 +clip_text = true diff --git a/data/character/hud.gd b/data/character/hud.gd new file mode 100644 index 0000000..f41bba5 --- /dev/null +++ b/data/character/hud.gd @@ -0,0 +1,16 @@ +extends Control + + +var padding = 30 + + +func resize(): + var viewport_size = get_viewport().size + position.x = (-(viewport_size[0]/2))+padding + position.y = (-(viewport_size[1]/2))+padding + size.x = (viewport_size[0])-padding*2 #I don't know why padding needs to be doubled + size.y = (viewport_size[1])-padding*2 + +func _ready(): + resize() + get_tree().get_root().size_changed.connect(resize) diff --git a/data/objects/stone.tscn b/data/objects/stone.tscn new file mode 100644 index 0000000..f4e2e13 --- /dev/null +++ b/data/objects/stone.tscn @@ -0,0 +1,25 @@ +[gd_scene load_steps=4 format=3 uid="uid://ikvaekbnft70"] + +[ext_resource type="Texture2D" uid="uid://ttb1b3k07qu5" path="res://textures/world/biome/forest/boulder.svg" id="1_474a4"] + +[sub_resource type="GDScript" id="GDScript_d7f4g"] +script/source = "extends StaticBody2D + + +var type = \"resource\" +var resource_type = \"stone\" +" + +[sub_resource type="CircleShape2D" id="CircleShape2D_fb1fv"] +radius = 64.0 + +[node name="stone" type="StaticBody2D"] +script = SubResource("GDScript_d7f4g") + +[node name="collision" type="CollisionShape2D" parent="."] +visible = false +shape = SubResource("CircleShape2D_fb1fv") + +[node name="body" type="Sprite2D" parent="."] +scale = Vector2(0.2, 0.2) +texture = ExtResource("1_474a4") diff --git a/data/objects/tree.tscn b/data/objects/tree.tscn new file mode 100644 index 0000000..db7ed13 --- /dev/null +++ b/data/objects/tree.tscn @@ -0,0 +1,24 @@ +[gd_scene load_steps=4 format=3 uid="uid://c7ir6imnqx4py"] + +[ext_resource type="Texture2D" uid="uid://i7fjjduk8b0c" path="res://textures/world/biome/forest/tree.svg" id="1_nvko3"] + +[sub_resource type="GDScript" id="GDScript_d7f4g"] +script/source = "extends StaticBody2D + + +var type = \"resource\" +var resource_type = \"wood\" +" + +[sub_resource type="CircleShape2D" id="CircleShape2D_fb1fv"] +radius = 32.0 + +[node name="tree" type="StaticBody2D"] +script = SubResource("GDScript_d7f4g") + +[node name="collision" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_fb1fv") + +[node name="body" type="Sprite2D" parent="."] +scale = Vector2(0.2, 0.2) +texture = ExtResource("1_nvko3") diff --git a/export_presets.cfg b/export_presets.cfg new file mode 100644 index 0000000..f29e133 --- /dev/null +++ b/export_presets.cfg @@ -0,0 +1,37 @@ +[preset.0] + +name="Web" +platform="Web" +runnable=true +dedicated_server=false +custom_features="" +export_filter="all_resources" +include_filter="" +exclude_filter="" +export_path="" +encryption_include_filters="" +encryption_exclude_filters="" +encrypt_pck=false +encrypt_directory=false + +[preset.0.options] + +custom_template/debug="" +custom_template/release="" +variant/extensions_support=false +vram_texture_compression/for_desktop=true +vram_texture_compression/for_mobile=false +html/export_icon=true +html/custom_html_shell="" +html/head_include="" +html/canvas_resize_policy=2 +html/focus_canvas_on_start=true +html/experimental_virtual_keyboard=false +progressive_web_app/enabled=false +progressive_web_app/offline_page="" +progressive_web_app/display=1 +progressive_web_app/orientation=0 +progressive_web_app/icon_144x144="" +progressive_web_app/icon_180x180="" +progressive_web_app/icon_512x512="" +progressive_web_app/background_color=Color(0, 0, 0, 1) diff --git a/project.godot b/project.godot index 9240c76..e22091b 100644 --- a/project.godot +++ b/project.godot @@ -11,10 +11,44 @@ config_version=5 [application] config/name="Runic" +run/main_scene="res://scenes/world.tscn" config/features=PackedStringArray("4.1", "GL Compatibility") config/icon="res://icon.svg" +[display] + +window/stretch/aspect="expand" + +[input] + +move_left={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null) +] +} +move_right={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null) +] +} +move_up={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null) +] +} +move_down={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null) +] +} +game_interact={ +"deadzone": 0.5, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(220, 23),"global_position":Vector2(224, 66),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) +] +} + [rendering] renderer/rendering_method="gl_compatibility" renderer/rendering_method.mobile="gl_compatibility" +environment/defaults/default_clear_color=Color(0, 0, 0, 1) diff --git a/scenes/world.tscn b/scenes/world.tscn new file mode 100644 index 0000000..cddcf8e --- /dev/null +++ b/scenes/world.tscn @@ -0,0 +1,56 @@ +[gd_scene load_steps=9 format=3 uid="uid://deus4t8mmx6pp"] + +[ext_resource type="PackedScene" uid="uid://4dsm0l7s6vki" path="res://data/character/character.tscn" id="1_gadv2"] +[ext_resource type="Texture2D" uid="uid://vyhureoc5qlp" path="res://textures/world/biome/forest/grass.svg" id="2_xtc31"] +[ext_resource type="PackedScene" uid="uid://ikvaekbnft70" path="res://data/objects/stone.tscn" id="3_l3ue5"] +[ext_resource type="PackedScene" uid="uid://c7ir6imnqx4py" path="res://data/objects/tree.tscn" id="4_qpvcg"] + +[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_0fcbb"] +normal = Vector2(0, 1) +distance = -2000.0 + +[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_cl8ds"] +normal = Vector2(-1, 0) +distance = -2000.0 + +[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_5jryn"] +distance = -2000.0 + +[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_j3vu4"] +normal = Vector2(1, 0) +distance = -2000.0 + +[node name="world" type="Node2D"] + +[node name="character" parent="." instance=ExtResource("1_gadv2")] + +[node name="biomes" type="Node2D" parent="."] +z_index = -10 + +[node name="grass" type="Sprite2D" parent="biomes"] +texture_repeat = 2 +texture = ExtResource("2_xtc31") +region_enabled = true +region_rect = Rect2(0, 0, 4000, 4000) + +[node name="objects" type="Node2D" parent="."] + +[node name="stone" parent="objects" instance=ExtResource("3_l3ue5")] +position = Vector2(-128, -64) + +[node name="tree" parent="objects" instance=ExtResource("4_qpvcg")] +position = Vector2(168, -152) + +[node name="world_boundaries" type="StaticBody2D" parent="."] + +[node name="north" type="CollisionShape2D" parent="world_boundaries"] +shape = SubResource("WorldBoundaryShape2D_0fcbb") + +[node name="east" type="CollisionShape2D" parent="world_boundaries"] +shape = SubResource("WorldBoundaryShape2D_cl8ds") + +[node name="south" type="CollisionShape2D" parent="world_boundaries"] +shape = SubResource("WorldBoundaryShape2D_5jryn") + +[node name="west" type="CollisionShape2D" parent="world_boundaries"] +shape = SubResource("WorldBoundaryShape2D_j3vu4") diff --git a/textures/character/character.svg b/textures/character/character.svg new file mode 100644 index 0000000..be2af55 --- /dev/null +++ b/textures/character/character.svg @@ -0,0 +1,80 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/textures/character/character.svg.import b/textures/character/character.svg.import new file mode 100644 index 0000000..86e3fd8 --- /dev/null +++ b/textures/character/character.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://gfxfxkfu8uk4" +path="res://.godot/imported/character.svg-b4037f0ca3de55c3550ddff36f5eaaa9.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://textures/character/character.svg" +dest_files=["res://.godot/imported/character.svg-b4037f0ca3de55c3550ddff36f5eaaa9.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/textures/world/biome/forest/boulder.svg b/textures/world/biome/forest/boulder.svg new file mode 100644 index 0000000..90a727b --- /dev/null +++ b/textures/world/biome/forest/boulder.svg @@ -0,0 +1,96 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/textures/world/biome/forest/boulder.svg.import b/textures/world/biome/forest/boulder.svg.import new file mode 100644 index 0000000..7969edb --- /dev/null +++ b/textures/world/biome/forest/boulder.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ttb1b3k07qu5" +path="res://.godot/imported/boulder.svg-886660507ab097f22361cd4de8f7af63.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://textures/world/biome/forest/boulder.svg" +dest_files=["res://.godot/imported/boulder.svg-886660507ab097f22361cd4de8f7af63.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/textures/world/biome/forest/grass.svg b/textures/world/biome/forest/grass.svg new file mode 100644 index 0000000..fe3522e --- /dev/null +++ b/textures/world/biome/forest/grass.svg @@ -0,0 +1,143 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/textures/world/biome/forest/grass.svg.import b/textures/world/biome/forest/grass.svg.import new file mode 100644 index 0000000..be2c38e --- /dev/null +++ b/textures/world/biome/forest/grass.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://vyhureoc5qlp" +path="res://.godot/imported/grass.svg-c7937a61141e85218fe957f9825e2602.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://textures/world/biome/forest/grass.svg" +dest_files=["res://.godot/imported/grass.svg-c7937a61141e85218fe957f9825e2602.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/textures/world/biome/forest/tree.svg b/textures/world/biome/forest/tree.svg new file mode 100644 index 0000000..74b67a9 --- /dev/null +++ b/textures/world/biome/forest/tree.svg @@ -0,0 +1,128 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/textures/world/biome/forest/tree.svg.import b/textures/world/biome/forest/tree.svg.import new file mode 100644 index 0000000..f377615 --- /dev/null +++ b/textures/world/biome/forest/tree.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://i7fjjduk8b0c" +path="res://.godot/imported/tree.svg-4d363f8900783b86fcadd9ed98eb0075.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://textures/world/biome/forest/tree.svg" +dest_files=["res://.godot/imported/tree.svg-4d363f8900783b86fcadd9ed98eb0075.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false