Skip to content

Commit

Permalink
Start applying Kobuge style guide to scripts
Browse files Browse the repository at this point in the history
Part of #8
  • Loading branch information
akien-mga committed Jul 17, 2016
1 parent 56e8654 commit ebfd399
Show file tree
Hide file tree
Showing 41 changed files with 1,205 additions and 1,886 deletions.
52 changes: 17 additions & 35 deletions characters/wise_alpaca/wise_alpaca.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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<d):
retc=c
d=ld


var ld = (get_global_pos() - c.get_global_pos()).length()
if ld < d:
retc = c
d = ld
return retc



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"):
get_node("anim").play("rant")
body.show_hint(hint)


func _on_body_exit( body ):
if (body extends preload("res://player/alpaca.gd")):
func _on_body_exit(body):
if body extends preload("res://player/alpaca.gd"):
get_node("anim").play("idle")
body.hide_hint()


func _on_enter_screen():
get_node("anim").set_active(true)
set_process(true)
Expand All @@ -66,7 +52,3 @@ func _on_exit_screen():
func _ready():
get_node("anim").play("idle")
get_node("anim").set_active(false)
# Initalization here
pass


46 changes: 14 additions & 32 deletions enemies/cannon/bubble.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,36 @@

extends RigidBody2D

# member variables here, example:
# var a=2
# var b="textvar"


var deleted=false
const RAISE_ACCEL=100
const RAISE_ACCEL = 100
const MAX_SPEED = 64



var deleted = false

func pop():
if (not deleted):
deleted=true
if not deleted:
deleted = true
get_node("burst").start()
deleted=true
deleted = true
get_node("anim").play("burst")

func attacked(by):
pop()

func _integrate_forces(state):
var lv = state.get_linear_velocity()

var lv=state.get_linear_velocity()

if (lv.y>-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)
Expand All @@ -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)







67 changes: 26 additions & 41 deletions enemies/cannon/cannon.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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


71 changes: 24 additions & 47 deletions enemies/cannon/heatseeker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Loading

0 comments on commit ebfd399

Please sign in to comment.