Skip to content

Commit

Permalink
Merge pull request #2 from Galbenshire/dev
Browse files Browse the repository at this point in the history
Dev Merge - v0.1
  • Loading branch information
Galbenshire authored Nov 9, 2019
2 parents 9aff281 + 5ce3423 commit d42adff
Show file tree
Hide file tree
Showing 25 changed files with 1,118 additions and 212 deletions.
48 changes: 0 additions & 48 deletions Prototype.tscn

This file was deleted.

31 changes: 0 additions & 31 deletions PrototypeEnemy.tscn

This file was deleted.

65 changes: 0 additions & 65 deletions PrototypePlayer.tscn

This file was deleted.

61 changes: 0 additions & 61 deletions PrototypePlayerBullet.tscn

This file was deleted.

File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

importer="texture"
type="StreamTexture"
path="res://.import/PrototypeBullet.png-acab51b667b4096dbdd575425710638d.stex"
path="res://.import/Bullet.png-3f3ed9f93cd72825dd36ec2e258ddc82.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://PrototypeBullet.png"
dest_files=[ "res://.import/PrototypeBullet.png-acab51b667b4096dbdd575425710638d.stex" ]
source_file="res://entities/_shared/Bullet.png"
dest_files=[ "res://.import/Bullet.png-3f3ed9f93cd72825dd36ec2e258ddc82.stex" ]

[params]

Expand Down
20 changes: 20 additions & 0 deletions entities/enemies/BaseEnemy.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
extends Area2D

onready var EnemySprite : Sprite = $Sprite

var original_colors : Color

func _ready() -> void:
original_colors = EnemySprite.modulate

func _take_damage() -> void:
EnemySprite.modulate = Color.yellow
yield(get_tree().create_timer(0.15), "timeout")
EnemySprite.modulate = original_colors

func _on_BaseEnemy_body_entered(body : PhysicsBody2D) -> void:
if body.is_in_group("player_projectile"):
if body.rebounded:
_take_damage()

body.queue_free()
21 changes: 21 additions & 0 deletions entities/enemies/BaseEnemy.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://entities/enemies/BaseEnemy.gd" type="Script" id=1]
[ext_resource path="res://entities/enemies/Enemy.png" type="Texture" id=2]

[sub_resource type="CircleShape2D" id=1]

[node name="BaseEnemy" type="Area2D" groups=[
"enemy",
]]
collision_layer = 8
collision_mask = 16
script = ExtResource( 1 )

[node name="Sprite" type="Sprite" parent="."]
modulate = Color( 0.74902, 0, 0, 1 )
texture = ExtResource( 2 )

[node name="Collision" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )
[connection signal="body_entered" from="." to="." method="_on_BaseEnemy_body_entered"]
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

importer="texture"
type="StreamTexture"
path="res://.import/PrototypeEntity.png-f5dcb5023c2de897eb225ec3929fc42d.stex"
path="res://.import/Enemy.png-cac8dcc6bd62db67df1d0e2666d143d8.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://PrototypeEntity.png"
dest_files=[ "res://.import/PrototypeEntity.png-f5dcb5023c2de897eb225ec3929fc42d.stex" ]
source_file="res://entities/enemies/Enemy.png"
dest_files=[ "res://.import/Enemy.png-cac8dcc6bd62db67df1d0e2666d143d8.stex" ]

[params]

Expand Down
103 changes: 103 additions & 0 deletions entities/player/Player.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
"""
This is the scene that represents the player.
It has twin stick shooter controls; moving & aiming are independent of each other.
There is support for both controllers & keyboard/mouse.
Depending on which is used, the code will adjust accordingly.
"""
extends KinematicBody2D

onready var PlayerSprite : Sprite = $Sprite
onready var BulletOrigin : Position2D = $Sprite/BulletOrigin
onready var Hitbox : Area2D = $Hitbox/Collision
onready var BlinkAnimation : AnimationPlayer = $BlinkAnimation
onready var HurtTimer : Timer = $HurtTimer

const BULLET := preload("res://entities/player/bullet/PlayerBullet.tscn")
const STICK_DEADZONE := 0.3
const MAX_BULLETS_ON_SCREEN = 3

export (float) var move_speed := 90.0

var _mouse_mode : bool = false

func _unhandled_input(event : InputEvent) -> void:
if _mouse_mode and _is_gamepad_used(event):
_mouse_mode = false
elif !_mouse_mode and _is_keyboard_used(event):
_mouse_mode = true

if event.is_action_pressed("player_shoot"):
_player_shoot()

func _physics_process(delta : float) -> void:
_player_movement()
_player_aiming()

func set_control_state(value : bool) -> void:
set_physics_process(value)
set_process_unhandled_input(value)

func set_camera_bounds(bounds : Rect2) -> void:
$Camera.limit_left = bounds.position.x
$Camera.limit_top = bounds.position.y
$Camera.limit_right = bounds.end.x
$Camera.limit_bottom = bounds.end.y

func _is_gamepad_used(event : InputEvent) -> bool:
if event is InputEventJoypadButton:
return true
if event is InputEventJoypadMotion and abs(event.axis_value) > STICK_DEADZONE:
return true
return false

func _is_keyboard_used(event : InputEvent) -> bool:
if event is InputEventKey:
return true
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
return true
return false

func _player_movement() -> void:
var input_direction := Vector2(Input.get_action_strength("player_right") - Input.get_action_strength("player_left"),
Input.get_action_strength("player_down") - Input.get_action_strength("player_up")).normalized()
# If I don't need 'delta' for move_and_slide, no point bringing it into 'player_movement()'
move_and_slide(input_direction * move_speed)

func _player_aiming() -> void:
if _mouse_mode:
PlayerSprite.look_at(get_global_mouse_position())
else:
# Not really worth making 4 whole input actions just for this single occurance.
var right_stick_direction := Vector2(Input.get_joy_axis(0, JOY_AXIS_2), Input.get_joy_axis(0, JOY_AXIS_3))
if right_stick_direction.length() > STICK_DEADZONE:
right_stick_direction = right_stick_direction.normalized()
PlayerSprite.rotation = right_stick_direction.angle()

func _player_shoot() -> void:
if get_tree().get_nodes_in_group("player_projectile").size() >= MAX_BULLETS_ON_SCREEN:
return

var bullet = BULLET.instance()
bullet.angle = PlayerSprite.rotation
bullet.global_position = BulletOrigin.global_position
get_parent().add_child(bullet)

func _take_damage() -> void:
if BlinkAnimation.is_playing():
return

# Start hurt invincibility
BlinkAnimation.play("blink")
HurtTimer.start()

func _on_Hitbox_body_entered(body : PhysicsBody2D) -> void:
if body.is_in_group("player_projectile"):
if body.rebounded:
_take_damage()
body.queue_free()

# Stop invincibility
func _on_HurtTimer_timeout() -> void:
BlinkAnimation.stop()
PlayerSprite.visible = true
Binary file added entities/player/Player.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d42adff

Please sign in to comment.