Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
polish up changes to include tutorial
- Loading branch information
Showing
17 changed files
with
246 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
gem 'dare', '0.1.2' | ||
gem 'opal', '0.7.0beta3' | ||
gem 'opal-jquery', '0.3.0beta1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
desc "Build tutorial.js" | ||
task :build do | ||
gem 'dare', '0.1.2' | ||
gem 'opal', '0.7.0beta3' | ||
gem 'opal-jquery', '0.3.0beta1' | ||
require 'opal' | ||
require 'opal-jquery' | ||
Opal::Processor.source_map_enabled = false | ||
Opal::Processor.inline_operators_enabled = true | ||
env = Sprockets::Environment.new | ||
Opal.paths.each do |path| | ||
env.append_path path | ||
end | ||
env.append_path "." | ||
env.append_path `bundle show dare`.chomp + '/lib' | ||
|
||
File.open("tutorial.js", "w+") do |out| | ||
out << env["tutorial"].to_s | ||
end | ||
end |
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title id="pageTitle"></title> | ||
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> | ||
<!-- Will add this back when 0.7.0 is released --> | ||
<!-- <script src="http://cdn.opalrb.org/opal/0.7.0/opal.min.js"></script> --> | ||
</head> | ||
<body> | ||
<script src="appp.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
require 'dare' | ||
|
||
class Star | ||
attr_reader :x, :y | ||
|
||
def initialize(animation) | ||
@animation = animation | ||
@creation_time = Dare.ms | ||
@x = rand 640 | ||
@y = rand 480 | ||
end | ||
|
||
def draw | ||
img = @animation[((Dare.ms-@creation_time)/100).to_i % @animation.size] | ||
img.draw_rot(@x, @y) | ||
end | ||
|
||
def update | ||
end | ||
|
||
end | ||
|
||
class Player | ||
|
||
def initialize | ||
@image = Dare::Image.new('assets/Starfighter.png') | ||
@grab_star_beep = Dare::Sound.new('assets/Beep.wav', overlap: 10) | ||
@x = @y = @vel_x = @vel_y = 0.0 | ||
@angle = 90.0 | ||
@score = 0 | ||
end | ||
|
||
def warp(x, y) | ||
@x, @y = x, y | ||
end | ||
|
||
def turn_left | ||
@angle += 4.5 | ||
end | ||
|
||
def turn_right | ||
@angle -= 4.5 | ||
end | ||
|
||
def accelerate | ||
@vel_x += Dare.offset_x(@angle, 0.5) | ||
@vel_y += Dare.offset_y(@angle, 0.5) | ||
end | ||
|
||
def move | ||
@x += @vel_x | ||
@y += @vel_y | ||
@x %= 640 | ||
@y %= 480 | ||
|
||
@vel_x *= 0.95 | ||
@vel_y *= 0.95 | ||
end | ||
|
||
def draw | ||
@image.draw_rot(@x, @y, @angle) | ||
end | ||
|
||
def score | ||
@score | ||
end | ||
|
||
def collect_stars(stars) | ||
if stars.reject! {|star| Dare.distance(@x, @y, star.x, star.y) < 35 } | ||
@score += 1 | ||
@grab_star_beep.play | ||
end | ||
end | ||
end | ||
|
||
class Game < Dare::Window | ||
|
||
def initialize | ||
super width: 640, height: 480, border: true | ||
self.caption = "Dare Tutorial Game" | ||
|
||
@background_image = Dare::Image.new('assets/Space.png') | ||
@player = Player.new | ||
@player.warp 320, 240 | ||
|
||
@star_animation = Dare::Image.load_tiles('assets/Star.png', width: 25) | ||
@stars = [] | ||
|
||
@font = Dare::Font.new(font: "Arial", size: 20, color: 'yellow') | ||
end | ||
|
||
def draw | ||
@background_image.draw | ||
@player.draw | ||
@stars.each(&:draw) | ||
@font.draw("Score: #{@player.score}", 20, 20) | ||
end | ||
|
||
def update | ||
if button_down? Dare::KbLeft | ||
@player.turn_left | ||
end | ||
if button_down? Dare::KbRight | ||
@player.turn_right | ||
end | ||
if button_down? Dare::KbUp | ||
@player.accelerate | ||
end | ||
@stars.each(&:update) | ||
@player.move | ||
@player.collect_stars(@stars) | ||
|
||
if rand(100) < 4 and @stars.size < 25 | ||
@stars << Star.new(@star_animation) | ||
end | ||
end | ||
|
||
end | ||
|
||
Game.new.run! |
Oops, something went wrong.