Vultraz

Untitled

Jun 25th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.44 KB | None | 0 0
  1. {
  2. id: "unit_avatar",
  3. is_strict: true,
  4.  
  5. zorder: 200,
  6.  
  7. properties: {
  8. unit: { type: "class unit" },
  9. orbs: { type: "[obj orb]", default: [] },
  10. disc: { type: "null|obj unit_disc" },
  11. lifebar: { type: "null|obj lifebar" },
  12.  
  13. perspective: { type: "string", default: "'s'", set: "if(value != _data, [set(_data, value), set(animation, 'stand-' + value)])" },
  14. has_north_frames: { type: "bool", default: false },
  15.  
  16. on_board: { type: "bool", default: true, set: "if(value != _data, [set(_data, value), fire_event('create')])" },
  17.  
  18. guard_image: { type: "null|obj image_widget" },
  19.  
  20. controller: { type: "obj game_controller" },
  21.  
  22. damage_flash: { type: "bool", default: false },
  23.  
  24. animate_damage: "def(int amount) ->commands
  25. [
  26. set(damage_flash, true),
  27. schedule(2, set(damage_flash, false)),
  28. if(lifebar != null,
  29. animate(lifebar, {
  30. current_hitpoints: lifebar.current_hitpoints - amount,
  31. }, {
  32. duration: 5,
  33. })
  34. ),
  35. ]
  36. ",
  37.  
  38. launch_projectile_animation: "def(obj unit_avatar target, int damage) ->commands null",
  39. launch_projectile_delay: "int :: 0",
  40. launch_projectile_impact_point: "int :: 23",
  41. melee_impact_point: "int :: 23",
  42.  
  43. summon_halo: "null|string :: null",
  44. summoned_halo: "null|string :: null",
  45.  
  46. show_halo: "def(null|string name) ->commands
  47. if(name != null,
  48. spawn(name, {
  49. mid_x: mid_x,
  50. mid_y: mid_y,
  51. zorder: zorder+10,
  52. })
  53. )
  54. ",
  55.  
  56. death_animation: "def(class animation.unit_death info) ->commands
  57. [
  58. controller.reserve_animation_time(20),
  59. map([lifebar,disc] + orbs,
  60. animate(custom_obj<- value, {
  61. alpha: 0,
  62. }, {
  63. duration: 20,
  64. })
  65. ),
  66.  
  67. animate(me, {
  68. alpha: 0,
  69. }, {
  70. duration: 20,
  71. on_complete: remove_object(me),
  72. }),
  73. ]
  74. ",
  75.  
  76. melee_attack_animation: "def(UnitAttack info, obj unit_avatar target, int damage) ->commands
  77. [
  78. set(animation, 'melee_attack-' + me.perspective),
  79. ]
  80. ",
  81.  
  82. cast_animation: "def(class animation.unit_cast info) ->commands
  83. [
  84. set(animation, 'magic-' + me.perspective),
  85. show_halo(summon_halo),
  86. ]",
  87.  
  88. summon_animation: "def(class animation.unit_summon info) ->commands
  89. [
  90. set(animation, 'magic-' + me.perspective),
  91. show_halo(summon_halo),
  92. ]",
  93.  
  94. summoned_animation: "def(class animation.unit_summon info) ->commands
  95. ;
  96. [
  97. set(alpha, 0);
  98. animate(me, {
  99. alpha: 255,
  100. }, {
  101. duration: 40,
  102. on_complete: set(me.on_board, true),
  103. }),
  104. show_halo(summoned_halo),
  105. ]",
  106.  
  107.  
  108. update: "def() ->commands
  109. execute(me,
  110. [
  111. if(unit.guard and guard_image = null, [
  112. spawn('image_widget', {
  113. image: 'guard-icon.png',
  114. image_area: [0,0,31,31],
  115. draw_width: 32,
  116. draw_height: 32,
  117. zorder: me.zorder+1,
  118. }, [
  119. set(me.guard_image, child),
  120. ])
  121. ]),
  122.  
  123. if(unit.guard = false and guard_image, [
  124. remove_object(guard_image),
  125. set(guard_image, null),
  126. ]),
  127.  
  128. if(lifebar, [
  129. set(lifebar.current_hitpoints, unit.current_hitpoints),
  130. set(lifebar.maximum_hitpoints, unit.hitpoints),
  131. ]),
  132. ])",
  133.  
  134. animate_heal: "def(class animation.unit_heal heal) ->commands
  135. controller.reserve_animation_time(10);
  136. show_halo(summon_halo);
  137. if(lifebar != null,
  138. animate(lifebar, {
  139. current_hitpoints: lifebar.current_hitpoints + heal.amount,
  140. }, {
  141. duration: 5,
  142. })
  143. )
  144. ",
  145.  
  146. animate_movement: "def(class animation.unit_move move) ->commands execute(me,
  147. [
  148. if(size(path) >= 2, [
  149. controller.reserve_animation_time(size(path)*10),
  150. set(mid_x, controller.tile_mid_x(path[0])),
  151. set(mid_y, controller.tile_mid_y(path[0])),
  152.  
  153. if(me.has_north_frames = true, [
  154. if(controller.tile_mid_y(path[0]) < controller.tile_mid_y(path[1]), set(me.perspective, 's'),
  155. controller.tile_mid_y(path[0]) > controller.tile_mid_y(path[1]), set(me.perspective, 'n')
  156. ),
  157. ]),
  158.  
  159. map(path[1:],
  160. if(controller.tile_mid_x(value) < controller.tile_mid_x(value++), set(me.facing, 1),
  161. controller.tile_mid_x(value) > controller.tile_mid_x(value++), set(me.facing, -1)
  162. );
  163.  
  164. animate(me, {
  165. mid_x: controller.tile_mid_x(value),
  166. mid_y: controller.tile_mid_y(value),
  167. }, {
  168. name: 'move',
  169. duration: 10,
  170. replace_existing: false,
  171. })
  172. )
  173. ])
  174. ]
  175. ) where path = move.path",
  176.  
  177. _preview_pane: { type: "null|obj unit_pane" },
  178. },
  179.  
  180. on_end_melee_attack_anim: "set(animation, 'stand-' + me.perspective)",
  181.  
  182. on_create: "
  183. if(on_board, [
  184. map(range(unit.num_moves),
  185. spawn('orb', {
  186. mid_x: mid_x,
  187. mid_y: mid_y - index*10,
  188. unit_avatar: me,
  189. is_enemy: unit.controller != controller.state.nplayer,
  190. }, [
  191. add(me.orbs, [child]),
  192. ])
  193. ),
  194.  
  195. spawn('lifebar', {
  196. current_hitpoints: unit.current_hitpoints,
  197. maximum_hitpoints: unit.hitpoints,
  198. }, [
  199. set(me.lifebar, child),
  200. ]),
  201.  
  202. if(unit.is_building = false,
  203. spawn('unit_disc', {
  204. mid_x: mid_x,
  205. mid_y: y2,
  206. zorder: zorder-1,
  207. color_map: if(
  208. unit.controller = 0, [1.0,0.0,0.0],
  209. unit.controller = 1, [0.0,0.0,1.0],
  210. unit.controller = 2, [0.0,1.0,0.0],
  211. unit.controller = 3, [1.0,1.0,0.0],
  212. unit.controller = 4, [1.0,0.0,1.0],
  213. [1.0,1.0,1.0]),
  214. }, [
  215. set(me.disc, child),
  216. ])
  217. ),
  218. ]
  219. )
  220. ",
  221.  
  222. on_process: "
  223. [
  224. map(orbs, [
  225. set(value.is_active, unit.has_moved <= index),
  226. set(value.is_currently_moving, controller.state.unit_moving = unit and unit.has_moved = index+1),
  227. set(value.mid_x, me.mid_x - 24),
  228. set(value.mid_y, me.mid_y - 20 - index*10),
  229. set(value.zorder, me.zorder+1),
  230. ]),
  231.  
  232. if(disc, [
  233. set(disc.mid_x, me.mid_x),
  234. set(disc.mid_y, me.y2-14),
  235. set(disc.zorder, me.zorder-1),
  236. ]),
  237.  
  238. if(lifebar, [
  239. set(lifebar.mid_x, me.mid_x - 24),
  240. set(lifebar.y, me.mid_y - 14),
  241. set(lifebar.zorder, me.zorder+1),
  242. ]),
  243.  
  244. if(guard_image, [
  245. set(guard_image.x, x+20),
  246. set(guard_image.y, y+20),
  247. ])
  248. ]
  249. ",
  250.  
  251. on_mouse_enter: "
  252. if(on_board and find(level.chars, value is obj unit_pane and value.unit = unit) = null, [
  253. spawn('unit_pane', {
  254. unit: unit,
  255. controller: controller,
  256. x: if(controller.mouse_pos_abs[0] > SCREEN_WIDTH/2,
  257. x - 190,
  258. x2 + 10
  259. ) - controller.screen_x,
  260. mid_y: mid_y - controller.screen_y,
  261. zorder: zorder + 10,
  262. has_border: true,
  263. }, [
  264. set(_preview_pane, child),
  265. ]),
  266. ])
  267. ",
  268.  
  269. on_mouse_leave: "[
  270. remove_object(_preview_pane),
  271. set(_preview_pane, null),
  272. ]",
  273.  
  274. on_being_removed: "map(spawned_children, remove_object(value))",
  275. on_type_updated: "fire_event('create')",
  276.  
  277. shader: {
  278. name: "unit_shader",
  279. vertex: "
  280. uniform mat4 u_anura_mvp_matrix;
  281. attribute vec4 a_anura_vertex;
  282. attribute vec2 a_anura_texcoord;
  283. varying vec2 v_texcoord;
  284.  
  285. void main()
  286. {
  287. v_texcoord = a_anura_texcoord;
  288. gl_Position = u_anura_mvp_matrix * a_anura_vertex;
  289. }
  290. ",
  291.  
  292. fragment: "
  293. #version 120
  294. uniform sampler2D u_anura_tex_map;
  295. uniform float u_alpha;
  296. uniform bool u_flash;
  297. varying vec2 v_texcoord;
  298. void main()
  299. {
  300. vec4 col = texture2D(u_anura_tex_map, v_texcoord);
  301. if(u_flash) {
  302. col[0] = col[1] = col[2] = 1.0;
  303. }
  304. col[3] *= u_alpha;
  305. gl_FragColor = col;
  306. }
  307. ",
  308.  
  309.  
  310. create: "[
  311. ]",
  312.  
  313. draw: "[
  314. set(uniform_commands.u_alpha, parent.alpha/255.0),
  315. set(uniform_commands.u_flash, parent.damage_flash),
  316. ]",
  317. },
  318. }
Advertisement
Add Comment
Please, Sign In to add comment