Skip to content

Commit

Permalink
Adding bullets. Buggy!!
Browse files Browse the repository at this point in the history
  • Loading branch information
bblodget committed Jul 28, 2020
1 parent 81efdcb commit cb48ec8
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 7 deletions.
27 changes: 27 additions & 0 deletions Bullet.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extends KinematicBody2D


# Max speeds
const BULLET_SPEED = 40

# Global Vars
var velocity = Vector2.ZERO
var heading = 0

# Called when the node enters the scene tree for the first time.
func _ready():
velocity.y = -100

func set_heading(new_heading):
heading = new_heading

func _physics_process(delta):

#velocity.x = delta * BULLET_SPEED * cos(heading * (PI/180))
#velocity.y = delta * BULLET_SPEED * sin(heading * (PI/180))
#move_and_collide(velocity)

if position.y < -1000:
queue_free()

move_and_slide(velocity)
14 changes: 14 additions & 0 deletions Bullet.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://bullet.png" type="Texture" id=1]
[ext_resource path="res://Bullet.gd" type="Script" id=2]

[node name="Bullet" type="KinematicBody2D"]
script = ExtResource( 2 )
__meta__ = {
"_edit_group_": true
}

[node name="bullet" type="Sprite" parent="."]
position = Vector2( 0.0633631, -0.0659924 )
texture = ExtResource( 1 )
27 changes: 23 additions & 4 deletions TankPlayer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,50 @@ export var ui_left : String
export var ui_right : String
export var ui_up : String
export var ui_down : String
export var ui_fire : String
export var initial_heading : float = 0.0

func _ready():
heading = get_rotation_degrees()
print("heading: ", heading)

$tank.texture = tank_sprite

func _physics_process(delta):
var fire = Input.get_action_strength(ui_fire)

if fire:
shoot()


var turn = TURN_SPEED * (Input.get_action_strength(ui_right) - Input.get_action_strength(ui_left))

heading = heading + (turn * delta)

if turn != 0:
set_rotation_degrees(heading)
print("heading: ", heading)


var fwd = FWD_SPEED * delta * (Input.get_action_strength(ui_down) - Input.get_action_strength(ui_up))

if fwd !=0:
var adj_heading = heading+90 - initial_heading
var adj_heading = heading+90 + initial_heading
velocity.x = fwd * cos(adj_heading * (PI/180))
velocity.y = fwd * sin(adj_heading * (PI/180))
print("velocity: ", velocity)

else:
velocity = Vector2.ZERO

move_and_collide(velocity)



func shoot():
var bullet_scene = load("res://Bullet.tscn")
var bullet = bullet_scene.instance()
var world = get_tree().get_root().get_node("World")

bullet.transform = world.transform
add_child_below_node(world, bullet)



2 changes: 1 addition & 1 deletion TankPlayer.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://TankPlayer.gd" type="Script" id=1]
[ext_resource path="res://dg_tank.png" type="Texture" id=2]
[ext_resource path="res://boat_guy_still.png" type="Texture" id=2]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 7.78017, 7.10828 )
Expand Down
6 changes: 4 additions & 2 deletions World.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ ui_left = "ui_p1_left"
ui_right = "ui_p1_right"
ui_up = "ui_p1_up"
ui_down = "ui_p1_down"
initial_heading = -90.0
ui_fire = "ui_p1_fire"
initial_heading = 90.0

[node name="Tank2" parent="." instance=ExtResource( 4 )]
position = Vector2( 14.3036, 98.4222 )
Expand All @@ -235,4 +236,5 @@ ui_left = "ui_p2_left"
ui_right = "ui_p2_right"
ui_up = "ui_p2_up"
ui_down = "ui_p2_down"
initial_heading = -90.0
ui_fire = "ui_p2_fire"
initial_heading = 90.0
Binary file added bullet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ ui_p2_down={
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
]
}
ui_p1_fire={
"deadzone": 0.5,
"events": [ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":7,"pressure":0.0,"pressed":false,"script":null)
]
}
ui_p2_fire={
"deadzone": 0.5,
"events": [ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":7,"pressure":0.0,"pressed":false,"script":null)
]
}

[rendering]

Expand Down

0 comments on commit cb48ec8

Please sign in to comment.