Skip to content

Instantly share code, notes, and snippets.

@superlou
Created March 15, 2014 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superlou/9566892 to your computer and use it in GitHub Desktop.
Save superlou/9566892 to your computer and use it in GitHub Desktop.
Game Logic
require 'artemis'
require './components.rb'
class GameServer
def run
puts "Starting server..."
@world = Artemis::World.new
@world.add_manager Artemis::TagManager.new
@world.set_system(RouteMovementSystem.new).setup
city = @world.create_entity(LocationComponent.new(0, 0))
city.add_to_world
force = @world.create_entity(LocationComponent.new(32, 10),
RouteComponent.new,
TopSpeedComponent.new)
force.add_to_world
client_handler = @world.create_entity
client_handler.add_to_world
game_loop
end
def game_loop
now = Time.now
counter = 1
loop do
if Time.now < now + counter
next
else
@world.delta = counter
@world.process
end
counter += 1
end
end
end
class RouteMovementSystem < Artemis::EntityProcessingSystem
def initialize
super(Artemis::Aspect.new_for_all TopSpeedComponent, RouteComponent, LocationComponent)
end
def setup
@location_mapper = Artemis::ComponentMapper.new(LocationComponent, @world)
end
def process_entity(entity)
puts "process #{entity}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment