diff --git a/Assets/tile.png b/Assets/tile.png new file mode 100644 index 0000000..0d819ce Binary files /dev/null and b/Assets/tile.png differ diff --git a/Assets/tile.png.import b/Assets/tile.png.import new file mode 100644 index 0000000..f499170 --- /dev/null +++ b/Assets/tile.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://vv33w22kwgpc" +path="res://.godot/imported/tile.png-9493555de8edb914756543e894238c3e.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/tile.png" +dest_files=["res://.godot/imported/tile.png-9493555de8edb914756543e894238c3e.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/Scene/Game.tscn b/Scene/Game.tscn new file mode 100644 index 0000000..07e6562 --- /dev/null +++ b/Scene/Game.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=3 format=3 uid="uid://clirt527jo4x2"] + +[ext_resource type="Script" path="res://Scripts/MapGenerator.gd" id="1_dyj4p"] +[ext_resource type="Texture2D" uid="uid://vv33w22kwgpc" path="res://Assets/tile.png" id="2_wiemx"] + +[node name="Node2D" type="Node2D"] + +[node name="GameManager" type="Node" parent="."] + +[node name="Map" type="Node2D" parent="."] +script = ExtResource("1_dyj4p") +texture = ExtResource("2_wiemx") + +[node name="Camera2D" type="Camera2D" parent="."] + +[node name="Tile" type="Sprite2D" parent="."] +position = Vector2(182, 214) +texture = ExtResource("2_wiemx") diff --git a/Scripts/MapGenerator.gd b/Scripts/MapGenerator.gd new file mode 100644 index 0000000..a006eb9 --- /dev/null +++ b/Scripts/MapGenerator.gd @@ -0,0 +1,52 @@ +extends Node + +@export var map_size := 15 +@export var texture : Texture2D +@export var scale := 32.0 +@export var gaps := 4 + +@export_category("Colors") +@export var tile_color := Color.WHITE +@export var snake_color := Color.GREEN +@export var apple_color := Color.RED + +# Array of all Tiles of the Map +var tiles = [] + + +func generate_tiles(): + for x in range(map_size): + tiles.append([]) + tiles[x] = [] + for y in range(map_size): + var tile = Tile.new() + tile.texture = texture + tile.scale = Vector2(scale, scale) + tile.position = Vector2(x * ( scale + gaps ) - map_size / 2 * (scale + gaps), y * (scale + gaps) - map_size / 2 * (scale + gaps)) + self.add_child(tile) + tiles[x].append([]) + tiles[x][y] = tile + pass + +func _ready(): + generate_tiles() + pass + +func update_tile_colors(): + for x in range(map_size): + for y in range(map_size): + match tiles[x][y].get_state(): + + Tile.States.EMPTY: + tiles[x][y].modulate = tile_color + + Tile.States.SNAKE: + tiles[x][y].modulate = snake_color + + Tile.States.APPLE: + tiles[x][y].modulate = apple_color + pass + +func _process(delta): + update_tile_colors() + pass diff --git a/Scripts/Tile.gd b/Scripts/Tile.gd new file mode 100644 index 0000000..187383b --- /dev/null +++ b/Scripts/Tile.gd @@ -0,0 +1,20 @@ +extends Sprite2D + +class_name Tile + +enum States { + EMPTY, + SNAKE, + APPLE +} + +@export var state : States + +func _init(): + state = States.EMPTY + +func get_state() -> States: + return state + +func set_state(_state : States): + state = _state diff --git a/project.godot b/project.godot index 4c2d699..2a7ca0b 100644 --- a/project.godot +++ b/project.godot @@ -11,6 +11,7 @@ config_version=5 [application] config/name="Snake" +run/main_scene="res://Scene/Game.tscn" config/features=PackedStringArray("4.0", "GL Compatibility") config/icon="res://icon.svg"