diff --git a/Project/Assets/Fonts/PressStart2P/OFL.txt b/Project/Assets/Fonts/PressStart2P/OFL.txt new file mode 100644 index 0000000..c0f4383 --- /dev/null +++ b/Project/Assets/Fonts/PressStart2P/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2012 The Press Start 2P Project Authors (cody@zone38.net), with Reserved Font Name "Press Start 2P". + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/Project/Assets/Fonts/PressStart2P/PressStart2P-Regular.ttf b/Project/Assets/Fonts/PressStart2P/PressStart2P-Regular.ttf new file mode 100644 index 0000000..e9b029c Binary files /dev/null and b/Project/Assets/Fonts/PressStart2P/PressStart2P-Regular.ttf differ diff --git a/Project/Assets/Fonts/PressStart2P/Ref.md b/Project/Assets/Fonts/PressStart2P/Ref.md new file mode 100644 index 0000000..c4b8b1e --- /dev/null +++ b/Project/Assets/Fonts/PressStart2P/Ref.md @@ -0,0 +1,6 @@ +# Press Start 2P + +## Refs + +- [Google Fonts](https://fonts.google.com/); +- [Press Start 2P](https://fonts.google.com/specimen/Press+Start+2P); diff --git a/Project/Food/Apple.gd b/Project/Food/Apple.gd new file mode 100644 index 0000000..a69c547 --- /dev/null +++ b/Project/Food/Apple.gd @@ -0,0 +1,21 @@ +extends Area2D + +var rng = RandomNumberGenerator.new() + +func _randomize_position() -> void: + var width = ProjectSettings.get_setting("display/window/size/width") + var height = ProjectSettings.get_setting("display/window/size/height") + var half_cell = GLOBALS.GRID_SIZE / 2 + var max_x = width / GLOBALS.GRID_SIZE + var max_y = height / GLOBALS.GRID_SIZE + + var x = rng.randi_range(0, max_x) * GLOBALS.GRID_SIZE - half_cell + x = clamp(x, half_cell, width - half_cell) + + var y = rng.randi_range(0, max_y) * GLOBALS.GRID_SIZE - half_cell + y = clamp(y, half_cell, height - half_cell) + global_position = Vector2(x, y) + + +func _on_Apple_area_entered(area: Area2D) -> void: + if area.is_in_group("player") and area.is_in_group("body"): _randomize_position() diff --git a/Project/Food/Apple.tscn b/Project/Food/Apple.tscn new file mode 100644 index 0000000..6dbdfa6 --- /dev/null +++ b/Project/Food/Apple.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Food/Apple.gd" type="Script" id=1] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 15, 15 ) + +[node name="Apple" type="Area2D" groups=["food"]] +script = ExtResource( 1 ) + +[node name="ColorRect" type="ColorRect" parent="."] +margin_left = -15.0 +margin_top = -15.0 +margin_right = 15.0 +margin_bottom = 15.0 +color = Color( 1, 0, 0, 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) + +[connection signal="area_entered" from="." to="." method="_on_Apple_area_entered"] diff --git a/Project/GLOBALS.gd b/Project/GLOBALS.gd new file mode 100644 index 0000000..d8630e3 --- /dev/null +++ b/Project/GLOBALS.gd @@ -0,0 +1,3 @@ +extends Node + +const GRID_SIZE: int = 32 diff --git a/Project/Player/BodyPart.tscn b/Project/Player/BodyPart.tscn new file mode 100644 index 0000000..8cae793 --- /dev/null +++ b/Project/Player/BodyPart.tscn @@ -0,0 +1,16 @@ +[gd_scene load_steps=2 format=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 15, 15 ) + +[node name="BodyPart" type="Area2D" groups=["body", "player"]] + +[node name="ColorRect" type="ColorRect" parent="."] +margin_left = -15.0 +margin_top = -15.0 +margin_right = 15.0 +margin_bottom = 15.0 +color = Color( 0, 1, 0.905882, 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) diff --git a/Project/Player/Player.gd b/Project/Player/Player.gd index dc108a0..8c9b71a 100644 --- a/Project/Player/Player.gd +++ b/Project/Player/Player.gd @@ -1,28 +1,63 @@ extends Area2D -export (float, 0.1, 1) var normal_speed: float = 0.25 +signal food_eated +export (float, 0.1, 1) var normal_speed: float = 0.2 -const GRID_SIZE = 64 var direction: Vector2 = Vector2.RIGHT var speed: float = normal_speed +onready var BodyPart: PackedScene = preload("res://Player/BodyPart.tscn") +var body = [] + func _ready() -> void: _set_speed(normal_speed) func _process(delta: float) -> void: - if Input.is_action_just_pressed("up"): direction = Vector2.UP - if Input.is_action_just_pressed("down"): direction = Vector2.DOWN - if Input.is_action_just_pressed("left"): direction = Vector2.LEFT - if Input.is_action_just_pressed("right"): direction = Vector2.RIGHT + if Input.is_action_just_pressed("up") and not direction == Vector2.DOWN: direction = Vector2.UP + if Input.is_action_just_pressed("down") and not direction == Vector2.UP: direction = Vector2.DOWN + if Input.is_action_just_pressed("left") and not direction == Vector2.RIGHT: direction = Vector2.LEFT + if Input.is_action_just_pressed("right") and not direction == Vector2.LEFT: direction = Vector2.RIGHT if Input.is_action_just_pressed("run"): _set_speed(normal_speed / 2) elif Input.is_action_just_released("run"): _set_speed(normal_speed) func _on_Move_timeout() -> void: - global_position += direction * GRID_SIZE + for i in range(body.size() - 1, 0, -1): + body[i].global_position = body[i - 1].global_position + + var lastHeadPosition = global_position + global_position += direction * GLOBALS.GRID_SIZE + + if body.size(): body[0].global_position = lastHeadPosition + + _fix_out_border_position() + +func _fix_out_border_position() -> void: + var half_cell = GLOBALS.GRID_SIZE / 2 + var max_x = ProjectSettings.get_setting("display/window/size/width") - half_cell + var max_y = ProjectSettings.get_setting("display/window/size/height") - half_cell + + if global_position.x > max_x: global_position.x = half_cell + elif global_position.x < 0: global_position.x = max_x + + if global_position.y > max_y: global_position.y = half_cell + elif global_position.y < 0: global_position.y = max_y func _set_speed(value: float) -> void: var move_timer = $Move speed = value move_timer.wait_time = speed move_timer.start() + +func _add_body() -> PackedScene: + var new_body = BodyPart.instance() + body.append(new_body) + return new_body + +func _on_Player_area_entered(area: Area2D) -> void: + if area.is_in_group("food"): + var new_body = _add_body() + area.call_deferred("_randomize_position") + emit_signal("food_eated", new_body, Vector2(-100, -100)) + elif area.is_in_group("body"): + get_tree().reload_current_scene() diff --git a/Project/Player/Player.tscn b/Project/Player/Player.tscn index 0d6832e..e23dc96 100644 --- a/Project/Player/Player.tscn +++ b/Project/Player/Player.tscn @@ -1,17 +1,19 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=3 format=2] -[ext_resource path="res://icon.png" type="Texture" id=1] [ext_resource path="res://Player/Player.gd" type="Script" id=2] [sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 29, 29 ) +extents = Vector2( 16, 16 ) -[node name="Player" type="Area2D"] +[node name="Player" type="Area2D" groups=["head", "player"]] script = ExtResource( 2 ) -[node name="Sprite" type="Sprite" parent="."] -rotation = 1.5708 -texture = ExtResource( 1 ) +[node name="ColorRect" type="ColorRect" parent="."] +margin_left = -16.0 +margin_top = -16.0 +margin_right = 16.0 +margin_bottom = 16.0 +color = Color( 0.156863, 0, 0.905882, 1 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource( 1 ) @@ -20,4 +22,5 @@ shape = SubResource( 1 ) wait_time = 0.25 autostart = true +[connection signal="area_entered" from="." to="." method="_on_Player_area_entered"] [connection signal="timeout" from="Move" to="." method="_on_Move_timeout"] diff --git a/Project/Scenes/Game2D.gd b/Project/Scenes/Game2D.gd new file mode 100644 index 0000000..63e7934 --- /dev/null +++ b/Project/Scenes/Game2D.gd @@ -0,0 +1,9 @@ +extends Node2D + +var score: int = 0 + +func _on_Player_food_eated(new_body, position: Vector2) -> void: + score += 1 + $Score.text = str(score) + $BodyPartsContainer.call_deferred("add_child", new_body) + new_body.global_position = position diff --git a/Project/Scenes/Game2D.tscn b/Project/Scenes/Game2D.tscn index f28195c..5821121 100644 --- a/Project/Scenes/Game2D.tscn +++ b/Project/Scenes/Game2D.tscn @@ -1,13 +1,47 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://Player/Player.tscn" type="PackedScene" id=1] +[ext_resource path="res://Food/Apple.tscn" type="PackedScene" id=2] +[ext_resource path="res://Assets/Fonts/PressStart2P/PressStart2P-Regular.ttf" type="DynamicFontData" id=3] +[ext_resource path="res://Scenes/Game2D.gd" type="Script" id=4] + +[sub_resource type="DynamicFont" id=1] +size = 50 +font_data = ExtResource( 3 ) [node name="Game2D" type="Node2D"] +script = ExtResource( 4 ) [node name="Background" type="ColorRect" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 margin_right = 1280.0 -margin_bottom = 720.0 +margin_bottom = 704.0 color = Color( 0, 0.741176, 0.239216, 1 ) +[node name="Score" type="Label" parent="."] +modulate = Color( 1, 1, 1, 0.588235 ) +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +margin_left = 615.0 +margin_top = 327.0 +margin_right = 665.0 +margin_bottom = 377.0 +custom_colors/font_color_shadow = Color( 1, 0, 0, 1 ) +custom_constants/shadow_offset_x = 5 +custom_constants/shadow_offset_y = 5 +custom_fonts/font = SubResource( 1 ) +text = "0" +align = 1 +valign = 1 + [node name="Player" parent="." instance=ExtResource( 1 )] -position = Vector2( 672, 384 ) +position = Vector2( 656, 368 ) + +[node name="Apple" parent="." instance=ExtResource( 2 )] +position = Vector2( 944, 368 ) + +[node name="BodyPartsContainer" type="Node2D" parent="."] + +[connection signal="food_eated" from="Player" to="." method="_on_Player_food_eated"] diff --git a/Project/export_presets.cfg b/Project/export_presets.cfg index c3fb62c..6374d37 100644 --- a/Project/export_presets.cfg +++ b/Project/export_presets.cfg @@ -85,7 +85,7 @@ custom_features="" export_filter="all_resources" include_filter="" exclude_filter="" -export_path="../_Build/MacOS/Snake-3D.dmg" +export_path="../_Build/Mac/Snake-3D.zip" script_export_mode=1 script_encryption_key="" @@ -123,7 +123,7 @@ codesign/entitlements/custom_file="" codesign/entitlements/allow_jit_code_execution=false codesign/entitlements/allow_unsigned_executable_memory=false codesign/entitlements/allow_dyld_environment_variables=false -codesign/entitlements/disable_library_validation=false +codesign/entitlements/disable_library_validation=true codesign/entitlements/audio_input=false codesign/entitlements/camera=false codesign/entitlements/location=false diff --git a/Project/project.godot b/Project/project.godot index 37a76ab..132f182 100644 --- a/Project/project.godot +++ b/Project/project.godot @@ -18,6 +18,10 @@ config/name="Snake 3D" run/main_scene="res://Scenes/Game2D.tscn" config/icon="res://icon.png" +[autoload] + +GLOBALS="*res://GLOBALS.gd" + [display] window/size/width=1280