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,91 @@
|
||||
@tool
|
||||
extends Node2D
|
||||
const FONT = preload("res://games/galaga/art/spr_galaga_screens_fonts.png")
|
||||
const SHEET = preload("res://games/galaga/art/spr_galaga.png")
|
||||
var attract_time := 0.0
|
||||
var previous_state := ""
|
||||
var high_score := 20000
|
||||
var edge_mask: Node2D
|
||||
|
||||
func _ready() -> void:
|
||||
texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
|
||||
edge_mask = preload("res://games/galaga/galaga_edge_mask.gd").new()
|
||||
edge_mask.z_index = 100
|
||||
add_child(edge_mask)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var game = get_parent()
|
||||
if game.state == "idle":
|
||||
if previous_state != "idle": attract_time = 0.0
|
||||
attract_time += delta
|
||||
for actor in get_children():
|
||||
if actor == edge_mask: continue
|
||||
if game.state == "idle" and not Engine.is_editor_hint(): actor.visible = false
|
||||
previous_state = game.state
|
||||
high_score = maxi(high_score,game.score)
|
||||
var size := get_viewport_rect().size
|
||||
var factor := maxf(0.1,minf(size.x/224.0,size.y/288.0))
|
||||
if factor >= 1: factor = floorf(factor)
|
||||
scale = Vector2.ONE*factor
|
||||
position = ((size-Vector2(224,288)*factor)/2).floor()
|
||||
queue_redraw()
|
||||
|
||||
func _draw() -> void:
|
||||
draw_rect(Rect2(-1000,-1000,2224,2288),Color.BLACK)
|
||||
var star_clock: float = attract_time if get_parent().state=="idle" else get_parent().clock
|
||||
for i in range(90):
|
||||
var x := fposmod(i*73.0,224)
|
||||
var y := fposmod(i*113.0+star_clock*(12+i%3*8),288)
|
||||
if (int(star_clock*2)+i)%7!=0:
|
||||
draw_rect(Rect2(Vector2(x,y).round(),Vector2.ONE),[Color.CYAN,Color.RED,Color.YELLOW,Color.BLUE,Color.MAGENTA,Color.WHITE][i%6]*0.7)
|
||||
if get_parent().state == "idle" and not Engine.is_editor_hint():
|
||||
_attract()
|
||||
return
|
||||
_text("1UP %06d" % get_parent().score,Vector2(8,4))
|
||||
if get_parent().state != "intro":
|
||||
for i in range(mini(5,maxi(0,get_parent().lives-1))):
|
||||
draw_texture_rect_region(SHEET,Rect2(8+i*16,270,16,16),Rect2(109,1,16,16))
|
||||
_text("STAGE %d" % get_parent().stage,Vector2(144,278))
|
||||
var text: String = {"intro":"PLAYER 1","stage_card":"STAGE %d" % get_parent().stage,"ready":"PLAYER 1 STAGE %d" % get_parent().stage,"won":"YOU WIN!","lost":"GAME OVER","clear":"STAGE CLEAR"}.get(get_parent().state,"")
|
||||
if text != "": _text(text,Vector2((224-text.length()*8)/2,180),Color.CYAN)
|
||||
if get_parent().state=="captured_return": _center("FIGHTER CAPTURED",180,Color.CYAN)
|
||||
elif get_parent().state=="capture_ready": _center("READY",180,Color.CYAN)
|
||||
var game = get_parent()
|
||||
if not game.beam.is_empty() and game.beam.mode=="beam":
|
||||
var source_x := 289+int(game.clock*8)%3*50
|
||||
draw_texture_rect_region(SHEET,Rect2(game.beam.node.position.round()+Vector2(-24,8),Vector2(48,79)),Rect2(source_x,36,48,79))
|
||||
|
||||
func _text(message: String, at: Vector2, tint := Color.WHITE) -> void:
|
||||
var chars := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
for i in range(message.length()):
|
||||
var index := chars.find(message[i])
|
||||
if index<0: continue
|
||||
var row := 0 if index<25 else 1
|
||||
var col := index if row==0 else index-25
|
||||
draw_texture_rect_region(FONT,Rect2(at+Vector2(i*8,0),Vector2(7,7)),Rect2(454+col*9,443+row*9,7,7),tint)
|
||||
|
||||
func _center(message: String, y: float, tint := Color.WHITE) -> void:
|
||||
_text(message,Vector2((224-message.length()*8)/2,y),tint)
|
||||
|
||||
func _attract() -> void:
|
||||
_text("1UP",Vector2(16,0),Color.RED)
|
||||
_text("HIGH SCORE",Vector2(72,0),Color.RED)
|
||||
_text("2UP",Vector2(184,0),Color.RED)
|
||||
_center(str(high_score).pad_zeros(6),10)
|
||||
if int(attract_time / 8.0) % 2 == 0:
|
||||
_center("PUSH START BUTTON",104,Color.CYAN)
|
||||
var bonus: int = get_parent().extra_life_score
|
||||
var messages := ["1ST BONUS FOR %d PTS" % bonus,"2ND BONUS FOR %d PTS" % get_parent().second_extra_life_score,"AND FOR EVERY %d PTS" % get_parent().repeat_extra_life_interval]
|
||||
for i in range(3):
|
||||
_text(messages[i],Vector2(24,136+i*24),Color.YELLOW)
|
||||
draw_texture_rect_region(SHEET,Rect2(8,132+i*24,16,16),Rect2(109,1,16,16))
|
||||
else:
|
||||
_center("THE GALACTIC HEROES",56,Color.BLUE)
|
||||
_center("BEST 5",112,Color.RED)
|
||||
_text("SCORE NAME",Vector2(64,152),Color.CYAN)
|
||||
for i in range(5):
|
||||
_text(["1ST","2ND","3RD","4TH","5TH"][i],Vector2(24,176+i*16),Color.CYAN)
|
||||
_text(str(high_score if i==0 else (5-i)*1000).pad_zeros(6),Vector2(64,176+i*16),Color.CYAN)
|
||||
_text(["AAA","BBB","CCC","DDD","EEE"][i],Vector2(144,176+i*16),Color.CYAN)
|
||||
_text("CREDIT %d" % get_parent().credits,Vector2(8,278))
|
||||
|
||||
Reference in new issue
Block a user