Copied the code from Inkjs-boilerplate

This commit is contained in:
Alexander Yakovlev 2017-04-20 21:23:03 +07:00
parent 974c29da35
commit 53d96165ca
3 changed files with 38 additions and 4 deletions

View File

@ -50,6 +50,7 @@ bundler = watchify(browserify({
}))
gulp.task('ink', () ->
return true # at the moment i don't have a working standalone inklecate
return gulp.src([
'game/ink/*.ink'
])

View File

@ -1,10 +1,10 @@
Story = require('inkjs').Story
musgrave = require('../../game/___.json')
musgrave = require('./ink/fogg.json')
class SimpleGame
game: null
constructor: () ->
@game = new Phaser.Game(800, 600, Phaser.AUTO, 'content',
@game = new Phaser.Game(800, 600, Phaser.AUTO, 'graphic',
{preload: this.preload, create: this.create})
preload: () ->
@game.stage.backgroundColor = '#ffffff'
@ -13,8 +13,35 @@ class SimpleGame
logo = @game.add.sprite(@game.world.centerX, @game.world.centerY, 'logo')
logo.anchor.setTo(0.5, 0.5)
continueToNextChoice = (s) ->
while (s.canContinue)
paragraphs = s.Continue().split("\n")
delay = 1000
for i in paragraphs
if i != ""
html = $.parseHTML(i)
$("#text").append($('<p>').hide().html(html).fadeIn(delay))
delay += 500
scrollTo = $('#options').offset().top
if (s.currentChoices.length > 0)
$("#options").html("").hide()
for choice in s.currentChoices
$("#options").append("<li><a href='#' id='choice-#{choice.index}' data-index=#{choice.index}>#{choice.text}</a></li>")
$("#options").fadeIn(800)
$("#options li a").click(() ->
s.ChooseChoiceIndex($(this).data("index"))
continueToNextChoice(s)
return false
)
else
$("#text").append("<p>THE END</p>")
$("#options").html("")
$('html, body').animate({
scrollTop: scrollTo
}, 800)
$(document).ready(() ->
game = new SimpleGame()
inkStory = new Story(musgrave)
console.log(inkStory.ContinueMaximally())
continueToNextChoice(inkStory)
)

View File

@ -11,7 +11,13 @@
<div id="page">
<div class="container">
<div id="content_wrapper" class="row">
<div id="content" class="content">
<div id="graphic" class="content">
</div>
<div id="text_container" class="content">
<div id="text">
</div>
<ul id="options">
</ul>
</div>
<a name="end_of_content"></a>
</div>