Add new features

- full controller support
- keyboard only support
- weapon can now attack up/left/down/right instead of targetting and clicking
- relics are now randomly placed
- player is now randomly placed
- zombies are now randomly placed
- zombies are now placed not too far from the player
- more rooms have been added
This commit is contained in:
Solene Rapenne 2022-04-30 20:11:51 +02:00
parent 6e0447a9bf
commit 63689f8e60
7 changed files with 139 additions and 71 deletions

5
src/Intro.gd Normal file
View File

@ -0,0 +1,5 @@
extends Node2D
func _input(event):
if event.is_action_pressed("ui_accept"):
$CanvasLayer/Node2D/Label._on_Button_pressed()

View File

@ -1,9 +1,11 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Label.gd" type="Script" id=1]
[ext_resource path="res://Intro.gd" type="Script" id=2]
[node name="CanvasLayer" type="Node2D"]
scale = Vector2( 6.25854, 7.12237 )
script = ExtResource( 2 )
[node name="CanvasLayer" type="CanvasLayer" parent="."]
@ -11,28 +13,28 @@ scale = Vector2( 6.25854, 7.12237 )
[node name="Label" type="Label" parent="CanvasLayer/Node2D"]
margin_left = 20.0
margin_top = 24.0
margin_top = 6.0
margin_right = 280.0
margin_bottom = 259.0
margin_bottom = 258.0
rect_scale = Vector2( 2, 2 )
text = "Welcome to Z-hack
You are a brave adventurer looking to retrieve five lost relics. You heard the relics may be found in an old dungeon where all the population got turned into zombies aeons ago.
You are a brave adventurer looking to retrieve lost relics. You heard the relics may be found in an old dungeon where all the population got turned into zombies aeons ago.
Death is only one bite away.
Controls:
- wasd or arrows to move
- click to swing your sword
- wasd/arrows/controller to move
- click/ijkl/controller buttons to swing your sword in a direction
Extra: type cheat to cheat"
autowrap = true
script = ExtResource( 1 )
[node name="Button" type="Button" parent="CanvasLayer/Node2D"]
margin_left = 117.0
margin_top = 516.0
margin_top = 526.0
margin_right = 246.0
margin_bottom = 536.0
margin_bottom = 546.0
rect_scale = Vector2( 3, 3 )
text = "Enter the dungeon"

View File

@ -1,27 +1,48 @@
extends Node2D
export(PackedScene) var zombie_scene
export(PackedScene) var relic_scene
var relic_left = 5
var relics = []
var relic_left = 0
var debug = 1
func add_zombie():
var zombie = zombie_scene.instance()
zombie.set_player($Player)
var zombie_spawn_location = get_node("Enemies/zombiePath/zombieSpawnLocation")
zombie_spawn_location.offset = randi()
zombie.position = zombie_spawn_location.position
if zombie.position.distance_to($Player.position) > 40:
# zombie.look_at($Player.position)
# zombie.linear_velocity = Vector2(100, 0).rotated(zombie.rotation)
zombie.connect("hit", self, 'player_got_hit')
add_child(zombie)
else:
add_zombie()
zombie.position = $TileMap.random_valid_safe_position($Player.position, "ground")
zombie.connect("hit", self, 'player_got_hit')
add_child(zombie)
func add_relics():
relic_left += 1
var relic = relic_scene.instance()
var relic_position = Vector2.ZERO
var found_position = 0
# avoid spawning a relic too close to another one
while found_position == 0:
found_position = 1
relic_position = $TileMap.random_valid_position("ground")
for r in relics:
if r.position.distance_to(relic_position) < 10*32:
found_position = 0
break
relic.position = relic_position
relic.connect("relic", self, 'score_increase')
relics.append(relic)
add_child(relic)
func _ready():
VisualServer.set_default_clear_color(Color(0.0,0.0,0.0,1.0))
randomize()
$Darkness.visible = true
for i in 8:
add_relics()
$Player.relic_left(relic_left)
var random_pos = $TileMap.random_valid_position("ground")
$Player.position = random_pos
func _on_SpawnEnemy_timeout():
add_zombie()

File diff suppressed because one or more lines are too long

View File

@ -40,15 +40,40 @@ func _input(event):
cheat = 5
$Camera2D/CanvasLayer/Cheater.visible = true
$Camera2D/CanvasLayer/CheatTimer.start()
if event.is_action_pressed("attack") and $WeaponTimer.is_stopped() :
$WeaponTimer.start()
var mouse_loc = get_global_mouse_position()
var sword = weapons.instance()
# sword.rotation = sword.position.angle_to_point(mouse_loc)
add_child(sword)
sword.look_at(mouse_loc)
sword.rotate(PI/2)
# allow to restart using keyboard or controller
if event.is_action_pressed("ui_accept"):
if $Camera2D/CanvasLayer/Restart.visible:
_on_Button_pressed()
if $WeaponTimer.is_stopped():
if event.is_action_pressed("attack_up"):
var sword = weapons.instance()
$WeaponTimer.start()
add_child(sword)
sword.rotate(TAU)
if event.is_action_pressed("attack_right"):
var sword = weapons.instance()
$WeaponTimer.start()
add_child(sword)
sword.rotate(PI/2)
if event.is_action_pressed("attack_left"):
var sword = weapons.instance()
$WeaponTimer.start()
add_child(sword)
sword.rotate(-PI/2)
if event.is_action_pressed("attack_down"):
var sword = weapons.instance()
$WeaponTimer.start()
add_child(sword)
sword.rotate(PI)
if event.is_action_pressed("attack"):
$WeaponTimer.start()
var mouse_loc = get_global_mouse_position()
var sword = weapons.instance()
add_child(sword)
sword.look_at(mouse_loc)
sword.rotate(PI/2)
func _process(delta):
var velocity = Vector2.ZERO

17
src/TileMap.gd Normal file
View File

@ -0,0 +1,17 @@
extends TileMap
func random_valid_position(tile_name):
var clear_tiles = get_used_cells()
while true:
var tile = clear_tiles[randi()%clear_tiles.size()]
if get_cellv(tile) == tile_set.find_tile_by_name(tile_name):
return(tile*self.cell_size + cell_size/2)
func random_valid_safe_position(player, tile_name):
var position
var position_to_player
while true:
position = random_valid_position(tile_name)
position_to_player = position.distance_to(player)
if position_to_player > 4*32 and position_to_player < 30*32:
return(position)

View File

@ -29,6 +29,7 @@ ui_left={
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":81,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
]
}
ui_right={
@ -36,6 +37,7 @@ ui_right={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
]
}
ui_up={
@ -44,6 +46,7 @@ ui_up={
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":90,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
]
}
ui_down={
@ -51,6 +54,7 @@ ui_down={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
]
}
attack={
@ -58,6 +62,30 @@ attack={
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
]
}
attack_left={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":74,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":2,"pressure":0.0,"pressed":false,"script":null)
]
}
attack_right={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":76,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":1,"pressure":0.0,"pressed":false,"script":null)
]
}
attack_up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":73,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":3,"pressure":0.0,"pressed":false,"script":null)
]
}
attack_down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":75,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
]
}
[physics]