-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Jump and Attack controls * Fixing magic numbers and removing unused vars * Added click to fire * Renamed Objects folder to Weapons * Removed space in typing * Adding types to parameters * Simplified weapon * Adjusted some static typing
- Loading branch information
1 parent
2f899df
commit e07e9bc
Showing
8 changed files
with
215 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,60 @@ | ||
[gd_scene load_steps=2 format=2] | ||
[gd_scene load_steps=4 format=2] | ||
|
||
[ext_resource path="res://icon.png" type="Texture" id=1] | ||
[ext_resource path="res://src/Actors/Player.tscn" type="PackedScene" id=2] | ||
|
||
[sub_resource type="RectangleShape2D" id=1] | ||
extents = Vector2( 32, 32 ) | ||
|
||
[node name="Node2D" type="Node2D"] | ||
|
||
[node name="icon" type="Sprite" parent="."] | ||
position = Vector2( 500, 300 ) | ||
[node name="KinematicBody2D" parent="." instance=ExtResource( 2 )] | ||
position = Vector2( 235.201, 58.2705 ) | ||
|
||
[node name="Floor" type="StaticBody2D" parent="."] | ||
position = Vector2( 223.547, 412.131 ) | ||
collision_layer = 4 | ||
|
||
[node name="icon" type="Sprite" parent="Floor"] | ||
texture = ExtResource( 1 ) | ||
__meta__ = { | ||
"_edit_lock_": true | ||
} | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Floor"] | ||
shape = SubResource( 1 ) | ||
__meta__ = { | ||
"_edit_lock_": true | ||
} | ||
|
||
[node name="Object" type="StaticBody2D" parent="."] | ||
position = Vector2( 580.586, 340.087 ) | ||
collision_layer = 4 | ||
|
||
[node name="icon" type="Sprite" parent="Object"] | ||
texture = ExtResource( 1 ) | ||
__meta__ = { | ||
"_edit_lock_": true | ||
} | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Object"] | ||
shape = SubResource( 1 ) | ||
__meta__ = { | ||
"_edit_lock_": true | ||
} | ||
|
||
[node name="Enemy" type="StaticBody2D" parent="."] | ||
position = Vector2( 492.651, 336.909 ) | ||
collision_layer = 2 | ||
|
||
[node name="icon" type="Sprite" parent="Enemy"] | ||
texture = ExtResource( 1 ) | ||
__meta__ = { | ||
"_edit_lock_": true | ||
} | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Enemy"] | ||
shape = SubResource( 1 ) | ||
__meta__ = { | ||
"_edit_lock_": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
extends KinematicBody2D | ||
class_name Player | ||
|
||
const JUMP_SPEED := 380 | ||
const TERMINAL_VELOCITY := 500 | ||
|
||
var velocity := Vector2() | ||
|
||
onready var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity") | ||
onready var weapon: Weapon = $Weapon | ||
|
||
func _physics_process(delta: float) -> void: | ||
velocity.y += gravity * delta | ||
velocity.y = min(TERMINAL_VELOCITY, velocity.y) | ||
velocity = move_and_slide(velocity, Vector2.UP) | ||
|
||
if is_on_floor() and Input.is_action_just_pressed("jump"): | ||
velocity.y = -JUMP_SPEED | ||
|
||
if Input.is_action_just_pressed("attack"): | ||
weapon.attack() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[gd_scene load_steps=5 format=2] | ||
|
||
[ext_resource path="res://icon.png" type="Texture" id=1] | ||
[ext_resource path="res://src/Actors/Player.gd" type="Script" id=2] | ||
[ext_resource path="res://src/Weapons/Weapon.tscn" type="PackedScene" id=3] | ||
|
||
[sub_resource type="CapsuleShape2D" id=1] | ||
radius = 32.0 | ||
height = 8.0 | ||
|
||
[node name="KinematicBody2D" type="KinematicBody2D"] | ||
script = ExtResource( 2 ) | ||
|
||
[node name="Sprite" type="Sprite" parent="."] | ||
texture = ExtResource( 1 ) | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
shape = SubResource( 1 ) | ||
|
||
[node name="Weapon" parent="." instance=ExtResource( 3 )] | ||
position = Vector2( 34, 0 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
extends Area2D | ||
class_name Projectile | ||
|
||
const SPEED := 500.0 | ||
const ENEMY_LAYER := 2 | ||
|
||
func _physics_process(delta: float) -> void: | ||
position.x += SPEED * delta | ||
|
||
func _on_Projectile_body_entered(body: Node) -> void: | ||
if body.collision_layer == ENEMY_LAYER: | ||
body.queue_free() | ||
queue_free() | ||
|
||
func _on_Expiration_timeout(): | ||
queue_free() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[gd_scene load_steps=4 format=2] | ||
|
||
[ext_resource path="res://icon.png" type="Texture" id=1] | ||
[ext_resource path="res://src/Weapons/Projectile.gd" type="Script" id=2] | ||
|
||
[sub_resource type="CircleShape2D" id=1] | ||
radius = 32.0 | ||
|
||
[node name="Projectile" type="Area2D"] | ||
collision_layer = 4 | ||
collision_mask = 6 | ||
script = ExtResource( 2 ) | ||
|
||
[node name="Sprite" type="Sprite" parent="."] | ||
texture = ExtResource( 1 ) | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
shape = SubResource( 1 ) | ||
|
||
[node name="Expiration" type="Timer" parent="."] | ||
wait_time = 1.5 | ||
one_shot = true | ||
autostart = true | ||
|
||
[connection signal="body_entered" from="." to="." method="_on_Projectile_body_entered"] | ||
[connection signal="timeout" from="Expiration" to="." method="_on_Expiration_timeout"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
extends Position2D | ||
class_name Weapon | ||
|
||
const Projectile := preload("res://src/Weapons/Projectile.tscn") | ||
|
||
onready var cooldown_timer: Timer = $Cooldown | ||
|
||
func attack() -> void: | ||
if cooldown_timer.is_stopped(): | ||
cooldown_timer.start() | ||
var projectile = Projectile.instance() | ||
projectile.global_position = global_position | ||
projectile.set_as_toplevel(true) | ||
add_child(projectile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[gd_scene load_steps=2 format=2] | ||
|
||
[ext_resource path="res://src/Weapons/Weapon.gd" type="Script" id=1] | ||
|
||
[node name="Weapon" type="Position2D"] | ||
script = ExtResource( 1 ) | ||
__meta__ = { | ||
"_gizmo_extents_": 16.0 | ||
} | ||
|
||
[node name="Cooldown" type="Timer" parent="."] | ||
process_mode = 0 | ||
wait_time = 0.3 | ||
one_shot = true |