--sprite packing sepcs bp = require "broadphase" main = require "main" action = require "action" color = require "color" reg = require "ability_reg" char = require "char" import Enemy from char mod = ... mod.big_frame_top_left = { texture: "ui.png", s1: 0 t1: 0 s2: 0 t2: 0 --hold on, maybe don't do this since we would have to mess with imagebuffers and textures } mod.create_big_button = (node, segments, x, y) -> --Constants section_width = 32 ret = {} trans = am.translate(x,y) button = am.group! button\append(trans^ am.sprite("data/big_frame_top_left.png",vec4(1,1,1,1),"left","top")) for i = 1,segments - 2 button\append(am.translate(((-32)*(segments/2)) + 32*i,y)^ am.sprite("data/big_frame_top_mid.png",vec4(1,1,1,1),"left","top")) button\append(am.translate((32*((segments/2)-1)),y)^ am.sprite("data/big_frame_top_right.png",vec4(1,1,1,1),"left","top")) ret["node"] = button bp.add(ret,x,y,segments*32,64) node\append(button) ret mod.create_small_button = (node, segments, x, y) -> assert(node ~= nil, "node was nil") assert(type(segments) == "number","segments must be a numbeR") assert(segments > 1, "segments must be at least 2") --Constants section_width = 18 section_height = 40 ret = {} trans = am.translate(x,y) button = am.group! button\append(trans^ am.sprite("data/small_frame_left.png",vec4(1,1,1,1),"left","top")) for i = 1,segments - 2 button\append(am.translate(x + (section_width*i),y)^ am.sprite("data/small_frame_mid.png",vec4(1,1,1,1),"left","top")) button\append(am.translate(x+(section_width*(segments - 1)),y)^ am.sprite("data/small_frame_right.png",vec4(1,1,1,1),"left","top")) ret["node"] = button bp.add(ret,x,y,segments*section_width,section_height) node\append(button) ret mod.create_any_button = (node, x_segs, y_segs, x, y) -> assert(x_segs >= 2, "x must have at least 2 segments") assert(y_segs >= 2, "y must have at leats 2 segments") section_width, section_height = 32,32 ret = {} button = am.group! button\append(am.translate(x,y)^ am.sprite("data/any_frame_top_left.png",vec4(1,1,1,1),"left","top")) for i = 1, x_segs - 2 button\append(am.translate(x + (i * section_width),y)^ am.sprite("data/any_frame_top_mid.png",vec4(1,1,1,1),"left","top")) button\append(am.translate(x + ((x_segs-1)*section_width),y)^ am.sprite("data/any_frame_top_right.png",vec4(1,1,1,1),"left","top")) for i = 1, y_segs - 2 button\append(am.translate(x,y - (i * section_height))^ am.sprite("data/any_frame_mid_left.png",vec4(1,1,1,1),"left","top")) for j = 1, x_segs - 2 button\append(am.translate(x + (j * section_width),y - (i * section_height))^ am.sprite("data/any_frame_mid_mid.png",vec4(1,1,1,1),"left","top")) button\append(am.translate(x + ((x_segs-1)*section_width),y - (i * section_height))^ am.sprite("data/any_frame_mid_right.png",vec4(1,1,1,1),"left","top")) button\append(am.translate(x,y - ((y_segs-1)*section_height))^ am.sprite("data/any_frame_bot_left.png",vec4(1,1,1,1),"left","top")) for i = 1, x_segs - 2 button\append(am.translate(x + (i * section_width),y - ((y_segs-1)*section_height))^ am.sprite("data/any_frame_bot_mid.png",vec4(1,1,1,1),"left","top")) button\append(am.translate(x+((x_segs-1)*section_width),y - ((y_segs-1)*section_height))^ am.sprite("data/any_frame_bot_right.png",vec4(1,1,1,1),"left","top")) button\append(am.translate(x,y)\tag("loc")) ret["node"] = button bp.add(ret,x,y,x_segs*section_width,y_segs*section_height) node\append(button) ret mod.create_char_selector2 = (node) -> left = mod.create_any_button(node,2,2,96,100) right = mod.create_any_button(node,2,2,-96-(32*2),100) text = am.text("Loading...",vec4(1,1,1,1),"center","top") node\append(am.translate(0,100)^ text) {left, right, text} mod.create_lobby_player = (node, peerid) -> floor_y = -200 rng_x = math.random(main.width) - (main.width/2) mod.create_char_selector = (node) -> s = am.group! slx = (-96/2)-18 sly = (96/2) srx = (96/2) sry = (96/2) scroll_left_node = am.translate(slx,sly)^ am.sprite("data/selector_left.png", vec4(1,1,1,1), "left","top") scroll_left = { node: scroll_left_node } scroll_right_node = am.translate(srx,sry)^ am.sprite("data/selector_right.png", vec4(1,1,1,1), "left","top") scroll_right = { node: scroll_right_node } s\append(scroll_left_node) s\append(scroll_right_node) bp.add(scroll_left,slx,sly,18,40) bp.add(scroll_right,srx,sry,18,40) node\append(s) {scroll_left, scroll_right} mod.fadeout = () -> fadeout_walltime = 0.1 screen = main.root("screen") hw = main.width/2 hh = main.height/2 bg = color.bg start_color = vec4(bg.r,bg.g,bg.b,0) fadeout = am.rect(-hw,hh,hw,-hh,color.bg)\tag("fade") screen\action(am.tween(0.1, { color: color.bg })) mod.fadein = () -> fadein_walltime = 0.1 fade = main.root("fade") fade\action(am.tween(0.1, { color: color.transparent })) mod.create_join_input = (node) -> segments=3 button_width = segments*18 button_height = 40 cell_padding = 18 grid_w = 4 grid_h = 4 buttons = {} --but = mod.create_small_button(node,3,-36,0) start_x = cell_padding - ((grid_w/2) * button_width) - (((grid_w - 1)/2) * cell_padding) start_y = 0 + ((grid_h/2) * button_height) + (((grid_h - 1)/2) * cell_padding) for i = 0,grid_h - 1 for j = 0, grid_w - 1 button_x = start_x + (j * button_width) + ((j-1) * cell_padding) button_y = start_y - (i * button_height) - ((i-1) * cell_padding) small_button = mod.create_small_button(node,3,button_x,button_y) table.insert(buttons, small_button) rnode = small_button.node text_map = { "0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f" } bt = text_map[(i * grid_w) + j + 1] rnode\append(am.translate(button_x+16,button_y-10)^ am.text(bt,vec4(1,1,1,1),"left","top")) small_button["text"] = bt selected = mod.create_big_button(node,6,-32*3,-100) buttons mod.tween_hit = (char, target, at_f) -> -- char is a character, target is a location (number) x_from, x_to = char.node("char_translate").x, 0 room = char.room if char.__class == Enemy then --x_from = room\enemy_location_of(char.data.location) x_to = room\player_location_of(target) else --x_from = room\player_location_of(char.data.location) x_to = room\enemy_location_of(target) am.wait(am.tween(char.node("char_translate"), 0.1, {x: x_to},am.windup)) if at_f at_f! am.wait(am.tween(char.node("char_translate"), 0.1, {x: x_from},am.linear)) mod.build_infocard = (node, ability) -> x_segs = 10 y_segs = 4 x = -310 y = 80 section_width, section_height = 32,32 button = am.group! button\append(am.translate(x,y)^ am.sprite("data/any_frame_top_left.png",vec4(1,1,1,1),"left","top")) for i = 1, x_segs - 2 button\append(am.translate(x + (i * section_width),y)^ am.sprite("data/any_frame_top_mid.png",vec4(1,1,1,1),"left","top")) button\append(am.translate(x + ((x_segs-1)*section_width),y)^ am.sprite("data/any_frame_top_right.png",vec4(1,1,1,1),"left","top")) for i = 1, y_segs - 2 button\append(am.translate(x,y - (i * section_height))^ am.sprite("data/any_frame_mid_left.png",vec4(1,1,1,1),"left","top")) for j = 1, x_segs - 2 button\append(am.translate(x + (j * section_width),y - (i * section_height))^ am.sprite("data/any_frame_mid_mid.png",vec4(1,1,1,1),"left","top")) button\append(am.translate(x + ((x_segs-1)*section_width),y - (i * section_height))^ am.sprite("data/any_frame_mid_right.png",vec4(1,1,1,1),"left","top")) button\append(am.translate(x,y - ((y_segs-1)*section_height))^ am.sprite("data/any_frame_bot_left.png",vec4(1,1,1,1),"left","top")) for i = 1, x_segs - 2 button\append(am.translate(x + (i * section_width),y - ((y_segs-1)*section_height))^ am.sprite("data/any_frame_bot_mid.png",vec4(1,1,1,1),"left","top")) button\append(am.translate(x+((x_segs-1)*section_width),y - ((y_segs-1)*section_height))^ am.sprite("data/any_frame_bot_right.png",vec4(1,1,1,1),"left","top")) button\append(am.translate(x,y)\tag("loc")) button("loc")\append(am.scale(2)^ am.translate(16,-8)^ am.text(ability.text, color.fg, "left","top")) button("loc")\append(am.scale(1)^ am.translate(16,-48)^ am.text(ability.description, color.fg, "left","top")) button("loc")\append(am.scale(1)^ am.translate(16,-80)^ am.text("Speed:" .. tostring(ability.speed), color.fg, "left","top")) button("loc")\append(am.scale(1)^ am.translate(16,-108)^ am.text("Hits:",color.fg,"left","center")) for i = 1,8 button("loc")\append(am.translate(42 + (i*24), -96)^ am.sprite("data/pip_frame.png",color.white,"left","top")) if ability.hits_icon[i] == 1 button("loc")\append(am.translate(42 + (i*24), -96)^ am.sprite("data/pip_light.png",color.white,"left","top")) node\append(button) button mod.battle_log = (text) -> sx, sy = math.random(-100,100), math.random(-40,40) trans = am.translate(sx,sy) trans\action(am.tween(3,{y:sy + 40})) t = am.text(text, color.fg) t\action(am.tween(3,{color:color.transparent})) t\action(coroutine.create( () -> am.wait(am.delay(4)) main.root("screen")\remove(trans) )) main.root("screen")\append(trans^ t) mod