game tryout
14
Gemfile
@ -9,22 +9,12 @@ gem 'volt-mongo', '~> 0.1.0'
|
||||
# Twitter bootstrap
|
||||
gem 'volt-bootstrap', '~> 0.0.10'
|
||||
|
||||
# Simple theme for bootstrap, remove to theme yourself.
|
||||
gem 'volt-bootstrap_jumbotron_theme', '~> 0.1.0'
|
||||
|
||||
# Use rbnacl for message bus encrpytion
|
||||
# (optional, if you don't need encryption, disable in app.rb and remove)
|
||||
#
|
||||
# Message Bus encryption is not supported on Windows at the moment.
|
||||
platform :ruby, :jruby do
|
||||
gem 'rbnacl', require: false
|
||||
gem 'rbnacl-libsodium', require: false
|
||||
end
|
||||
|
||||
# Asset compilation gems, they will be required when needed.
|
||||
gem 'csso-rails', '~> 0.3.4', require: false
|
||||
gem 'uglifier', '>= 2.4.0', require: false
|
||||
|
||||
gem 'opal-phaser' , :path => "../opal-phaser"
|
||||
|
||||
group :test do
|
||||
# Testing dependencies
|
||||
gem 'rspec', '~> 3.2.0'
|
||||
|
15
Gemfile.lock
@ -1,3 +1,9 @@
|
||||
PATH
|
||||
remote: ../opal-phaser
|
||||
specs:
|
||||
opal-phaser (0.2.0)
|
||||
opal (>= 0.7.0, < 0.9.0)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
@ -67,10 +73,6 @@ GEM
|
||||
rb-fsevent (0.9.5)
|
||||
rb-inotify (0.9.5)
|
||||
ffi (>= 0.5.0)
|
||||
rbnacl (3.2.0)
|
||||
ffi
|
||||
rbnacl-libsodium (1.0.3)
|
||||
rbnacl (~> 3.0, >= 3.0.1)
|
||||
ref (1.0.5)
|
||||
rspec (3.2.0)
|
||||
rspec-core (~> 3.2.0)
|
||||
@ -125,7 +127,6 @@ GEM
|
||||
sprockets-sass (~> 1.0.0)
|
||||
thor (~> 0.19.0)
|
||||
volt-bootstrap (0.0.10)
|
||||
volt-bootstrap_jumbotron_theme (0.1.0)
|
||||
volt-mongo (0.1.1)
|
||||
mongo (~> 1.9.0)
|
||||
websocket (1.2.2)
|
||||
@ -144,15 +145,13 @@ DEPENDENCIES
|
||||
chromedriver2-helper (~> 0.0.8)
|
||||
concurrent-ruby-ext (~> 0.8.0)
|
||||
csso-rails (~> 0.3.4)
|
||||
opal-phaser!
|
||||
opal-rspec (~> 0.4.2)
|
||||
poltergeist (~> 1.5.0)
|
||||
rbnacl
|
||||
rbnacl-libsodium
|
||||
rspec (~> 3.2.0)
|
||||
selenium-webdriver (~> 2.43.0)
|
||||
thin (~> 1.6.0)
|
||||
uglifier (>= 2.4.0)
|
||||
volt (= 0.9.4)
|
||||
volt-bootstrap (~> 0.0.10)
|
||||
volt-bootstrap_jumbotron_theme (~> 0.1.0)
|
||||
volt-mongo (~> 0.1.0)
|
||||
|
@ -4,7 +4,7 @@ just starting and not quite sure, but here is the direction
|
||||
|
||||
# Debugger
|
||||
|
||||
I don't want to use gdb anymore, and it would be easier with using the qemu setup, so:
|
||||
I don't want to use gdb anymore, and it would be easier without using the qemu setup, so:
|
||||
|
||||
- single step debugging of the register machine level (as close to arm as need be)
|
||||
- visual transitions for steps
|
||||
|
216
app/game.rb
Normal file
@ -0,0 +1,216 @@
|
||||
|
||||
class Score
|
||||
attr_accessor :score
|
||||
attr_reader :scoreText
|
||||
|
||||
def initialize(game)
|
||||
@game = game
|
||||
end
|
||||
|
||||
def preload
|
||||
# nothing in here for this class
|
||||
end
|
||||
|
||||
def create
|
||||
@score = 0
|
||||
@scoreText = @game.add.text(16, 16, 'score: 0', {fontSize: '32px', fill: '#000'})
|
||||
end
|
||||
end
|
||||
|
||||
class Star
|
||||
attr_accessor :stars
|
||||
|
||||
def initialize(game)
|
||||
@sprite_key = 'star'
|
||||
@sprite_url = 'assets/star.png'
|
||||
@game = game
|
||||
end
|
||||
|
||||
def preload
|
||||
@game.load.image(@sprite_key, @sprite_url)
|
||||
end
|
||||
|
||||
def create
|
||||
@stars = @game.add.group
|
||||
stars.enable_body = true
|
||||
|
||||
12.times do |n|
|
||||
star = @game.add.sprite(n * 70, 0, 'star')
|
||||
@game.physics.arcade.enable(star)
|
||||
star.body.gravity.y = 6
|
||||
star.body.bounce.y = 0.7 + rand * 0.2
|
||||
stars.add(star)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Sky
|
||||
def initialize(game)
|
||||
@sprite_key = 'sky'
|
||||
@sprite_url = 'assets/sky.png'
|
||||
@game = game
|
||||
end
|
||||
|
||||
def preload
|
||||
@game.load.image(@sprite_key, @sprite_url)
|
||||
end
|
||||
|
||||
def create
|
||||
@game.add.sprite(0, 0, @sprite_key)
|
||||
end
|
||||
end
|
||||
|
||||
class Platforms
|
||||
attr_accessor :platforms
|
||||
|
||||
def initialize(game)
|
||||
@sprite_key = 'ground'
|
||||
@sprite_url = 'assets/platform.png'
|
||||
@game = game
|
||||
end
|
||||
|
||||
def preload
|
||||
@game.load.image(@sprite_key, @sprite_url)
|
||||
end
|
||||
|
||||
def create
|
||||
@game.physics.start_system(Phaser::Physics::ARCADE)
|
||||
@platforms = @game.add.group
|
||||
@platforms.enable_body = true
|
||||
|
||||
create_ground
|
||||
create_ledge(400, 400)
|
||||
create_ledge(-150, 250)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_ground
|
||||
ground = @platforms.create(0, @game.world.height - 64, @sprite_key)
|
||||
ground.scale.setTo(2, 2)
|
||||
ground.body.immovable = true
|
||||
end
|
||||
|
||||
def create_ledge(x, y)
|
||||
ledge = @platforms.create(x, y, @sprite_key)
|
||||
ledge.body.immovable = true
|
||||
end
|
||||
end
|
||||
|
||||
class Player
|
||||
attr_accessor :player
|
||||
|
||||
def initialize(game)
|
||||
@game = game
|
||||
|
||||
@sprite_key = 'dude'
|
||||
@sprite_url = 'assets/dude.png'
|
||||
|
||||
@x = 32
|
||||
@y = @game.world.height - 150
|
||||
end
|
||||
|
||||
def preload
|
||||
@game.load.spritesheet(@sprite_key, @sprite_url, 32, 48)
|
||||
end
|
||||
|
||||
def create
|
||||
@player = @game.add.sprite(@x, @y, @sprite_key)
|
||||
|
||||
@game.physics.arcade.enable(@player)
|
||||
|
||||
player.body.bounce.y = 0.2
|
||||
player.body.gravity.y = 300
|
||||
player.body.collide_world_bounds = true
|
||||
|
||||
player.animations.add('left', [0, 1, 2, 3], 10, true)
|
||||
player.animations.add('right', [5, 6, 7, 8], 10, true)
|
||||
end
|
||||
|
||||
def update
|
||||
cursors = @game.input.keyboard.create_cursor_keys
|
||||
movement(cursors)
|
||||
end
|
||||
|
||||
def movement(cursors)
|
||||
player.body.velocity.x = 0
|
||||
|
||||
case
|
||||
when cursors.left.isDown
|
||||
player.body.velocity.x = -150
|
||||
player.animations.play('left')
|
||||
when cursors.right.isDown
|
||||
player.body.velocity.x = 150
|
||||
player.animations.play('right')
|
||||
else
|
||||
player.animations.stop
|
||||
player.frame = 4
|
||||
end
|
||||
|
||||
if cursors.up.isDown && player.body.touching.down
|
||||
player.body.velocity.y = -350
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Game
|
||||
def initialize
|
||||
run
|
||||
end
|
||||
|
||||
def run
|
||||
game = Phaser::Game.new
|
||||
state = MainLevel.new(game)
|
||||
game.state.add(:main, state, true)
|
||||
end
|
||||
end
|
||||
|
||||
class MainLevel < Phaser::State
|
||||
def preload
|
||||
pp game
|
||||
puts "preload"
|
||||
initialize_entities
|
||||
entities_call :preload
|
||||
end
|
||||
|
||||
def create
|
||||
puts "create"
|
||||
entities_call :create
|
||||
end
|
||||
|
||||
def update
|
||||
game.physics.arcade.collide(@player.player, @platforms.platforms)
|
||||
game.physics.arcade.collide(@star.stars, @platforms.platforms)
|
||||
game.physics.arcade.overlap(@player.player, @star.stars) do |p, s|
|
||||
s.kill
|
||||
@score.score += 10
|
||||
@score.scoreText.text = "score: #{@score.score}"
|
||||
end
|
||||
|
||||
@player.update
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def collect_star(player, star, score)
|
||||
star = Phaser::Sprite.new(star)
|
||||
star.kill
|
||||
|
||||
@score.score += 10
|
||||
@score.scoreText.text = "score: #{@score.score}"
|
||||
end
|
||||
|
||||
def initialize_entities
|
||||
@sky = Sky.new(game)
|
||||
@platforms = Platforms.new(game)
|
||||
@player = Player.new(game)
|
||||
@star = Star.new(game)
|
||||
@score = Score.new(game)
|
||||
|
||||
@entities ||= [@sky, @platforms, @player, @star, @score]
|
||||
end
|
||||
|
||||
def entities_call(method)
|
||||
@entities.each { |e| e.send(method) }
|
||||
end
|
||||
end
|
BIN
app/main/assets/baddie.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
app/main/assets/diamond.png
Executable file
After Width: | Height: | Size: 508 B |
BIN
app/main/assets/dude.png
Executable file
After Width: | Height: | Size: 3.2 KiB |
BIN
app/main/assets/firstaid.png
Executable file
After Width: | Height: | Size: 554 B |
89590
app/main/assets/js/phaser.js
Normal file
BIN
app/main/assets/platform.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
app/main/assets/sky.png
Executable file
After Width: | Height: | Size: 4.6 KiB |
BIN
app/main/assets/star.png
Executable file
After Width: | Height: | Size: 443 B |
@ -3,6 +3,3 @@
|
||||
|
||||
# bootstrap css framework
|
||||
component 'bootstrap'
|
||||
|
||||
# a default theme for the bootstrap framework
|
||||
component 'bootstrap_jumbotron_theme'
|
||||
|
1
app/main/config/initializers/client/phaser.rb
Normal file
@ -0,0 +1 @@
|
||||
require 'opal-phaser'
|
@ -1,8 +1,13 @@
|
||||
# By default Volt generates this controller for your Main component
|
||||
|
||||
|
||||
module Main
|
||||
class MainController < Volt::ModelController
|
||||
def index
|
||||
# Add code for when the index view is loaded
|
||||
require "game"
|
||||
|
||||
Game.new()
|
||||
|
||||
end
|
||||
|
||||
def about
|
||||
|
@ -3,4 +3,3 @@
|
||||
|
||||
<:Body>
|
||||
<h1>Home</h1>
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
<:nav href="/">Home</:nav>
|
||||
<:nav href="/about">About</:nav>
|
||||
</ul>
|
||||
<h3 class="text-muted">salama-debugger</h3>
|
||||
<h3 class="text-muted">Salama Debugger</h3>
|
||||
</div>
|
||||
|
||||
<:volt:notices />
|
||||
@ -16,7 +16,7 @@
|
||||
{{ view main_path, 'body', {controller_group: 'main'} }}
|
||||
|
||||
<div class="footer">
|
||||
<p>© Company {{ Time.now.year }}</p>
|
||||
<p> <a href="http://salama-vm.org/" >Salama</a> {{ Time.now.year }}</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@ -100,8 +100,8 @@ Volt.configure do |config|
|
||||
# config.message_bus.bus_name = 'peer_to_peer'
|
||||
#
|
||||
# Encrypt message bus - messages on the message bus are encrypted by default
|
||||
# using rbnacl.
|
||||
# config.message_bus.disable_encryption = true
|
||||
# but this is meant to be used locally by a developer
|
||||
config.message_bus.disable_encryption = true
|
||||
#
|
||||
# ## MessageBus Server -- the message bus binds to a port and ip which the
|
||||
# other volt instances need to be able to connect to. You can customize
|
||||
|