game are, some registers names on the screen

This commit is contained in:
Torsten Ruger 2015-07-09 15:23:36 +03:00
parent 3f8f5cdc72
commit ab48f10ee8
3 changed files with 30 additions and 17 deletions

View File

@ -1,13 +1,14 @@
# By default Volt generates this controller for your Main component
if RUBY_PLATFORM == 'opal'
require "main/lib/game"
require "main/lib/main_view"
end
module Main
class MainController < Volt::ModelController
def index
Game.new()
MainView.new()
end
def about

View File

@ -1,35 +1,29 @@
require 'opal/pixi'
require 'native'
#require_relative "registers"
require "main/lib/registers_view"
class Game
class MainView
def initialize
stage = PIXI::Container.new
@container = PIXI::Container.new
height = `window.innerHeight`
width = `window.innerWidth`
puts width
renderer = PIXI::WebGLRenderer.new( width - 100 , height - 100, {})
# opal-jquery would clean this up
renderer = PIXI::WebGLRenderer.new( width - 100 , height - 100, {"backgroundColor" => 0xFFFFFF})
body = Native(`window.document.body`)
# bit of a hack as it assumes index's structure
html_con = body.firstElementChild
html_con.insertBefore renderer.view , html_con.lastElementChild
texture = PIXI::Texture.from_image "/assets/images/bunny.png"
bunny = PIXI::Sprite.new texture
bunny.anchor = PIXI::Point.new(0.5, 0.5)
bunny.position = PIXI::Point.new(300, 150)
stage.add_child(bunny)
@container.add_child RegisterView.new(height - 150)
animate = Proc.new do
`requestAnimationFrame(animate)`
bunny.rotation += 0.1
renderer.render stage
renderer.render @container
end
animate.call
end
attr_reader :container
end

View File

@ -0,0 +1,18 @@
class RegisterView < PIXI::Container
@@register_names = (0..8).collect {|i| "r#{i}"}
def initialize at_y
super()
@registers = {}
x = 0
@@register_names.each do |name|
reg = PIXI::Text.new( name )
reg.position = PIXI::Point.new x , at_y
x += reg.width + 20
@registers[name] = reg
self.add_child reg
end
end
end