Prepare for dynamically loading worlds
This commit is contained in:
parent
7a89f57ee5
commit
fccf163a4a
36
Global_structures.gd
Normal file
36
Global_structures.gd
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
extends Node2D
|
||||||
|
|
||||||
|
class base_tilemap:
|
||||||
|
var width = 150
|
||||||
|
var height = 150
|
||||||
|
var background_ts = null
|
||||||
|
var background_map = []
|
||||||
|
var interaction_ts = null
|
||||||
|
var interaction_map = []
|
||||||
|
var player_ts = null
|
||||||
|
var player_map = []
|
||||||
|
var vegetation_ts = null
|
||||||
|
var vegetation_map = []
|
||||||
|
|
||||||
|
func init_map(width, height, background_ts_path, background_map, interaction_ts_path, interaction_map, player_ts_path, player_map, vegetation_ts_path, vegetation_map):
|
||||||
|
self.width = width
|
||||||
|
self.height = height
|
||||||
|
self.background_ts = background_ts_path
|
||||||
|
self.background_map = background_map
|
||||||
|
self.interaction_ts = interaction_ts_path
|
||||||
|
self.interaction_map = interaction_map
|
||||||
|
self.player_ts = player_ts_path
|
||||||
|
self.player_map = player_map
|
||||||
|
self.vegetation_ts = vegetation_ts_path
|
||||||
|
self.vegetation_map = vegetation_map
|
||||||
|
|
||||||
|
func t():
|
||||||
|
print("woo")
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
#func _process(delta):
|
||||||
|
# pass
|
@ -12,9 +12,15 @@ onready var interaction = get_node("/root/Map1/player_interaction")
|
|||||||
var velocity = Vector2()
|
var velocity = Vector2()
|
||||||
var world_position
|
var world_position
|
||||||
var ItemClass = preload("res://MiscScenes/Item.tscn")
|
var ItemClass = preload("res://MiscScenes/Item.tscn")
|
||||||
|
var previous_position = Vector2(0,0)
|
||||||
|
|
||||||
#Moving buttons
|
#Moving buttons
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
|
var cur = Vector2(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y))
|
||||||
|
if(cur != previous_position):
|
||||||
|
interaction.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y) , 0)
|
||||||
|
interaction.set_cell(previous_position.x, previous_position.y, -1)
|
||||||
|
previous_position = Vector2(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y))
|
||||||
if Input.is_key_pressed(KEY_SPACE) or Input.is_mouse_button_pressed(BUTTON_LEFT):
|
if Input.is_key_pressed(KEY_SPACE) or Input.is_mouse_button_pressed(BUTTON_LEFT):
|
||||||
_interaction_process()
|
_interaction_process()
|
||||||
velocity.y += delta * GRAVITY
|
velocity.y += delta * GRAVITY
|
||||||
@ -30,10 +36,8 @@ func _physics_process(delta):
|
|||||||
velocity.x = 0
|
velocity.x = 0
|
||||||
velocity.y = 0
|
velocity.y = 0
|
||||||
move_and_slide(velocity, Vector2(0, -1))
|
move_and_slide(velocity, Vector2(0, -1))
|
||||||
|
|
||||||
Global.current_camera.Update()
|
Global.current_camera.Update()
|
||||||
# if(interaction.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y)) == -1):
|
|
||||||
# interaction.clear()
|
|
||||||
# interaction.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), 0)
|
|
||||||
|
|
||||||
func InteractWithCell():
|
func InteractWithCell():
|
||||||
var plant_cell_mouse = plants_map.get_cell(int(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y))
|
var plant_cell_mouse = plants_map.get_cell(int(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y))
|
||||||
@ -41,6 +45,7 @@ func InteractWithCell():
|
|||||||
|
|
||||||
var background_cell = background_map.get_cell(int(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y))
|
var background_cell = background_map.get_cell(int(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y))
|
||||||
var interaction_cell = interaction.get_cell(int(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y))
|
var interaction_cell = interaction.get_cell(int(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y))
|
||||||
|
|
||||||
if plant_cell_mouse > 0 and plant_cell_mouse % 2 == 0:
|
if plant_cell_mouse > 0 and plant_cell_mouse % 2 == 0:
|
||||||
Global.AddInventoryItem(plant_cell_mouse/2, 1)
|
Global.AddInventoryItem(plant_cell_mouse/2, 1)
|
||||||
plants_map.set_cell(int(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y), (plant_cell_mouse-1))
|
plants_map.set_cell(int(world_position[0] / cell_size.x), int(world_position[1] / cell_size.y), (plant_cell_mouse-1))
|
||||||
@ -52,7 +57,11 @@ func InteractWithCell():
|
|||||||
AnimationOnInteraction(1)
|
AnimationOnInteraction(1)
|
||||||
|
|
||||||
func _interaction_process():
|
func _interaction_process():
|
||||||
if Input.is_key_pressed(KEY_SPACE) or Input.is_mouse_button_pressed(BUTTON_LEFT):
|
|
||||||
|
if Input.is_mouse_button_pressed(BUTTON_LEFT):
|
||||||
|
world_position = get_global_mouse_position()
|
||||||
|
InteractWithCell()
|
||||||
|
elif Input.is_key_pressed(KEY_SPACE):
|
||||||
world_position = get_global_mouse_position()
|
world_position = get_global_mouse_position()
|
||||||
InteractWithCell()
|
InteractWithCell()
|
||||||
|
|
||||||
|
@ -6,6 +6,18 @@ func _ready():
|
|||||||
func _on_Btn_PlayGame_pressed():
|
func _on_Btn_PlayGame_pressed():
|
||||||
Global.LoadSave()
|
Global.LoadSave()
|
||||||
Global.GoToScene("river_intersection_home_2")
|
Global.GoToScene("river_intersection_home_2")
|
||||||
|
return
|
||||||
|
Global.LoadSave()
|
||||||
|
var game_data = GlobalStructures.base_tilemap.new()
|
||||||
|
var map_data = [[]]
|
||||||
|
for x in range(150):
|
||||||
|
map_data.append([])
|
||||||
|
for y in range(150):
|
||||||
|
map_data[x].append(int(rand_range(0, 6)))
|
||||||
|
game_data.init_map(150, 150, "res://omgeving/Floor.tres",map_data, "res://omgeving/Floor.tres", map_data, "res://omgeving/Floor.tres", map_data, "res://omgeving/Floor.tres", map_data)
|
||||||
|
var game = load("res://base_tilemap/base_tilemap.tscn").instance()
|
||||||
|
game.load_scene(game_data)
|
||||||
|
get_tree().get_root().add_child(game)
|
||||||
|
|
||||||
func _on_Btn_LoadGame_pressed():
|
func _on_Btn_LoadGame_pressed():
|
||||||
Global.GoToScene("loadgame_screen")
|
Global.GoToScene("loadgame_screen")
|
||||||
|
Binary file not shown.
BIN
Savegames/Storage.dbStorage.db
Normal file
BIN
Savegames/Storage.dbStorage.db
Normal file
Binary file not shown.
@ -48,6 +48,8 @@ func CreateWorldDatabase():
|
|||||||
self.db.insert_row("player_inventory", items)
|
self.db.insert_row("player_inventory", items)
|
||||||
items.clear()
|
items.clear()
|
||||||
|
|
||||||
|
#interaction_map
|
||||||
|
|
||||||
#Other world data
|
#Other world data
|
||||||
|
|
||||||
func OpenConnection():
|
func OpenConnection():
|
||||||
|
190
base_tilemap/base_tilemap.tscn
Normal file
190
base_tilemap/base_tilemap.tscn
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
[gd_scene load_steps=19 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://MiscCodes/background_script.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://MiscCodes/Tilemap_CameraView.gd" type="Script" id=2]
|
||||||
|
[ext_resource path="res://MiscCodes/TouchScreenButton.gd" type="Script" id=3]
|
||||||
|
[ext_resource path="res://MiscCodes/KinematicBody2D.gd" type="Script" id=4]
|
||||||
|
[ext_resource path="res://kbscene/char.png" type="Texture" id=5]
|
||||||
|
[ext_resource path="res://pictures/gui/buttons/LeftButton.png" type="Texture" id=6]
|
||||||
|
[ext_resource path="res://pictures/gui/player_interaction.tres" type="TileSet" id=7]
|
||||||
|
[ext_resource path="res://pictures/gui/buttons/TopButton.png" type="Texture" id=8]
|
||||||
|
[ext_resource path="res://pictures/gui/buttons/inventory.png" type="Texture" id=9]
|
||||||
|
[ext_resource path="res://pictures/gui/buttons/TopButtonPressed.png" type="Texture" id=10]
|
||||||
|
[ext_resource path="res://pictures/gui/buttons/instellingen2.png" type="Texture" id=11]
|
||||||
|
[ext_resource path="res://pictures/gui/buttons/crafting_alchemy.png" type="Texture" id=12]
|
||||||
|
[ext_resource path="res://pictures/gui/buttons/map.png" type="Texture" id=13]
|
||||||
|
[ext_resource path="res://pictures/gui/buttons/LeftButtonPressed.png" type="Texture" id=14]
|
||||||
|
[ext_resource path="res://pictures/gui/buttons/quick_item_button.png" type="Texture" id=15]
|
||||||
|
[ext_resource path="res://base_tilemap/init.gd" type="Script" id=16]
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleShape2D" id=1]
|
||||||
|
radius = 20.0
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id=2]
|
||||||
|
|
||||||
|
[node name="base_scene" type="Node2D"]
|
||||||
|
script = ExtResource( 16 )
|
||||||
|
|
||||||
|
[node name="background" type="TileMap" parent="."]
|
||||||
|
cell_size = Vector2( 32, 32 )
|
||||||
|
cell_custom_transform = Transform2D( 16, 0, 0, 16, 0, 0 )
|
||||||
|
format = 1
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
|
[node name="vegetation" type="TileMap" parent="."]
|
||||||
|
cell_size = Vector2( 32, 32 )
|
||||||
|
format = 1
|
||||||
|
|
||||||
|
[node name="interaction_map" type="TileMap" parent="."]
|
||||||
|
cell_size = Vector2( 32, 32 )
|
||||||
|
cell_custom_transform = Transform2D( 16, 0, 0, 16, 0, 0 )
|
||||||
|
centered_textures = true
|
||||||
|
format = 1
|
||||||
|
|
||||||
|
[node name="player_interaction" type="TileMap" parent="."]
|
||||||
|
tile_set = ExtResource( 7 )
|
||||||
|
cell_size = Vector2( 32, 32 )
|
||||||
|
cell_custom_transform = Transform2D( 16, 0, 0, 16, 0, 0 )
|
||||||
|
format = 1
|
||||||
|
tile_data = PoolIntArray( 9371749, 0, 0 )
|
||||||
|
|
||||||
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
position = Vector2( 705.297, 1197.88 )
|
||||||
|
current = true
|
||||||
|
limit_left = 0
|
||||||
|
limit_top = 0
|
||||||
|
limit_right = 4800
|
||||||
|
limit_bottom = 4800
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
|
[node name="Interactive" type="Node2D" parent="Camera2D"]
|
||||||
|
position = Vector2( -705.297, -1197.88 )
|
||||||
|
|
||||||
|
[node name="MiscButtons" type="TouchScreenButton" parent="Camera2D/Interactive"]
|
||||||
|
visible = false
|
||||||
|
position = Vector2( 272.559, 948.524 )
|
||||||
|
scale = Vector2( 13.402, 62.475 )
|
||||||
|
z_index = 12
|
||||||
|
normal = ExtResource( 8 )
|
||||||
|
action = "ui_end"
|
||||||
|
script = ExtResource( 7 )
|
||||||
|
|
||||||
|
[node name="GameButtons" type="Node2D" parent="Camera2D/Interactive"]
|
||||||
|
|
||||||
|
[node name="Inventory" type="TouchScreenButton" parent="Camera2D/Interactive/GameButtons"]
|
||||||
|
position = Vector2( 91.7642, 898.314 )
|
||||||
|
scale = Vector2( 1.23042, 1.11552 )
|
||||||
|
z_index = 13
|
||||||
|
normal = ExtResource( 9 )
|
||||||
|
action = "inventory_button"
|
||||||
|
|
||||||
|
[node name="Crafting" type="TouchScreenButton" parent="Camera2D/Interactive/GameButtons"]
|
||||||
|
position = Vector2( 1184.49, 1376.73 )
|
||||||
|
scale = Vector2( 1.23051, 1.07731 )
|
||||||
|
z_index = 13
|
||||||
|
normal = ExtResource( 12 )
|
||||||
|
|
||||||
|
[node name="Settings" type="TouchScreenButton" parent="Camera2D/Interactive/GameButtons"]
|
||||||
|
position = Vector2( 1319.96, 1020.83 )
|
||||||
|
rotation = -3.14158
|
||||||
|
scale = Vector2( 1.22003, 1.11562 )
|
||||||
|
z_index = 13
|
||||||
|
normal = ExtResource( 11 )
|
||||||
|
|
||||||
|
[node name="Map" type="TouchScreenButton" parent="Camera2D/Interactive/GameButtons"]
|
||||||
|
position = Vector2( 88.136, 1376.12 )
|
||||||
|
scale = Vector2( 1.21844, 1.10424 )
|
||||||
|
z_index = 13
|
||||||
|
normal = ExtResource( 13 )
|
||||||
|
|
||||||
|
[node name="QuickItems" type="TouchScreenButton" parent="Camera2D/Interactive/GameButtons"]
|
||||||
|
visible = false
|
||||||
|
position = Vector2( 1130.11, 1096.88 )
|
||||||
|
scale = Vector2( 1.73434, 1.80493 )
|
||||||
|
z_index = 13
|
||||||
|
normal = ExtResource( 15 )
|
||||||
|
|
||||||
|
[node name="MoveDown" type="TouchScreenButton" parent="Camera2D/Interactive/GameButtons"]
|
||||||
|
position = Vector2( 224.332, 1376.07 )
|
||||||
|
scale = Vector2( 14.9928, 14.9987 )
|
||||||
|
z_index = 11
|
||||||
|
normal = ExtResource( 8 )
|
||||||
|
pressed = ExtResource( 10 )
|
||||||
|
shape_centered = false
|
||||||
|
action = "move_down"
|
||||||
|
visibility_mode = 1
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
|
[node name="MoveRight" type="TouchScreenButton" parent="Camera2D/Interactive/GameButtons"]
|
||||||
|
position = Vector2( 1183.87, 1024.23 )
|
||||||
|
scale = Vector2( 16.7497, 5.49206 )
|
||||||
|
z_index = 11
|
||||||
|
normal = ExtResource( 6 )
|
||||||
|
pressed = ExtResource( 14 )
|
||||||
|
action = "move_right"
|
||||||
|
visibility_mode = 1
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
|
[node name="MoveUp" type="TouchScreenButton" parent="Camera2D/Interactive/GameButtons"]
|
||||||
|
position = Vector2( 224.361, 899.343 )
|
||||||
|
scale = Vector2( 14.9907, 15.5676 )
|
||||||
|
z_index = 11
|
||||||
|
normal = ExtResource( 8 )
|
||||||
|
pressed = ExtResource( 10 )
|
||||||
|
action = "move_up"
|
||||||
|
visibility_mode = 1
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
|
[node name="MoveLeft" type="TouchScreenButton" parent="Camera2D/Interactive/GameButtons"]
|
||||||
|
position = Vector2( 89.342, 1022.54 )
|
||||||
|
scale = Vector2( 16.8861, 5.52137 )
|
||||||
|
z_index = 11
|
||||||
|
z_as_relative = false
|
||||||
|
normal = ExtResource( 6 )
|
||||||
|
pressed = ExtResource( 14 )
|
||||||
|
shape_centered = false
|
||||||
|
action = "move_left"
|
||||||
|
visibility_mode = 1
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
|
[node name="dev_statistics" type="MarginContainer" parent="Camera2D"]
|
||||||
|
margin_left = -615.0
|
||||||
|
margin_top = -300.0
|
||||||
|
margin_right = 614.0
|
||||||
|
margin_bottom = 297.0
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="fps_stats" type="Label" parent="Camera2D/dev_statistics"]
|
||||||
|
margin_top = 291.0
|
||||||
|
margin_right = 1229.0
|
||||||
|
margin_bottom = 305.0
|
||||||
|
|
||||||
|
[node name="Player" type="KinematicBody2D" parent="."]
|
||||||
|
position = Vector2( 700, 1200 )
|
||||||
|
script = ExtResource( 4 )
|
||||||
|
|
||||||
|
[node name="Sprite" type="Sprite" parent="Player"]
|
||||||
|
texture = ExtResource( 5 )
|
||||||
|
flip_h = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Player"]
|
||||||
|
shape = SubResource( 1 )
|
||||||
|
one_way_collision_margin = 96.0
|
||||||
|
|
||||||
|
[node name="MapInteraction" type="TouchScreenButton" parent="Player/CollisionShape2D"]
|
||||||
|
show_behind_parent = true
|
||||||
|
position = Vector2( -150, -150 )
|
||||||
|
scale = Vector2( 15, 15 )
|
||||||
|
z_index = 11
|
||||||
|
shape = SubResource( 2 )
|
||||||
|
action = "map_interaction"
|
||||||
|
|
||||||
|
[node name="Tween" type="Tween" parent="."]
|
||||||
|
[connection signal="pressed" from="Camera2D/Interactive/GameButtons/Inventory" to="background" method="_on_Inventory_pressed"]
|
||||||
|
[connection signal="pressed" from="Camera2D/Interactive/GameButtons/MoveDown" to="Player" method="_on_TouchScreenButton_pressed"]
|
||||||
|
[connection signal="pressed" from="Camera2D/Interactive/GameButtons/MoveRight" to="Player" method="_on_TouchScreenButton_pressed"]
|
||||||
|
[connection signal="pressed" from="Camera2D/Interactive/GameButtons/MoveUp" to="Player" method="_on_TouchScreenButton_pressed"]
|
||||||
|
[connection signal="released" from="Player/CollisionShape2D/MapInteraction" to="Player" method="_interaction_process"]
|
||||||
|
[connection signal="tween_completed" from="Tween" to="Camera2D" method="_on_Tween_tween_completed"]
|
16
base_tilemap/init.gd
Normal file
16
base_tilemap/init.gd
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
extends Node2D
|
||||||
|
|
||||||
|
func load_scene(map_data):
|
||||||
|
var imageset = load("res://omgeving/Floor.tres")
|
||||||
|
$background.tile_set = imageset
|
||||||
|
for x in range(map_data.width):
|
||||||
|
for y in range(map_data.height):
|
||||||
|
$background.set_cell(x, y, map_data.background_map[x][y])
|
||||||
|
$vegetation.set_cell(x, y, map_data.background_map[x][y])
|
||||||
|
$interaction_map.set_cell(x, y, map_data.background_map[x][y])
|
||||||
|
$player_interaction.set_cell(x, y, 0)
|
||||||
|
if(1==1):
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
pass # Replace with function body.
|
@ -23,6 +23,7 @@ config/icon="res://pictures/gui/buttons/delete_ringofraces.png"
|
|||||||
|
|
||||||
Global="*res://Global.gd"
|
Global="*res://Global.gd"
|
||||||
Database="*res://Storage/Database.gd"
|
Database="*res://Storage/Database.gd"
|
||||||
|
GlobalStructures="*res://Global_structures.gd"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user