Added Glitch Room Source code to Gitty
This commit is contained in:
commit
1ac9eb5644
505 files changed
+28504
No files matched your search
@@ -0,0 +1,82 @@
|
||||
extends ArcadeGame
|
||||
const Model = preload("res://games/pacman/pacman_model.gd")
|
||||
const View = preload("res://games/pacman/pacman_view.gd")
|
||||
const Sound = preload("res://games/pacman/pacman_audio.gd")
|
||||
|
||||
@export_group("Room Objective")
|
||||
## Zero means unlimited boards. Set a score target or use arcade mode.
|
||||
@export_range(0, 100, 1) var boards_to_win: int = 1
|
||||
@export_range(0, 1000000, 100) var score_to_win: int = 0
|
||||
@export_range(1, 9, 1) var starting_lives: int = 3
|
||||
@export var extra_life_score: int = 10000
|
||||
var model = Model.new()
|
||||
var view
|
||||
var audio
|
||||
var accumulator := 0.0
|
||||
|
||||
func _ready() -> void:
|
||||
view = View.new()
|
||||
view.model = model
|
||||
add_child(view)
|
||||
audio = Sound.new()
|
||||
add_child(audio)
|
||||
model.sound_requested.connect(audio.play_effect)
|
||||
model.finished.connect(_on_finished)
|
||||
_apply_config()
|
||||
|
||||
func configure(config: Dictionary = {}) -> void:
|
||||
super.configure(config)
|
||||
_apply_config()
|
||||
|
||||
func _apply_config() -> void:
|
||||
model.boards_to_win = maxi(0, int(run_config.get("boards_to_win", boards_to_win)))
|
||||
model.score_to_win = maxi(0, int(run_config.get("score_to_win", score_to_win)))
|
||||
model.initial_lives = clampi(int(run_config.get("starting_lives", starting_lives)), 1, 9)
|
||||
model.extra_life_score = maxi(0, int(run_config.get("extra_life_score", extra_life_score)))
|
||||
|
||||
func start_game() -> bool:
|
||||
if is_running: return false
|
||||
_apply_config()
|
||||
audio.stop_all()
|
||||
model.start()
|
||||
accumulator = 0.0
|
||||
return super.start_game()
|
||||
|
||||
func reset_game() -> void:
|
||||
audio.stop_all()
|
||||
model.reset()
|
||||
accumulator = 0.0
|
||||
super.reset_game()
|
||||
|
||||
func win_game() -> void:
|
||||
if not is_running: return
|
||||
model.state = "won"
|
||||
audio.stop_all()
|
||||
super.win_game()
|
||||
|
||||
func lose_game() -> void:
|
||||
if not is_running: return
|
||||
model.state = "lost"
|
||||
audio.stop_all()
|
||||
super.lose_game()
|
||||
|
||||
func _on_finished(won: bool) -> void:
|
||||
if won: win_game()
|
||||
else: lose_game()
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("arcade_start"):
|
||||
start_game()
|
||||
get_viewport().set_input_as_handled()
|
||||
for pair in [["arcade_up", Vector2i.UP], ["arcade_left", Vector2i.LEFT], ["arcade_down", Vector2i.DOWN], ["arcade_right", Vector2i.RIGHT]]:
|
||||
if event.is_action_pressed(pair[0]): model.requested = pair[1]
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if not is_running:
|
||||
model.clock += delta
|
||||
if is_running:
|
||||
accumulator += minf(delta, 0.25)
|
||||
while accumulator >= 1.0 / 60.0 and is_running:
|
||||
model.update(1.0 / 60.0)
|
||||
accumulator -= 1.0 / 60.0
|
||||
if audio != null: audio.set_background(model.background_sound() if is_running else "")
|
||||
Reference in new issue
Block a user