Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
Implements code improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
brenomfviana committed Nov 16, 2017
1 parent 1f8bc20 commit 8563745
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 61 deletions.
2 changes: 1 addition & 1 deletion game/engine.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[application]

name="Kheridien's Revenge"
main_scene="res://scenes/main.tscn"
main_scene="res://scenes/screens/main.tscn"
icon="res://icon.png"

[autoload]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
[ext_resource path="res://scenes/player/ninja.tscn" type="PackedScene" id=25]
[ext_resource path="res://scenes/sounds/phase_sound.tscn" type="PackedScene" id=26]

[node name="phase_one" type="Node2D"]
[node name="w1l1" type="Node2D"]

[node name="ParallaxLayer" type="ParallaxLayer" parent="."]

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions game/scenes/main.tscn → game/scenes/screens/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1

[node name="start_game" type="Button" parent="panel"]
[node name="new_game" type="Button" parent="panel"]

focus/ignore_mouse = false
focus/stop_mouse = true
Expand All @@ -95,7 +95,7 @@ custom_fonts/font = ExtResource( 7 )
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
text = "Start"
text = "New Game"
flat = true

[node name="load_game" type="Button" parent="panel"]
Expand Down
16 changes: 12 additions & 4 deletions game/scripts/enemies/zombie.gd
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
###
# This script is responsible for zombie behaviors.
# Author Breno Viana
# Version: 13/11/2017
# Version: 16/11/2017
###
extends KinematicBody2D

################################################################################

# Physics constants
const GRAVITY = 2000.0
# Zombie constants
Expand All @@ -13,15 +15,21 @@ const MAX_STEPS = 120
const DAMAGE = 5
const PONTUATION = 10

# Animations
var initial_position
var steps
################################################################################

# Ninja states controllers
var stopped
var walking
var dead
# Zombie movement
var initial_position
var steps
var velocity
var direction
# Zombie attributes
var current_life

################################################################################

func _ready():
""" Called every time the node is added to the scene.
Expand Down
21 changes: 11 additions & 10 deletions game/scripts/globals.gd
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
###
# This script is responsible for game over menu.
# Author: Breno Viana
# Version: 21/10/2017
# Version: 16/11/2017
###
extends Node2D

func _ready():
""" Called every time the node is added to the scene.
""" Called every time the node is added to the scene.
Initialization here. """
# Game settings
Globals.set("paused", false)
# Enemies settings
Globals.set("enemy_group", "enemies")
# Player attributes
Globals.set("score", 0)
Globals.set("number_of_lifes", 3)
Globals.set("amount_of_kunais", 5)
# Game settings
Globals.set("paused", false)
Globals.set("current_level", "w1l1")
# Enemies settings
Globals.set("enemy_group", "enemies")
# Player attributes
Globals.set("score", 0)
Globals.set("number_of_lifes", 3)
Globals.set("amount_of_kunais", 5)
8 changes: 4 additions & 4 deletions game/scripts/menus/back.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
###
# This script is responsible for main game menu.
# This script is responsible for back button function.
# Author: Breno Viana
# Version: 20/10/2017
# Version: 16/11/2017
###
extends Node2D

Expand All @@ -13,6 +13,6 @@ func _ready():

func _process(delta):
""" Called every frame. Check the interactions with the menu. """
# Start game
# Check if the back button was pressed
if(get_node("panel/back").is_pressed()):
get_tree().change_scene("res://scenes/main.tscn")
get_tree().change_scene("res://scenes/screens/main.tscn")
2 changes: 1 addition & 1 deletion game/scripts/menus/load_game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ func _process(delta):
""" Called every frame. Check the interactions with the menu. """
# Start game
if(get_node("panel/back").is_pressed()):
get_tree().change_scene("res://scenes/main.tscn")
get_tree().change_scene("res://scenes/screens/main.tscn")
16 changes: 8 additions & 8 deletions game/scripts/menus/menu.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
###
# This script is responsible for main game menu.
# Author: Breno Viana
# Version: 20/10/2017
# Version: 16/12/2017
###
extends Node2D

Expand All @@ -13,18 +13,18 @@ func _ready():

func _process(delta):
""" Called every frame. Check the interactions with the menu. """
# Start game
if(get_node("panel/start_game").is_pressed()):
get_tree().change_scene("res://scenes/phases/phase_one.tscn")
# Load Game
# Start a new game
if(get_node("panel/new_game").is_pressed()):
get_tree().change_scene("res://scenes/levels/w1l1.tscn")
# Load saved game
if(get_node("panel/load_game").is_pressed()):
get_tree().change_scene("res://scenes/menu/load_game.tscn")
get_tree().change_scene("res://scenes/screens/load_game.tscn")
# Instructions
if(get_node("panel/instructions").is_pressed()):
get_tree().change_scene("res://scenes/menu/instructions.tscn")
get_tree().change_scene("res://scenes/screens/instructions.tscn")
# Credits
if(get_node("panel/credits").is_pressed()):
get_tree().change_scene("res://scenes/menu/credits.tscn")
get_tree().change_scene("res://scenes/screens/credits.tscn")
# Quit game
if(get_node("panel/quit_game").is_pressed()):
get_tree().quit()
9 changes: 5 additions & 4 deletions game/scripts/phases/arrow_sign.gd
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
###
# This script is responsible for sword behaviors.
# This script is responsible for the completion of levels.
# Author: Breno Viana
# Version: 20/10/2017
# Version: 16/11/2017
###
extends Area2D

func _ready():
""" Called every time the node is added to the scene.
Initialization here. """
# Connect behavior when entering the body
connect("body_enter", self, "_on_body_enter")

func _on_body_enter(body):
""" Called when a body entered the crate. """
# Check if the ninja enter the crate
# Check if the ninja enter the arrow sign
if(body.get_name() == "ninja"):
get_tree().change_scene("res://scenes/menu/credits.tscn")
get_tree().change_scene("res://scenes/screens/credits.tscn")
34 changes: 19 additions & 15 deletions game/scripts/player/kunai.gd
Original file line number Diff line number Diff line change
@@ -1,55 +1,59 @@
###
# This script is responsible for kunai behaviors.
# Author: Breno Viana
# Version: 20/10/2017
# Version: 16/11/2017
###
extends Area2D

################################################################################

# Kunai damage
var damage
# Kunai movement
var direction
var position

################################################################################

func _ready():
""" Called every time the node is added to the scene.
Initialization here. """
damage = 10
# Initialize values
damage = 10
# Check direction
if(get_parent().get_node("sprite").is_flipped_h()):
direction = -1
get_node("sprite").set_flip_v(true)
else:
direction = 1
# Set direction
if(direction == 1):
direction = 1
get_node("sprite").set_flip_v(false)
elif(direction == -1):
get_node("sprite").set_flip_v(true)
# Set position
position = get_parent().get_pos()
position = get_parent().get_pos()
position.x += 40 * direction
set_pos(position)
# Set processes
set_fixed_process(true)
# Kunai becomes independent of the ninja
set_as_toplevel(true)
# Connect behavior when entering the body
connect("body_enter", self, "_on_body_enter")
# Set processes
set_fixed_process(true)

func _fixed_process(delta):
""" Called every frame. """
# Check if the game is paused
# Check if the game is not paused
if(not Globals.get("paused")):
# Kunai movement
var move = get_pos()
move.x += 10 * direction
move.x += 10 * direction
set_pos(move)

func _on_body_enter(body):
""" Called when a body entered the crate. """
# Check if the ninja enter the crate
# Check if the kunai hit a enemy
if(body.is_in_group(Globals.get("enemy_group"))):
# Check if is not dead
# Check if the enemy is not dead
if(not body.dead):
Globals.set("score", Globals.get("score") + body.PONTUATION)
body.dead = true
# Delete kunai
# Delete this kunai
queue_free()
13 changes: 5 additions & 8 deletions game/scripts/player/ninja.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
###
# This script is responsible for ninja behaviors.
# Author: Breno Viana
# Version: 12/11/2017
# Version: 15/11/2017
###
extends KinematicBody2D

################################################################################

# INFO
const LIFE_BAR_SCALE = 0.3
# Current phase
var current_phase

################################################################################

Expand All @@ -22,9 +24,6 @@ const MAX_LIFE = 100

################################################################################

# Current phase
var current_phase

# Ninja states controllers
var deading
var dead
Expand All @@ -35,11 +34,9 @@ var attacking
var kunai
var sword
var invencible

# Ninja movement
var velocity
var direction

# Ninja attributes
var current_life

Expand Down Expand Up @@ -228,9 +225,9 @@ func _on_deading_timer_timeout():
Globals.set("number_of_lifes", Globals.get("number_of_lifes") - 1)
# Check number of lifes
if(Globals.get("number_of_lifes") <= 0):
get_tree().change_scene("res://scenes/game_over.tscn")
get_tree().change_scene("res://scenes/screens/game_over.tscn")
else:
get_tree().change_scene("res://scenes/phases/" + current_phase + ".tscn")
get_tree().change_scene("res://scenes/levels/" + current_phase + ".tscn")
dead = false

func _on_invincibility_timer_timeout():
Expand Down
12 changes: 9 additions & 3 deletions game/scripts/player/sword.gd
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
###
# This script is responsible for sword behaviors.
# Author: Breno Viana
# Version: 20/10/2017
# Version: 16/11/2017
###
extends Area2D

################################################################################

# Sword damage
var damage

################################################################################

func _ready():
""" Called every time the node is added to the scene.
Initialization here. """
# Initialize values
damage = 25
# Connect behavior when entering the body
connect("body_enter", self, "_on_body_enter")

func _on_body_enter(body):
""" Called when a body entered the crate. """
# Check if the ninja enter the crate
# Check if the kunai hit a enemy
if(body.is_in_group(Globals.get("enemy_group"))):
# Check if is not dead
# Check if the enemy is not dead
if(not body.dead):
Globals.set("score", Globals.get("score") + body.PONTUATION)
body.dead = true

0 comments on commit 8563745

Please sign in to comment.