diff --git a/2d/shower_of_bullets/bullet.png b/2d/shower_of_bullets/bullet.png new file mode 100644 index 00000000..74663741 Binary files /dev/null and b/2d/shower_of_bullets/bullet.png differ diff --git a/2d/shower_of_bullets/bullets.gd b/2d/shower_of_bullets/bullets.gd new file mode 100644 index 00000000..f76fcc38 --- /dev/null +++ b/2d/shower_of_bullets/bullets.gd @@ -0,0 +1,76 @@ + +extends Node2D + +# This demo is an example of controling a high number of 2D objects with logic and collision without using scene nodes. +# This technique is a lot more efficient than using instancing and nodes, but requires more programming and is less visual + +const BULLET_COUNT = 500 +const SPEED_MIN = 20 +const SPEED_MAX = 50 + +var bullets=[] +var shape + +class Bullet: + var pos = Vector2() + var speed = 1.0 + var body = RID() + + +func _draw(): + + var t = preload("res://bullet.png") + var tofs = -t.get_size()*0.5 + for b in bullets: + draw_texture(t,b.pos+tofs) + + +func _process(delta): + var width = get_viewport_rect().size.x*2.0 + var mat = Matrix32() + for b in bullets: + b.pos.x-=b.speed*delta + if (b.pos.x < -30): + b.pos.x+=width + mat.o=b.pos + + Physics2DServer.body_set_state(b.body,Physics2DServer.BODY_STATE_TRANSFORM,mat) + + update() + + +func _ready(): + + shape = Physics2DServer.shape_create(Physics2DServer.SHAPE_CIRCLE) + Physics2DServer.shape_set_data(shape,8) #radius + + for i in range(BULLET_COUNT): + var b = Bullet.new() + b.speed=rand_range(SPEED_MIN,SPEED_MAX) + b.body = Physics2DServer.body_create(Physics2DServer.BODY_MODE_KINEMATIC) + Physics2DServer.body_set_space(b.body,get_world_2d().get_space()) + Physics2DServer.body_add_shape(b.body,shape) + + b.pos = Vector2( get_viewport_rect().size * Vector2(randf()*2.0,randf()) ) #twice as long + b.pos.x += get_viewport_rect().size.x # start outside + var mat = Matrix32() + mat.o=b.pos + Physics2DServer.body_set_state(b.body,Physics2DServer.BODY_STATE_TRANSFORM,mat) + + bullets.append(b) + + + set_process(true) + + +func _exit_tree(): + for b in bullets: + Physics2DServer.free(b.body) + + Physics2DServer.free(shape) + # Initalization here + bullets.clear() + + pass + + diff --git a/2d/shower_of_bullets/engine.cfg b/2d/shower_of_bullets/engine.cfg new file mode 100644 index 00000000..cad57519 --- /dev/null +++ b/2d/shower_of_bullets/engine.cfg @@ -0,0 +1,16 @@ +[application] + +name="Bullet Shower" +main_scene="res://shower.scn" +icon="res://icon.png" + +[display] + +width=1024 +height=600 +resizable=true +stretch_aspect="keep" + +[physics_2d] + +cell_size=64 diff --git a/2d/shower_of_bullets/face_happy.png b/2d/shower_of_bullets/face_happy.png new file mode 100644 index 00000000..6ed643b6 Binary files /dev/null and b/2d/shower_of_bullets/face_happy.png differ diff --git a/2d/shower_of_bullets/face_sad.png b/2d/shower_of_bullets/face_sad.png new file mode 100644 index 00000000..d6318b20 Binary files /dev/null and b/2d/shower_of_bullets/face_sad.png differ diff --git a/2d/shower_of_bullets/icon.png b/2d/shower_of_bullets/icon.png new file mode 100644 index 00000000..432c74a5 Binary files /dev/null and b/2d/shower_of_bullets/icon.png differ diff --git a/2d/shower_of_bullets/shower.gd b/2d/shower_of_bullets/shower.gd new file mode 100644 index 00000000..bba84317 --- /dev/null +++ b/2d/shower_of_bullets/shower.gd @@ -0,0 +1,32 @@ + +extends Node2D + +# member variables here, example: +# var a=2 +# var b="textvar" + +var touching=0 + +func _input(ev): + + if (ev.type==InputEvent.MOUSE_MOTION): + get_node("player").set_pos(ev.pos-Vector2(0,16)) + + +func _on_player_body_enter_shape( body_id, body, body_shape, area_shape ): + + touching+=1 + if (touching==1): + get_node("player/sprite").set_frame(1) + + +func _on_player_body_exit_shape( body_id, body, body_shape, area_shape ): + + touching-=1 + if (touching==0): + get_node("player/sprite").set_frame(0) + + +func _ready(): + set_process_input(true) + pass diff --git a/2d/shower_of_bullets/shower.scn b/2d/shower_of_bullets/shower.scn new file mode 100644 index 00000000..648888d0 Binary files /dev/null and b/2d/shower_of_bullets/shower.scn differ diff --git a/misc/autoload/global.gd b/misc/autoload/global.gd index d9fa308a..a0415c6e 100644 --- a/misc/autoload/global.gd +++ b/misc/autoload/global.gd @@ -12,12 +12,12 @@ func goto_scene(scene): #instance the new scene current_scene = s.instance() #add it to the active scene, as child of root - get_scene().get_root().add_child(current_scene) + get_tree().get_root().add_child(current_scene) func _ready(): # get the current scene # it is always the last child of root, # after the autoloaded nodes - var root = get_scene().get_root() + var root = get_tree().get_root() current_scene = root.get_child( root.get_child_count() -1 ) diff --git a/misc/pause/spinpause.gd b/misc/pause/spinpause.gd index c21c13b4..1b8f8388 100644 --- a/misc/pause/spinpause.gd +++ b/misc/pause/spinpause.gd @@ -5,11 +5,11 @@ extends Spatial func _on_pause_pressed(): get_node("pause_popup").set_exclusive(true) get_node("pause_popup").popup() - get_scene().set_pause(true) + get_tree().set_pause(true) func _on_unpause_pressed(): get_node("pause_popup").hide() - get_scene().set_pause(false) + get_tree().set_pause(false)