basic pew pew without damage or collision
This commit is contained in:
		| @@ -1,3 +0,0 @@ | ||||
| [gd_scene format=3 uid="uid://cpo8qy3y0fuui"] | ||||
|  | ||||
| [node name="basic_projectile" type="Node2D"] | ||||
| @@ -1,5 +0,0 @@ | ||||
| [gd_scene format=3 uid="uid://cmtuq84761y0i"] | ||||
|  | ||||
| [node name="basic_weapon" type="Node2D"] | ||||
|  | ||||
| [node name="Sprite2D" type="Sprite2D" parent="."] | ||||
| @@ -3,8 +3,16 @@ extends CharacterBody2D | ||||
| @export var MAX_SPEED = 600.0; | ||||
| @export var ACCELERATION = 2000.0; | ||||
| @export var FRICTION = 3000.0; | ||||
| @export var HP = 3; | ||||
| @export var STARTING_WEAPON : PackedScene; | ||||
|  | ||||
| @onready var raycast = $RayCast2D; | ||||
| var current_weapon = null; | ||||
|  | ||||
| func _ready(): | ||||
| 	call_deferred("call_set_player"); | ||||
| 	current_weapon = STARTING_WEAPON.instantiate(); | ||||
| 	raycast.add_child(current_weapon); | ||||
|  | ||||
| func _physics_process(delta): | ||||
| 	var input_vector = get_input_vector(); | ||||
| @@ -14,6 +22,21 @@ func _physics_process(delta): | ||||
| 	 | ||||
| 	var look_vec = get_global_mouse_position() - global_position; | ||||
| 	raycast.rotation = atan2(look_vec.y,look_vec.x); | ||||
| 	 | ||||
| 	if Input.is_action_pressed("shoot"): | ||||
| 		attack(); | ||||
|  | ||||
|  | ||||
| func attack(): | ||||
| 	if current_weapon: current_weapon.fire(); | ||||
|  | ||||
| func take_damage(damage): | ||||
| 	HP = HP - damage; | ||||
| 	if HP <= 0: | ||||
| 		kill(); | ||||
|  | ||||
| func kill(): | ||||
| 	get_tree().reload_current_scene(); | ||||
|  | ||||
| func get_input_vector(): | ||||
| 	var input_vector = Vector2.ZERO; | ||||
| @@ -30,6 +53,8 @@ func apply_friction(input_vector,delta): | ||||
| 	if(input_vector == Vector2.ZERO): | ||||
| 		velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta); | ||||
|  | ||||
| func call_set_player(): | ||||
| 	get_tree().call_group("enemies", "set_player",self); | ||||
|  | ||||
| func _on_area_2d_area_entered(area): | ||||
| 	$"../School_Snare".volume_db(-6); | ||||
|   | ||||
| @@ -1,13 +1,14 @@ | ||||
| [gd_scene load_steps=5 format=3 uid="uid://b62h0w8gjm6tj"] | ||||
| [gd_scene load_steps=6 format=3 uid="uid://xev8p1td1icx"] | ||||
|  | ||||
| [ext_resource type="Script" path="res://Player/player.gd" id="1_mbyc2"] | ||||
| [ext_resource type="Texture2D" uid="uid://wkeakqjvu3gg" path="res://Sprites/dingo_jam_mc_front_64.png" id="2_ae25p"] | ||||
| [ext_resource type="PackedScene" uid="uid://cmtuq84761y0i" path="res://Weapons/basic_weapon.tscn" id="2_bo475"] | ||||
| [ext_resource type="Texture2D" uid="uid://wkeakqjvu3gg" path="res://Sprites/placeholder_player.png" id="2_bqbmq"] | ||||
|  | ||||
| [sub_resource type="SpriteFrames" id="SpriteFrames_mqbrd"] | ||||
| animations = [{ | ||||
| "frames": [{ | ||||
| "duration": 1.0, | ||||
| "texture": ExtResource("2_ae25p") | ||||
| "texture": ExtResource("2_bqbmq") | ||||
| }], | ||||
| "loop": true, | ||||
| "name": &"default", | ||||
| @@ -15,10 +16,11 @@ animations = [{ | ||||
| }] | ||||
|  | ||||
| [sub_resource type="RectangleShape2D" id="RectangleShape2D_ng5bv"] | ||||
| size = Vector2(64, 64) | ||||
| size = Vector2(40, 64) | ||||
|  | ||||
| [node name="Player" type="CharacterBody2D"] | ||||
| script = ExtResource("1_mbyc2") | ||||
| STARTING_WEAPON = ExtResource("2_bo475") | ||||
|  | ||||
| [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] | ||||
| frames = SubResource("SpriteFrames_mqbrd") | ||||
| @@ -33,6 +35,7 @@ current = true | ||||
| target_position = Vector2(2000, 0) | ||||
|  | ||||
| [node name="Line2D" type="Line2D" parent="RayCast2D"] | ||||
| visible = false | ||||
| points = PackedVector2Array(0, 0, 2000, 0) | ||||
| width = 5.0 | ||||
| default_color = Color(1, 0, 0, 0.392157) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user