Skip to content

Commit

Permalink
Fixed Coins Completely
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockOG committed Nov 7, 2021
1 parent 5b8073b commit c4c1608
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ export_presets.cfg
# Mono-specific ignores
.mono/
data_*/

# Builds folder
Builds/
6 changes: 5 additions & 1 deletion Scenes/Coin.tscn
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Assets/Tiles/coin.res" type="Texture" id=1]
[ext_resource path="res://Scripts/Coin.gd" type="Script" id=2]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 11, 16 )

[node name="Coin" type="Area2D"]
script = ExtResource( 2 )

[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )

[connection signal="body_entered" from="." to="." method="_on_Coin_body_entered"]
11 changes: 3 additions & 8 deletions Scenes/Edit Scene.tscn
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
[gd_scene load_steps=6 format=2]

[ext_resource path="res://Scripts/Edit Scene.gd" type="Script" id=1]
[ext_resource path="res://Assets/Tiles.tres" type="TileSet" id=2]
[ext_resource path="res://Scenes/Tiles.tscn" type="PackedScene" id=2]
[ext_resource path="res://Scripts/God Mode.gd" type="Script" id=3]
[ext_resource path="res://Assets/Tiles/tiles.res" type="Texture" id=4]
[ext_resource path="res://Assets/Tiles/Chosen Tile.png" type="Texture" id=5]

[node name="Game Scene" type="Node2D"]
[node name="Edit Scene" type="Node2D"]
script = ExtResource( 1 )

[node name="Tiles" type="TileMap" parent="."]
tile_set = ExtResource( 2 )
cell_size = Vector2( 32, 32 )
collision_layer = 4
collision_mask = 0
format = 1
[node name="Tiles" parent="." instance=ExtResource( 2 )]

[node name="Selected Tile" type="Sprite" parent="."]
modulate = Color( 1, 1, 1, 0.498039 )
Expand Down
10 changes: 3 additions & 7 deletions Scenes/Game Scene.tscn
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Scenes/Player.tscn" type="PackedScene" id=1]
[ext_resource path="res://Assets/Tiles.tres" type="TileSet" id=2]
[ext_resource path="res://Scenes/Tiles.tscn" type="PackedScene" id=2]
[ext_resource path="res://Scripts/Game Scene.gd" type="Script" id=3]

[node name="Game Scene" type="Node2D"]
script = ExtResource( 3 )

[node name="Particles" type="Node2D" parent="."]

[node name="Tiles" type="TileMap" parent="."]
tile_set = ExtResource( 2 )
cell_size = Vector2( 32, 32 )
collision_layer = 4
collision_mask = 0
format = 1
[node name="Tiles" parent="." instance=ExtResource( 2 )]

[node name="Player" parent="." instance=ExtResource( 1 )]
position = Vector2( 300, -300 )
Expand All @@ -28,4 +23,5 @@ turn_accel = 0.2
speed_accel = 0.1
jump_frames = 22

[connection signal="coin_placed" from="Tiles" to="." method="_on_Tiles_coin_placed"]
[connection signal="skid" from="Player" to="." method="_on_Player_skid"]
7 changes: 6 additions & 1 deletion Scenes/Tiles.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Assets/Tiles.tres" type="TileSet" id=1]
[ext_resource path="res://Scenes/Coin Grid.tscn" type="PackedScene" id=2]
[ext_resource path="res://Scripts/Tiles.gd" type="Script" id=3]

[node name="Tiles" type="TileMap"]
tile_set = ExtResource( 1 )
cell_size = Vector2( 32, 32 )
collision_layer = 4
collision_mask = 0
format = 1
script = ExtResource( 3 )

[node name="Coin Grid" parent="." instance=ExtResource( 2 )]
18 changes: 18 additions & 0 deletions Scripts/Coin Grid.gd
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
extends Node2D


var pos
var temp


func set_cell(x, y, coin):
pos = str(x) + " " + str(y)
if get_node_or_null(pos):
if !coin:
get_node(pos).queue_free()
else:
if coin:
temp = Global.tiles[6][1].instance()
temp.position.x = clamp(x, 0, Global.width - 1) * 32 + 16
temp.position.y = clamp(y, -1 -Global.height, 0) * 32 + 16
temp.name = pos

add_child(temp)
8 changes: 8 additions & 0 deletions Scripts/Coin.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends Area2D


signal body_entered_coin(body, coin)


func _on_Coin_body_entered(body):
emit_signal("body_entered_coin", body, self)
22 changes: 7 additions & 15 deletions Scripts/Edit Scene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,13 @@ func _ready():
func set_cell(cell, type):
Global.grid[cell.x][cell.y] = type

if Global.tiles[Global.grid[cell.x][cell.y]][0] == -2:
temp = Global.tiles[Global.grid[cell.x][cell.y]][1].instance()
temp.position.x = clamp(cell.x, 0, Global.width - 1) * 32 + 16
temp.position.y = clamp(-cell.y, -1 -Global.height, 0) * 32 - 16

tiles.add_child(temp)
coin_grid[cell.x][cell.y] = temp
else:
tiles.set_cell(
cell.x,
-1 - cell.y,
Global.tiles[Global.grid[cell.x][cell.y]][0],
false, false, false,
Global.tiles[Global.grid[cell.x][cell.y]][1]
)
tiles.set_tile(
cell.x,
-1 - cell.y,
Global.tiles[Global.grid[cell.x][cell.y]][0],
false, false, false,
Global.tiles[Global.grid[cell.x][cell.y]][1]
)
tiles.update_bitmask_region(cell, cell)


Expand Down
10 changes: 10 additions & 0 deletions Scripts/Game Scene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ func _process(_delta):
if Input.is_action_just_pressed("ui_cancel"):
# warning-ignore:return_value_discarded
get_tree().change_scene("res://Scenes/Main Scene.tscn")


func _on_Tiles_coin_placed(coin):
coin.connect("body_entered_coin", self, "_on_Coin_body_entered")


func _on_Coin_body_entered(body, coin):
if body == player:
player.pickup_coin()
coin.queue_free()
23 changes: 8 additions & 15 deletions Scripts/Global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var tiles = [
[ 1, Vector2(0, 0)],
[ 2, Vector2(0, 0)],
[ 0, Vector2(0, 0)],
[ -2, coin],
[-2, coin],
]


Expand All @@ -32,20 +32,13 @@ func load_tiles(tilemap):
yield(get_tree(), "idle_frame")
for x in width:
for y in height:
if tiles[grid[x][y]][0] == -2:
temp = tiles[grid[x][y]][1].instance()
temp.position.x = clamp(x, 0, width - 1) * 32 + 16
temp.position.y = clamp(-y, -1 -height, 0) * 32 - 16

tilemap.add_child(temp)
else:
tilemap.set_cell(
x,
-1 - y,
tiles[grid[x][y]][0],
false, false, false,
tiles[grid[x][y]][1]
)
tilemap.set_tile(
x,
-1 - y,
tiles[grid[x][y]][0],
false, false, false,
tiles[grid[x][y]][1]
)
tilemap.update_bitmask_region(Vector2(0, -1), Vector2(Global.width, -1 - Global.height))


Expand Down
16 changes: 16 additions & 0 deletions Scripts/Tiles.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extends TileMap


signal coin_placed(coin)

onready var coin_grid = $"Coin Grid"


func set_tile(x, y, tile, flip_x, flip_y, transpose, autotile_coord):
if tile == -2:
set_cell(x, y, Global.tiles[0][0], flip_x, flip_y, transpose, Global.tiles[0][1])
coin_grid.set_cell(x, y, true)
emit_signal("coin_placed", get_node("Coin Grid/" + str(x) + " " + str(y)))
else:
set_cell(x, y, tile, flip_x, flip_y, transpose, autotile_coord)
coin_grid.set_cell(x, y, false)
17 changes: 9 additions & 8 deletions export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path=""
export_path="Builds/Linux.x86_64"
script_export_mode=1
script_encryption_key=""

Expand All @@ -16,7 +16,7 @@ script_encryption_key=""
custom_template/debug=""
custom_template/release=""
binary_format/64_bits=true
binary_format/embed_pck=false
binary_format/embed_pck=true
texture_format/bptc=false
texture_format/s3tc=true
texture_format/etc=false
Expand All @@ -32,7 +32,7 @@ custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path=""
export_path="Builds/Windows.exe"
script_export_mode=1
script_encryption_key=""

Expand All @@ -41,7 +41,7 @@ script_encryption_key=""
custom_template/debug=""
custom_template/release=""
binary_format/64_bits=true
binary_format/embed_pck=false
binary_format/embed_pck=true
texture_format/bptc=false
texture_format/s3tc=true
texture_format/etc=false
Expand All @@ -55,7 +55,7 @@ codesign/timestamp_server_url=""
codesign/digest_algorithm=1
codesign/description=""
codesign/custom_options=PoolStringArray( )
application/icon=""
application/icon="res://icon.png"
application/file_version=""
application/product_version=""
application/company_name=""
Expand All @@ -73,7 +73,7 @@ custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path=""
export_path="Builds/MacOS.zip"
script_export_mode=1
script_encryption_key=""

Expand All @@ -83,9 +83,10 @@ custom_template/debug=""
custom_template/release=""
application/name=""
application/info="Made with Godot Engine"
application/icon=""
application/identifier=""
application/icon="res://icon.png"
application/identifier="com.blockog.mtsg"
application/signature=""
application/app_category="Games"
application/short_version="1.0"
application/version="1.0"
application/copyright=""
Expand Down

0 comments on commit c4c1608

Please sign in to comment.