tilemaps!

This commit is contained in:
zoe 2022-05-01 01:28:31 +02:00
parent f5f66b5918
commit b38a39e127
15 changed files with 146 additions and 6 deletions

13
godot/world/terrain.gd Normal file
View file

@ -0,0 +1,13 @@
extends TileMap
var width = 256
var height = 256
# Called when the node enters the scene tree for the first time.
func _ready():
fill()
func fill():
for x in width:
for y in height:
set_cell(x,y,0,false,false,false,Vector2(1,0))

View file

@ -0,0 +1,26 @@
[gd_resource type="TileSet" load_steps=2 format=2]
[ext_resource path="res://sprite/tiles/terrain/default.png" type="Texture" id=1]
[resource]
0/name = "default.png 0"
0/texture = ExtResource( 1 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 1, 1, 1, 1 )
0/region = Rect2( 0, 0, 128, 128 )
0/tile_mode = 2
0/autotile/icon_coordinate = Vector2( 0, 0 )
0/autotile/tile_size = Vector2( 32, 32 )
0/autotile/spacing = 0
0/autotile/occluder_map = [ ]
0/autotile/navpoly_map = [ ]
0/autotile/priority_map = [ ]
0/autotile/z_index_map = [ ]
0/occluder_offset = Vector2( 0, 0 )
0/navigation_offset = Vector2( 0, 0 )
0/shape_offset = Vector2( 0, 0 )
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
0/shape_one_way = false
0/shape_one_way_margin = 0.0
0/shapes = [ ]
0/z_index = 0

View file

@ -1,3 +1,29 @@
[gd_scene format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://world/terrain/terrain.tres" type="TileSet" id=1]
[ext_resource path="res://world/terrain.gd" type="Script" id=2]
[ext_resource path="res://world/worldcam.gd" type="Script" id=3]
[node name="World" type="Node2D"]
[node name="terrain" type="TileMap" parent="."]
position = Vector2( -2, 0 )
mode = 1
tile_set = ExtResource( 1 )
cell_size = Vector2( 32, 16 )
format = 1
tile_data = PoolIntArray( -393219, 0, 196609, -393218, 0, 196609, -393217, 0, 196609, -458752, 0, 196609, -458751, 0, 196609, -327683, 0, 196609, -327682, 0, 196609, -327681, 0, 196609, -393216, 0, 196609, -393215, 0, 196609, -393214, 0, 196609, -262147, 0, 196609, -262146, 0, 196609, -262145, 0, 196609, -327680, 0, 196609, -327679, 0, 196609, -327678, 0, 196609, -327677, 0, 196609, -196611, 0, 196609, -196610, 0, 196609, -196609, 0, 131072, -262144, 0, 196609, -262143, 0, 196609, -262142, 0, 196609, -262141, 0, 196609, -262140, 0, 196609, -131075, 0, 196609, -131074, 0, 196609, -131073, 0, 196609, -196608, 0, 196609, -196607, 0, 196609, -196606, 0, 196609, -196605, 0, 196609, -196604, 0, 196609, -196603, 0, 196609, -65539, 0, 196609, -65538, 0, 196609, -65537, 0, 196609, -131072, 0, 196609, -131071, 0, 196609, -131070, 0, 196609, -131069, 0, 196609, -131068, 0, 196609, -131067, 0, 196609, -131066, 0, 196609, -2, 0, 196609, -1, 0, 196609, -65536, 0, 196609, -65535, 0, 196609, -65534, 0, 196609, -65533, 0, 196609, -65532, 0, 196609, -65531, 0, 196609, -65530, 0, 196609, 65534, 0, 196609, 65535, 0, 196609, 0, 0, 196609, 1, 0, 196609, 2, 0, 196609, 3, 0, 196609, 4, 0, 196609, 131070, 0, 196609, 131071, 0, 196609, 65536, 0, 196609, 65537, 0, 196609, 65538, 0, 196609, 65539, 0, 196609, 65540, 0, 196609, 196607, 0, 196609, 131072, 0, 196609, 131073, 0, 196609, 131074, 0, 196609, 131075, 0, 196609, 131076, 0, 196609, 131077, 0, 196609, 196608, 0, 196609, 196609, 0, 196609, 196610, 0, 196609, 196611, 0, 196609, 196612, 0, 196609, 196613, 0, 196609, 262144, 0, 196609, 262145, 0, 196609, 262146, 0, 196609, 262147, 0, 196609, 262148, 0, 196609, 262149, 0, 196609, 327683, 0, 196609, 327684, 0, 196609 )
script = ExtResource( 2 )
[node name="TileMap" type="TileMap" parent="."]
position = Vector2( -2, 0 )
mode = 1
tile_set = ExtResource( 1 )
cell_size = Vector2( 32, 16 )
format = 1
tile_data = PoolIntArray( -196609, 0, 65539, -262144, 0, 65539, -262143, 0, 65539, -196608, 0, 65539, -196607, 0, 65536, -196606, 0, 65536, -196605, 0, 65539, -65537, 0, 65536, -131072, 0, 65536, -131071, 0, 65536, -131070, 0, 65536, -131069, 0, 65536, -131068, 0, 65536, -65536, 0, 65539, -65535, 0, 65539, -65534, 0, 196609, 1, 0, 65539, 2, 0, 2, 65537, 0, 2, 65538, 0, 196609 )
[node name="worldcam" type="Camera2D" parent="."]
current = true
zoom = Vector2( 0.4, 0.4 )
script = ExtResource( 3 )

21
godot/world/worldcam.gd Normal file
View file

@ -0,0 +1,21 @@
extends Camera2D
export var min_zoom = 0.4
export var speed = 200
var zoomlevel = 0.4
func _process(delta):
move_around(delta)
handle_zoom()
func move_around(delta):
var xdirection = Input.get_action_strength("camera_right") - Input.get_action_strength("camera_left")
var ydirection = Input.get_action_strength("camera_down") - Input.get_action_strength("camera_up")
var direction = Vector2(xdirection, ydirection).normalized() * delta * speed * zoom
position = lerp(position, position + direction, 2)
func handle_zoom():
if Input.is_action_just_pressed("zoom_in"):
zoomlevel = clamp(zoomlevel - 0.1, 0.1, 2)
if Input.is_action_just_pressed("zoom_out"):
zoomlevel = clamp(zoomlevel + 0.1, 0.1, 2)
zoom = Vector2(zoomlevel, zoomlevel)