commit 6442cac73e8275c3073e5eb81f05bbbbc79354cb
parent d908a4926ee423bb349ab96eada94c6830181f23
Author: bsandro <email@bsandro.tech>
Date: Mon, 19 Aug 2024 23:01:54 +0300
bouncing box
Diffstat:
5 files changed, 58 insertions(+), 6 deletions(-)
diff --git a/cell_green.png b/cell_green.png
Binary files differ.
diff --git a/cell_green.png.import b/cell_green.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://dmrfry0b4kavp"
+path="res://.godot/imported/cell_green.png-0373065b5eb0d0fa2f8bb9e6bdc0eed0.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://cell_green.png"
+dest_files=["res://.godot/imported/cell_green.png-0373065b5eb0d0fa2f8bb9e6bdc0eed0.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
diff --git a/scenes/Cell.tscn b/scenes/Cell.tscn
@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://68b4ti6s884b"]
-[sub_resource type="CanvasTexture" id="CanvasTexture_4mctk"]
+[ext_resource type="Texture2D" uid="uid://dmrfry0b4kavp" path="res://cell_green.png" id="1_k1vbj"]
[node name="Cell" type="Sprite2D"]
-texture = SubResource("CanvasTexture_4mctk")
+texture = ExtResource("1_k1vbj")
diff --git a/scenes/main.tscn b/scenes/main.tscn
@@ -1,6 +1,8 @@
-[gd_scene load_steps=2 format=3 uid="uid://bgi1n1lt16wa6"]
+[gd_scene load_steps=3 format=3 uid="uid://bgi1n1lt16wa6"]
[ext_resource type="Script" path="res://scripts/main.gd" id="1_jly7k"]
+[ext_resource type="PackedScene" uid="uid://68b4ti6s884b" path="res://scenes/Cell.tscn" id="2_tjoxl"]
[node name="Node" type="Node"]
script = ExtResource("1_jly7k")
+cell_scene = ExtResource("2_tjoxl")
diff --git a/scripts/main.gd b/scripts/main.gd
@@ -1,11 +1,27 @@
extends Node
+@export var cell_scene:PackedScene
+var cell:Node
+var cell_w: int
+var cell_h: int
+var x_mul:int = 1
+var y_mul:int = 1
# Called when the node enters the scene tree for the first time.
func _ready():
- pass # Replace with function body.
-
+ print("ehlo")
+ cell = cell_scene.instantiate()
+ cell.position = Vector2(randi_range(50, 100), randi_range(50, 100))
+ add_child(cell)
+ cell_w = cell.texture.get_width()
+ cell_h = cell.texture.get_height()
+ print("cell size:", cell_w, cell_h)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
- pass
+ cell.position.x += randi_range(1, 2) * x_mul
+ cell.position.y += randi_range(1, 2) * y_mul
+ if cell.position.x > get_window().size.x-cell_w/2 || cell.position.x < cell_w/2:
+ x_mul *= -1
+ if cell.position.y > get_window().size.y-cell_h/2 || cell.position.y < cell_h/2:
+ y_mul *= -1