X-Git-Url: http://nitlanguage.org diff --git a/contrib/friendz/src/friendz.nit b/contrib/friendz/src/friendz.nit index e745040..218e5ce 100644 --- a/contrib/friendz/src/friendz.nit +++ b/contrib/friendz/src/friendz.nit @@ -13,10 +13,13 @@ module friendz is app_version(0, 1, git_revision) end +import app::audio import mnit import realtime import solver import mnit::tileset +import app::data_store +import md5 intrude import grid intrude import level @@ -140,7 +143,6 @@ class TextButton var textx: Int redef fun draw(ctx) do - var x = self.x if self.toggleable then var w if self.toggled or not self.enabled then w = 6 else w = 7 @@ -167,7 +169,7 @@ class TextButton do if over1 == null then return if not self.enabled then return - game.snd_click.replay + game.snd_click.play self.ttl = 10 self.dirty = true self.enter2 @@ -180,14 +182,14 @@ class TextButton redef fun click(ev) do if not self.enabled then - game.snd_bing.replay + game.snd_bing.play else if self.toggleable then self.toggled = not self.toggled if self.toggled then self.over = self.over2 else self.over = self.over1 game.statusbar.over_txt = self.over end - game.snd_whip.replay + game.snd_whip.play end self.click2(ev) end @@ -215,11 +217,11 @@ class LevelButton self.over = self.level.fullname if self.level.get_state >= l.l_won then - if game.levels[9].get_state >= l.l_won then self.over += " --- {self.level.score}/{self.level.par}" + if game.levels[9].get_state >= l.l_won then self.over += " --- {self.level.score}/{self.level.gold}" else if self.level.get_state >= l.l_open then - if game.levels[9].get_state >= l.l_open then self.over += " --- ?/{self.level.par}" + if game.levels[9].get_state >= l.l_open then self.over += " --- ?/{self.level.gold}" end - #self.enabled = l.get_state >= l.l_open + self.enabled = l.get_state >= l.l_open or game.cheated end redef fun draw(ctx) @@ -240,7 +242,7 @@ class LevelButton end ctx.blit(game.img[ix,iy], self.x, self.y) - if s == l.l_par then + if s == l.l_gold then ctx.blit(game.img2[7,0], self.x + bw*5/8, self.y-bh*1/8) end ctx.textx(self.level.name, self.x+5, self.y+5, 24, null, null) @@ -249,10 +251,10 @@ class LevelButton redef fun click(ev) do if self.enabled then - game.snd_whip.replay + game.snd_whip.play game.play(self.level) else - game.snd_bing.replay + game.snd_bing.play game.statusbar.set_tmp("Locked level", "red") end end @@ -292,10 +294,10 @@ class Achievement redef fun click(ev) do if not self.enabled then - game.snd_bing.replay + game.snd_bing.play game.statusbar.set_tmp("Locked achievement!", "red") else - game.snd_whip.replay + game.snd_whip.play self.click2(ev) end end @@ -454,7 +456,7 @@ class Button if game.selected_button == game.button_size then game.board.dirty=true if sel != null then sel.dirty=true game.selected_button = self - game.snd_click.replay + game.snd_click.play end # Current inputed chain @@ -468,36 +470,36 @@ class Button if ev.drag and self.kind>0 and not chain.is_empty then if self.chain.length >= 2 and self.chain[1] == t then var t2 = self.chain.shift - game.snd_click.replay + game.snd_click.play if t2.fixed and not game.editing then return t2.update(0) return end if t.fixed and t.kind == self.kind then self.chain.unshift(t) - game.snd_click.replay + game.snd_click.play return end if (self.chain[0].x - t.x).abs + (self.chain[0].y - t.y).abs != 1 then return if t.fixed and not game.editing then - game.snd_bing.replay + game.snd_bing.play return end if t.kind != 0 and t.kind != self.kind then t.shocked = 5 - game.snd_duh.replay + game.snd_duh.play return end self.chain.unshift(t) if t.kind == self.kind then return - game.snd_click.replay + game.snd_click.play t.update(self.kind) return end if t.fixed and not game.editing then if t.kind == 0 then - game.snd_bing.replay + game.snd_bing.play return end if t.kind != self.kind and not ev.drag then @@ -505,13 +507,13 @@ class Button game.buttons[t.kind].chain = [t] else self.chain = [t] - game.snd_bing.replay + game.snd_bing.play end return end if t.fixed and game.editing and self == game.button_erase and t.kind == 0 then t.fixed = false - game.snd_click.replay + game.snd_click.play return end @@ -521,7 +523,7 @@ class Button if t.kind == 0 then return if self.kind != 0 and t.kind != self.kind then t.shocked = 5 - game.snd_duh.replay + game.snd_duh.play return end nkind = 0 @@ -533,7 +535,7 @@ class Button self.chain.clear end if nkind == t.kind then return - game.snd_click.replay + game.snd_click.play t.update(nkind) end end @@ -640,7 +642,7 @@ class MetalButton if not ev.drag then self.fixed = not t.fixed if t.fixed == self.fixed then return t.fixed = self.fixed - game.snd_click.replay + game.snd_click.play end end @@ -683,7 +685,7 @@ class ResizeButton var w = t.x+1 var h = t.y+1 if w < 3 or h < 3 then - game.snd_bing.replay + game.snd_bing.play game.statusbar.set_tmp("Too small!", "red") return end @@ -700,11 +702,11 @@ class ResizeButton end end if aborts then - game.snd_duh.replay + game.snd_duh.play game.statusbar.set_tmp("Monsters on the way!", "red") return end - game.snd_click.replay + game.snd_click.play grid.resize(w,h) end end @@ -728,9 +730,9 @@ class Score end if game.levels[9].get_state >= level.l_won then if level.is_challenge then - ctx.textx("GOAL: {level.par}",self.x,self.y+44,21,"yellow",null) + ctx.textx("GOAL: {level.gold}",self.x,self.y+44,21,"yellow",null) else - ctx.textx("PAR: {level.par}",self.x,self.y+44,21,"yellow",null) + ctx.textx("GOLD: {level.gold}",self.x,self.y+44,21,"yellow",null) end end end @@ -804,23 +806,6 @@ end # ************************************************************************/ -# Simple audio asset -class Audio - var path: String - - # placebo - fun play do end - - # placebo - fun pause do end - - # Play a sound. - fun replay - do - sys.system("aplay assets/{path} &") - end -end - redef class Display # Display a text fun textx(str: String, x, y, height: Int, color, color2: nullable String) @@ -834,7 +819,7 @@ redef class Display fun measureText(str: String, height: Int): Int do var font = app.game.font - return str.length * (app.game.font.width + app.game.font.hspace) + return str.length * (font.width + font.hspace.to_i) end # displays a debug rectangle @@ -888,26 +873,6 @@ redef class Game # Font var font = new TileSetFont(app.load_image("deltaforce_font.png"), 16, 17, "ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789.:;!?\"'() -,/") - var xxx = """ - fun save_cookie(name, val:String) do - var days = 365 - var date = new Date() - date.setTime(date.getTime()+(days*24*60*60*1000)) - document.cookie = name+"="+val+"; expires="+date.toGMTString()+"; path=/" - end - - fun read_cookie(name:String):String do - var key = name + "=" - var ca = document.cookie.split(';') - for(var i=0; i 0 then score else null + end +end