diff options
author | David Luevano Alvarado <david@luevano.xyz> | 2022-06-04 23:00:58 -0600 |
---|---|---|
committer | David Luevano Alvarado <david@luevano.xyz> | 2022-06-04 23:00:58 -0600 |
commit | 36abc689d783774ce4f2d7b5a1bb621d8684be45 (patch) | |
tree | a3dbed6069fbd8d9a588c7510ce581af3e847af0 /src/entities | |
parent | 9a2bcf02c2623c8f3e8f5e74e70b3c0333790484 (diff) |
added more ui for after gameplay, generalized basic food
Diffstat (limited to 'src/entities')
-rw-r--r-- | src/entities/actors/snake/scripts/head.gd | 13 | ||||
-rw-r--r-- | src/entities/actors/snake/scripts/snake.gd | 2 | ||||
-rw-r--r-- | src/entities/food/scripts/food.gd | 2 | ||||
-rw-r--r-- | src/entities/food/scripts/food_basic.gd | 6 | ||||
-rw-r--r-- | src/entities/food/scripts/food_manager.gd | 27 | ||||
-rw-r--r-- | src/entities/food/sprites/apple.png | bin | 135 -> 155 bytes | |||
-rw-r--r-- | src/entities/food/sprites/banana.png | bin | 0 -> 184 bytes | |||
-rw-r--r-- | src/entities/food/sprites/banana.png.import | 35 |
8 files changed, 70 insertions, 15 deletions
diff --git a/src/entities/actors/snake/scripts/head.gd b/src/entities/actors/snake/scripts/head.gd index 32847f7..8747910 100644 --- a/src/entities/actors/snake/scripts/head.gd +++ b/src/entities/actors/snake/scripts/head.gd @@ -28,6 +28,19 @@ func _physics_process(delta: float) -> void: # not sure if needed, worked wonders when using a Node2D instead of KB2D velocity = move_and_slide(velocity) + + # slow down on collisions, so it isn't as unfair + if get_last_slide_collision(): + var speed: float = velocity.length() + Global.SNAKE_SPEED = speed + else: + Global.SNAKE_SPEED = Global.SNAKE_SPEED_BACKUP + + # handle slow speeds + if Global.SNAKE_SPEED <= Global.SNAKE_SPEED_BACKUP / 4.0: + Global.SNAKE_SPEED = Global.SNAKE_SPEED_BACKUP + Event.emit_signal("game_over") + _handle_time_elapsed(delta) diff --git a/src/entities/actors/snake/scripts/snake.gd b/src/entities/actors/snake/scripts/snake.gd index 91e4e39..bae6e83 100644 --- a/src/entities/actors/snake/scripts/snake.gd +++ b/src/entities/actors/snake/scripts/snake.gd @@ -6,6 +6,8 @@ export(PackedScene) var TAIL_SEGMENT_NP: PackedScene onready var path: Path2D = $Path +var stats: Stats = SaveData.get_stats() + var finished_adding_initial_segments: bool = false var current_body_segments: int = 0 var body_segment_stack: Array diff --git a/src/entities/food/scripts/food.gd b/src/entities/food/scripts/food.gd index ca27acc..aa5207f 100644 --- a/src/entities/food/scripts/food.gd +++ b/src/entities/food/scripts/food.gd @@ -47,7 +47,7 @@ func _set_properties() -> void: func randomize_stats() -> void: - points = int(rand_range(1, 30)) + points = int(rand_range(1, 10)) func _on_body_entered(body: Node) -> void: diff --git a/src/entities/food/scripts/food_basic.gd b/src/entities/food/scripts/food_basic.gd index 0a56208..032ec23 100644 --- a/src/entities/food/scripts/food_basic.gd +++ b/src/entities/food/scripts/food_basic.gd @@ -2,9 +2,11 @@ class_name FoodBasic extends Food enum Type { - APPLE + APPLE, + BANANA } func _ready(): - texture[Type.APPLE] = preload("res://entities/food/sprites/apple.png")
\ No newline at end of file + texture[Type.APPLE] = preload("res://entities/food/sprites/apple.png") + texture[Type.BANANA] = preload("res://entities/food/sprites/banana.png")
\ No newline at end of file diff --git a/src/entities/food/scripts/food_manager.gd b/src/entities/food/scripts/food_manager.gd index 4196806..bbe27be 100644 --- a/src/entities/food/scripts/food_manager.gd +++ b/src/entities/food/scripts/food_manager.gd @@ -6,8 +6,7 @@ export(NodePath) var WORLD_GENERATOR_NP: NodePath onready var world_generator: Node2D = get_node(WORLD_GENERATOR_NP) onready var possible_food_locations: Array = world_generator.get_valid_map_coords() -var max_apples: int = 10 -var current_food: Array = [] +var current_basic_food: Array = [] func _ready(): @@ -16,13 +15,13 @@ func _ready(): func _process(delta) -> void: - if current_food.size() < max_apples: - _place_new_food() + if current_basic_food.size() < Global.MAX_BASIC_FOOD: + _place_new_basic_food() -func _place_new_food() -> void: +func _place_new_basic_food() -> void: var food: FoodBasic = FOOD_BASIC.instance() - var type: int = FoodBasic.Type.APPLE + var type: int = _get_random_food_type(FoodBasic.Type) Event.emit_signal("food_placing_new_food", type) var pos_loc: Array = _get_random_pos() var pos: Vector2 = pos_loc[0] @@ -31,13 +30,17 @@ func _place_new_food() -> void: # need to set the position first, else it will spawn on the middle and the moved food.global_position = pos add_child(food) - food.set_type(FoodBasic.Type.APPLE) + food.set_type(type) food.set_location(loc) - food.properties["points"] = 1 - current_food.append(loc) + # food.properties["points"] = 1 + current_basic_food.append(loc) Event.emit_signal("food_placed_new_food", food.properties["type"], food.properties["location"]) +func _get_random_food_type(type) -> int: + return randi() % type.size() + + func _get_random_pos() -> Array: var found_valid_loc: bool = false var index: int @@ -46,12 +49,12 @@ func _get_random_pos() -> Array: while not found_valid_loc: index = randi() % possible_food_locations.size() location = possible_food_locations[index] - if current_food.find(location) == -1: + if current_basic_food.find(location) == -1: found_valid_loc = true return [world_generator.get_centered_world_position(location), location] func _on_food_eaten(properties: Dictionary) -> void: - var index: int = current_food.find(properties["location"]) - current_food.remove(index) + var index: int = current_basic_food.find(properties["location"]) + current_basic_food.remove(index) diff --git a/src/entities/food/sprites/apple.png b/src/entities/food/sprites/apple.png Binary files differindex 7111450..2eb9080 100644 --- a/src/entities/food/sprites/apple.png +++ b/src/entities/food/sprites/apple.png diff --git a/src/entities/food/sprites/banana.png b/src/entities/food/sprites/banana.png Binary files differnew file mode 100644 index 0000000..afe7b51 --- /dev/null +++ b/src/entities/food/sprites/banana.png diff --git a/src/entities/food/sprites/banana.png.import b/src/entities/food/sprites/banana.png.import new file mode 100644 index 0000000..e4da833 --- /dev/null +++ b/src/entities/food/sprites/banana.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/banana.png-790b92b84b3b62d7a7828565ae8ed4ec.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://entities/food/sprites/banana.png" +dest_files=[ "res://.import/banana.png-790b92b84b3b62d7a7828565ae8ed4ec.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=false +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 |