1{ 2 zorder: 2, 3 "animation": [ 4 { 5 "frames": 2, 6 "id": "flying", 7 "image": "copter.png", 8 "rect": [4,10,55,41], 9 solid_area: [10,10, 40, 20], 10 body_area: "all", 11 duration: 6 12 }, 13 { 14 "frames": 1, 15 "id": "spawning", 16 "image": "copter.png", 17 "rect": [0,0,1,1], 18 duration: 150 19 } 20 ], 21 editor_info: { 22 category: "duxduo" 23 }, 24 vars: { 25 side: 2, 26 _fuel: 1000, 27 _money: 0, 28 _ammo: 20, 29 pending_purchase: null, 30 purchase_ready: 0, 31 carry: null, 32 respawn_x: 0, 33 respawn_y: 0 34 }, 35 properties: { 36 fuel: { get: "vars._fuel", set: "set(vars._fuel, median(0, value, max_fuel))" }, 37 max_fuel: "1000", 38 ammo: { get: "vars._ammo", set: "set(vars._ammo, median(0, value, max_ammo))" }, 39 max_ammo: "20", 40 money: { get: "vars._money", set: "set(vars._money, value)" }, 41 42 buy: "def(type, amount) if(self.money >= cost and (not vars.pending_purchase), 43 [set(message_label.text, 'building ' + type), schedule(amount*5, fire_event(self, 'purchase_ready')), set(self.vars.purchase_ready, self.cycle + amount*5),add(self.money, -cost), set(self.vars.pending_purchase, object(type, 0, 0, 1))]) where cost = amount*100", 44 45 gui: "find(level.chars, value.type = 'gui_controller')", 46 message_label: "get_widget(gui, 'message_label')", 47 48 die_and_respawn: "def() [spawn('explosion_big_dusty', mid_x, mid_y, facing), 49 set(me.xy, [vars.respawn_x, vars.respawn_y]), 50 set(me.fuel, max_fuel), 51 set(me.ammo, max_ammo), 52 set(me.hitpoints, max_hitpoints) 53 /*set(animation, 'spawning')*/]", 54 get_hit: "def(hit_by) if(me.hitpoints <= hit_by.damage, die_and_respawn(), 55 [add(me.hitpoints, -hit_by.damage), 56 add(me.velocity_x, (3*hit_by.velocity_x*hit_by.damage)/100), 57 add(me.velocity_y, (3*hit_by.velocity_y*hit_by.damage)/100)])", 58 ctrl_up: "mid_y > level.local_player.mid_y or ammo = 0", 59 ctrl_down: "false", 60 ctrl_left: "mid_x > level.local_player.mid_x+500 and ammo > 0", 61 ctrl_right: "mid_x < level.local_player.mid_x-500 or ammo = 0", 62 ctrl_tongue: "facing < 0 and level.local_player.mid_x > mid_x or facing > 0 and level.local_player.mid_x < mid_x", 63 64 }, 65 on_create: "[set(vars.respawn_x, x), set(vars.respawn_y, y)]", 66 on_collide_feet: "[if(velocity_y > 200, set(velocity_y, -velocity_y/10))]", 67 68 on_process: "resolve_solid(me, 0, 2)", 69 on_die: "die_and_respawn()", 70 71 "hitpoints": 100, 72 "id": "ai_chopper", 73 always_active: true, 74 "mass": 3, 75 friction: 2000, 76 traction_in_air: 1000, 77 on_spawn_unit: "if(spawner, spawn(choose(['tank', 'infantry', 'sam', 'cannon', 'artillery']), spawner.mid_x - 150, spawner.mid_y, -1)) where spawner = choose(filter(level.chars, value.type = 'base' and value.vars.side = vars.side and abs(value.mid_x - level.local_player.mid_x) > 800))", 78 on_process_flying: "[ 79 if(cycle%500 = 0, fire_event('spawn_unit')), 80 if(abs(mid_x - level.local_player.mid_x) < 600 and 1d100 < 10, fire_event('ctrl_jump')), if(ctrl_tongue, fire_event('ctrl_tongue')), add(money, 10*size(filter(level.chars, value.type = 'base' and value.vars.side = vars.side))), 81 if(velocity_y >= 0 and standing_on and standing_on.type = 'base' and standing_on.vars.side = vars.side, 82 [if(hitpoints < max_hitpoints, add(hitpoints, 1)), add(fuel, 5), add(ammo, 1)]), 83 if(lift, add(fuel, -2)), 84 set(accel_y, 10 + ctrl_down*40 - lift*50), 85 set(accel_x, 30*if(facing > 0, ctrl_right, ctrl_left) - 86 20*if(facing < 0, ctrl_right, ctrl_left)), 87 if(rotate < target_rotation, add(rotate, 1), 88 if(rotate > target_rotation, add(rotate, -1))) 89 where target_rotation = facing*accel_x/4, 90 if(lift, add(time_in_animation, 1)), 91 if(y < level.dimensions[1] and velocity_y < 0, 92 [set(velocity_y, 400)]), 93 if(fuel = 0, die_and_respawn())] 94 where lift = ctrl_up and fuel > 0", 95 on_ctrl_tongue: "if(animation = 'flying', set(facing, -facing))", 96 on_ctrl_jump: "if(animation = 'flying' and (not is_standing) and ammo > 0, [add(ammo, -1), spawn('missile', midpoint_x, midpoint_y+10, facing, [set(child.scale, 0.5), set(child.vars.damage, 10), set(child.vars.side, vars.side)])])", 97 on_ctrl_attack: "if(animation = 'flying', [if(vars.carry = null and standing_on and standing_on.type = 'base' and standing_on.vars.side = vars.side and vars.pending_purchase and cycle > vars.purchase_ready, 98 //picking up a unit from base 99 [set(message_label.text, ''), 100 set(vars.carry, vars.pending_purchase), 101 set(vars.pending_purchase.side, vars.side), 102 set(vars.pending_purchase, null), 103 set(scale, 1.5), 104 ], 105 106 //see if we can pick somebody up from the battlefield 107 if(vars.carry = null and nearby_friendly, 108 [set(vars.carry, nearby_friendly), 109 remove_object(nearby_friendly), 110 set(scale, 1.5)]) 111 where nearby_friendly = find(level.chars, value.side = vars.side and (not (value.type in ['base', 'chopper', 'missile'])) and abs(mid_x - value.mid_x) < 50 and abs(mid_y - value.mid_y) < 100) 112 ), 113 if(vars.carry, [set(vars.carry.mid_x, mid_x), 114 set(vars.carry.mid_y, mid_y), 115 set(vars.carry.facing, facing), 116 add_object(vars.carry), 117 set(vars.carry, null), 118 set(scale, 1.0)])])", 119 on_end_flying_anim: "set(animation, 'flying')", 120 on_end_spawning_animation: "set(animation, 'flying')" 121} 122