Skip to content

Commit

Permalink
monster töten
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Heinen committed Apr 9, 2017
1 parent 1bc00d8 commit 4d764e3
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
11 changes: 10 additions & 1 deletion bullet/bullet.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ tracks/2/keys = { "times":FloatArray( 0.9 ), "transitions":FloatArray( 1 ), "val
offsets = FloatArray( 0, 0.109453, 0.328358, 0.626866, 0.860696, 0.920398, 1 )
colors = ColorArray( 0, 0, 0, 1, 0.996094, 0, 0, 1, 1, 1, 1, 1, 0.23524, 0.789062, 0.138702, 1, 0.283582, 0.283582, 0.283582, 1, 0.590618, 0.590618, 0.590618, 1, 0.110092, 0.181364, 0.761719, 1 )

[node name="bullet" type="RigidBody2D"]
[node name="bullet" type="RigidBody2D" groups=[ "bullet" ]]

input/pickable = false
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
shapes/0/trigger = false
shapes/1/shape = SubResource( 1 )
shapes/1/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
shapes/1/trigger = true
collision/layers = 1
collision/mask = 1
mode = 0
Expand Down Expand Up @@ -73,6 +76,12 @@ shape = SubResource( 1 )
trigger = false
_update_shape_index = 0

[node name="trigger" type="CollisionShape2D" parent="."]

shape = SubResource( 1 )
trigger = true
_update_shape_index = 1

[node name="bulletanim" type="AnimationPlayer" parent="."]

playback/process_mode = 1
Expand Down
67 changes: 64 additions & 3 deletions enemy/enemy.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[gd_scene load_steps=4 format=1]
[gd_scene load_steps=6 format=1]

[ext_resource path="res://enemy/enemy.png" type="Texture" id=1]
[ext_resource path="res://enemy/explosion.png" type="Texture" id=2]

[sub_resource type="RectangleShape2D" id=1]

Expand All @@ -9,7 +10,29 @@ extents = Vector2( 9.9237, 9.89589 )

[sub_resource type="GDScript" id=2]

script/source = "#extends RigidBody2D\nvar WALK_ACCEL = 800.0\nvar WALK_DEACCEL = 800.0\nvar WALK_MAX_VELOCITY = 200.0\nvar damage = 10\nvar health = 100\n\nvar move_direction = Vector2(1,0)\n\nvar enemy_size\n\nvar direction = Vector2(0.0, 0.0) #right\n\nvar monstertextures = load(\"res://enemy/all_monsters.png\")\nvar numberOfDifEnemys = 2\n\n\t\nfunc set_texture():\n\trandomize()\n\tvar nr = randi()% numberOfDifEnemys\n\tvar texture = AtlasTexture.new()\n\ttexture.set_atlas(monstertextures)\n\t#texture.set_region(Rect2(0,0,60,60))\n\ttexture.set_region(getTextureRect(nr))\n\tget_node(\"enemy\").set_texture(texture)\n\n\n\nfunc getTextureRect(nummer):\n\tvar x= nummer % numberOfDifEnemys * 60\n\tvar y = 0\n\treturn Rect2(x,y,60,60)\n\nfunc _ready():\n\t# Called every time the node is added to the scene.\n\t# Initialization here\n\tset_texture()\n\tenemy_size = get_node(\"enemy\").get_texture().get_size()\n\t\n\t\n\tset_fixed_process(true)\n\n\nfunc _integrate_forces(s):\n\t\n\trandomize()\n\tvar x = (randf() -0.5) * 50\n\tvar y = (randf() -0.5) * 50\n\t#print(s.get_contact_count())\n\t\n\tvar lv = s.get_linear_velocity()\n\tvar step = s.get_step()\n\t\n\tvar move_left = false\n\tvar move_right = false\n\tvar move_up = false\n\tvar move_down = false\n\t\n\t#var shoot = Input.is_action_pressed(\"shoot\")\n\n\tvar enemy_rect = Rect2( get_node(\"enemy\").get_pos() - enemy_size*0.5, enemy_size )\n\tvar enemy_pos = get_node(\"enemy\").get_pos()\n\t\n\t#print(lv)\n\t\n\tlv.x += x\n\tlv.y += y\n\t\t\t\n\ts.set_linear_velocity(lv)\n\n\nfunc _on_enemy_body_enter( body ):\n\t#body.\n\tprint(\"enemy coll\")\n\tpass # replace with function body\n\nfunc getDamage():\n\treturn damage"
script/source = "#extends RigidBody2D\nvar WALK_ACCEL = 800.0\nvar WALK_DEACCEL = 800.0\nvar WALK_MAX_VELOCITY = 200.0\nvar damage = 10\nvar health = 100\n\nvar move_direction = Vector2(1,0)\n\nvar enemy_size\n\nvar direction = Vector2(0.0, 0.0) #right\n\nvar monstertextures = load(\"res://enemy/all_monsters.png\")\nvar numberOfDifEnemys = 2\n\n\t\nfunc set_texture():\n\trandomize()\n\tvar nr = randi()% numberOfDifEnemys\n\tvar texture = AtlasTexture.new()\n\ttexture.set_atlas(monstertextures)\n\t#texture.set_region(Rect2(0,0,60,60))\n\ttexture.set_region(getTextureRect(nr))\n\tget_node(\"enemy\").set_texture(texture)\n\n\n\nfunc getTextureRect(nummer):\n\tvar x= nummer % numberOfDifEnemys * 60\n\tvar y = 0\n\treturn Rect2(x,y,60,60)\n\nfunc _ready():\n\t# Called every time the node is added to the scene.\n\t# Initialization here\n\tset_texture()\n\tenemy_size = get_node(\"enemy\").get_texture().get_size()\n\t\n\t\n\tset_fixed_process(true)\n\n\nfunc _integrate_forces(s):\n\t\n\trandomize()\n\tvar x = (randf() -0.5) * 50\n\tvar y = (randf() -0.5) * 50\n\t#print(s.get_contact_count())\n\t\n\tvar lv = s.get_linear_velocity()\n\tvar step = s.get_step()\n\t\n\tvar move_left = false\n\tvar move_right = false\n\tvar move_up = false\n\tvar move_down = false\n\t\n\t#var shoot = Input.is_action_pressed(\"shoot\")\n\n\tvar enemy_rect = Rect2( get_node(\"enemy\").get_pos() - enemy_size*0.5, enemy_size )\n\tvar enemy_pos = get_node(\"enemy\").get_pos()\n\t\n\t#print(lv)\n\t\n\tlv.x += x\n\tlv.y += y\n\t\t\t\n\ts.set_linear_velocity(lv)\n\n\nfunc _on_enemy_body_enter( body ):\n\t#body.\n\tprint(\"enemy coll\")\n\tpass # replace with function body\n\nfunc getDamage():\n\treturn damage\n\nfunc _on_Area2D_body_enter( body ):\n\tif(health > 0):\n\t\tif(body.is_in_group(\"bullet\")):\n\t\t\thealth = 0\n\t\t\tset_mode(1)\n\t\t\tget_node(\"anim\").play(\"death\")\n\t\t\tget_node(\"enemy\").set_opacity(0)\n\t\t\t#self.queue_free()\n\tpass # replace with function body\n"

[sub_resource type="Animation" id=3]

resource/name = "death"
length = 0.5
loop = false
step = 0.1
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:transform/scale")
tracks/0/interp = 1
tracks/0/imported = false
tracks/0/keys = { "times":FloatArray( 0, 0.3 ), "transitions":FloatArray( 1, 1 ), "update":0, "values":[ Vector2( 0.1, 0.1 ), Vector2( 2, 2 ) ] }
tracks/1/type = "value"
tracks/1/path = NodePath("Sprite:visibility/opacity")
tracks/1/interp = 1
tracks/1/imported = false
tracks/1/keys = { "times":FloatArray( 0, 0.2 ), "transitions":FloatArray( 1, 1 ), "update":0, "values":[ 0.0, 1.0 ] }
tracks/2/type = "method"
tracks/2/path = NodePath(".")
tracks/2/interp = 1
tracks/2/imported = false
tracks/2/keys = { "times":FloatArray( 0.4 ), "transitions":FloatArray( 1 ), "values":[ { "args":[ ], "method":"queue_free" } ] }

[node name="enemy" type="RigidBody2D" groups=[ "enemy" ]]

Expand Down Expand Up @@ -43,13 +66,51 @@ script/script = SubResource( 2 )
transform/pos = Vector2( -2.95717, 0.300346 )
texture = ExtResource( 1 )

[node name="Area2D" type="Area2D" parent="."]

input/pickable = true
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, -3.11282, 0.396297 )
shapes/0/trigger = true
gravity_vec = Vector2( 0, 1 )
gravity = 98.0
linear_damp = 0.1
angular_damp = 1.0

[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]

transform/pos = Vector2( -3.11282, 0.396297 )
transform/scale = Vector2( 1, 1 )
shape = SubResource( 1 )
trigger = true
_update_shape_index = 0

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]

transform/pos = Vector2( -3.11282, 0.396297 )
transform/scale = Vector2( 1, 1 )
shape = SubResource( 1 )
trigger = false
_update_shape_index = 0

[connection signal="body_enter" from="." to="." method="_on_enemy_body_enter"]
[node name="anim" type="AnimationPlayer" parent="."]

playback/process_mode = 1
playback/default_blend_time = 0.0
root/root = NodePath("..")
anims/death = SubResource( 3 )
playback/active = true
playback/speed = 1.0
blend_times = [ ]
autoplay = ""

[node name="Sprite" type="Sprite" parent="."]

visibility/opacity = 0.0
transform/pos = Vector2( 1.82878, -0.609598 )
transform/scale = Vector2( 2, 2 )
texture = ExtResource( 2 )

[connection signal="body_enter" from="Area2D" to="." method="_on_Area2D_body_enter"]


Binary file added enemy/explosion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4d764e3

Please sign in to comment.