Skip to content

Commit

Permalink
bullet fix#1
Browse files Browse the repository at this point in the history
  • Loading branch information
Danduriel committed Apr 9, 2017
1 parent 6f0c90d commit 7c741de
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion player/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extents = Vector2( 10, 10 )

[sub_resource type="GDScript" id=2]

script/source = "extends RigidBody2D\n\nvar WALK_ACCEL = 800.0\nvar WALK_DEACCEL = 800.0\nvar WALK_MAX_VELOCITY = 200.0\n\nvar receiveDamage = 0\nvar health = 1000\n\nvar player_size\nvar bullet = preload(\"res://bullet/bullet.tscn\")\n\nvar direction = Vector2(1.0, 0.0) #right\n\nfunc _ready():\n\t# Called every time the node is added to the scene.\n\t# Initialization here\n\tplayer_size = get_node(\"player\").get_texture().get_size()\n\tget_node(\"cl0/inventory\").hide()\n\t#get_node(\"cl0/inventory_button\").hide()\n\t#get_node(\"player\").show()\n\t\n\tset_fixed_process(true)\n\nfunc _fixed_process(delta):\n\thealth -= receiveDamage *delta\n\tif(receiveDamage > 0):\n\t\tprint(health)\n\nfunc _integrate_forces(s):\n\tvar speedup = 0\n\tvar damage = 0\n\tvar weaponrange = 0\n\tspeedup = get_node(\"cl0/inventory\").getStats()[0]\n\t#print (speedup)\n\tWALK_MAX_VELOCITY = 200 + speedup * 20\n\t\n\t#print (WALK_MAX_VELOCITY)\n\t\n\tvar lv = s.get_linear_velocity()\n\tvar step = s.get_step()\n\t\n\t#Inputs\n\tvar move_left = Input.is_action_pressed(\"move_left\")\n\tvar move_right = Input.is_action_pressed(\"move_right\")\n\tvar move_up = Input.is_action_pressed(\"move_up\")\n\tvar move_down = Input.is_action_pressed(\"move_down\")\n\tvar shoot = Input.is_action_pressed(\"shoot\")\n\n\tvar player_rect = Rect2( get_node(\"player\").get_pos() - player_size*0.5, player_size )\n\tvar player_pos = get_node(\"player\").get_pos()\n\t\n\t#Shooting\n\tif(shoot):\n\t\tvar shoot_time = 0\n\t\tvar bi = bullet.instance()\n\t\tvar pos = get_pos() + get_node(\"bullet_shoot\").get_pos()\n\t\t\n\t\tbi.set_pos(pos)\n\t\tget_parent().add_child(bi)\n\t\t\n\t\tbi.set_linear_velocity(direction * 320)\n\t\t#get_node(\"sprite/smoke\").set_emitting(true)\n\t\t#get_node(\"sound\").play(\"shoot\")\n\t\tPS2D.body_add_collision_exception(bi.get_rid(), get_rid()) # Make bullet and this not collide\n\t\n\t# MOVING \n\tif (move_left and not move_right): #left\n\t\tif (lv.x > -WALK_MAX_VELOCITY):\n\t\t\tlv.x -= WALK_ACCEL*step\n\t\tdirection = Vector2(-1.0, 0.0)\n\telif (move_right and not move_left): #right\n\t\tif (lv.x < WALK_MAX_VELOCITY):\n\t\t\tlv.x += WALK_ACCEL*step\n\t\tdirection = Vector2(1.0, 0.0)\n\telif (move_down and not move_up): #down\n\t\tif (lv.y < WALK_MAX_VELOCITY):\n\t\t\tlv.y += WALK_ACCEL*step\n\t\tdirection = Vector2(0.0, 1.0)\n\telif (move_up and not move_down): #up\n\t\tif (lv.y > -WALK_MAX_VELOCITY):\n\t\t\tlv.y -= WALK_ACCEL*step\n\t\tdirection = Vector2(0.0, -1.0)\n\telse: #Getting the player to stand still again\n\t\t\tvar xv = abs(lv.x)\n\t\t\tvar yv = abs(lv.y)\n\t\t\t\n\t\t\txv -= WALK_DEACCEL*step\n\t\t\tif (xv < 0):\n\t\t\t\txv = 0\n\t\t\tlv.x = sign(lv.x)*xv\n\t\t\t\n\t\t\tyv -= WALK_DEACCEL*step\n\t\t\tif (yv < 0):\n\t\t\t\tyv = 0\n\t\t\tlv.y = sign(lv.y)*yv\n\t\t\t\n\ts.set_linear_velocity(lv)\n\nfunc _on_inventory_pressed():\n\t#get_node(\"cl0/inventory_button\").hide()\n\tget_node(\"cl0/inventory\").show()\n\t#hide()\n\t#print(\"inventory\")\n\tpass # replace with function body\n\n\nfunc _on_player_body_enter( body ):\n\tprint(\"player collision\")\n\tpass # replace with function body\n\n\nfunc _on_Area2D_body_enter( body ):\n\tif(body.is_in_group(\"enemy\")):\n\t\tenemyCollision(body,1)\n\tpass # replace with function body\n\nfunc _on_Area2D_body_exit( body ):\n\tif(body.is_in_group(\"enemy\")):\n\t\tenemyCollision(body,-1)\n\tpass # replace with function body\n\n#add = [1,-1]\nfunc enemyCollision(enemy,add):\n\treceiveDamage += enemy.getDamage() *add\n"
script/source = "extends RigidBody2D\n\nvar WALK_ACCEL = 800.0\nvar WALK_DEACCEL = 800.0\nvar START_WALK_MAX_VELOCITY = 200.0\nvar WALK_MAX_VELOCITY = 200.0\n\nvar receiveDamage = 0\nvar health = 1000\n\nvar player_size\nvar bullet = preload(\"res://bullet/bullet.tscn\")\n\n#is the player currently shooting\?\nvar shooting = false\nvar shoot_time = 1e20\n\nvar direction = Vector2(1.0, 0.0) #right\n\nfunc _ready():\n\t# Called every time the node is added to the scene.\n\t# Initialization here\n\tplayer_size = get_node(\"player\").get_texture().get_size()\n\tget_node(\"cl0/inventory\").hide()\n\t#get_node(\"cl0/inventory_button\").hide()\n\t#get_node(\"player\").show()\n\t\n\tset_fixed_process(true)\n\nfunc _fixed_process(delta):\n\thealth -= receiveDamage *delta\n\tif(receiveDamage > 0):\n\t\tprint(health)\n\nfunc _integrate_forces(s):\n\tvar speedup = 0\n\tvar damage = 0\n\tvar weaponrange = 0\n\tspeedup = get_node(\"cl0/inventory\").getStats()[0]\n\t#print (speedup)\n\tWALK_MAX_VELOCITY = START_WALK_MAX_VELOCITY + speedup * 20\n\t\n\t#print (WALK_MAX_VELOCITY)\n\t\n\tvar lv = s.get_linear_velocity()\n\tvar step = s.get_step()\n\t\n\t#Inputs\n\tvar move_left = Input.is_action_pressed(\"move_left\")\n\tvar move_right = Input.is_action_pressed(\"move_right\")\n\tvar move_up = Input.is_action_pressed(\"move_up\")\n\tvar move_down = Input.is_action_pressed(\"move_down\")\n\tvar shoot = Input.is_action_pressed(\"shoot\")\n\n\tvar player_rect = Rect2( get_node(\"player\").get_pos() - player_size*0.5, player_size )\n\tvar player_pos = get_node(\"player\").get_pos()\n\t\n\t#Shooting\n\tif(shoot and not shooting):\n\t\tshoot_time = 0\n\t\tvar bi = bullet.instance()\n\t\tvar pos = get_pos() + get_node(\"bullet_shoot\").get_pos()\n\t\t\n\t\tbi.set_pos(pos)\n\t\tget_parent().add_child(bi)\n\t\t\n\t\tbi.set_linear_velocity(direction * 320)\n\t\t#get_node(\"sprite/smoke\").set_emitting(true)\n\t\t#get_node(\"sound\").play(\"shoot\")\n\t\tPS2D.body_add_collision_exception(bi.get_rid(), get_rid()) # Make bullet and this not collide\n\telse:\n\t\tshoot_time += step\n\n\t# MOVING \n\tif (move_left and not move_right): #left\n\t\tif (lv.x > -WALK_MAX_VELOCITY):\n\t\t\tlv.x -= WALK_ACCEL*step\n\t\tdirection = Vector2(-1.0, 0.0)\n\telif (move_right and not move_left): #right\n\t\tif (lv.x < WALK_MAX_VELOCITY):\n\t\t\tlv.x += WALK_ACCEL*step\n\t\tdirection = Vector2(1.0, 0.0)\n\telif (move_down and not move_up): #down\n\t\tif (lv.y < WALK_MAX_VELOCITY):\n\t\t\tlv.y += WALK_ACCEL*step\n\t\tdirection = Vector2(0.0, 1.0)\n\telif (move_up and not move_down): #up\n\t\tif (lv.y > -WALK_MAX_VELOCITY):\n\t\t\tlv.y -= WALK_ACCEL*step\n\t\tdirection = Vector2(0.0, -1.0)\n\telse: #Getting the player to stand still again\n\t\t\tvar xv = abs(lv.x)\n\t\t\tvar yv = abs(lv.y)\n\t\t\t\n\t\t\txv -= WALK_DEACCEL*step\n\t\t\tif (xv < 0):\n\t\t\t\txv = 0\n\t\t\tlv.x = sign(lv.x)*xv\n\t\t\t\n\t\t\tyv -= WALK_DEACCEL*step\n\t\t\tif (yv < 0):\n\t\t\t\tyv = 0\n\t\t\tlv.y = sign(lv.y)*yv\n\t\t\t\n\tshooting = shoot\n\ts.set_linear_velocity(lv)\n\nfunc _on_inventory_pressed():\n\t#get_node(\"cl0/inventory_button\").hide()\n\tget_node(\"cl0/inventory\").show()\n\t#hide()\n\t#print(\"inventory\")\n\tpass # replace with function body\n\n\nfunc _on_player_body_enter( body ):\n\tprint(\"player collision\")\n\tpass # replace with function body\n\n\nfunc _on_Area2D_body_enter( body ):\n\tif(body.is_in_group(\"enemy\")):\n\t\tenemyCollision(body,1)\n\tpass # replace with function body\n\nfunc _on_Area2D_body_exit( body ):\n\tif(body.is_in_group(\"enemy\")):\n\t\tenemyCollision(body,-1)\n\tpass # replace with function body\n\n#add = [1,-1]\nfunc enemyCollision(enemy,add):\n\treceiveDamage += enemy.getDamage() *add\n"

[node name="player" type="RigidBody2D"]

Expand Down

0 comments on commit 7c741de

Please sign in to comment.