diff --git a/.import/Duck.png-09368b9ecb7440ffc80609345a04c943.md5 b/.import/Duck.png-09368b9ecb7440ffc80609345a04c943.md5 new file mode 100644 index 0000000..f68f7c5 --- /dev/null +++ b/.import/Duck.png-09368b9ecb7440ffc80609345a04c943.md5 @@ -0,0 +1,3 @@ +source_md5="ca2d599ef54a2643f218531e12c042f1" +dest_md5="b0901b03b2b8bb064742c4c46eb82b06" + diff --git a/.import/Duck.png-09368b9ecb7440ffc80609345a04c943.stex b/.import/Duck.png-09368b9ecb7440ffc80609345a04c943.stex new file mode 100644 index 0000000..139bc1e Binary files /dev/null and b/.import/Duck.png-09368b9ecb7440ffc80609345a04c943.stex differ diff --git a/.import/New Piskel.png-4b57200a9b5d4d6f89cce1bdbbdb2eec.md5 b/.import/New Piskel.png-4b57200a9b5d4d6f89cce1bdbbdb2eec.md5 new file mode 100644 index 0000000..5722afc --- /dev/null +++ b/.import/New Piskel.png-4b57200a9b5d4d6f89cce1bdbbdb2eec.md5 @@ -0,0 +1,3 @@ +source_md5="a33962dbd961bfd22b29d62f4bd7d75a" +dest_md5="f4249c44be2ea010745f0021faed38e2" + diff --git a/.import/New Piskel.png-4b57200a9b5d4d6f89cce1bdbbdb2eec.stex b/.import/New Piskel.png-4b57200a9b5d4d6f89cce1bdbbdb2eec.stex new file mode 100644 index 0000000..3e9ef13 Binary files /dev/null and b/.import/New Piskel.png-4b57200a9b5d4d6f89cce1bdbbdb2eec.stex differ diff --git a/.import/New Piskel.png-c94dd3d76cd11d1bdd359e599bb14365.md5 b/.import/New Piskel.png-c94dd3d76cd11d1bdd359e599bb14365.md5 new file mode 100644 index 0000000..5722afc --- /dev/null +++ b/.import/New Piskel.png-c94dd3d76cd11d1bdd359e599bb14365.md5 @@ -0,0 +1,3 @@ +source_md5="a33962dbd961bfd22b29d62f4bd7d75a" +dest_md5="f4249c44be2ea010745f0021faed38e2" + diff --git a/.import/Stone.png-72d924ca1fd7a477c205cb72a1d6337b.md5 b/.import/Stone.png-72d924ca1fd7a477c205cb72a1d6337b.md5 new file mode 100644 index 0000000..1e7aa05 --- /dev/null +++ b/.import/Stone.png-72d924ca1fd7a477c205cb72a1d6337b.md5 @@ -0,0 +1,3 @@ +source_md5="4a950cf8deae6b98bd20401e41475f5a" +dest_md5="5738966f09649ceafc4f38ccdd982e27" + diff --git a/.import/Stone.png-72d924ca1fd7a477c205cb72a1d6337b.stex b/.import/Stone.png-72d924ca1fd7a477c205cb72a1d6337b.stex new file mode 100644 index 0000000..93180a7 Binary files /dev/null and b/.import/Stone.png-72d924ca1fd7a477c205cb72a1d6337b.stex differ diff --git a/Duck.gd b/Duck.gd new file mode 100644 index 0000000..53234e9 --- /dev/null +++ b/Duck.gd @@ -0,0 +1,14 @@ +extends Thing + +func _init(hp = 10, mass = 2, hardness = 1).(hp, mass, hardness): #call parent class (Thing) constructor with these parameters + pass + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass + + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass diff --git a/Interaction.gd b/Interaction.gd new file mode 100644 index 0000000..9486ca4 --- /dev/null +++ b/Interaction.gd @@ -0,0 +1,43 @@ +extends Node +#var Thing = preload("res://Thing.gd") + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + + +func destroy(thing:Node): + thing.free(); + +func combine(thing1:Thing, thing2:Thing): + print("combining...") + var newThing = Thing.new( + (thing1.hp + thing2.hp) / 2, + (thing1.mass + thing2.mass) / 2, + (thing1.hardness + thing2.hardness) / 2); + newThing.transform = thing1.transform; + newThing.name = thing1.name + thing2.name; + + var sprite = Sprite.new(); + newThing.add_child(sprite); + #blending the images: + var image1 = thing1.get_child(0).texture.get_data(); + var image2 = thing2.get_child(0).texture.get_data(); + var newTexture = ImageTexture.new(); + var newImage = image1.blit_rect(image2, Rect2(Vector2(0,0),Vector2(32,64)), Vector2(0,0)); + #var newImage = image1; + newTexture.create_from_image(image1); + newThing.get_child(0).texture = newTexture; + + #adding collision shape + var shape = RectangleShape2D.new(); + shape.set_extents(Vector2(32,32)); + var collShape = CollisionShape2D.new(); + collShape.set_shape(shape); + newThing.add_child(collShape) + + thing1.get_parent().add_child(newThing); + thing1.free(); + thing2.free(); diff --git a/Stone.gd b/Stone.gd new file mode 100644 index 0000000..12c7068 --- /dev/null +++ b/Stone.gd @@ -0,0 +1,14 @@ +extends Thing + +func _init(hp = 100, mass = 100, hardness = 10).(hp, mass, hardness): #call parent class (Thing) constructor with these parameters + pass + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass + + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass diff --git a/Thing.gd b/Thing.gd new file mode 100644 index 0000000..c898955 --- /dev/null +++ b/Thing.gd @@ -0,0 +1,17 @@ +extends RigidBody2D +class_name Thing + +var hp; +var hardness; + +func _init(hp, mass, hardness): + self.hp = hp; + self.mass = mass; + self.hardness = hardness; # on a scale from 0 to 10 + self.gravity_scale = 0; + self.linear_damp = mass * 0.1 + self.angular_damp = mass * 0.1 + + +func _ready(): + print("The " + name + " has the following properties: hp: " + str(hp) + ", mass: " + str(mass) + ", hardness: " + str(hardness)); diff --git a/Visuals/Duck.png b/Visuals/Duck.png new file mode 100644 index 0000000..9206f87 Binary files /dev/null and b/Visuals/Duck.png differ diff --git a/Visuals/Duck.png.import b/Visuals/Duck.png.import new file mode 100644 index 0000000..a9411e5 --- /dev/null +++ b/Visuals/Duck.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Duck.png-09368b9ecb7440ffc80609345a04c943.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Visuals/Duck.png" +dest_files=[ "res://.import/Duck.png-09368b9ecb7440ffc80609345a04c943.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=true +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=true +svg/scale=1.0 diff --git a/Visuals/Stone.png b/Visuals/Stone.png new file mode 100644 index 0000000..9341cde Binary files /dev/null and b/Visuals/Stone.png differ diff --git a/Visuals/Stone.png.import b/Visuals/Stone.png.import new file mode 100644 index 0000000..3219396 --- /dev/null +++ b/Visuals/Stone.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Stone.png-72d924ca1fd7a477c205cb72a1d6337b.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Visuals/Stone.png" +dest_files=[ "res://.import/Stone.png-72d924ca1fd7a477c205cb72a1d6337b.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=true +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=true +svg/scale=1.0 diff --git a/controller.gd b/controller.gd new file mode 100644 index 0000000..9790695 --- /dev/null +++ b/controller.gd @@ -0,0 +1,62 @@ +extends Node + +var robot : KinematicBody2D +var camera : Camera2D +var MAX_SPEED = 2 +var ACCELERATION = 100 +var motion = Vector2.ZERO +var rotation_dir = 0 + +func _physics_process(delta): + var axis = get_input_axis() + if robot != null: + robot.rotation += rotation_dir * 1.5 * delta + if axis == Vector2.ZERO: + apply_friction(ACCELERATION * delta) + else: + apply_movement(axis * ACCELERATION * delta) + robot.move_and_collide(motion) + +func get_input_axis(): + var axis = Vector2.ZERO + rotation_dir = int(Input.is_action_pressed("robo_right")) - int(Input.is_action_pressed("robo_left")) + axis.y = int(Input.is_action_pressed("robo_down")) - int(Input.is_action_pressed("robo_up")) + return axis.normalized().rotated(robot.rotation) + +func apply_friction(amount): + if motion.length() > amount: + motion -= motion.normalized() * amount + else: + motion = Vector2.ZERO + +func apply_movement(amount): + motion += amount + motion = motion.clamped(MAX_SPEED) + +# Called when the node enters the scene tree for the first time. +func _ready(): + robot = $"/root/sandbox/robot" + camera = $"/root/sandbox/Camera2D" + camera.get_parent().remove_child(camera) + robot.add_child(camera) + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + +func _input(event): + if event.is_action_pressed("robo_action"): + if robot.myname == "robot1": + robot.remove_child(camera) + robot = $"/root/sandbox/robot2" + robot.add_child(camera) + else: + robot.remove_child(camera) + robot = $"/root/sandbox/robot" + robot.add_child(camera) + if event.is_action_pressed("robo_combine"): + get_node("/root/sandbox/Interaction").combine( + get_node("/root/sandbox/Interaction/Stone"), + get_node("/root/sandbox/Interaction/Duck")); diff --git a/controller.tscn b/controller.tscn new file mode 100644 index 0000000..bfe4ed3 --- /dev/null +++ b/controller.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://controller.gd" type="Script" id=1] + +[node name="controller" type="Node"] +script = ExtResource( 1 ) diff --git a/default_env.tres b/default_env.tres index 98f26a7..20207a4 100644 --- a/default_env.tres +++ b/default_env.tres @@ -1,5 +1,7 @@ [gd_resource type="Environment" load_steps=2 format=2] + [sub_resource type="ProceduralSky" id=1] + [resource] background_mode = 2 background_sky = SubResource( 1 ) diff --git a/project.godot b/project.godot index 3e6c616..2f60ab0 100644 --- a/project.godot +++ b/project.godot @@ -8,16 +8,59 @@ config_version=4 -_global_script_classes=[ ] +_global_script_classes=[ { +"base": "RigidBody2D", +"class": "Thing", +"language": "GDScript", +"path": "res://Thing.gd" +} ] _global_script_class_icons={ - +"Thing": "" } [application] config/name="Project- Proxy" +run/main_scene="res://sandbox.tscn" config/icon="res://icon.png" +[autoload] + +Controller="*res://controller.tscn" + +[input] + +robo_up={ +"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":87,"unicode":0,"echo":false,"script":null) + ] +} +robo_down={ +"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":83,"unicode":0,"echo":false,"script":null) + ] +} +robo_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":65,"unicode":0,"echo":false,"script":null) + ] +} +robo_right={ +"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":68,"unicode":0,"echo":false,"script":null) + ] +} +robo_action={ +"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) + ] +} +robo_combine={ +"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":70,"unicode":0,"echo":false,"script":null) + ] +} + [rendering] environment/default_environment="res://default_env.tres" diff --git a/robot.gd b/robot.gd new file mode 100644 index 0000000..360b0cc --- /dev/null +++ b/robot.gd @@ -0,0 +1,17 @@ +extends KinematicBody2D + +export var myname = "" +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + + +# Called when the node enters the scene tree for the first time. +func _ready(): + $Label.text = myname + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass diff --git a/robot.tscn b/robot.tscn new file mode 100644 index 0000000..1c35dbf --- /dev/null +++ b/robot.tscn @@ -0,0 +1,26 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://icon.png" type="Texture" id=1] +[ext_resource path="res://robot.gd" type="Script" id=2] + +[sub_resource type="CircleShape2D" id=1] +radius = 30.0 + +[node name="robot" type="KinematicBody2D"] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) + +[node name="Label" type="Label" parent="."] +margin_left = -22.238 +margin_top = 32.0 +margin_right = 23.762 +margin_bottom = 46.0 +text = "ROBOT" +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/sandbox.tscn b/sandbox.tscn new file mode 100644 index 0000000..ab70c6c --- /dev/null +++ b/sandbox.tscn @@ -0,0 +1,104 @@ +[gd_scene load_steps=11 format=2] + +[ext_resource path="res://robot.tscn" type="PackedScene" id=1] +[ext_resource path="res://Interaction.gd" type="Script" id=2] +[ext_resource path="res://Stone.gd" type="Script" id=3] +[ext_resource path="res://Duck.gd" type="Script" id=4] +[ext_resource path="res://Visuals/Duck.png" type="Texture" id=5] +[ext_resource path="res://Visuals/Stone.png" type="Texture" id=6] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 40, 40 ) + +[sub_resource type="RectangleShape2D" id=2] +extents = Vector2( 80, 80 ) + +[sub_resource type="RectangleShape2D" id=4] +extents = Vector2( 32, 32 ) + +[sub_resource type="RectangleShape2D" id=3] +extents = Vector2( 32, 32 ) + +[node name="sandbox" type="Node2D"] + +[node name="robot" parent="." instance=ExtResource( 1 )] +position = Vector2( 215.775, 360.402 ) +myname = "robot1" + +[node name="robot2" parent="." instance=ExtResource( 1 )] +position = Vector2( 681.091, 382.563 ) +myname = "robot2" + +[node name="RigidBody2D" type="RigidBody2D" parent="."] +mass = 10.2041 +gravity_scale = 0.0 +linear_damp = 10.0 +angular_damp = 10.0 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"] +position = Vector2( 193, 179 ) +shape = SubResource( 1 ) + +[node name="Polygon2D" type="Polygon2D" parent="RigidBody2D"] +polygon = PoolVector2Array( 153.106, 140.18, 232.139, 140.18, 232.738, 218.016, 153.705, 217.417 ) + +[node name="StaticBody2D" type="StaticBody2D" parent="."] +position = Vector2( 452.544, 267.094 ) + +[node name="Polygon2D" type="Polygon2D" parent="StaticBody2D"] +polygon = PoolVector2Array( -86.2895, -80.1853, 76.9996, -77.8526, 75.8333, 76.1057, -79.2914, 74.9394 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] +shape = SubResource( 2 ) + +[node name="Camera2D" type="Camera2D" parent="."] +current = true +smoothing_enabled = true + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="UI" type="Control" parent="CanvasLayer"] +margin_right = 40.0 +margin_bottom = 40.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Label" type="Label" parent="CanvasLayer/UI"] +margin_right = 40.0 +margin_bottom = 14.0 +text = "WASD = move +E = switch robots +F = combine Stone and Duck" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Interaction" type="Node" parent="."] +script = ExtResource( 2 ) + +[node name="Stone" type="RigidBody2D" parent="Interaction"] +position = Vector2( 238.668, 469.723 ) +script = ExtResource( 3 ) +__meta__ = { +"_edit_group_": true +} + +[node name="Sprite" type="Sprite" parent="Interaction/Stone"] +texture = ExtResource( 6 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Interaction/Stone"] +shape = SubResource( 4 ) + +[node name="Duck" type="RigidBody2D" parent="Interaction"] +position = Vector2( 395.124, 450.939 ) +script = ExtResource( 4 ) +__meta__ = { +"_edit_group_": true +} + +[node name="Sprite" type="Sprite" parent="Interaction/Duck"] +texture = ExtResource( 5 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Interaction/Duck"] +shape = SubResource( 3 )