Added protype scripts for Alternate Tank and Power Plant, changed naming convention of assets to: package -> name instead of: package -> model

This commit is contained in:
2019-09-25 22:01:03 -05:00
parent 19f5a0cd9c
commit eb7a7fc6d6
12 changed files with 101 additions and 40 deletions

View File

@@ -91,6 +91,7 @@ class IMICFPS
if @entity
@entity.orientation.y += delta
@entity.orientation.y %= 360.0
position_camera
else
free_move

View File

@@ -7,7 +7,7 @@ class IMICFPS
attr_reader :name, :bound_model, :first_person_view
def setup
bind_model("base", "biped")
bind_model
@collision = :dynamic
@physics = true

View File

@@ -17,7 +17,7 @@ class IMICFPS
@backface_culling = backface_culling
@name = @manifest.name
@bound_model = map_entity ? bind_model(map_entity.package, map_entity.model) : nil
@bound_model = map_entity ? bind_model : nil
@visible = true
@renderable = true
@@ -32,7 +32,7 @@ class IMICFPS
# :static => does not move ever,
# :none => no collision check, entities can pass through
@collision = :static
@physics = false # Entity affected by gravity and what not
@physics = @manifest.physics # Entity affected by gravity and what not
@mass = 100 # kg
@delta_time = Gosu.milliseconds
@@ -56,7 +56,7 @@ class IMICFPS
@collidable.include?(@collision)
end
def bind_model(package, name)
def bind_model
model = ModelLoader.new(manifest: @manifest, entity: @dummy_entity)
raise "model isn't a model!" unless model.is_a?(ModelLoader)

View File

@@ -1,17 +1,19 @@
class IMICFPS
class Manifest
attr_reader :name, :model, :collision, :collision_mesh, :scripts, :uses
def initialize(manifest_file: nil, package: nil, model: nil)
attr_reader :name, :model, :collision, :collision_mesh, :physics, :scripts, :uses
def initialize(manifest_file: nil, package: nil, name: nil)
unless manifest_file
raise "Entity package not specified!" unless package
raise "Entity model not specified!" unless model
manifest_file = "#{IMICFPS.assets_path}/#{package}/#{model}/manifest.yaml"
raise "Entity name not specified!" unless name
manifest_file = "#{IMICFPS.assets_path}/#{package}/#{name}/manifest.yaml"
end
raise "No manifest found at: #{manifest_file}" unless File.exist?(manifest_file)
@file = manifest_file
parse(manifest_file)
pp @scripts
end
def parse(file)
@@ -24,12 +26,34 @@ class IMICFPS
# optional
@collision = data["collision"] ? data["collision"] : nil
@collision_mesh = data["collision_mesh"] ? data["collision_mesh"] : nil
@scripts = data["scripts"] ? data["scripts"] : []
@uses = data["uses"] ? data["uses"] : [] # List of entities that this Entity uses
@physics = data["physics"] ? data["physics"] : false
@scripts = data["scripts"] ? parse_scripts(data["scripts"]) : []
@uses = data["uses"] ? parse_dependencies(data["uses"]) : [] # List of entities that this Entity uses
end
def parse_scripts(scripts)
list = []
scripts.each do |script|
list << Script.new(script, File.read("#{file_path}/scripts/#{script}.rb"))
end
return list
end
def parse_dependencies(list)
dependencies = []
list.each do |item|
dependencies << Dependency.new(item["package"], item["name"])
end
return dependencies
end
def file_path
File.expand_path("./../", @file)
end
Script = Struct.new(:name, :source)
Dependency = Struct.new(:package, :name)
end
end

View File

@@ -31,7 +31,7 @@ class IMICFPS
if section = data["terrain"]
@terrain.package = section["package"]
@terrain.model = section["model"]
@terrain.name = section["name"]
@terrain.position = Vector.new
@terrain.orientation = Vector.new
if section["scale"]
@@ -55,7 +55,7 @@ class IMICFPS
if section = data["skydome"]
@skydome.package = section["package"]
@skydome.model = section["model"]
@skydome.name = section["name"]
@skydome.position = Vector.new
@skydome.orientation = Vector.new
if section["scale"]
@@ -80,7 +80,7 @@ class IMICFPS
section.each do |ent|
entity = Map::Entity.new
entity.package = ent["package"]
entity.model = ent["model"]
entity.name = ent["name"]
entity.position = Vector.new(
ent["position"]["x"],
ent["position"]["y"],
@@ -132,7 +132,7 @@ class IMICFPS
end
MetaData = Struct.new(:name, :gamemode, :authors, :datetime, :thumbnail, :description)
Entity = Struct.new(:package, :model, :position, :orientation, :scale, :water_level, :scripts)
Entity = Struct.new(:package, :name, :position, :orientation, :scale, :water_level, :scripts)
SpawnPoint = Struct.new(:team, :position, :orientation)
end
end

View File

@@ -6,17 +6,17 @@ class IMICFPS
@collision_manager = CollisionManager.new(game_state: self)
@renderer = Renderer.new(game_state: self)
@map = @options[:map]
add_entity(Terrain.new(map_entity: @map.terrain, manifest: Manifest.new(package: @map.terrain.package, model: @map.terrain.model)))
add_entity(Terrain.new(map_entity: @map.terrain, manifest: Manifest.new(package: @map.terrain.package, name: @map.terrain.name)))
@draw_skydome = true
@skydome = Skydome.new(map_entity: @map.skydome, manifest: Manifest.new(package: @map.skydome.package, model: @map.skydome.model), backface_culling: false)
@skydome = Skydome.new(map_entity: @map.skydome, manifest: Manifest.new(package: @map.skydome.package, name: @map.skydome.name), backface_culling: false)
add_entity(@skydome)
@map.entities.each do |ent|
add_entity(Entity.new(map_entity: ent, manifest: Manifest.new(package: ent.package, model: ent.model)))
add_entity(Entity.new(map_entity: ent, manifest: Manifest.new(package: ent.package, name: ent.name)))
end
@player = Player.new(spawnpoint: @map.spawnpoints.sample, manifest: Manifest.new(package: "base", model: "biped"))
@player = Player.new(spawnpoint: @map.spawnpoints.sample, manifest: Manifest.new(package: "base", name: "biped"))
add_entity(@player)
@camera = Camera.new(position: @player.position.clone)
@camera.attach_to(@player)

View File

@@ -14,10 +14,10 @@ class IMICFPS
@asset_index = 0
# add_asset(:shader, nil, "default")
add_asset(:model, @map.terrain.package, @map.terrain.model)
add_asset(:model, @map.skydome.package, @map.skydome.model)
add_asset(:model, @map.terrain.package, @map.terrain.name)
add_asset(:model, @map.skydome.package, @map.skydome.name)
@map.entities.each do |entity|
add_asset(:model, entity.package, entity.model)
add_asset(:model, entity.package, entity.name)
end
add_asset(:model, "base", "biped")
@@ -53,6 +53,7 @@ class IMICFPS
case hash[:type]
when :model
manifest = Manifest.new(manifest_file: IMICFPS.assets_path + "/#{hash[:package]}/#{hash[:name]}/manifest.yaml")
add_required_assets(manifest)
ModelLoader.new(manifest: manifest, entity: @dummy_entity)
when :shader
Shader.new(name: hash[:name], vertex: "shaders/vertex/#{hash[:name]}.glsl", fragment: "shaders/fragment/#{hash[:name]}.glsl")
@@ -82,6 +83,15 @@ class IMICFPS
@assets << {type: type, package: package, name: name}
end
def add_required_assets(manifest)
manifest.uses.each do |dependency|
known = @assets.detect {|asset| asset[:package] == dependency.package && asset[:name] == dependency.name}
unless known
add_asset(:model, dependency.package, dependency.name)
end
end
end
def progressbar(x = window.width/4, y = window.height - 104)
@percentage.draw
progress = (@asset_index.to_f/@assets.count)*window.width/2