Skip to content

Commit

Permalink
Up
Browse files Browse the repository at this point in the history
  • Loading branch information
vietanhtwdk committed Jul 5, 2021
1 parent 148eb04 commit 76ffa0a
Show file tree
Hide file tree
Showing 27 changed files with 111 additions and 132 deletions.
2 changes: 1 addition & 1 deletion Level/Level3.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cell_size = Vector2( 32, 32 )
collision_layer = 4
collision_mask = 4
format = 1
tile_data = PoolIntArray( 655392, 1, 0, 655393, 1, 0, 720928, 1, 0, 720929, 1, 0 )
tile_data = PoolIntArray( 655392, 4, 0, 655393, 4, 0, 720928, 4, 0, 720929, 4, 0 )

[node name="Tree" type="TileMap" parent="."]
z_index = 1
Expand Down
2 changes: 1 addition & 1 deletion Level/Level4.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cell_size = Vector2( 32, 32 )
collision_layer = 4
collision_mask = 4
format = 1
tile_data = PoolIntArray( 196640, 1, 0, 196641, 1, 0, 262176, 1, 0, 262177, 1, 0, 458784, 1, 0, 458785, 1, 0, 524320, 1, 0, 524321, 1, 0, 589854, 1, 0, 589855, 1, 0, 589856, 1, 0, 589857, 1, 0, 655390, 1, 0, 655391, 1, 0, 655392, 1, 0, 655393, 1, 0, 720909, 1, 0, 720910, 1, 0, 720911, 1, 0, 720912, 1, 0, 720913, 1, 0, 720914, 1, 0, 720915, 1, 0, 720916, 1, 0, 720917, 1, 0, 720918, 1, 0, 720919, 1, 0, 720920, 1, 0, 720921, 1, 0, 720922, 1, 0, 720923, 1, 0, 720924, 1, 0, 720925, 1, 0, 720926, 1, 0, 720927, 1, 0, 786445, 1, 0, 786446, 1, 0, 786447, 1, 0, 786448, 1, 0, 786449, 1, 0, 786450, 1, 0, 786451, 1, 0, 786452, 1, 0, 786453, 1, 0, 786454, 1, 0, 786455, 1, 0, 786456, 1, 0, 786457, 1, 0, 786458, 1, 0, 786459, 1, 0, 786460, 1, 0, 786461, 1, 0, 786462, 1, 0, 786463, 1, 0, 851979, 1, 0, 851980, 1, 0, 851981, 1, 0, 851982, 1, 0, 917515, 1, 0, 917516, 1, 0, 917517, 1, 0, 917518, 1, 0, 983051, 1, 0, 983052, 1, 0, 1048587, 1, 0, 1048588, 1, 0 )
tile_data = PoolIntArray( 196640, 4, 0, 196641, 4, 0, 262176, 4, 0, 262177, 4, 0, 458784, 4, 0, 458785, 4, 0, 524320, 4, 0, 524321, 4, 0, 589854, 4, 0, 589855, 4, 0, 589856, 4, 0, 589857, 4, 0, 655390, 4, 0, 655391, 4, 0, 655392, 4, 0, 655393, 4, 0, 720909, 4, 0, 720910, 4, 0, 720911, 4, 0, 720912, 4, 0, 720913, 4, 0, 720914, 4, 0, 720915, 4, 0, 720916, 4, 0, 720917, 4, 0, 720918, 4, 0, 720919, 4, 0, 720920, 4, 0, 720921, 4, 0, 720922, 4, 0, 720923, 4, 0, 720924, 4, 0, 720925, 4, 0, 720926, 4, 0, 720927, 4, 0, 786445, 4, 0, 786446, 4, 0, 786447, 4, 0, 786448, 4, 0, 786449, 4, 0, 786450, 4, 0, 786451, 4, 0, 786452, 4, 0, 786453, 4, 0, 786454, 4, 0, 786455, 4, 0, 786456, 4, 0, 786457, 4, 0, 786458, 4, 0, 786459, 4, 0, 786460, 4, 0, 786461, 4, 0, 786462, 4, 0, 786463, 1, 0, 851979, 4, 0, 851980, 4, 0, 851981, 4, 0, 851982, 4, 0, 917515, 4, 0, 917516, 4, 0, 917517, 4, 0, 917518, 4, 0, 983051, 4, 0, 983052, 4, 0, 1048587, 4, 0, 1048588, 4, 0 )

[node name="Tree" type="TileMap" parent="."]
z_index = 1
Expand Down
16 changes: 10 additions & 6 deletions SS/Enemy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extends KinematicBody2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
export var speed = 300
var speed
var bullet = preload("res://SS/Bullet.tscn")
var MainGame
var rng = RandomNumberGenerator.new()
Expand All @@ -13,19 +13,25 @@ var damage
var health
var froze
var Player
var scoreReward

# Called when the node enters the scene tree for the first time.
func _ready():
speed = 300
move = 0
damage = 1
health = 1
froze = 0
scoreReward = 300
rng.randomize()
MainGame = get_node("/root/Main")


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
custom_process(delta)

func custom_process(delta):
if froze == 0:
# Player = get_node_or_null("/root/Main/Level/Player")
# if Player != null:
Expand Down Expand Up @@ -67,8 +73,6 @@ func _process(delta):
var collision = move_and_collide(velocity*delta)
if collision:
move = 0



func shoot():
if $ReloadTime.is_stopped() == true :
Expand All @@ -90,7 +94,9 @@ func hit(damageTaken):
health -= damageTaken
if health <= 0:
var oldScore = MainGame.score
MainGame.score += 300

MainGame.score += scoreReward

if(floor(float((MainGame.score/10000))) - floor(float((oldScore/10000)))==1):
MainGame.playerLife+=1
MainGame.enemyLeft -= 1
Expand All @@ -99,7 +105,6 @@ func hit(damageTaken):
queue_free()

func react(rayVector):

var toPlayer = (rayVector*-1)

if toPlayer.x > 0:
Expand All @@ -114,7 +119,6 @@ func react(rayVector):
elif toPlayer.y < 0:
$AnimatedSprite.animation = "Default"
rotation_degrees = 0

shoot()


62 changes: 8 additions & 54 deletions SS/Enemy2.gd
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
extends KinematicBody2D
extends "res://SS/Enemy.gd"


# Declare member variables here. Examples:
# var a = 2
# var b = "text"
export var speed = 400
var bullet = preload("res://SS/Bullet.tscn")
var MainGame
var rng = RandomNumberGenerator.new()
var move
var damage
var health
var froze
var Player

var PlayerBase
var toPlayerBase

# Called when the node enters the scene tree for the first time.
func _ready():
speed = 400
move = 0
damage = 1
health = 1
froze = 0
scoreReward = 400
rng.randomize()
MainGame = get_node("/root/Main")

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
#func _process(delta):
#

func custom_process(delta):
if froze == 0:
var velocity = Vector2()

Expand Down Expand Up @@ -70,49 +67,6 @@ func _process(delta):
if collision:
move = 0


func shoot():

if $ReloadTime.is_stopped() == true :
var bulletn = bullet.instance()
bulletn.damage = damage
bulletn.add_collision_exception_with(self)
bulletn.start($AnimatedSprite/Muzzle.global_position, get_rotation())
MainGame.currentLevel.add_child(bulletn)
$ReloadTime.start()
else:
pass


func _on_MoveDelay_timeout():
move = rng.randi_range(0, 9)
$MoveDelay.start()

func hit(damageTaken):
health -= damageTaken
if health <= 0:
MainGame.score += 400
MainGame.enemyLeft -= 1
if MainGame.enemyLeft == 0:
MainGame.level_clear()
queue_free()

func react(rayVector):

var toPlayer = (rayVector*-1)

if toPlayer.x > 0:
$AnimatedSprite.animation = "Default"
rotation_degrees = 90
elif toPlayer.x < 0:
$AnimatedSprite.animation = "Default"
rotation_degrees = -90
elif toPlayer.y > 0:
$AnimatedSprite.animation = "Default"
rotation_degrees = 180
elif toPlayer.y < 0:
$AnimatedSprite.animation = "Default"
rotation_degrees = 0

shoot()

67 changes: 11 additions & 56 deletions SS/Enemy3.gd
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
extends KinematicBody2D
extends "res://SS/Enemy.gd"


# Declare member variables here. Examples:
# var a = 2
# var b = "text"
export var speed = 200
var bullet = preload("res://SS/Bullet.tscn")
var MainGame
var rng = RandomNumberGenerator.new()
var move
var damage
var health
var froze
var Player
var toPlayer
var toPlayer3

# Called when the node enters the scene tree for the first time.
func _ready():
speed = 200
move = 0
damage = 2
health = 4
froze = 0
scoreReward = 500
rng.randomize()
MainGame = get_node("/root/Main")


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
#func _process(delta):
#

func custom_process(delta):
if froze == 0:
var velocity = Vector2()

if move>4 && move<10:
Player = get_node_or_null("/root/Main/Level/Player")
if Player != null:
toPlayer = Vector2(Player.position - position)
velocity += toPlayer.normalized().round()
toPlayer3 = Vector2(Player.position - position)
velocity += toPlayer3.normalized().round()



if move == 0:
Expand Down Expand Up @@ -72,48 +69,6 @@ func _process(delta):
if collision:
move = 0


func shoot():
if $ReloadTime.is_stopped() == true :
var bulletn = bullet.instance()
bulletn.damage = damage
bulletn.add_collision_exception_with(self)
bulletn.start($AnimatedSprite/Muzzle.global_position, get_rotation())
MainGame.currentLevel.add_child(bulletn)
$ReloadTime.start()
else:
pass


func _on_MoveDelay_timeout():
move = rng.randi_range(0, 9)
$MoveDelay.start()

func hit(damageTaken):
health -= damageTaken
if health <= 0:
MainGame.score += 500
MainGame.enemyLeft -= 1
if MainGame.enemyLeft == 0:
MainGame.level_clear()
queue_free()

func react(rayVector):

var toPlayer = (rayVector*-1)

if toPlayer.x > 0:
$AnimatedSprite.animation = "Default"
rotation_degrees = 90
elif toPlayer.x < 0:
$AnimatedSprite.animation = "Default"
rotation_degrees = -90
elif toPlayer.y > 0:
$AnimatedSprite.animation = "Default"
rotation_degrees = 180
elif toPlayer.y < 0:
$AnimatedSprite.animation = "Default"
rotation_degrees = 0

shoot()

10 changes: 9 additions & 1 deletion SS/HUD.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ extends CanvasLayer
# Called when the node enters the scene tree for the first time.
func _ready():
$PauseMenu.hide()

if OS.get_name()=="Windows":
$ColorRect/Shoot.hide()
$ColorRect2/Down.hide()
$ColorRect2/Right.hide()
$ColorRect2/Up.hide()
$ColorRect2/Left.hide()





# Called every frame. 'delta' is the elapsed time since the previous frame.
Expand Down
32 changes: 29 additions & 3 deletions SS/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,16 @@ func load_level(var stage):


func spawn_player():
player = Player.instance()
currentLevel.add_child(player)
player.position = playerPosition
yield(get_tree().create_timer(1.5), "timeout")
# print_tree()
if get_node_or_null("/root/Main/Level/Player"):
pass
else:
if get_node_or_null("/root/Main/Level"):
player = Player.instance()
currentLevel.add_child(player)
player.position = playerPosition


func spawn_enemy():
var enemyType = rng.randi_range(0, 5)
Expand All @@ -102,6 +109,7 @@ func level_clear():
$EnemySpawnTimer.stop()
$PowerUpSpawnTimer.stop()
currentLevel.queue_free()
yield(get_tree().create_timer(1.0), "timeout")
levelNum += 1
load_level(levelNum)

Expand Down Expand Up @@ -160,3 +168,21 @@ func _on_ResultTimer_timeout():
resultScreen.get_node("Label").text = str("Level Reached: "
+ str(levelNum) + "\nScore: " + str(score))
add_child(resultScreen)


#func _on_Button_pressed():
# print_tree()
#
#
#func _on_Button2_pressed():
# get_node("/root/Main/Level/Player").hit(10)
# spawn_player()
# game_over()
# level_clear()
# var enemies = get_tree().get_nodes_in_group("Enemies")
# for enemy in enemies:
# enemy.hit(10)


#func _on_Button2_pressed():
# enemyLeft=5
20 changes: 20 additions & 0 deletions SS/ResultScreen.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ extends CanvasLayer

# Called when the node enters the scene tree for the first time.
func _ready():
get_node("/root/Main/EnemySpawnTimer").stop()
get_node("/root/Main/PowerUpSpawnTimer").stop()
if (int(load_high_score())<get_node("/root/Main").score):
save_high_score()
$Label2.text= str("High score: " + str(get_node("/root/Main").score))
else:
$Label2.text= str("High score: " + load_high_score())
$AdMob.load_banner()


Expand All @@ -17,6 +24,7 @@ func _ready():


func _on_Button_pressed():
$AdMob.hide_banner()
get_node("/root/Main")._on_MainMenu_start_game()
queue_free()

Expand All @@ -26,3 +34,15 @@ func _on_Button_pressed():
func _on_Button2_pressed():
get_tree().reload_current_scene()

func save_high_score():
var file = File.new()
file.open("user://high_score.txt", File.WRITE)
file.store_string(str(get_node("/root/Main").score))
file.close()

func load_high_score():
var file = File.new()
file.open("user://high_score.txt", File.READ)
var content = file.get_as_text()
file.close()
return content
Loading

0 comments on commit 76ffa0a

Please sign in to comment.