diff --git a/characters/wise_alpaca/wise_alpaca.gd b/characters/wise_alpaca/wise_alpaca.gd index 5cecdf2..4279e1e 100644 --- a/characters/wise_alpaca/wise_alpaca.gd +++ b/characters/wise_alpaca/wise_alpaca.gd @@ -4,57 +4,43 @@ extends Area2D -# member variables here, example: -# var a=2 -# var b="textvar" - -export(String) var hint="It's dangerous outside. Take this JetPack." +export(String) var hint = "It's dangerous outside. Take this Jetpack." var side_right = true func _process(delta): - var cc = get_closest_character() - - if (false and cc): - + + if false and cc: var looking_right = (cc.get_global_pos().x > get_global_pos().x) - if (looking_right != side_right): - side_right=looking_right - if (side_right): - get_node("body").set_scale( Vector2(1,1) ) + if looking_right != side_right: + side_right = looking_right + if side_right: + get_node("body").set_scale(Vector2(1, 1)) else: - get_node("body").set_scale( Vector2(-1,1) ) - + get_node("body").set_scale(Vector2(-1, 1)) func get_closest_character(): - var clist = get_tree().get_nodes_in_group("character") var d = 1.0e10 - var retc=null + var retc = null for c in clist: - var ld = (get_global_pos()-c.get_global_pos()).length() - if (ld-MAX_SPEED): - lv.y-=RAISE_ACCEL*state.get_step() + if lv.y > -MAX_SPEED: + lv.y -= RAISE_ACCEL*state.get_step() state.set_linear_velocity(lv) - + for i in range(state.get_contact_count()): var co = state.get_contact_collider_object(i) - if (not co or not (co extends RigidBody2D)): + if not co or not (co extends RigidBody2D): pop() - - #get_node("anim").play("appear") -func _on_timeout(): - get_parent().call_deferred("remove_and_delete_child",self) - +func _on_timeout(): + get_parent().call_deferred("remove_and_delete_child", self) + func _on_enter_screen(): get_node("anim").set_active(true) set_mode(MODE_CHARACTER) @@ -52,16 +42,8 @@ func _on_enter_screen(): func _on_exit_screen(): get_node("anim").set_active(false) set_mode(MODE_STATIC) - - + func _enter_tree(): get_node("anim").play("appear") get_node("anim").queue("wobble") get_node("anim").set_active(false) - - - - - - - diff --git a/enemies/cannon/cannon.gd b/enemies/cannon/cannon.gd index 6240681..0a733e3 100644 --- a/enemies/cannon/cannon.gd +++ b/enemies/cannon/cannon.gd @@ -4,63 +4,53 @@ extends StaticBody2D -# member variables here, example: -# var a=2 -# var b="textvar" +const TYPE_MISSILE = 0 +const TYPE_SEEKER = 1 +const TYPE_BUBBLE = 2 -const TYPE_MISSILE=0 -const TYPE_SEEKER=1 -const TYPE_BUBBLE=2 - -export(int) var interval=2.0 -export(int) var max_alive=4 -export(int,"missile","heatseeker","bubbles") var type=0 +export(int) var interval = 2.0 +export(int) var max_alive = 4 +export(int, "missile", "heatseeker", "bubbles") var type = 0 +var alive = 0 func _killed_one(): - alive-=1 - -var alive=0 + alive -= 1 func _on_timeout(): - get_node("anim").play("firing") get_node("anim").queue("idle") func fire(): - print("TIMEOUT") get_node("timer").set_wait_time(interval) get_node("timer").start() - if (alive>=max_alive): + if alive >= max_alive: return - + var t = get_global_transform() - var s + var spawn var dir = -t[0] var pos = get_node("cannon_sprites_r90/cannon_rotation/body_orientation/missile2d").get_global_pos() var ofs = 0 - - if (type==TYPE_SEEKER or type==TYPE_MISSILE): - s=preload("res://enemies/cannon/heatseeker.tscn").instance() - s.set_rot( t.get_rotation() ) - s.set_seek_heat(type==TYPE_SEEKER) - elif (type==TYPE_BUBBLE): - s=preload("res://enemies/cannon/bubble.tscn").instance() - ofs=128 - - var p=get_parent() - while(p extends CanvasItem): - p=get_parent() - - s.set_pos(pos+dir*ofs) - p.add_child(s) - s.connect("exit_scene",self,"_killed_one") - alive+=1 - + if type == TYPE_SEEKER or type == TYPE_MISSILE: + spawn = preload("res://enemies/cannon/heatseeker.tscn").instance() + spawn.set_rot(t.get_rotation()) + spawn.set_seek_heat(type == TYPE_SEEKER) + elif type == TYPE_BUBBLE: + spawn = preload("res://enemies/cannon/bubble.tscn").instance() + ofs = 128 + var parent = get_parent() + while parent extends CanvasItem: + parent = get_parent() + + spawn.set_pos(pos + dir*ofs) + parent.add_child(spawn) + spawn.connect("exit_scene", self, "_killed_one") + alive += 1 func _on_enter_screen(): get_node("timer").set_wait_time(interval) @@ -71,11 +61,6 @@ func _on_exit_screen(): get_node("timer").stop() get_node("anim").set_active(false) - func _ready(): - # Initalization here get_node("anim").play("idle") get_node("anim").set_active(false) - pass - - diff --git a/enemies/cannon/heatseeker.gd b/enemies/cannon/heatseeker.gd index 2c17785..f4e6640 100644 --- a/enemies/cannon/heatseeker.gd +++ b/enemies/cannon/heatseeker.gd @@ -4,73 +4,50 @@ extends "res://enemies/enemy.gd" -# member variables here, example: -# var a=2 -# var b="textvar" +const FOLLOW_SPEED = 450 +const FOLLOW_ACCEL = 2.5 +const TURN_SPEED = 5 -const FOLLOW_SPEED=450 -const FOLLOW_ACCEL=2.5 -const TURN_SPEED=5 - -export(bool) var seek_heat=true +export(bool) var seek_heat = true func set_seek_heat(seek): - seek_heat=seek + seek_heat = seek func _integrate_forces(state): - - var lv=state.get_linear_velocity() - var vel =lv.length() - var cc=get_closest_character() - var t = state.get_transform() - if (cc and seek_heat): - - if (cc.is_jetpack_on()): - var cvec=(cc.get_global_pos() - t.get_origin()).normalized() - var lvec= -t[0].normalized() - var vel=lv.length() - var a = atan2(lvec.tangent().dot(cvec),lvec.dot(cvec)) - t=t.rotated(a*state.get_step()*TURN_SPEED) + var lv = state.get_linear_velocity() + var vel = lv.length() + var cc = get_closest_character() + var t = state.get_transform() + if cc and seek_heat: + if cc.is_jetpack_on(): + var cvec = (cc.get_global_pos() - t.get_origin()).normalized() + var lvec = -t[0].normalized() + var vel = lv.length() + var a = atan2(lvec.tangent().dot(cvec), lvec.dot(cvec)) + t = t.rotated(a*state.get_step()*TURN_SPEED) state.set_transform(t) - - vel+=FOLLOW_ACCEL - if (vel>FOLLOW_SPEED): - vel=FOLLOW_SPEED - lv=-t[0].normalized()*vel + vel += FOLLOW_ACCEL + if vel > FOLLOW_SPEED: + vel = FOLLOW_SPEED + lv = -t[0].normalized()*vel state.set_linear_velocity(lv) state.set_angular_velocity(0) - - if (state.get_contact_count()): #explode at first contact + + if state.get_contact_count(): # Explode at first contact for i in range(state.get_contact_count()): var co = state.get_contact_collider_object(i) if co and co.has_method("attacked"): - co.call("attacked",self) - - - explode() - - + co.call("attacked", self) + explode() func _on_enter_screen(): set_mode(MODE_RIGID) get_node("particles").set_emitting(true) - func _on_exit_screen(): - #set_mode(MODE_STATIC) - #get_node("particles").set_emitting(false) - queue_free() - - pass - - func _ready(): - # Initalization here set_can_sleep(false) - - - diff --git a/enemies/enemy.gd b/enemies/enemy.gd index 888a992..27eee26 100644 --- a/enemies/enemy.gd +++ b/enemies/enemy.gd @@ -4,16 +4,13 @@ extends RigidBody2D +const DROP_NONE = 0 +const DROP_HEART = 1 +const DROP_KEY1 = 2 +const DROP_KEY2 = 3 +const DROP_KEY3 = 4 -const DROP_NONE=0 -const DROP_HEART=1 -const DROP_KEY1=2 -const DROP_KEY2=3 -const DROP_KEY3=4 - - - -export(int,"None","Heart","Key1","Key2","Key3") var drop=DROP_NONE +export(int, "None", "Heart", "Key1", "Key2", "Key3") var drop = DROP_NONE var explosion = null func inflicts_damage(): @@ -23,19 +20,17 @@ func takes_damage(): return false func get_closest_character(): - var clist = get_tree().get_nodes_in_group("character") var d = 1.0e10 - var retc=null + var retc = null for c in clist: - var ld = (get_global_pos()-c.get_global_pos()).length() - if (ld FLUFF_FOLLOW_DISTANCE): + if cc: + if not spiked and cdist > FLUFF_FOLLOW_DISTANCE: var v = lv.length() v -= state.get_step()*FLUFF_AIR_FRICTION - if (v<0): - v=0 - lv = lv.normalized()*v + if v < 0: + v = 0 + lv = lv.normalized()*v else: var strength = 40 var lvl = lv.length() var maxvel - if (fluff_type==FLUFF_TYPE_FAST_FOLLOW): - maxvel=FLUFF_FAST_FOLLOW_MAX_VEL + if fluff_type == FLUFF_TYPE_FAST_FOLLOW: + maxvel = FLUFF_FAST_FOLLOW_MAX_VEL else: - maxvel=FLUFF_FOLLOW_MAX_VEL - if (spiked or lvl0): - spikes_banned-=state.get_step() - - - if (action_time<0 and get_node("anim").get_current_animation()!="spike_burst"): - - #print("SWITCH TO SLEEP") - if (spiked): + spiked = true + action_time = ATTACK_TIME + if spikes_banned > 0: + spikes_banned -= state.get_step() + + if action_time < 0 and get_node("anim").get_current_animation() != "spike_burst": + #print("SWITCH TO SLEEP") + if spiked: get_node("anim").play("spike_retract") - spiked=false - action_time=FOLLOW_TIME + spiked = false + action_time = FOLLOW_TIME get_node("anim").queue("awake_loop") - spikes_banned=SPIKE_BAN_TIME + spikes_banned = SPIKE_BAN_TIME else: - action_time=SLEEP_TIME+rand_range(0,SLEEP_RANDOM_TIME) - - get_node("anim").play("to_sleep") + action_time = SLEEP_TIME + rand_range(0, SLEEP_RANDOM_TIME) + + get_node("anim").play("to_sleep") get_node("anim").queue("sleep_loop") - sleeping=true - spikes_banned=0 - - - - - - + sleeping = true + spikes_banned = 0 + state.set_linear_velocity(lv) - - -func _on_body_enter( body_id, body ): - if (body extends preload("res://player/alpaca.gd")): +func _on_body_enter(body_id, body): + if body extends preload("res://player/alpaca.gd"): body.hit_begin() - -func _on_body_exit( body_id, body ): - pass # replace with function body - if (body extends preload("res://player/alpaca.gd")): +func _on_body_exit(body_id, body): + if body extends preload("res://player/alpaca.gd"): body.hit_end() func _on_enter_screen(): set_mode(MODE_CHARACTER) - disabled=false - current_anim="" + disabled = false + current_anim = "" # get_node("smoke").set_emitting(true) #set_sleeping(false) get_node("anim").set_active(true) - func _on_exit_screen(): set_mode(MODE_STATIC) - disabled=true + disabled = true get_node("anim").set_active(false) #get_node("smoke").set_emitting(false) - - -func _ready(): - # Initalization here - pass - - diff --git a/enemies/frog/frog.gd b/enemies/frog/frog.gd index a382145..a3c866f 100644 --- a/enemies/frog/frog.gd +++ b/enemies/frog/frog.gd @@ -4,163 +4,149 @@ extends "res://enemies/enemy.gd" -# member variables here, example: -# var a=2 -# var b="textvar" - - -const STATUS_IDLE=0 -const STATUS_JUMP_PREPARE=1 -const STATUS_JUMP_UP=2 -const STATUS_JUMP_FALLING=3 -const STATUS_ADVANCING=4 -const STATUS_DYING=5 +const STATUS_IDLE = 0 +const STATUS_JUMP_PREPARE = 1 +const STATUS_JUMP_UP = 2 +const STATUS_JUMP_FALLING = 3 +const STATUS_ADVANCING = 4 +const STATUS_DYING = 5 const WALK_SPEED = 200.0 const STOP_SPEED = 2000.0 -var timeout=0 -var anim="" -var siding = -1.0 +export(bool) var can_move = false +var timeout = 0 +var anim = "" + +var siding = -1.0 var status = STATUS_IDLE -export(bool) var can_move=false -var jump_go_up=false -var damaging=false +var jump_go_up = false +var damaging = false func propel_up(): - jump_go_up=true + jump_go_up = true func begin_damage(): - damaging=true + damaging = true func inflicts_damage(): return damaging func takes_damage(): - return not damaging and status!=STATUS_DYING - + return not damaging and status != STATUS_DYING + func squatted(): explode() - + func attacked(bywho): + if not damaging and status != STATUS_DYING: + status = STATUS_DYING - if (not damaging and status!=STATUS_DYING): - status=STATUS_DYING +func _integrate_forces(state): + var lv = state.get_linear_velocity() + var new_anim = "" -func _integrate_forces(state): + if status == STATUS_IDLE: + new_anim = "idle" + lv.x = dectime(lv.x, STOP_SPEED, state.get_step()) - var lv = state.get_linear_velocity() - - var new_anim="" - - if (status==STATUS_IDLE): - new_anim="idle" - lv.x=dectime(lv.x,STOP_SPEED,state.get_step()) - - - if (lv.y<0): - lv.y=0 + if lv.y < 0: + lv.y = 0 else: - lv.y+=300.0*state.get_step() + lv.y += 300.0*state.get_step() var c = get_closest_character() - if (c): + if c: var dvec = c.get_global_pos() - state.get_transform().get_origin() - if (abs(dvec.x) < 100 and ( dvec.y<0 and dvec.y < 500)): - status=STATUS_JUMP_PREPARE - jump_go_up=false - new_anim="jump_begin" - - timeout-=state.get_step() - if (status==STATUS_IDLE and timeout<0): - if (randi()%2==0): - siding=-1.0 - get_node("body").set_scale(Vector2(1,1)) + if abs(dvec.x) < 100 and dvec.y < 0 and dvec.y < 500: + status = STATUS_JUMP_PREPARE + jump_go_up = false + new_anim = "jump_begin" + + timeout -= state.get_step() + if status == STATUS_IDLE and timeout < 0: + if randi() % 2 == 0: + siding = -1.0 + get_node("body").set_scale(Vector2(1, 1)) else: - siding=1.0 - get_node("body").set_scale(Vector2(-1,1)) - - status=STATUS_ADVANCING + siding = 1.0 + get_node("body").set_scale(Vector2(-1, 1)) + + status = STATUS_ADVANCING set_friction(0) - timeout=3.0 - elif (status==STATUS_ADVANCING): - new_anim="walk" - timeout-=state.get_step() - if (can_move): - lv.x=siding*WALK_SPEED + timeout = 3.0 + + elif status == STATUS_ADVANCING: + new_anim = "walk" + timeout -= state.get_step() + if can_move: + lv.x = siding*WALK_SPEED else: - lv.x=dectime(lv.x,STOP_SPEED,state.get_step()) - - if (lv.y<0): - lv.y=0 + lv.x = dectime(lv.x, STOP_SPEED, state.get_step()) + + if lv.y < 0: + lv.y = 0 else: - lv.y+=300.0*state.get_step() - - if (timeout<0): - status=STATUS_IDLE - timeout=3 + lv.y += 300.0*state.get_step() + + if timeout < 0: + status = STATUS_IDLE + timeout = 3 set_friction(1) - elif (status==STATUS_JUMP_PREPARE): - new_anim=anim # keep - if (jump_go_up): - jump_go_up=false - lv.y=-500 - lv.x=siding*100.0 - status=STATUS_JUMP_UP + + elif status == STATUS_JUMP_PREPARE: + new_anim = anim # keep + if jump_go_up: + jump_go_up = false + lv.y = -500 + lv.x = siding*100.0 + status = STATUS_JUMP_UP get_node("anim").play("jump_begin") - elif (status==STATUS_JUMP_UP): - anim="burst_fall" - new_anim="burst_fall" - if (not get_node("anim").is_active()): - status=STATUS_JUMP_FALLING + + elif status == STATUS_JUMP_UP: + anim = "burst_fall" + new_anim = "burst_fall" + if not get_node("anim").is_active(): + status = STATUS_JUMP_FALLING get_node("anim").play("burst") get_node("anim").queue("burst_fall") - elif (status==STATUS_JUMP_FALLING): - new_anim=anim # keep - var found_floor=false + + elif status == STATUS_JUMP_FALLING: + new_anim = anim # keep + var found_floor = false for i in range(state.get_contact_count()): var co = state.get_contact_collider_object(i) - if (co and co extends preload("res://player/alpaca.gd")): + if co and co extends preload("res://player/alpaca.gd"): continue var n = state.get_contact_local_normal(i) - print("cn",n) - if (n.y < -0.507): - found_floor=true + print("cn", n) + if n.y < -0.507: + found_floor = true break - - if (found_floor): - status=STATUS_IDLE - damaging=false - new_anim="idle" - - elif (status==STATUS_DYING): - if (anim!="croak"): - lv.y=500 - new_anim="croak" - - - - + + if found_floor: + status = STATUS_IDLE + damaging = false + new_anim = "idle" + + elif status == STATUS_DYING: + if anim != "croak": + lv.y = 500 + new_anim = "croak" + state.set_linear_velocity(lv) - - if (anim!=new_anim): + + if anim != new_anim: get_node("anim").play(new_anim) - anim=new_anim + anim = new_anim func _on_enter_screen(): get_node("anim").set_active(true) set_mode(MODE_CHARACTER) set_sleeping(false) - + func _on_exit_screen(): get_node("anim").set_active(false) set_mode(MODE_STATIC) - - -func _ready(): - # Initalization here - pass - - diff --git a/enemies/snake/snake.gd b/enemies/snake/snake.gd index a6ad129..ed90975 100644 --- a/enemies/snake/snake.gd +++ b/enemies/snake/snake.gd @@ -4,110 +4,79 @@ extends "res://enemies/enemy.gd" -# member variables here, example: -# var a=2 -# var b="textvar" - const ROLE_HEAD = 0 const ROLE_MIDDLE = 1 const ROLE_TAIL = 2 -const DIR_CHANGE_TIMEOUT=3.0 +const DIR_CHANGE_TIMEOUT = 3.0 const TARGET_SPEED = 80.0 const TURN_SPEED = 80.0 const ATTACK_DISTANCE = 500.0 -export(int,"Head","Middle","Tail") var role=0 +export(int, "Head", "Middle", "Tail") var role = 0 -var target_a=randf()*PI*2.0 +var target_a = randf()*PI*2.0 -var timeout=4.0 +var timeout = 4.0 func _on_enter_screen(): - set_sleeping(false) - func _on_exit_screen(): - set_sleeping(true) func _integrate_forces(state): - var lv= state.get_linear_velocity() var av = state.get_angular_velocity() - if (role==ROLE_HEAD): - - - #var d = lv.normalized() - var s=TARGET_SPEED - - - #print("d ",d," s ",s) - #var dvec = state.get_transform()[1] - #lv-=dvec*dvec.dot(lv) - - var t = state.get_transform() - - var ta=target_a - - var cc = get_closest_character(); - - if (cc): + if role == ROLE_HEAD: + var s = TARGET_SPEED + var t = state.get_transform() + var ta = target_a + var cc = get_closest_character() + + if cc: var cpos = cc.get_global_pos() - var cposd=cpos.distance_to(t.get_origin()) - - if (cposd a): - rdist=ta-a + if ta > a: + rdist = ta - a else: - rdist=(2.0*PI+ta)-a + rdist = 2.0*PI + ta -a - if (rdist<0.1 or rdist>2*PI-0.1): - - av=0 - elif (rdist>PI): - av=state.get_step()*TURN_SPEED + if rdist < 0.1 or rdist > 2*PI - 0.1: + av = 0 + elif rdist > PI: + av = state.get_step()*TURN_SPEED else: - av=-state.get_step()*TURN_SPEED + av = -state.get_step()*TURN_SPEED lv = -t[1]*s - - timeout-=state.get_step() - if (timeout<0): - target_a=randf()*PI*2.0 - timeout=DIR_CHANGE_TIMEOUT - - - else: - + + timeout -= state.get_step() + if timeout < 0: + target_a = randf()*PI*2.0 + timeout = DIR_CHANGE_TIMEOUT + + else: var d = lv.normalized() var s = lv.length() - + s -= 500.0 * state.get_step() - if (s<0): - s=0 + if s < 0: + s = 0 lv = d*s av = 0 - + state.set_linear_velocity(lv) state.set_angular_velocity(av) - - func _init(): set_sleeping(true) func _ready(): - # Initalization here set_use_custom_integrator(true) - set_friction(0) - - pass - - diff --git a/enemies/spikes/spikes.gd b/enemies/spikes/spikes.gd index e66a3f0..8a77ffe 100644 --- a/enemies/spikes/spikes.gd +++ b/enemies/spikes/spikes.gd @@ -13,10 +13,10 @@ func _ready(): func _on_body_enter(body): if body extends preload("res://player/alpaca.gd"): - if !tutorial_mode: + if not tutorial_mode: body.hit_begin() func _on_body_exit(body): if body extends preload("res://player/alpaca.gd"): - if !tutorial_mode: + if not tutorial_mode: body.hit_end() diff --git a/enemies/spore_flower/sporadic_flower.gd b/enemies/spore_flower/sporadic_flower.gd index 03d56e5..8a1e1fa 100644 --- a/enemies/spore_flower/sporadic_flower.gd +++ b/enemies/spore_flower/sporadic_flower.gd @@ -4,112 +4,90 @@ extends "res://enemies/enemy.gd" -# member variables here, example: -# var a=2 -# var b="textvar" - - const STATUS_PREPARE = 0 -const STATUS_SPITTING = 1 +const STATUS_SPITTING = 1 const STATUS_STOPPED_SPITTING = 2 const STATUS_WAITING_SEEDS = 3 const STATUS_IDLE = 4 -var active_seeds=0 -var timeout=0.0 - -var status = STATUS_IDLE - const SPIT_TIME = 2 const STOP_SPIT_TIME = 1 const SPIT_INTERVAL = 0.1 -var spores = [] +var active_seeds = 0 +var timeout = 0.0 -var spit_timeout=0 +var status = STATUS_IDLE +var spores = [] +var spit_timeout = 0 func _seed_died(): - active_seeds-=1 + active_seeds -= 1 func _process(delta): - - - if (status==STATUS_IDLE): - + if status == STATUS_IDLE: var cc = get_closest_character() - if (cc): + if cc: var gt = get_global_transform() var ct = cc.get_global_transform() var dp = -gt[1].dot((ct.get_origin() - gt.get_origin()).normalized()) var d = ct.get_origin().distance_to(gt.get_origin()) - - if (dp > 0.2 and d < 500): - status=STATUS_PREPARE - spores=[] - timeout=SPIT_TIME - spit_timeout=SPIT_INTERVAL + + if dp > 0.2 and d < 500: + status = STATUS_PREPARE + spores = [] + timeout = SPIT_TIME + spit_timeout = SPIT_INTERVAL get_node("anim").play("2opening") get_node("anim").queue("3opened") - - elif (status==STATUS_PREPARE): - - if (get_node("anim").get_current_animation()=="3opened"): - status=STATUS_SPITTING - elif (status==STATUS_SPITTING): - - timeout-=delta - spit_timeout-=delta - while(spit_timeout<0): - spit_timeout+=SPIT_INTERVAL + + elif status == STATUS_PREPARE: + if get_node("anim").get_current_animation()=="3opened": + status = STATUS_SPITTING + + elif status == STATUS_SPITTING: + timeout -= delta + spit_timeout -= delta + while spit_timeout < 0: + spit_timeout += SPIT_INTERVAL print("SPIT!!") var s = preload("res://enemies/spore_flower/spore.tscn") var sp = s.instance() - sp.set_pos( get_node("shooter").get_global_pos() ) - sp.connect("exit_scene",self,"_seed_died") - var outvec = -get_global_transform()[1] - outvec = Matrix32().rotated( (randf() *2.0 -1.0)*PI*0.5 ).xform(outvec) - - sp.set_linear_velocity( outvec * (200.0+400*randf()) ) + sp.set_pos(get_node("shooter").get_global_pos()) + sp.connect("exit_scene", self, "_seed_died") + var outvec = -get_global_transform()[1] + outvec = Matrix32().rotated((randf()*2.0 - 1.0)*PI*0.5).xform(outvec) + + sp.set_linear_velocity(outvec*(200.0 + 400*randf())) get_parent().add_child(sp) spores.push_back(sp) - active_seeds+=1 - - if (timeout<0): - status=STATUS_STOPPED_SPITTING - timeout=STOP_SPIT_TIME + active_seeds += 1 - elif (status==STATUS_STOPPED_SPITTING): + if timeout < 0: + status = STATUS_STOPPED_SPITTING + timeout = STOP_SPIT_TIME - timeout-=delta - if (timeout<0): - status=STATUS_WAITING_SEEDS + elif status == STATUS_STOPPED_SPITTING: + timeout -= delta + if timeout < 0: + status = STATUS_WAITING_SEEDS for x in spores: - x.activate() # activate all spores + x.activate() # Activate all spores get_node("anim").play("4closing") get_node("anim").queue("1closed") - - elif (status==STATUS_WAITING_SEEDS): - if (active_seeds==0): - status=STATUS_IDLE - - + elif status == STATUS_WAITING_SEEDS: + if active_seeds == 0: + status = STATUS_IDLE func _on_enter_screen(): - get_node("anim").set_active(true) set_process(true) - func _on_exit_screen(): - get_node("anim").set_active(false) set_process(false) - func _ready(): - # Initalization here get_node("anim").play("1closed") get_node("anim").set_active(false) - pass - diff --git a/enemies/spore_flower/spore.gd b/enemies/spore_flower/spore.gd index 563f4be..92e940f 100644 --- a/enemies/spore_flower/spore.gd +++ b/enemies/spore_flower/spore.gd @@ -4,11 +4,6 @@ extends "res://enemies/enemy.gd" -# member variables here, example: -# var a=2 -# var b="textvar" - - const STATUS_CREATED = 1 const STATUS_SPIKY = 2 const STATUS_DYING = 3 @@ -19,74 +14,57 @@ const DYING_TIME = 2 const AIR_FRICTION = 150 const STOP_FRICTION = 300 +const FALL_SPEED = 1400 var status = STATUS_CREATED -var timeout=2 -const FALL_SPEED = 1400 +var timeout = 2 -var spr=null +var spr = null func activate(): - if (status==STATUS_CREATED): - status=STATUS_SPIKY - timeout=SPIKY_TIME+randf()*SPIKY_RAND_TIME + if status == STATUS_CREATED: + status = STATUS_SPIKY + timeout = SPIKY_TIME + randf()*SPIKY_RAND_TIME get_node("anim").play("spike") get_node("anim").queue("fall") - func inflicts_damage(): - return spr.get_frame()==2 + return spr.get_frame() == 2 func _integrate_forces(state): + timeout -= state.get_step() - - timeout-=state.get_step() - - if (status==STATUS_CREATED): - + if status == STATUS_CREATED: var lv = state.get_linear_velocity() var v = lv.length() v -= state.get_step()*AIR_FRICTION - if (v<0): - v=0 + if v < 0: + v = 0 lv = lv.normalized()*v state.set_linear_velocity(lv) - - elif (status==STATUS_SPIKY): - - + + elif status == STATUS_SPIKY: var lv = state.get_linear_velocity() var v = lv.length() v -= state.get_step()*STOP_FRICTION - if (v<0): - v=0 + if v < 0: + v = 0 lv = lv.normalized()*v - lv.y=FALL_SPEED*state.get_step() + lv.y = FALL_SPEED*state.get_step() state.set_linear_velocity(lv) - - if (timeout<0): - status=STATUS_DYING - timeout=DYING_TIME + + if timeout < 0: + status = STATUS_DYING + timeout = DYING_TIME get_node("anim").play("dissolve") - - elif (status==STATUS_DYING): - - var so = timeout/DYING_TIME + elif status == STATUS_DYING: + + var so = timeout/DYING_TIME spr.set_self_opacity(so) - if (timeout<0): + if timeout < 0: queue_free() - - - - - - func _ready(): - # Initalization here - spr=get_node("sprite") - pass - - + spr = get_node("sprite") diff --git a/enemies/warrior/warrior.gd b/enemies/warrior/warrior.gd index 7efd76b..71e7764 100644 --- a/enemies/warrior/warrior.gd +++ b/enemies/warrior/warrior.gd @@ -4,176 +4,152 @@ extends "res://enemies/enemy.gd" -# member variables here, example: -# var a=2 -# var b="textvar" +const STATUS_IDLE = 0 +const STATUS_ATTACK = 1 +const STATUS_FLIPPING = 2 +const STATUS_TIRED = 3 +const STATUS_DAMAGED = 4 +const STATUS_DEAD = 5 -const STATUS_IDLE=0 -const STATUS_ATTACK=1 -const STATUS_FLIPPING=2 -const STATUS_TIRED=3 -const STATUS_DAMAGED=4 -const STATUS_DEAD=5 +var tired_time = 2.0 +var idle_time = 2.0 +var idle_countdown = 0.0 -var tired_time=2.0 -var idle_time=2.0 -var idle_countdown=0.0 +var tired_countdown = 0.0 -var tired_countdown=0.0 - -var status=STATUS_IDLE +var status = STATUS_IDLE var energy = 1 -var anim="" -var siding_left=true +var anim = "" +var siding_left = true + +var alpacas = [] +var others = [] func takes_damage(): - return status!=STATUS_ATTACK and status!=STATUS_DAMAGED and status !=STATUS_DEAD + return status != STATUS_ATTACK and status != STATUS_DAMAGED and status != STATUS_DEAD func inflicts_damage(): return false func attacked(bywho): - if (status==STATUS_IDLE): + if status == STATUS_IDLE: get_node("sprites/Rib/Chest/shield_orientation/ArmFG/ForearmFG/HandFG/Shield/fire").set_emitting(true) - anim="attack" - status=STATUS_ATTACK + anim = "attack" + status = STATUS_ATTACK get_node("anim").play("block") get_node("anim").queue("attack") - elif (energy>1): - status=STATUS_DAMAGED + elif energy > 1: + status = STATUS_DAMAGED get_node("anim").play("take_damage") - anim="take_damage" - energy-=1 + anim = "take_damage" + energy -= 1 else: - status=STATUS_DEAD + status = STATUS_DEAD get_node("anim").play("death") - anim="death" - - - - -var alpacas=[] -var others=[] + anim = "death" func _on_body_enter(body): - if (body extends preload("res://player/alpaca.gd")): + if body extends preload("res://player/alpaca.gd"): alpacas.push_back(body) - elif (body extends RigidBody): + elif body extends RigidBody: others.push_back(body) - func _on_body_exit(body): - if (body extends preload("res://player/alpaca.gd")): + if body extends preload("res://player/alpaca.gd"): alpacas.erase(body) - elif (body extends RigidBody): + elif body extends RigidBody: others.erase(body) - func _on_damage_enter(body): - if (body extends preload("res://player/alpaca.gd")): + if body extends preload("res://player/alpaca.gd"): body.hit_begin() - body.set_linear_velocity( (body.get_global_pos() - get_global_pos()).normalized()*700 ) - + body.set_linear_velocity((body.get_global_pos() - get_global_pos()).normalized()*700) func _on_damage_exit(body): - if (body extends preload("res://player/alpaca.gd")): + if body extends preload("res://player/alpaca.gd"): body.hit_end() func _do_flip(): - siding_left=!siding_left + siding_left = !siding_left var scale - if (siding_left): - scale=Vector2(1,1) + if siding_left: + scale = Vector2(1,1) else: - scale=Vector2(-1,1) + scale = Vector2(-1,1) get_node("sprites").set_scale(scale) func _integrate_forces(state): - var lv = state.get_linear_velocity() - var new_anim="" + var new_anim = "" var fixed_pos = true - if (status==STATUS_IDLE): - - new_anim="idle" - - idle_countdown-=state.get_step() - - if (alpacas.size() or others.size()): - - var attacking=false - + if status == STATUS_IDLE: + new_anim = "idle" + idle_countdown -= state.get_step() + + if alpacas.size() or others.size(): + var attacking = false + for a in alpacas: - if (a.is_attacking()): - attacking=true + if a.is_attacking(): + attacking = true var attackvec = (state.get_transform().get_origin() - a.get_global_pos()).normalized() - + var anglefix = -PI*0.5 - if (not siding_left): - anglefix=-anglefix - get_node("sprites/Rib/Chest/shield_orientation").set_rot(atan2(attackvec.x,attackvec.y)+anglefix) - idle_countdown=1.0 - - if (not attacking and idle_countdown<0): - status=STATUS_ATTACK - new_anim="attack" + if not siding_left: + anglefix = -anglefix + get_node("sprites/Rib/Chest/shield_orientation").set_rot(atan2(attackvec.x, attackvec.y) + anglefix) + idle_countdown = 1.0 + + if not attacking and idle_countdown < 0: + status = STATUS_ATTACK + new_anim = "attack" get_node("sprites/Rib/Chest/shield_orientation").set_rot(0) + else: - var cc = get_closest_character() - if ((cc.get_global_pos().x < get_global_pos().x) != siding_left): - status=STATUS_FLIPPING - new_anim="flipping" - - - - - - elif (status==STATUS_ATTACK): - new_anim="attack" - if (not get_node("anim").is_playing()): - status=STATUS_TIRED - tired_countdown=tired_time - elif (status==STATUS_TIRED): - tired_countdown-=state.get_step() - if (tired_countdown<0): - status=STATUS_IDLE - idle_countdown=idle_time - new_anim="tired" - elif (status==STATUS_FLIPPING): - if (!get_node("anim").is_playing()): - status=STATUS_IDLE - elif (status==STATUS_DAMAGED): - if (!get_node("anim").is_playing()): - status=STATUS_IDLE - elif (status==STATUS_DEAD): - if (!get_node("anim").is_playing()): + if (cc.get_global_pos().x < get_global_pos().x) != siding_left: + status = STATUS_FLIPPING + new_anim = "flipping" + + elif status == STATUS_ATTACK: + new_anim = "attack" + if not get_node("anim").is_playing(): + status = STATUS_TIRED + tired_countdown = tired_time + + elif status == STATUS_TIRED: + tired_countdown -= state.get_step() + if tired_countdown < 0: + status = STATUS_IDLE + idle_countdown = idle_time + new_anim = "tired" + + elif status == STATUS_FLIPPING: + if !get_node("anim").is_playing(): + status = STATUS_IDLE + + elif status == STATUS_DAMAGED: + if !get_node("anim").is_playing(): + status = STATUS_IDLE + + elif status == STATUS_DEAD: + if !get_node("anim").is_playing(): queue_free() - - if (fixed_pos): + + if fixed_pos: var lvlen = lv.length() - if (lvlen): + if lvlen: var lvn = lv.normalized() lvlen -= state.get_step()*1000.0 - if (lvlen<0): - lvlen=0 + if lvlen < 0: + lvlen = 0 lv = lvn * lvlen - - - + state.set_linear_velocity(lv) - if (new_anim!=anim): + if new_anim != anim: get_node("anim").play(new_anim) - anim=new_anim - -func _ready(): - # Initalization here -# var snode = get_node("sprites/Rib/Chest/ArmBG/ForearmBG/HandBG/Sword/damager/sword_solid").get_node() -# Physics2DServer.body_add_collision_exception(get_body(),snode.get_body()) - pass - - + anim = new_anim diff --git a/hud/crosshair.gd b/hud/crosshair.gd index 5670f66..fa19371 100644 --- a/hud/crosshair.gd +++ b/hud/crosshair.gd @@ -4,31 +4,16 @@ extends Node2D -# member variables here, example: -# var a=2 -# var b="textvar" - -var active=false - - +var active = false func lock(pos): - set_pos(pos) - if(not active): + if not active: get_node("anim").play("lock") get_node("anim").queue("rotate") - active=true - -func unlock(): + active = true - if(active): +func unlock(): + if active: get_node("anim").play("unlock") - active=false - - -func _ready(): - # Initalization here - pass - - + active = false diff --git a/hud/hud.gd b/hud/hud.gd index 6667b8f..389bce6 100644 --- a/hud/hud.gd +++ b/hud/hud.gd @@ -4,11 +4,7 @@ extends ReferenceFrame -# member variables here, example: -# var a=2 -# var b="textvar" - -const LIFE_MAX=2 +const LIFE_MAX = 2 func _on_pause_pressed(): if get_tree().is_paused(): @@ -20,14 +16,13 @@ func _on_pause_pressed(): #var gd = get_tree().get_root().get_node("game_data") #var wpc = gd.current_world.path #get_tree().get_root().get_node("main").goto_scene(wpc) - + func _on_back_pressed(): get_tree().set_pause(false) get_tree().get_root().get_node("main").goto_scene("res://menu/stage_select.tscn") - func hint_show(text): - get_node("anim").get_animation("fadein").track_set_key_value(0,1,text) + get_node("anim").get_animation("fadein").track_set_key_value(0, 1, text) get_node("anim").play("fadein") func hint_hide(): @@ -35,15 +30,14 @@ func hint_hide(): func set_energy(level): for x in range(LIFE_MAX): - var n = get_node("life/heart_"+str(x)) - if (xmax_speed): - speed=max_speed - - if (distance>0): - moved+=tomove - if (moved>target): - moved=target - done=true + var tomove = speed*delta + if speed < max_speed: + speed += 20*delta + if speed > max_speed: + speed = max_speed + + if distance > 0: + moved += tomove + if moved > target: + moved = target + done = true else: - moved-=tomove - if (movedmax_distance): + if get_closest_character_pos().distance_to(p.get_global_pos()) > max_distance: _reset() else: - get_tree().call_group(0,"_fire_triggers","set_on_fire",get_node("platform/trigger").get_global_pos()) - -func _reset(): + get_tree().call_group(0, "_fire_triggers", "set_on_fire", get_node("platform/trigger").get_global_pos()) +func _reset(): set_process(false) var p = get_node("platform") p.set_mode(RigidBody2D.MODE_STATIC) p.set_global_transform(get_global_transform()) p.set_linear_velocity(Vector2()) p.set_angular_velocity(0) - active=false + active = false func _ready(): _reset() - - + func _on_enter_screen(): get_node("platform/fire").set_emitting(true) - + func _on_enter_exit(): get_node("platform/fire").set_emitting(false) - - - - func _on_body_enter(body): - if (active): + if active: return - if (body extends preload("res://player/alpaca.gd")): + if body extends preload("res://player/alpaca.gd"): get_node("platform").set_mode(RigidBody2D.MODE_RIGID) get_node("platform").set_sleeping(false) # suspend - active=true + active = true set_process(true) - - - - - - diff --git a/interaction/platform/spinning_log.gd b/interaction/platform/spinning_log.gd index f2853d1..4ffff5e 100644 --- a/interaction/platform/spinning_log.gd +++ b/interaction/platform/spinning_log.gd @@ -4,17 +4,12 @@ extends StaticBody2D -# member variables here, example: -# var a=2 -# var b="textvar" - -var r=0 -var rnode=null +var r = 0 +var rnode = null func _process(delta): - r-=delta*get_constant_angular_velocity() + r -= delta*get_constant_angular_velocity() rnode.set_rot(r) - func _on_enter_screen(): set_process(true) @@ -23,8 +18,4 @@ func _on_exit_screen(): set_process(false) func _ready(): - # Initalization here - rnode=get_node("sprite") - pass - - + rnode = get_node("sprite") diff --git a/interaction/roulette/goal.gd b/interaction/roulette/goal.gd index 58831a0..dc461ed 100644 --- a/interaction/roulette/goal.gd +++ b/interaction/roulette/goal.gd @@ -4,20 +4,8 @@ extends Area2D -# member variables here, example: -# var a=2 -# var b="textvar" +export var next_world = Vector2() - -export var next_world=Vector2(0,0) - -func _on_body_enter( body ): - if (body extends preload("res://player/alpaca.gd")): +func _on_body_enter(body): + if body extends preload("res://player/alpaca.gd"): body.end_level(next_world) - - -func _ready(): - # Initalization here - pass - - diff --git a/interaction/roulette/roulette.gd b/interaction/roulette/roulette.gd index 7541928..64734a9 100644 --- a/interaction/roulette/roulette.gd +++ b/interaction/roulette/roulette.gd @@ -4,36 +4,18 @@ extends Node2D -var prize=0 -var ended=false +var prize = 0 +var ended = false func _on_body_enter(body): - if (not ended and body extends preload("res://player/alpaca.gd")): + if not ended and body extends preload("res://player/alpaca.gd"): get_node("anim").play("button") get_node("anim").queue("prize_select") - ended=true + ended = true func _random_select_prize(): - - prize=randi() % 6 - get_node("Ruleta/ruleta_select").set_rot( prize / 6.0 * 2.0 * PI ) # rotate randomly + prize = randi() % 6 + get_node("Ruleta/ruleta_select").set_rot(prize/6.0*2.0*PI) # Rotate randomly func _end_spin(): get_node("/root/main").goto_scene("res://menu/stage_select.tscn") - pass -# member variables here, example: -# var a=2 -# var b="textvar" - -#func _init(): - #get_node("anim").set_active(false) - - - -func _ready(): - # Initalization here - pass - - - - diff --git a/main.gd b/main.gd index b69d49f..57132e5 100644 --- a/main.gd +++ b/main.gd @@ -4,18 +4,15 @@ extends Node -var current_child=null -var next_scene="" -var current_scene=null -var current_scene_path="" - +var current_child = null +var next_scene = "" +var current_scene = null +var current_scene_path = "" func _load_scene(path): + print("load: ", path) - print("load: ",path) - - - var current = get_tree().get_root().get_child( get_tree().get_root().get_child_count() -1 ) + var current = get_tree().get_root().get_child(get_tree().get_root().get_child_count() - 1) get_tree().get_root().remove_child(current) print("LOAD: FREEING") current.free() @@ -32,36 +29,21 @@ func set_new_scene(scene_res): current_scene = scene_res var scene = scene_res.instance() printt("instanced scene ", scene, scene.get_filename()) - if (scene): + if scene: get_tree().get_root().add_child(scene) printt("added to tree") - func goto_scene(scene): - - next_scene=scene - call_deferred("_load_scene",scene) + next_scene = scene + call_deferred("_load_scene", scene) get_tree().set_pause(false) # get_node("anim").play("fadeout") # get_node("change").start() -func init(): - -# if (not get_tree().get_root().get_child(0)): -# goto_scene("res://menu/main_menu.tscn") - pass - func _ready(): - var vm = OS.get_video_mode_size() var rate = float(vm.x)/float(vm.y) - var height = int(1280.0 / rate) - get_tree().get_root().set_size_override(true,Vector2(1280,height)) + var height = int(1280.0/rate) + get_tree().get_root().set_size_override(true, Vector2(1280, height)) get_tree().get_root().set_size_override_stretch(true) - - - - - - diff --git a/menu/main_menu.gd b/menu/main_menu.gd index 433b2b7..f7711b1 100644 --- a/menu/main_menu.gd +++ b/menu/main_menu.gd @@ -11,12 +11,10 @@ func _ready(): func play_pressed(): get_tree().change_scene("res://menu/stage_select.tscn") - + func settings_pressed(): pass # TODO: make settings screen func _input(event): - if event.is_action("ui_accept") && event.pressed: + if event.is_action("ui_accept") and event.pressed: play_pressed() - - diff --git a/menu/stage_select.gd b/menu/stage_select.gd index d624e2b..b5cca13 100644 --- a/menu/stage_select.gd +++ b/menu/stage_select.gd @@ -10,7 +10,6 @@ onready var tabs = get_node("items/worlds") func _ready(): add_levels() - func add_levels(): var world_tabs = {} print("Adding levels...") @@ -19,45 +18,44 @@ func add_levels(): for level in game_data.levels: if !level.enabled: continue - + printt("Adding level", level.enabled, level.path) - + if !(level.id.x in world_tabs): var tab_center_container = CenterContainer.new() tab_center_container.set_name(str("World ", level.id[0])) tabs.add_child(tab_center_container) - + var tab_levels_grid = GridContainer.new() tab_levels_grid.set_columns(column_count) tab_center_container.add_child(tab_levels_grid) world_tabs[level.id.x] = tab_levels_grid - + var tab_levels_grid = world_tabs[level.id.x] - + var level_vbox = VBoxContainer.new() - + var level_button = Button.new() level_button.set_button_icon(load(level.preview_path)) - level_button.connect("pressed",self,"select_stage",[level]) + level_button.connect("pressed", self, "select_stage", [level]) level_vbox.add_child(level_button) - + var level_name = Label.new() level_name.set_align(Label.ALIGN_CENTER) level_name.set_text(level.name) level_name.add_font_override("font", preload("res://art/font.xfnt")) level_vbox.add_child(level_name) - + if !gave_focus: level_button.call_deferred("grab_focus") gave_focus = true - + tab_levels_grid.add_child(level_vbox) func select_stage(stage): game_data.current_world = stage -# get_tree().get_root().get_node("game_data").current_checkpoint=null +# get_tree().get_root().get_node("game_data").current_checkpoint = null get_tree().get_root().get_node("main").goto_scene(stage.path) - func back_pressed(): get_tree().change_scene("res://menu/main_menu.tscn") diff --git a/player/alpaca.gd b/player/alpaca.gd index a1a4310..811349a 100644 --- a/player/alpaca.gd +++ b/player/alpaca.gd @@ -4,867 +4,715 @@ extends RigidBody2D -var jpart_names=["body/culete/rocket_fg/jetpack_a","body/culete/rocket_bg/jetpack_b"] -var jpart_atk="body/culete/rocket_fg/jetpack_atk" +const CONTROL_TAP = 1 +const CONTROL_FULL = 2 -var enemy_class=preload("res://enemies/enemy.gd") +const FLY_FORCE = 400 +const HIT_INVINCIBILITY_TIME = 3 +const MAX_ENERGY = 2 -const CONTROL_TAP = 1 -const CONTROL_FULL = 2 +const ATTACK_SPEED = 950 +const ATTACK_DURATION = 0.7 # 0.8 +const ATTACK_PREPARE_DURATION = 0.15 +const ATTACK_SLIDE_TRESHOLD = 50 +const ATTACK_TIME_TRESHOLD = 0.4 -var control_mode=CONTROL_TAP +const enemy_class = preload("res://enemies/enemy.gd") +var jpart_names = ["body/culete/rocket_fg/jetpack_a", "body/culete/rocket_bg/jetpack_b"] +var jpart_atk = "body/culete/rocket_fg/jetpack_atk" + +var control_mode = CONTROL_TAP var moving_left = false var moving_right = false var attack_begin = false -var airborne_time=1000 +var airborne_time = 1000 -var anim ="" -var attack_anim="" -var fruit_count=0 -var big_coins=[] +var anim = "" +var attack_anim = "" +var fruit_count = 0 +var big_coins = [] -var prev_jpa_emitting=false +var prev_jpa_emitting = false var walk_max_speed = 350 var walk_accel = 500 -var walk_deaccel = 800 -var dead=false - -const FLY_FORCE=400 - -var jetpack_off_time=1000 - - -var extra_fly_anim_min_speed=650 -var side_fly_anim_min_speed=100 -var side_flip_anim_min_speed=300 -var extra_fall_anim_min_speed=350 +var walk_deaccel = 800 +var dead = false -var siding_left=false +var jetpack_off_time = 1000 -var jetpack_ignited=false -var jetpack_ignited_time=0.0 -var prev_jetpack_ignited=false +var extra_fly_anim_min_speed = 650 +var side_fly_anim_min_speed = 100 +var side_flip_anim_min_speed = 300 +var extra_fall_anim_min_speed = 350 +var siding_left = false -var jetpack_thrust=false -var jpvoice=null +var jetpack_ignited = false +var jetpack_ignited_time = 0.0 +var prev_jetpack_ignited = false +var jetpack_thrust = false +var jpvoice = null -var prev_jetpack_on_fire=false +var prev_jetpack_on_fire = false +var invincibility = 0 +var hit_count = 0 +var hit_frame = false +var energy = 2 -const HIT_INVINCIBILITY_TIME=3 -var invincibility=0 -var hit_count=0 -var hit_frame=false -const MAX_ENERGY=2 -var energy=2 +var can_jetpack = true -var can_jetpack=true +var attack_time = 0 +var attack_enemy = null +var prev_closest_enemy = false +var closest_enemy = null +var closest_enemy_pos = Vector2() +var slide_1 = Vector2() +var slide_1_time = 0.0 -var ATTACK_SPEED=950 -var ATTACK_DURATION=0.7#0.8 -var ATTACK_PREPARE_DURATION=0.15 -var attack_time=0 -var ATTACK_SLIDE_TRESHOLD=50 -var ATTACK_TIME_TRESHOLD=0.4 -var attack_enemy=null +var slide_2 = Vector2() +var slide_2_time = 0.0 -var prev_closest_enemy=false -var closest_enemy=null -var closest_enemy_pos=Vector2() +var touch_left = -1 +var touch_right = -1 -var slide_1=Vector2() -var slide_1_time=0.0 +var camera_h_ofs = 0 +var camera_v_ofs = 0 -var slide_2=Vector2() -var slide_2_time=0.0 +var attack_vector = Vector2() -var touch_left=-1 -var touch_right=-1 +var prev_floor_speed = Vector2() +var prev_floor = false -var camera_h_ofs=0 -var camera_v_ofs=0 +var crosshair = null -const ATTACK_SLIDE_TRESHOLD=50 +var enemies_to_attack = [] -var attack_vector=Vector2() - - -var prev_floor_speed=Vector2() -var prev_floor=false - -var crosshair=null - -var enemies_to_attack=[] +var flipping = false +var do_change_flipping = false func _attack_area_enter(body): - print("ENTER BODY?") - if (body extends enemy_class): + if body extends enemy_class: enemies_to_attack.push_back(body) print("ENTER BODY!") else: - print("NO!: ",body.get_type()," - ",body.get_path()) - -func _attack_area_exit(body): + print("NO!: ", body.get_type(), " - ", body.get_path()) +func _attack_area_exit(body): print("EXIT BODY?") - if (body extends enemy_class): + if body extends enemy_class: enemies_to_attack.erase(body) print("EXIT BODY!") - - -var flipping=false -var do_change_flipping=false - - func _do_flip(): - do_change_flipping=true - - + do_change_flipping = true func is_jetpack_on(): return jetpack_ignited - func _update_siding(): - var scale = Vector2(1,1) - if (siding_left): - scale.x=-scale.x - + var scale = Vector2(1, 1) + if siding_left: + scale.x = -scale.x + get_node("body").set_scale( scale ) - - -func _integrate_forces(state): - if (dead): +func _integrate_forces(state): + if dead: return - var new_anim="" + var new_anim = "" var found_floor=false var floor_index=0 - - slide_1_time+=state.get_step() - slide_2_time+=state.get_step() - var floor_normal=Vector2() - var attacked_target=null + slide_1_time += state.get_step() + slide_2_time += state.get_step() + + var floor_normal = Vector2() + var attacked_target = null for i in range(state.get_contact_count()): var co = state.get_contact_collider_object(i) - if (co and co extends enemy_class and co.inflicts_damage()): - hit_frame=true + if co and co extends enemy_class and co.inflicts_damage(): + hit_frame = true var n = state.get_contact_local_normal(i) - if (attack_time>0 and co and co extends RigidBody2D and attack_vector.dot(n)<-0.707): - attacked_target=co - - if (n.y < -0.707): - found_floor=true - floor_index=i - floor_normal=n + if attack_time > 0 and co and co extends RigidBody2D and attack_vector.dot(n) < -0.707: + attacked_target = co + + if n.y < -0.707: + found_floor = true + floor_index = i + floor_normal = n break - -#Closest Enemy (for aiming) - closest_enemy=null - var closest_enemy_dist=0 - var pos=state.get_transform().get_origin() - #if (enemies_to_attack.size()): - # print("ETA: ",enemies_to_attack.size()) - + + # Closest Enemy (for aiming) + closest_enemy = null + var closest_enemy_dist = 0 + var pos = state.get_transform().get_origin() + for e in enemies_to_attack: - if (not e.takes_damage()): + if not e.takes_damage(): continue var epos = e.get_global_pos() - var d = epos.distance_to(pos) - if (not closest_enemy or d PI/4.0): - #Down + attack_enemy = null + attack_vector = Vector2(0, 1) + if attack_vector.dot(Vector2(0, 1)) > PI/4.0: # Down get_node("animation").play("attack_down_1start") - anim="attack_down_2loop" - elif (attack_vector.dot(Vector2(0,-1)) > PI/4.0): - #Up + anim = "attack_down_2loop" + elif attack_vector.dot(Vector2(0, -1)) > PI/4.0: # Up get_node("animation").play("attack_up_1start") - anim="attack_up_2loop" + anim = "attack_up_2loop" else: var frontvec - if (siding_left): - frontvec=Vector2(-1,0) + if siding_left: + frontvec = Vector2(-1, 0) else: - frontvec=Vector2(1,0) - - if (attack_vector.dot(frontvec) > PI/4.0): - #Front + frontvec = Vector2(1, 0) + + if attack_vector.dot(frontvec) > PI/4.0: # Front get_node("animation").play("attack_front_1start") - anim="attack_front_2loop" - else: - #Back - if (not flipping): - get_node("animation").play("flip_attack") - anim="attack_front_2loop" - flipping=true - - #get_node("animation").play("attack_back_1start") - #anim="attack_back_2loop" - + anim = "attack_front_2loop" + else: # Back + if not flipping: + get_node("animation").play("flip_attack") + anim = "attack_front_2loop" + flipping = true + get_node("animation").queue(anim) - attack_anim=anim - - attack_begin=false - - var jetpack_on_fire=false - - if (attack_time>0): - - if (attacked_target): - - attack_time=0 - if (attacked_target extends enemy_class and attacked_target.takes_damage()): - hit_frame=false - lv=attack_vector*-50 - var enmvec = (attacked_target.get_global_transform().get_origin()-state.get_transform().get_origin()).normalized()*40.0 - - attacked_target.call("attacked",self) - get_node("starhit").set_pos(enmvec) - get_node("starhit").set_emitting(true) - get_node("event_sounds").play("attack") - get_node("camera_animation").play("shake") - - new_anim="hover" - - elif (false and on_floor): + attack_anim = anim + + attack_begin = false + + var jetpack_on_fire = false + + if attack_time > 0: + if attacked_target: attack_time=0 + if attacked_target extends enemy_class and attacked_target.takes_damage(): + hit_frame = false + lv = attack_vector*(-50) + var enmvec = (attacked_target.get_global_transform().get_origin() - state.get_transform().get_origin()).normalized()*40.0 + + attacked_target.call("attacked", self) + get_node("starhit").set_pos(enmvec) + get_node("starhit").set_emitting(true) + get_node("event_sounds").play("attack") + get_node("camera_animation").play("shake") + + new_anim = "hover" + + elif false and on_floor: + attack_time = 0 pass # not? else: - jetpack_on_fire=true + jetpack_on_fire = true var td = ATTACK_DURATION - ATTACK_PREPARE_DURATION var can_begin = attack_time > td - attack_time-=step - if (attack_time <=td): - if (attack_enemy): - if (attack_enemy): + attack_time -= step + if attack_time <= td: + if attack_enemy: + if attack_enemy: var ae = attack_enemy.get_ref() - if (ae): + if ae: attack_vector = (ae.get_global_transform().get_origin() - state.get_transform().get_origin()).normalized() - attack_enemy=null - - var attack_dir=attack_vector #(ae.get_global_pos() - pos).normalized(); - #var current_dir=lv.normalized() + attack_enemy = null + + var attack_dir = attack_vector # (ae.get_global_pos() - pos).normalized() print(attack_dir) lv = attack_dir * ATTACK_SPEED - - if (attack_time<0): - attack_time=0 - anim=attack_anim + + if attack_time < 0: + attack_time = 0 + anim = attack_anim else: - attack_enemy=null - + attack_enemy = null - var jetpack_thrust=false + var jetpack_thrust = false - var accel_x=0.0 + var accel_x = 0.0 var ac = Input.get_accelerometer() - if (false and ac!=Vector3()): - ac=ac.normalized() - var av=ac.y - var sgn=sign(av) - var v=abs(av) - if (v<0.10): - v=0.0 + if false and ac!=Vector3(): + ac = ac.normalized() + var av = ac.y + var sgn = sign(av) + var v = abs(av) + if v < 0.10: + v = 0.0 else: - v=1.0 -# if (v<0.2): -# v=0.0 -# elif (v>1.0): -# v=1.0 - accel_x=v*sgn + v = 1.0 + accel_x = v*sgn print(accel_x) - - - if (not jetpack_ignited and moving_left and moving_right): - if (can_jetpack): - jetpack_ignited=true - if (on_floor): - if (can_jetpack): - lv.y=-100 + + if not jetpack_ignited and moving_left and moving_right: + if can_jetpack: + jetpack_ignited = true + if on_floor: + if can_jetpack: + lv.y = -100 else: - lv.y=-250 - - - if (not jetpack_ignited): - if (can_jetpack): - lv.y+=300.0*state.get_step() + lv.y = -250 + + if not jetpack_ignited: + if can_jetpack: + lv.y += 300.0*state.get_step() else: - lv.y+=600.0*state.get_step() - - var can_thrust=jetpack_ignited and (moving_left or moving_right) - - - if (attack_time==0 and can_thrust ): - #print(attack_time==0) - #print((!on_floor and (moving_left or moving_right))) - #print((moving_left and moving_right)) - jetpack_on_fire=true - + lv.y += 600.0*state.get_step() + + var can_thrust = jetpack_ignited and (moving_left or moving_right) + + if attack_time == 0 and can_thrust: + jetpack_on_fire = true + var force = Vector2() - if (moving_left and moving_right): - force=Vector2(0,-1) - if (lv.y>0): - force*=2.0 - elif (moving_left): - force=Vector2(-1,0).normalized() - if (lv.x>0): - force*=2.0 - elif (moving_right): - force=Vector2(1,0).normalized() - if (lv.x<0): - force*=2.0 - - - - lv+=force*step*FLY_FORCE - - if (lv.normalized().y< -0.707 and lv.y < -extra_fly_anim_min_speed): - - new_anim="fly_up" + if moving_left and moving_right: + force = Vector2(0, -1) + if lv.y > 0: + force *= 2.0 + elif moving_left: + force = Vector2(-1, 0).normalized() + if lv.x > 0: + force *= 2.0 + elif moving_right: + force = Vector2(1, 0).normalized() + if lv.x < 0: + force *= 2.0 + + lv += force*step*FLY_FORCE + + if lv.normalized().y < -0.707 and lv.y < -extra_fly_anim_min_speed: + new_anim = "fly_up" else: - - if (not flipping): + if not flipping: var v = lv.x - if (siding_left): - v=-v - - if (v > extra_fly_anim_min_speed): + if siding_left: + v = -v + + if v > extra_fly_anim_min_speed: new_anim = "fly_front_2" - elif (v > side_fly_anim_min_speed): + elif v > side_fly_anim_min_speed: new_anim = "fly_front" - elif (v > -side_fly_anim_min_speed): + elif v > -side_fly_anim_min_speed: new_anim = "hover" - elif (v > -side_flip_anim_min_speed): + elif v > -side_flip_anim_min_speed: new_anim = "fly_back" else: - print(" GO FLIP!!!") + print("GO FLIP!!!") get_node("animation").play("flip_air") - get_node("animation").queue("fly_front") - anim="fly_front" - new_anim="fly_front" - flipping=true + get_node("animation").queue("fly_front") + anim = "fly_front" + new_anim = "fly_front" + flipping = true else: - new_anim="fly_front" - - - - - - elif (on_floor): - - jetpack_off_time=0 - - jetpack_ignited=false - - if (moving_left and !moving_right): - - if (lv.x > -walk_max_speed): - lv.x+=-walk_accel*step + new_anim = "fly_front" + + elif on_floor: + jetpack_off_time = 0 + jetpack_ignited = false + + if moving_left and !moving_right: + if lv.x > -walk_max_speed: + lv.x += -walk_accel*step else: - lv.x+=walk_accel*step - - elif (moving_right && !moving_left): - - if (lv.x < walk_max_speed): - lv.x+=walk_accel*step + lv.x += walk_accel*step + + elif moving_right and !moving_left: + if lv.x < walk_max_speed: + lv.x += walk_accel*step else: - lv.x+=-walk_accel*step - - else: - #go towards 0 - var sg=0 - if (lv.x<0): - sg=-1 - elif (lv.x>0): - sg=1 + lv.x += -walk_accel*step + + else: # go towards 0 + var sg = 0 + if lv.x < 0: + sg = -1 + elif lv.x > 0: + sg = 1 var speed = abs(lv.x) - - speed-=walk_deaccel*step - if (speed<0): - speed=0 - lv.x=speed*sg - - if (abs(lv.x)>0.1): - - new_anim="walk" - - if (not flipping): - if ( (moving_right and lv.x>0 and siding_left) or (moving_left and lv.x<0 and not siding_left)): - get_node("animation").play("flip") - get_node("animation").queue("walk") - anim="walk" - flipping=true - + speed -= walk_deaccel*step + if speed < 0: + speed = 0 + lv.x = speed*sg + + if abs(lv.x) > 0.1: + new_anim = "walk" + + if not flipping: + if (moving_right and lv.x > 0 and siding_left) or (moving_left and lv.x < 0 and not siding_left): + get_node("animation").play("flip") + get_node("animation").queue("walk") + anim = "walk" + flipping = true else: - if (not flipping): - new_anim="idle" + if not flipping: + new_anim = "idle" else: - new_anim="walk" - - - elif (attack_time>0): + new_anim = "walk" - new_anim=attack_anim - #jetpack_on=true + elif attack_time > 0: + new_anim = attack_anim else: - - if (not jetpack_ignited): - if (moving_left and !moving_right): - - if (lv.x > -walk_max_speed): - lv.x+=-walk_accel*step + if not jetpack_ignited: + if moving_left and !moving_right: + if lv.x > -walk_max_speed: + lv.x += -walk_accel*step else: - lv.x+=walk_accel*step - - elif (moving_right && !moving_left): - - if (lv.x < walk_max_speed): - lv.x+=walk_accel*step + lv.x += walk_accel*step + + elif moving_right and !moving_left: + if lv.x < walk_max_speed: + lv.x += walk_accel*step else: - lv.x+=-walk_accel*step - - jetpack_off_time+=step - if (jetpack_off_time>1.5 && lv.y > extra_fall_anim_min_speed): - new_anim="fall" + lv.x += -walk_accel*step - for i in range(2): + jetpack_off_time += step + if jetpack_off_time > 1.5 and lv.y > extra_fall_anim_min_speed: + new_anim = "fall" - var p = get_node(jpart_names[i]) + for i in range(2): + var p = get_node(jpart_names[i]) p.set_emitting(jetpack_ignited) - if (can_thrust): - p.set_param( Particles2D.PARAM_SPREAD, 10 ) - p.set_param( Particles2D.PARAM_LINEAR_VELOCITY, 130 ) + if can_thrust: + p.set_param(Particles2D.PARAM_SPREAD, 10) + p.set_param(Particles2D.PARAM_LINEAR_VELOCITY, 130) p.set_self_opacity(1.0) else: - p.set_param( Particles2D.PARAM_SPREAD, 80 ) - p.set_param( Particles2D.PARAM_LINEAR_VELOCITY, 50 ) + p.set_param(Particles2D.PARAM_SPREAD, 80) + p.set_param(Particles2D.PARAM_LINEAR_VELOCITY, 50) p.set_self_opacity(0.35) - + p.set_initial_velocity(lv) - var p2 = get_node(jpart_names[i]+"f") + var p2 = get_node(jpart_names[i] + "f") p2.set_emitting(can_thrust and jetpack_ignited) - #p2.set_initial_velocity(lv) - - - - if (new_anim!=anim): - - anim=new_anim + + if new_anim!=anim: + anim = new_anim get_node("animation").play(anim) - - - if (do_change_flipping): - siding_left=not siding_left - do_change_flipping=false - flipping=false + + if do_change_flipping: + siding_left = not siding_left + do_change_flipping = false + flipping = false _update_siding() - - if (flipping): - + + if flipping: var an = get_node("animation").get_current_animation() - if (an!="flip" and an!="flip_air" and an!="flip_attack"): - siding_left=not siding_left + if an != "flip" and an != "flip_air" and an != "flip_attack": + siding_left = not siding_left _update_siding() - flipping=false - do_change_flipping=false - -# if (new_siding_left!=siding_left): - - - if (found_floor): - prev_floor=true - prev_floor_speed=state.get_contact_collider_velocity_at_pos(floor_index) - prev_floor_speed.y=0 - #print("floorspeed: ",prev_floor_speed) - lv+=prev_floor_speed - - + flipping = false + do_change_flipping = false + + if found_floor: + prev_floor = true + prev_floor_speed = state.get_contact_collider_velocity_at_pos(floor_index) + prev_floor_speed.y = 0 + lv += prev_floor_speed + state.set_linear_velocity(lv) - - if (prev_jetpack_ignited!=jetpack_ignited): - - if (jetpack_ignited): - - jpvoice=get_node("jetpack_sound").play("jetpack") - get_node("jetpack_sound").set_pitch_scale(jpvoice,1.0+lv.length()/800.0) - get_node("jetpack_sound").set_volume(jpvoice,0.3) - - else: + if prev_jetpack_ignited != jetpack_ignited: + if jetpack_ignited: + jpvoice = get_node("jetpack_sound").play("jetpack") + get_node("jetpack_sound").set_pitch_scale(jpvoice, 1.0 + lv.length()/800.0) + get_node("jetpack_sound").set_volume(jpvoice, 0.3) + else: get_node("jetpack_sound").stop_all() - jpvoice=null + jpvoice = null else: - if (jetpack_ignited): - if (jetpack_on_fire): - if (not prev_jetpack_on_fire): - get_node("jetpack_sound").stop_all() - jpvoice=get_node("jetpack_sound").play("jetpack") - get_node("jetpack_sound").set_volume(jpvoice,0.3) - + if jetpack_ignited: + if jetpack_on_fire: + if not prev_jetpack_on_fire: + get_node("jetpack_sound").stop_all() + jpvoice = get_node("jetpack_sound").play("jetpack") + get_node("jetpack_sound").set_volume(jpvoice, 0.3) else: - get_node("jetpack_sound").set_volume(jpvoice,0.1) - - get_node("jetpack_sound").set_pitch_scale(jpvoice,1.0+lv.length()/800.0) - - - - - if (jetpack_ignited): - jetpack_ignited_time+=state.get_step() + get_node("jetpack_sound").set_volume(jpvoice, 0.1) + + get_node("jetpack_sound").set_pitch_scale(jpvoice, 1.0 + lv.length()/800.0) + + if jetpack_ignited: + jetpack_ignited_time += state.get_step() else: - jetpack_ignited_time=0.0 - - if (prev_jpa_emitting != attack_time>0): - prev_jpa_emitting=attack_time>0 + jetpack_ignited_time = 0.0 + + if prev_jpa_emitting != attack_time > 0: + prev_jpa_emitting = attack_time > 0 get_node(jpart_atk).set_emitting(prev_jpa_emitting) - - - prev_jetpack_ignited=jetpack_ignited - prev_jetpack_on_fire=jetpack_on_fire - - - + + prev_jetpack_ignited = jetpack_ignited + prev_jetpack_on_fire = jetpack_on_fire + + func _unhandled_input(event): - #print("UHinput!") - if (event.is_echo()): + if event.is_echo(): return - if (event.is_action("quit") && event.is_pressed()): + if event.is_action("quit") && event.is_pressed(): get_node("/root/main").goto_scene("res://menu/stage_select.tscn") - if (event.is_action("jetpack_right")): - moving_right=event.is_pressed() - elif (event.is_action("jetpack_left")): - moving_left=event.is_pressed() - - if (event.is_action("attack") and !attack_begin and event.is_pressed() and closest_enemy): - attack_begin=true - #print("ATTACK!") - - - if (event.type==InputEvent.SCREEN_TOUCH): + if event.is_action("jetpack_right"): + moving_right = event.is_pressed() + elif event.is_action("jetpack_left"): + moving_left = event.is_pressed() + + if event.is_action("attack") and !attack_begin and event.is_pressed() and closest_enemy: + attack_begin = true - if (control_mode==CONTROL_TAP): + if event.type == InputEvent.SCREEN_TOUCH: + if control_mode == CONTROL_TAP: var mp = get_tree().get_root().get_final_transform().affine_inverse().xform(event.pos) - - if (event.pressed): - - if (closest_enemy and !attack_begin): - + + if event.pressed: + if closest_enemy and !attack_begin: var aleft = get_node("hud/base/jp_left/attack") var aright = get_node("hud/base/jp_right/attack") var r = aleft.get_texture().get_size().height*0.9 - #print("R: ",r) - #print("EP: ",event.pos) - #print("ARD: ",mp.distance_to(aleft.get_global_pos())," gp ",aleft.get_global_pos()) - #print("ARD: ",mp.distance_to(aright.get_global_pos())," gp ",aright.get_global_pos()) - if (mp.distance_to(aleft.get_global_pos()) < r or mp.distance_to(aright.get_global_pos()) < r): - attack_begin=true + #print("R: ", r) + #print("EP: ", event.pos) + #print("ARD: ", mp.distance_to(aleft.get_global_pos()), " gp ", aleft.get_global_pos()) + #print("ARD: ", mp.distance_to(aright.get_global_pos()), " gp ", aright.get_global_pos()) + if mp.distance_to(aleft.get_global_pos()) < r or mp.distance_to(aright.get_global_pos()) < r: + attack_begin = true if event.device != 0: return var left = mp.x < get_viewport_rect().size.x*0.5 - + if left and touch_left == -1: + touch_left = event.index + moving_left = true - if (left and touch_left==-1): + if !left and touch_right==-1: + touch_right = event.index + moving_right = true - touch_left=event.index - moving_left=true - - if (!left and touch_right==-1): + if event.index == 0: + slide_1 = Vector2() + slide_1_time = 0.0 - touch_right=event.index - moving_right=true - - if (event.index==0): - slide_1=Vector2() - slide_1_time=0.0 + if event.index == 1: + slide_2 = Vector2() + slide_2_time = 0.0 - if (event.index==1): - slide_2=Vector2() - slide_2_time=0.0 - else: + if touch_left != -1 and touch_left == event.index: + touch_left = -1 + moving_left = false + if touch_right != -1 and touch_right == event.index: + touch_right = -1 + moving_right = false - if (touch_left!=-1 and touch_left==event.index): - - touch_left=-1 - moving_left=false - - if (touch_right!=-1 and touch_right==event.index): + if event.index == 0: + slide_1 = Vector2() + slide_1_time = 0.0 - touch_right=-1 - moving_right=false - - - if (event.index==0): - slide_1=Vector2() - slide_1_time=0.0 + if event.index == 1: + slide_2 = Vector2() + slide_2_time = 0.0 - if (event.index==1): - slide_2=Vector2() - slide_2_time=0.0 - - else: - pass - - - if (event.type==InputEvent.SCREEN_DRAG): + if event.index == 0: + slide_1 += event.relative_pos - if (event.index==0): - slide_1+=event.relative_pos + if event.index == 1: + slide_2 += event.relative_pos - if (event.index==1): - slide_2+=event.relative_pos + if ((slide_1_time < ATTACK_TIME_TRESHOLD and slide_1.length() > ATTACK_SLIDE_TRESHOLD) + or (slide_2_time < ATTACK_TIME_TRESHOLD and slide_2.length() > ATTACK_SLIDE_TRESHOLD)): + slide_1=Vector2() + slide_1_time=1 + slide_2=Vector2() + slide_2_time=1 - if ( (slide_1_time < ATTACK_TIME_TRESHOLD and slide_1.length() > ATTACK_SLIDE_TRESHOLD) or (slide_2_time < ATTACK_TIME_TRESHOLD and slide_2.length() > ATTACK_SLIDE_TRESHOLD)): - #attack_begin=true - - slide_1=Vector2() - slide_1_time=1 - slide_2=Vector2() - slide_2_time=1 - - - #print("delta left: ",sliding_from_left-sliding_left) - #print("delta right: ",sliding_from_right-sliding_right) - - - - func _restart(): get_node("../..").restart() - -func _process(delta): - if ((hit_frame or hit_count>0) and invincibility==0 and energy>0): - #character was hit! - energy-=1 +func _process(delta): + if (hit_frame or hit_count > 0) and invincibility == 0 and energy > 0: + # character was hit! + energy -= 1 get_node("hud/base").set_energy(energy) - if (energy==0): # you lose, player - dead=true + if energy == 0: # you lose, player + dead = true var gd = get_tree().get_root().get_node("game_data") - gd.life_count-=1 + gd.life_count -= 1 set_mode(MODE_STATIC) get_node("restart_wait").start() get_node("animation").play("death") - #play animation - else: - invincibility=HIT_INVINCIBILITY_TIME - - if (invincibility>0): - - invincibility-=delta - if (invincibility<=0): - invincibility=0 + invincibility = HIT_INVINCIBILITY_TIME + + if invincibility > 0: + invincibility -= delta + if invincibility <= 0: + invincibility = 0 get_node("body").show() else: - if (fmod(invincibility,0.05)<0.025): + if fmod(invincibility, 0.05) < 0.025: get_node("body").show() else: get_node("body").hide() - - hit_frame=false - # compensate attack shape transform + hit_frame = false + + # Compensate attack shape transform var attack_area_offset = get_global_pos() - get_node("camera").get_camera_screen_center() -# print(attack_area_offset) -# get_node("attack_area").set_pos( -attack_area_offset ) - - #adjust camera + # Adjust camera var lv = get_linear_velocity() - + var camera_adj_speed = 0.7 - if (abs(lv.x)> 300): + if abs(lv.x) > 300: camera_adj_speed = 1.2 - - if (siding_left): - if (camera_h_ofs>-1): - var rem = camera_h_ofs*0.5+0.5; - camera_h_ofs-=delta*camera_adj_speed*rem + + if siding_left: + if camera_h_ofs > -1: + var rem = camera_h_ofs*0.5 + 0.5 + camera_h_ofs -= delta*camera_adj_speed*rem else: - if (camera_h_ofs<1): - var rem = -camera_h_ofs*0.5+0.5; - camera_h_ofs+=delta*camera_adj_speed*rem - - get_node("camera").set_h_offset(camera_h_ofs) + if camera_h_ofs < 1: + var rem = -camera_h_ofs*0.5 + 0.5 + camera_h_ofs += delta*camera_adj_speed*rem -#Vertical camera adjust code + get_node("camera").set_h_offset(camera_h_ofs) + # Vertical camera adjust code var camera_adj_vspeed = 1.2 - var camera_vtarget=0.0 -# if (airborne_time<0.3): -# camera_vtarget=-0.35 - if (lv.y>400): - camera_vtarget=1 - elif (lv.y<-400): - camera_vtarget=-1 + var camera_vtarget = 0.0 + if lv.y > 400: + camera_vtarget = 1 + elif lv.y < -400: + camera_vtarget = -1 else: - camera_vtarget=0.0 - -# camera_adj_vspeed*=abs(lv.y)*0.001 + camera_vtarget = 0.0 - if (camera_v_ofs < camera_vtarget): - camera_v_ofs=min(camera_v_ofs+camera_adj_vspeed*delta,camera_vtarget) - elif (camera_v_ofs > camera_vtarget): - camera_v_ofs=max(camera_v_ofs-camera_adj_vspeed*delta,camera_vtarget) - + if camera_v_ofs < camera_vtarget: + camera_v_ofs = min(camera_v_ofs + camera_adj_vspeed*delta, camera_vtarget) + elif camera_v_ofs > camera_vtarget: + camera_v_ofs = max(camera_v_ofs - camera_adj_vspeed*delta, camera_vtarget) get_node("camera").set_v_offset(camera_v_ofs) - -# get_node("camera").set_zoom(Vector2(3,3)) - var cenemy = closest_enemy!=null - if (cenemy!=prev_closest_enemy): - if (cenemy): + var cenemy = closest_enemy != null + if cenemy != prev_closest_enemy: + if cenemy: get_node("hud/base/attack_glow").play("glow") else: get_node("hud/base/attack_glow").play("noglow") - prev_closest_enemy=cenemy - -func _level_end(): + prev_closest_enemy = cenemy + +func _level_end(): get_node("../..").level_end() - + func end_level(next): - get_tree().get_root().get_node("game_data").get_level(next).enabled=true + get_tree().get_root().get_node("game_data").get_level(next).enabled = true set_mode(MODE_STATIC) get_node("level_end_wait").start() - - + func hit_begin(): - - hit_count+=1 - hit_frame=true - + hit_count += 1 + hit_frame = true + func hit_end(): - - hit_count-=1 - + hit_count -= 1 + func add_fruit(): - - fruit_count+=1 + fruit_count += 1 get_node("hud/base").set_fruit_count(fruit_count) - - + func add_key(idx): - get_tree().get_root().get_node("game_data").current_keys[idx]=true + get_tree().get_root().get_node("game_data").current_keys[idx] = true get_node("hud/base").update_keys() - + func add_big_coin(idx): - big_coins.push_back(idx) get_node("hud/base").set_big_coin_on(idx) func restore_life(amount): - energy+=amount - if (energy>MAX_ENERGY): - energy=MAX_ENERGY - + energy += amount + if energy > MAX_ENERGY: + energy = MAX_ENERGY + get_node("hud/base").set_energy(energy) - -func _ready(): +func _ready(): var cp = get_tree().get_root().get_node("game_data").current_checkpoint - if (cp): + if cp: print(cp) cp = get_node(cp) print(cp) - if (cp): + if cp: set_global_transform(cp.get_global_transform()) - - crosshair=ResourceLoader.load("res://hud/crosshair.tscn").instance() - get_node("../..").call_deferred("add_child",crosshair) - get_node("attack_area").get_shape(0).set_extents( OS.get_video_mode_size() / 2 ) - -func show_hint(hint): + crosshair = ResourceLoader.load("res://hud/crosshair.tscn").instance() + get_node("../..").call_deferred("add_child", crosshair) + get_node("attack_area").get_shape(0).set_extents(OS.get_video_mode_size() / 2) +func show_hint(hint): get_node("hud/base").hint_show(hint) - + func hide_hint(): get_node("hud/base").hint_hide() func is_attacking(): - return attack_time>0 + return attack_time > 0 func cancel_attack(): - attack_time=0 - + attack_time = 0 + func _init(): set_process(true) set_process_unhandled_input(true) - - - diff --git a/props/breakable/breakable.gd b/props/breakable/breakable.gd index 29e2747..992068c 100644 --- a/props/breakable/breakable.gd +++ b/props/breakable/breakable.gd @@ -4,28 +4,14 @@ extends "res://enemies/enemy.gd" -# member variables here, example: -# var a=2 -# var b="textvar" - - func inflicts_damage(): return false func takes_damage(): return true -func attacked(s): - if (s extends preload("res://player/alpaca.gd")): +func attacked(by): + if (by extends preload("res://player/alpaca.gd")): get_node("../particles").set_emitting(true) get_node("../sample").play("rock_explode") - #clear_shapes() - #hide() queue_free() - - -func _ready(): - # Initalization here - pass - - diff --git a/props/breakable/jar.gd b/props/breakable/jar.gd index 77f749b..d8c88fb 100644 --- a/props/breakable/jar.gd +++ b/props/breakable/jar.gd @@ -4,35 +4,26 @@ extends RigidBody2D -# member variables here, example: -# var a=2 -# var b="textvar" -var broken=false -export var has_key=false -export var key_index=0 +export var has_key = false +export var key_index = 0 +var broken = false func _on_timeout(): print("DEADED!") - get_parent().call_deferred("remove_and_delete_child",self) + get_parent().call_deferred("remove_and_delete_child", self) func attacked(by): - if (broken): + if broken: return clear_shapes() get_node("sprite").hide() get_node("particles").set_emitting(true) get_node("death").start() get_node("player").play("break") - broken=true - if (has_key): + broken = true + if has_key: var ki = preload("res://interaction/door/key.tscn").instance() ki.set_pos(get_global_pos()) - ki.key_index=key_index + ki.key_index = key_index get_parent().add_child(ki) - -func _ready(): - # Initalization here - pass - - diff --git a/props/house/house.gd b/props/house/house.gd index 9c91a10..7b56201 100644 --- a/props/house/house.gd +++ b/props/house/house.gd @@ -4,18 +4,8 @@ extends StaticBody2D -# member variables here, example: -# var a=2 -# var b="textvar" - func _on_enter_screen(): get_node("parts").set_emitting(true) func _on_exit_screen(): get_node("parts").set_emitting(false) - -func _ready(): - # Initalization here - pass - - diff --git a/shared/game_data.gd b/shared/game_data.gd index aa83a33..9f1451a 100644 --- a/shared/game_data.gd +++ b/shared/game_data.gd @@ -6,7 +6,7 @@ extends Node class LevelInfo: var id = Vector2() - var big_coins = [false,false,false] + var big_coins = [false, false, false] var max_fruit = 0 var preview_path = "" var path = "" @@ -21,7 +21,7 @@ var current_checkpoint = "" var current_world = null var current_big_coins = [false, false, false] var current_keys = [false, false, false] -var life_count=5 +var life_count = 5 func _init(): var stage_list = preload("res://stages/stage_list.gd").get_stage_list() diff --git a/shared/progress.gd b/shared/progress.gd index 015e88c..c165d6b 100644 --- a/shared/progress.gd +++ b/shared/progress.gd @@ -15,22 +15,22 @@ func _process(time): return var t = OS.get_ticks_msec() - while(OS.get_ticks_msec() < t + TMAX): + while OS.get_ticks_msec() < t + TMAX: var res = ril.poll() - if (res==ERR_FILE_EOF): + if res == ERR_FILE_EOF: printt("progress finished!") set_process(false) get_node("/root/main").set_new_scene(ril.get_resource()) - ril=null + ril = null hide() break else: - assert( res==OK ) - animation.seek(ril.get_stage() / float(ril.get_stage_count()) * animation.get_current_animation_length(), true) + assert(res == OK) + animation.seek(ril.get_stage()/float(ril.get_stage_count())*animation.get_current_animation_length(), true) func do_load(path): ril = ResourceLoader.load_interactive(path) - assert( ril != null ) + assert(ril != null) animation.set_current_animation("progress") animation.seek(0, true) diff --git a/stages/stage.gd b/stages/stage.gd index dd948ca..9bdfdcc 100644 --- a/stages/stage.gd +++ b/stages/stage.gd @@ -4,11 +4,6 @@ extends Node -# member variables here, example: -# var a=2 -# var b="textvar" - - func level_end(): var gd = get_tree().get_root().get_node("game_data") gd.stage_clear() @@ -16,33 +11,19 @@ func level_end(): func restart(): var gd = get_tree().get_root().get_node("game_data") - if (gd.life_count<0): - #out of lifes + if gd.life_count < 0: # Out of lives gd.game_over() get_tree().get_root().get_node("main").goto_scene("res://menu/stage_select.tscn") - else: - #restart level + else: # Restart level var wpc = gd.current_world.path - # get_tree().get_root().get_node("game_data").current_checkpoint=null + # get_tree().get_root().get_node("game_data").current_checkpoint = null get_tree().get_root().get_node("main").goto_scene(wpc) - - func _enter_tree(): - get_tree().get_root().get_node("game_data").set_current_stage(get_filename()) var charnode = preload("res://player/alpaca.tscn").instance() get_node("launch").add_child(charnode) var gd = get_tree().get_root().get_node("game_data") - gd.current_big_coins=[false,false,false] + gd.current_big_coins = [false, false, false] for x in gd.current_world.big_coins: gd.current_big_coins.push_back(x) - - - - -func _ready(): - # Initalization here - pass - - diff --git a/stages/stage_list.gd b/stages/stage_list.gd index 379beb5..3991dc7 100644 --- a/stages/stage_list.gd +++ b/stages/stage_list.gd @@ -3,15 +3,12 @@ # Distributed under the terms of the MIT license (cf. LICENSE.md file) static func get_stage_list(): - - - var sl=[ - { "id":Vector2(1,1), "path":"res://stages/world_1/intro" }, - { "id":Vector2(1,2), "path":"res://stages/world_1/forest_fun" }, - { "id":Vector2(1,3), "path":"res://stages/world_1/roller_coaster" }, - { "id":Vector2(1,5), "path":"res://stages/gcon/demo_gcon_004" }, - { "id":Vector2(1,7), "path":"res://stages/gcon/demo_gcon_006" } + var sl = [ + { "id": Vector2(1, 1), "path": "res://stages/world_1/intro" }, + { "id": Vector2(1, 2), "path": "res://stages/world_1/forest_fun" }, + { "id": Vector2(1, 3), "path": "res://stages/world_1/roller_coaster" }, + { "id": Vector2(1, 5), "path": "res://stages/gcon/demo_gcon_004" }, + { "id": Vector2(1, 7), "path": "res://stages/gcon/demo_gcon_006" } ] - - return sl + return sl