spacevroom

A SkyRoads clone with only one boring "level" written in Godot Engine version 3.
git clone https://kaka.farm/~git/spacevroom
Log | Files | Refs | LICENSE

LevelLoader.gd (2077B)


      1 extends Node
      2 
      3 
      4 # Space Vroom, an unoriginal space racer.
      5 # Copyright (C) 2021  Yuval Langer
      6 #
      7 # This program is free software: you can redistribute it and/or modify
      8 # it under the terms of the GNU Affero General Public License as
      9 # published by the Free Software Foundation, either version 3 of the
     10 # License, or (at your option) any later version.
     11 #
     12 # This program is distributed in the hope that it will be useful,
     13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 # GNU Affero General Public License for more details.
     16 #
     17 # You should have received a copy of the GNU Affero General Public License
     18 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
     19 
     20 
     21 func load_level(level_text: String) -> Spatial:
     22 	var boxes: Spatial = Spatial.new()
     23 	var line_index: int = 0
     24 	for line in level_text.split("\n"):
     25 		var column_index: int = 0
     26 		for c in line:
     27 			if c == '#':
     28 				var box: CSGBox = CSGBox.new()
     29 				box.use_collision = true
     30 				box.width = Constants.road_box_dimensions.x
     31 				box.height = Constants.road_box_dimensions.y
     32 				box.depth = Constants.road_box_dimensions.z
     33 				box.translation = Vector3(
     34 					Constants.road_box_dimensions.x * (column_index - 3),
     35 					 0,
     36 					 -Constants.road_box_dimensions.z * line_index
     37 				)
     38 				box.add_to_group("platforms")
     39 				boxes.add_child(box)
     40 			if c == 'z':
     41 				var box: CSGBox = CSGBox.new()
     42 				box.use_collision = true
     43 				box.width = Constants.road_box_dimensions.x
     44 				box.height = Constants.road_box_dimensions.y
     45 				box.depth = Constants.road_box_dimensions.z
     46 				box.translation = Vector3(
     47 					Constants.road_box_dimensions.x * (column_index - 3),
     48 					 0,
     49 					 -Constants.road_box_dimensions.z * line_index
     50 				)
     51 				var spatial_material: SpatialMaterial = SpatialMaterial.new()
     52 				# https://en.wikipedia.org/wiki/Gold_(color)
     53 				spatial_material.albedo_color = Color("#FFD700")
     54 				box.material = spatial_material
     55 				box.add_to_group("goal")
     56 				boxes.add_child(box)
     57 			column_index += 1
     58 		line_index += 1
     59 	return boxes