Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Node2D;
- const SHIP_SPEED = 0.3; #Usually 1 should be slow enough but fsr it isnt
- const SHOT_COOLDOWN = 300; #The value has to be this big cuz it's pretty much measured in frames
- var bullet_id = preload("res://Scenes/Shot.tscn");
- var shot_timer = 0;
- func _ready():
- set_process(true);
- func shoot(node):
- var bullet_obj = bullet_id.instance();
- bullet_obj.set_global_position(node.get_global_position());
- get_owner().add_child(bullet_obj);
- func _process(delta):
- #Comment more often >:I
- #(Don't over-do it tho, not everything needs it)
- #Also eu escrevo tudo em ingles pra ser mais consistente mesmo (e pra praticar também)
- #Movement
- var left_input = float(Input.is_action_pressed("left"));
- var right_input = float(Input.is_action_pressed("right"));
- var xdir = right_input - left_input;
- translate(Vector2(xdir * SHIP_SPEED,0));
- position.x = clamp(position.x,50,640-50);
- #Shooting
- if Input.is_action_pressed("shot"):
- if shot_timer <= 0:
- shoot(get_node("Pos_Gun1"));
- shoot(get_node("Pos_Gun2"));
- shot_timer = SHOT_COOLDOWN;
- shot_timer -= 1;
- shot_timer = max(0,shot_timer); #Makes so shot_timer can't go below 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement