Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- id: "unit_avatar",
- is_strict: true,
- zorder: 200,
- properties: {
- unit: { type: "class unit" },
- orbs: { type: "[obj orb]", default: [] },
- disc: { type: "null|obj unit_disc" },
- lifebar: { type: "null|obj lifebar" },
- perspective: { type: "string", default: "'s'", set: "if(value != _data, [set(_data, value), set(animation, 'stand-' + value)])" },
- has_north_frames: { type: "bool", default: false },
- on_board: { type: "bool", default: true, set: "if(value != _data, [set(_data, value), fire_event('create')])" },
- guard_image: { type: "null|obj image_widget" },
- controller: { type: "obj game_controller" },
- damage_flash: { type: "bool", default: false },
- animate_damage: "def(int amount) ->commands
- [
- set(damage_flash, true),
- schedule(2, set(damage_flash, false)),
- if(lifebar != null,
- animate(lifebar, {
- current_hitpoints: lifebar.current_hitpoints - amount,
- }, {
- duration: 5,
- })
- ),
- ]
- ",
- launch_projectile_animation: "def(obj unit_avatar target, int damage) ->commands null",
- launch_projectile_delay: "int :: 0",
- launch_projectile_impact_point: "int :: 23",
- melee_impact_point: "int :: 23",
- summon_halo: "null|string :: null",
- summoned_halo: "null|string :: null",
- show_halo: "def(null|string name) ->commands
- if(name != null,
- spawn(name, {
- mid_x: mid_x,
- mid_y: mid_y,
- zorder: zorder+10,
- })
- )
- ",
- death_animation: "def(class animation.unit_death info) ->commands
- [
- controller.reserve_animation_time(20),
- map([lifebar,disc] + orbs,
- animate(custom_obj<- value, {
- alpha: 0,
- }, {
- duration: 20,
- })
- ),
- animate(me, {
- alpha: 0,
- }, {
- duration: 20,
- on_complete: remove_object(me),
- }),
- ]
- ",
- melee_attack_animation: "def(UnitAttack info, obj unit_avatar target, int damage) ->commands
- [
- set(animation, 'melee_attack-' + me.perspective),
- ]
- ",
- cast_animation: "def(class animation.unit_cast info) ->commands
- [
- set(animation, 'magic-' + me.perspective),
- show_halo(summon_halo),
- ]",
- summon_animation: "def(class animation.unit_summon info) ->commands
- [
- set(animation, 'magic-' + me.perspective),
- show_halo(summon_halo),
- ]",
- summoned_animation: "def(class animation.unit_summon info) ->commands
- ;
- [
- set(alpha, 0);
- animate(me, {
- alpha: 255,
- }, {
- duration: 40,
- on_complete: set(me.on_board, true),
- }),
- show_halo(summoned_halo),
- ]",
- update: "def() ->commands
- execute(me,
- [
- if(unit.guard and guard_image = null, [
- spawn('image_widget', {
- image: 'guard-icon.png',
- image_area: [0,0,31,31],
- draw_width: 32,
- draw_height: 32,
- zorder: me.zorder+1,
- }, [
- set(me.guard_image, child),
- ])
- ]),
- if(unit.guard = false and guard_image, [
- remove_object(guard_image),
- set(guard_image, null),
- ]),
- if(lifebar, [
- set(lifebar.current_hitpoints, unit.current_hitpoints),
- set(lifebar.maximum_hitpoints, unit.hitpoints),
- ]),
- ])",
- animate_heal: "def(class animation.unit_heal heal) ->commands
- controller.reserve_animation_time(10);
- show_halo(summon_halo);
- if(lifebar != null,
- animate(lifebar, {
- current_hitpoints: lifebar.current_hitpoints + heal.amount,
- }, {
- duration: 5,
- })
- )
- ",
- animate_movement: "def(class animation.unit_move move) ->commands execute(me,
- [
- if(size(path) >= 2, [
- controller.reserve_animation_time(size(path)*10),
- set(mid_x, controller.tile_mid_x(path[0])),
- set(mid_y, controller.tile_mid_y(path[0])),
- if(me.has_north_frames = true, [
- if(controller.tile_mid_y(path[0]) < controller.tile_mid_y(path[1]), set(me.perspective, 's'),
- controller.tile_mid_y(path[0]) > controller.tile_mid_y(path[1]), set(me.perspective, 'n')
- ),
- ]),
- map(path[1:],
- if(controller.tile_mid_x(value) < controller.tile_mid_x(value++), set(me.facing, 1),
- controller.tile_mid_x(value) > controller.tile_mid_x(value++), set(me.facing, -1)
- );
- animate(me, {
- mid_x: controller.tile_mid_x(value),
- mid_y: controller.tile_mid_y(value),
- }, {
- name: 'move',
- duration: 10,
- replace_existing: false,
- })
- )
- ])
- ]
- ) where path = move.path",
- _preview_pane: { type: "null|obj unit_pane" },
- },
- on_end_melee_attack_anim: "set(animation, 'stand-' + me.perspective)",
- on_create: "
- if(on_board, [
- map(range(unit.num_moves),
- spawn('orb', {
- mid_x: mid_x,
- mid_y: mid_y - index*10,
- unit_avatar: me,
- is_enemy: unit.controller != controller.state.nplayer,
- }, [
- add(me.orbs, [child]),
- ])
- ),
- spawn('lifebar', {
- current_hitpoints: unit.current_hitpoints,
- maximum_hitpoints: unit.hitpoints,
- }, [
- set(me.lifebar, child),
- ]),
- if(unit.is_building = false,
- spawn('unit_disc', {
- mid_x: mid_x,
- mid_y: y2,
- zorder: zorder-1,
- color_map: if(
- unit.controller = 0, [1.0,0.0,0.0],
- unit.controller = 1, [0.0,0.0,1.0],
- unit.controller = 2, [0.0,1.0,0.0],
- unit.controller = 3, [1.0,1.0,0.0],
- unit.controller = 4, [1.0,0.0,1.0],
- [1.0,1.0,1.0]),
- }, [
- set(me.disc, child),
- ])
- ),
- ]
- )
- ",
- on_process: "
- [
- map(orbs, [
- set(value.is_active, unit.has_moved <= index),
- set(value.is_currently_moving, controller.state.unit_moving = unit and unit.has_moved = index+1),
- set(value.mid_x, me.mid_x - 24),
- set(value.mid_y, me.mid_y - 20 - index*10),
- set(value.zorder, me.zorder+1),
- ]),
- if(disc, [
- set(disc.mid_x, me.mid_x),
- set(disc.mid_y, me.y2-14),
- set(disc.zorder, me.zorder-1),
- ]),
- if(lifebar, [
- set(lifebar.mid_x, me.mid_x - 24),
- set(lifebar.y, me.mid_y - 14),
- set(lifebar.zorder, me.zorder+1),
- ]),
- if(guard_image, [
- set(guard_image.x, x+20),
- set(guard_image.y, y+20),
- ])
- ]
- ",
- on_mouse_enter: "
- if(on_board and find(level.chars, value is obj unit_pane and value.unit = unit) = null, [
- spawn('unit_pane', {
- unit: unit,
- controller: controller,
- x: if(controller.mouse_pos_abs[0] > SCREEN_WIDTH/2,
- x - 190,
- x2 + 10
- ) - controller.screen_x,
- mid_y: mid_y - controller.screen_y,
- zorder: zorder + 10,
- has_border: true,
- }, [
- set(_preview_pane, child),
- ]),
- ])
- ",
- on_mouse_leave: "[
- remove_object(_preview_pane),
- set(_preview_pane, null),
- ]",
- on_being_removed: "map(spawned_children, remove_object(value))",
- on_type_updated: "fire_event('create')",
- shader: {
- name: "unit_shader",
- vertex: "
- uniform mat4 u_anura_mvp_matrix;
- attribute vec4 a_anura_vertex;
- attribute vec2 a_anura_texcoord;
- varying vec2 v_texcoord;
- void main()
- {
- v_texcoord = a_anura_texcoord;
- gl_Position = u_anura_mvp_matrix * a_anura_vertex;
- }
- ",
- fragment: "
- #version 120
- uniform sampler2D u_anura_tex_map;
- uniform float u_alpha;
- uniform bool u_flash;
- varying vec2 v_texcoord;
- void main()
- {
- vec4 col = texture2D(u_anura_tex_map, v_texcoord);
- if(u_flash) {
- col[0] = col[1] = col[2] = 1.0;
- }
- col[3] *= u_alpha;
- gl_FragColor = col;
- }
- ",
- create: "[
- ]",
- draw: "[
- set(uniform_commands.u_alpha, parent.alpha/255.0),
- set(uniform_commands.u_flash, parent.damage_flash),
- ]",
- },
- }
Advertisement
Add Comment
Please, Sign In to add comment