Browse Source

Import Grid Godot template

DricomDragon 5 years ago
parent
commit
7d48ee6f88
16 changed files with 419 additions and 0 deletions
  1. 17 0
      .gitattributes
  2. 14 0
      CharTween.gd
  3. 109 0
      Game.tscn
  4. 21 0
      LICENSE.md
  5. 14 0
      Obstacle.tscn
  6. 77 0
      Player.gd
  7. BIN
      basic.png
  8. 34 0
      basic.png.import
  9. 7 0
      default_env.tres
  10. BIN
      icon.png
  11. 34 0
      icon.png.import
  12. BIN
      obstacle.png
  13. 34 0
      obstacle.png.import
  14. BIN
      player.png
  15. 34 0
      player.png.import
  16. 24 0
      project.godot

+ 17 - 0
.gitattributes

@@ -0,0 +1,17 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs     diff=csharp
+
+# Standard to msysgit
+*.doc	 diff=astextplain
+*.DOC	 diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot  diff=astextplain
+*.DOT  diff=astextplain
+*.pdf  diff=astextplain
+*.PDF	 diff=astextplain
+*.rtf	 diff=astextplain
+*.RTF	 diff=astextplain

+ 14 - 0
CharTween.gd

@@ -0,0 +1,14 @@
+extends Tween
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+	pass # Replace with function body.
+
+func connect_into(o):
+	connect("tween_completed", o, "_on_tween_completed")
+	pass
+
+func move_char(c, t_pos):
+	interpolate_property(c, "position", c.get_position(), t_pos, 0.75, Tween.TRANS_LINEAR, Tween.EASE_IN)
+	start()
+	pass

File diff suppressed because it is too large
+ 109 - 0
Game.tscn


+ 21 - 0
LICENSE.md

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2020 pikadon92
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 14 - 0
Obstacle.tscn

@@ -0,0 +1,14 @@
+[gd_scene load_steps=3 format=2]
+
+[ext_resource path="res://obstacle.png" type="Texture" id=1]
+
+[sub_resource type="RectangleShape2D" id=1]
+extents = Vector2( 16, 16 )
+
+[node name="Obstacle" type="Area2D"]
+
+[node name="Sprite" type="Sprite" parent="."]
+texture = ExtResource( 1 )
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
+shape = SubResource( 1 )

+ 77 - 0
Player.gd

@@ -0,0 +1,77 @@
+extends Area2D
+
+var direction = Vector2()
+const DEG_UP = 0
+const DEG_RIGHT = 90
+const DEG_DOWN = 180
+const DEG_LEFT = 270
+
+var grid
+
+var is_moving = false
+var tween
+var target_pos = Vector2()
+var blocks = []
+var is_blocked:bool = false
+export (NodePath) var rayU
+export (NodePath) var rayD
+export (NodePath) var rayL
+export (NodePath) var rayR
+var raycast
+
+func _ready():
+	grid = get_parent()
+	
+	tween = $Tween
+	tween.connect_into(self)
+	turn(Vector2(0,1))
+	pass
+
+func _physics_process(delta):
+	direction = Vector2()
+		
+	if Input.is_action_pressed("ui_up"):
+		direction.y -= 1
+	elif Input.is_action_pressed("ui_down"):
+		direction.y += 1
+	elif Input.is_action_pressed("ui_left"):
+		direction.x -= 1
+	elif Input.is_action_pressed("ui_right"):
+		direction.x += 1
+	
+	if !is_moving and direction != Vector2():
+		
+		turn(direction)
+		
+		if !raycast.is_colliding():
+			target_pos = get_position() + direction * grid.get_cell_size()
+			tween.move_char(self, target_pos)
+			is_moving = true
+	pass
+	
+func _on_tween_completed(o, k):
+	is_moving = false
+	pass
+
+func _on_area_entered(a):
+	if a.get_parent() != $Position2D:
+		print(a)
+		blocks.append(a)
+		is_blocked = true
+	pass
+
+func _on_area_exited(a):
+	blocks.erase(a)
+	is_blocked = blocks.size()
+	pass
+	
+func turn(dir:Vector2):
+	if dir.y < 0:
+		raycast=get_node(rayU)
+	elif dir.x < 0:
+		raycast=get_node(rayL)
+	elif dir.x > 0:
+		raycast=get_node(rayR)
+	else:
+		raycast=get_node(rayD)
+	pass

BIN
basic.png


+ 34 - 0
basic.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/basic.png-e2edf0fa2bfe6c69a86cb28814640423.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://basic.png"
+dest_files=[ "res://.import/basic.png-e2edf0fa2bfe6c69a86cb28814640423.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

+ 7 - 0
default_env.tres

@@ -0,0 +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 )

BIN
icon.png


+ 34 - 0
icon.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://icon.png"
+dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.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

BIN
obstacle.png


+ 34 - 0
obstacle.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/obstacle.png-dfb3e99d3af573251007cdf5e1c252b9.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://obstacle.png"
+dest_files=[ "res://.import/obstacle.png-dfb3e99d3af573251007cdf5e1c252b9.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

BIN
player.png


+ 34 - 0
player.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/player.png-2dd0af52de4b213777cd8c9df94c0978.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://player.png"
+dest_files=[ "res://.import/player.png-2dd0af52de4b213777cd8c9df94c0978.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

+ 24 - 0
project.godot

@@ -0,0 +1,24 @@
+; Engine configuration file.
+; It's best edited using the editor UI and not directly,
+; since the parameters that go here are not all obvious.
+;
+; Format:
+;   [section] ; section goes between []
+;   param=value ; assign values to parameters
+
+config_version=4
+
+_global_script_classes=[  ]
+_global_script_class_icons={
+
+}
+
+[application]
+
+config/name="Grid Movement"
+run/main_scene="res://Game.tscn"
+config/icon="res://icon.png"
+
+[rendering]
+
+environment/default_environment="res://default_env.tres"