I can't remember the changes for this one

master
Luke Hubmayer-Werner 2020-04-20 20:00:00 +09:30
parent 0b9d14f18f
commit 190a995167
19 changed files with 539 additions and 179 deletions

43
HBoxContainer.gd 100644
View File

@ -0,0 +1,43 @@
extends Control
var cursor = load('res://assets/sprites/downarrow.png')
func _ready():
pass
func _process(delta):
update()
var cursor_sprites = [
null,
load('res://assets/sprites/belt.tres'),
load('res://assets/sprites/channel.tres'),
load('res://assets/sprites/2x2belt.tres'),
load('res://assets/sprites/smelter.tres'),
load('res://assets/sprites/forge.tres'),
load('res://assets/sprites/lathe.tres'),
load('res://assets/sprites/welder.tres'),
]
func _draw():
var p1_s = $"/root/Main".p1_selection
var x_offsets = [0, 16, 28, 44, 68, 96, 128, 164]
var pos1 = Vector2(x_offsets[p1_s]+4, 336)
draw_texture(cursor, pos1, Color.yellow)
if p1_s > 0:
var mouse_pos = get_viewport().get_mouse_position()
mouse_pos = Vector2(floor(mouse_pos.x/8)*8, floor(mouse_pos.y/8)*8)
draw_texture(cursor_sprites[p1_s], mouse_pos, Color(0.75, 0.75, 0.75, 0.75))
func _input(event):
if event is InputEventMouseButton and event.pressed:
if event.button_mask & BUTTON_MASK_LEFT:
if $HBoxContainer.get_rect().has_point(event.position):
for i in 8:
if $HBoxContainer.get_child(i).get_global_rect().has_point(event.position):
$"/root/Main".p1_selection = i
break
elif event is InputEventMouseMotion:
pass

View File

@ -1,4 +1,5 @@
extends Node2D
var p1_selection = 0
var crosshair_16 = preload("res://assets/sprites/cursor_16.tres")
var crosshair_32 = preload("res://assets/sprites/cursor_32.tres")
@ -7,6 +8,7 @@ var crosshair_64 = preload("res://assets/sprites/cursor_64.tres")
func _ready():
update_cursor(1)
func update_cursor(size):
match size:
0:
@ -17,3 +19,4 @@ func update_cursor(size):
Input.set_custom_mouse_cursor(crosshair_48, Input.CURSOR_ARROW, Vector2(24, 24))
3:
Input.set_custom_mouse_cursor(crosshair_64, Input.CURSOR_ARROW, Vector2(32, 32))

218
Main.tscn

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,9 @@
[gd_resource type="DynamicFont" load_steps=2 format=2]
[sub_resource type="DynamicFontData" id=1]
[ext_resource path="res://assets/NotoSans.tres" type="DynamicFontData" id=1]
[resource]
font_data = SubResource( 1 )
size = 5
outline_size = 1
outline_color = Color( 0, 0, 0, 1 )
font_data = ExtResource( 1 )

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/downarrow.png-08119f1ff9a5cbf3528c37872329e05f.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/sprites/downarrow.png"
dest_files=[ "res://.import/downarrow.png-08119f1ff9a5cbf3528c37872329e05f.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=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

15
bgm.gd
View File

@ -1,11 +1,20 @@
extends AudioStreamPlayer
const BAR_LENGTH = 0.5
const SEGMENT_TIMES = [1.0, 9.0, 15.0, 33.0, 41.0, 57.0, 83.0]
enum SEGMENT_NAMES {Intro, Bass, Piano, KeyChange, Return, Outro, Fanfare}
const START_DELAY = 1.0
const BAR_LENGTH = 2.0
#const SEGMENT_TIMES = [0.0, 8.0, 16.0, 32.0, 40.0, 56.0, 76.0, 82.0]+1
const SEGMENT_TIMES = [1.0, 9.0, 17.0, 33.0, 41.0, 57.0, 77.0, 83.0]
enum SEGMENT_NAMES {Intro, Bass, Piano, KeyChange, Return, Outro, Ending, Fanfare}
var queue = [SEGMENT_NAMES.Intro, SEGMENT_NAMES.Bass, SEGMENT_NAMES.Bass, SEGMENT_NAMES.Bass]
func _ready():
pass
func get_bartime(realtime):
return (realtime - START_DELAY) / BAR_LENGTH
func queue_fanfare():
var current_bartime = get_bartime(get_playback_position())
func set_volume(value):
set_volume_db(linear2db(value))

View File

@ -1,3 +1,4 @@
tool
extends Node
enum MATERIAL_TYPE {iORE, iSTOCK, iROD, iLADDER, iLADDER2, iLADDER4, iMOLTEN}
@ -7,5 +8,23 @@ var RECIPES = {
MACHINE_TYPE.SMELTER: {input=MATERIAL_TYPE.iORE, output=MATERIAL_TYPE.iMOLTEN, time=4.0},
MACHINE_TYPE.FORGE: {input=MATERIAL_TYPE.iMOLTEN, output=MATERIAL_TYPE.iSTOCK, time=4.0},
MACHINE_TYPE.LATHE: {input=MATERIAL_TYPE.iSTOCK, output=MATERIAL_TYPE.iROD, time=4.0},
MACHINE_TYPE.WELDER: {input=MATERIAL_TYPE.iROD, output=MATERIAL_TYPE.iLADDER, time=8.0},
MACHINE_TYPE.WELDER: {input=MATERIAL_TYPE.iROD, output=MATERIAL_TYPE.iLADDER, time=4.0},
}
onready var MACHINE_SCENES = {
MACHINE_TYPE.SMELTER: load("res://machines/Smelter.tscn"),
MACHINE_TYPE.FORGE: load("res://machines/Forge.tscn"),
MACHINE_TYPE.LATHE: load("res://machines/Lathe.tscn"),
MACHINE_TYPE.WELDER: load("res://machines/Welder.tscn"),
}
onready var MATERIAL_SCENES = {
MATERIAL_TYPE.iORE: load("res://objects/IronOre.tscn"),
MATERIAL_TYPE.iSTOCK: load("res://objects/IronStock.tscn"),
MATERIAL_TYPE.iROD: load("res://objects/IronRod.tscn"),
MATERIAL_TYPE.iLADDER: load("res://objects/SmallLadder.tscn"),
MATERIAL_TYPE.iLADDER2: load("res://objects/MedLadder.tscn"),
MATERIAL_TYPE.iLADDER4: load("res://objects/BigLadder.tscn"),
}
var font = preload("res://assets/UI_module_names.tres")

View File

@ -6,22 +6,118 @@ export var max_input_buffer := 3
var num_inputs = 0
var working := false setget set_working
var idle_time := 0.0
var work_time := 0.0
var anim_speed = 1.0
onready var rect = $sprite.get_rect()
onready var width = rect.size.x
onready var height = rect.size.y
onready var w_cells = width/8
onready var h_cells = height/8
onready var beltmap = $"/root/Main/TileMap/BeltTiles"
var surrounding_tilename_indices
var surrounding_tilename_indices_internal
var surrounding_tilename_indices_dir
var was_started = false
var dir_vectors = [Vector2(1,0), Vector2(0,-1), Vector2(-1,0), Vector2(0,1)]
var dir_angles = [0, 90, 0, 90] # Angles to rotate output by
func get_belt_direction(tx, ty):
var xflip = beltmap.is_cell_x_flipped(tx, ty)
var tp = beltmap.is_cell_transposed(tx, ty)
return int(tp) + int(xflip)*2
onready var recipe = Constants.RECIPES[machine_type]
func _ready():
pass
var top_left_corner_tile = position - Vector2(width/2-4, height/2-4)
var tlct = beltmap.world_to_map(top_left_corner_tile)
surrounding_tilename_indices = []
surrounding_tilename_indices_internal = []
surrounding_tilename_indices_dir = []
# Add all orthogonal cells in clockwise order
for i in w_cells:
surrounding_tilename_indices.append(tlct+Vector2(i,-1))
surrounding_tilename_indices_internal.append(tlct+Vector2(i,0))
surrounding_tilename_indices_dir.append(1)
for i in h_cells:
surrounding_tilename_indices.append(tlct+Vector2(w_cells,i))
surrounding_tilename_indices_internal.append(tlct+Vector2(w_cells-1,i))
surrounding_tilename_indices_dir.append(0)
for i in w_cells:
surrounding_tilename_indices.append(tlct+Vector2(w_cells-1-i,h_cells))
surrounding_tilename_indices_internal.append(tlct+Vector2(w_cells-1-i,h_cells-1))
surrounding_tilename_indices_dir.append(3)
for i in h_cells:
surrounding_tilename_indices.append(tlct+Vector2(-1,h_cells-1-i))
surrounding_tilename_indices_internal.append(tlct+Vector2(0,h_cells-1-i))
surrounding_tilename_indices_dir.append(2)
func _process(delta):
if num_inputs < max_input_buffer:
if num_inputs < max_input_buffer and recipe.input != Constants.MATERIAL_TYPE.iMOLTEN:
suck_materials()
if working:
if work_time >= recipe.time:
output()
else:
work_time += delta
return
if num_inputs <= 0:
if not was_started:
return
self.working = false
idle_time += delta
var overspeed = clamp(floor(idle_time/2)*2, 1, 8)
$sprite.material.set_shader_param('rps', overspeed*anim_speed)
else:
self.working = true
was_started = true
num_inputs -= 1
work_time = 0
idle_time = 0
func output():
if recipe.output == Constants.MATERIAL_TYPE.iMOLTEN:
for i in len(surrounding_tilename_indices):
var ind = surrounding_tilename_indices[i]
if beltmap.get_cell(ind.x, ind.y) == 4: # Channel
var dir = get_belt_direction(ind.x, ind.y)
if dir != surrounding_tilename_indices_dir[i]:
continue
else:
var xy = ind
while(true):
xy += dir_vectors[dir]
if beltmap.get_cell(xy.x, xy.y) == 4:
if get_belt_direction(xy.x, xy.y) == dir:
continue
else:
for child in get_parent().get_children(): # Check if a suitable machine is on this tile
if child.rect.has_point(child.to_local(beltmap.map_to_world(xy) + Vector2(4,4))):
child.feed(null)
return
break
else:
for i in len(surrounding_tilename_indices):
var ind = surrounding_tilename_indices[i]
var celltype = beltmap.get_cell(ind.x, ind.y)
if celltype >= 0 and celltype != 4: # Belt
# For correct logic on 2wide outputs, we'd have to check for 2 adjacent belts
# Since we have no time, we'll just throw it out as if there was a second belt
# If people think they're exploiting the game, they're only playing themselves
var dir = get_belt_direction(ind.x, ind.y)
if dir != surrounding_tilename_indices_dir[i]:
continue
var product = Constants.MATERIAL_SCENES[recipe.output].instance()
var outpos = beltmap.map_to_world(surrounding_tilename_indices_internal[i]) + Vector2(4, 4)
if recipe.output > 2: # Make a proper check later
outpos += dir_vectors[surrounding_tilename_indices_dir[i]-1]*4 # the list progresses CCW, we want CW
product.position = outpos
product.rotation_degrees = dir_angles[surrounding_tilename_indices_dir[i]]
outpos -= dir_vectors[surrounding_tilename_indices_dir[i]] # Hack to make feed exit work
product.leave_machine(self, outpos)
$"/root/Main/TileMap/Objects".add_child(product)
return
func set_working(state):
working = state
@ -30,5 +126,15 @@ func set_working(state):
func suck_materials():
for candidate in $SuckArea.get_overlapping_bodies():
if candidate.has_method('enter_machine'):
if candidate.material_type == recipe.input:
pass
if candidate.material_type == recipe.input and not candidate.entering_machine:
var displacement = candidate.position - position
var nearest_col = clamp(round((displacement.x + width/2 - 4)/8), 0, w_cells-1)
var nearest_row = clamp(round((displacement.y + height/2 - 4)/8), 0, h_cells-1)
var port = position + Vector2(nearest_col*8-width/2+4, nearest_row*8-height/2+4)
candidate.enter_machine(self, port)
func feed(object):
if object:
object.get_parent().remove_child(object)
object.queue_free()
num_inputs += 1

View File

@ -0,0 +1,40 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://machine.gd" type="Script" id=1]
[ext_resource path="res://assets/sprites/forge.tres" type="Texture" id=2]
[ext_resource path="res://assets/machine.shader" type="Shader" id=3]
[ext_resource path="res://machines/text.gd" type="Script" id=4]
[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 3 )
shader_param/rps = 0.0
shader_param/bg_color = Vector3( 0.251, 0.251, 0.251 )
[node name="Forge" type="StaticBody2D"]
script = ExtResource( 1 )
machine_type = 1
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
polygon = PoolVector2Array( -12, -8, -12, 8, 12, 8, 12, -8 )
__meta__ = {
"_edit_lock_": true
}
[node name="sprite" type="Sprite" parent="."]
material = SubResource( 1 )
texture = ExtResource( 2 )
__meta__ = {
"_edit_lock_": true
}
[node name="SuckArea" type="Area2D" parent="."]
script = ExtResource( 4 )
__meta__ = {
"_edit_lock_": true
}
[node name="Polygon2D" type="CollisionPolygon2D" parent="SuckArea"]
polygon = PoolVector2Array( -12, -12, 12, -12, 16, -8, 16, 8, 12, 12, -12, 12, -16, 8, -16, -8 )
__meta__ = {
"_edit_lock_": true
}

View File

@ -0,0 +1,40 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://machine.gd" type="Script" id=1]
[ext_resource path="res://assets/sprites/lathe.tres" type="Texture" id=2]
[ext_resource path="res://assets/machine.shader" type="Shader" id=3]
[ext_resource path="res://machines/text.gd" type="Script" id=4]
[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 3 )
shader_param/rps = 0.0
shader_param/bg_color = Vector3( 0.251, 0.251, 0.251 )
[node name="Lathe" type="StaticBody2D"]
script = ExtResource( 1 )
machine_type = 2
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
polygon = PoolVector2Array( -16, -8, -16, 8, 16, 8, 16, -8 )
__meta__ = {
"_edit_lock_": true
}
[node name="sprite" type="Sprite" parent="."]
material = SubResource( 1 )
texture = ExtResource( 2 )
__meta__ = {
"_edit_lock_": true
}
[node name="SuckArea" type="Area2D" parent="."]
script = ExtResource( 4 )
__meta__ = {
"_edit_lock_": true
}
[node name="Polygon2D" type="CollisionPolygon2D" parent="SuckArea"]
polygon = PoolVector2Array( -16, -12, 16, -12, 20, -8, 20, 8, 16, 12, -16, 12, -20, 8, -20, -8 )
__meta__ = {
"_edit_lock_": true
}

View File

@ -0,0 +1,39 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://machine.gd" type="Script" id=1]
[ext_resource path="res://assets/sprites/smelter.tres" type="Texture" id=2]
[ext_resource path="res://assets/machine.shader" type="Shader" id=3]
[ext_resource path="res://machines/text.gd" type="Script" id=4]
[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 3 )
shader_param/rps = 0.0
shader_param/bg_color = Vector3( 0.251, 0.251, 0.251 )
[node name="Smelter" type="StaticBody2D"]
script = ExtResource( 1 )
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
polygon = PoolVector2Array( -12, -8, -12, 8, 12, 8, 12, -8 )
__meta__ = {
"_edit_lock_": true
}
[node name="sprite" type="Sprite" parent="."]
material = SubResource( 1 )
texture = ExtResource( 2 )
__meta__ = {
"_edit_lock_": true
}
[node name="SuckArea" type="Area2D" parent="."]
script = ExtResource( 4 )
__meta__ = {
"_edit_lock_": true
}
[node name="Polygon2D" type="CollisionPolygon2D" parent="SuckArea"]
polygon = PoolVector2Array( -12, -12, 12, -12, 16, -8, 16, 8, 12, 12, -12, 12, -16, 8, -16, -8 )
__meta__ = {
"_edit_lock_": true
}

View File

@ -0,0 +1,40 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://machine.gd" type="Script" id=1]
[ext_resource path="res://assets/sprites/welder.tres" type="Texture" id=2]
[ext_resource path="res://assets/machine.shader" type="Shader" id=3]
[ext_resource path="res://machines/text.gd" type="Script" id=5]
[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 3 )
shader_param/rps = 0.0
shader_param/bg_color = Vector3( 0.251, 0.251, 0.251 )
[node name="Welder" type="StaticBody2D"]
script = ExtResource( 1 )
machine_type = 3
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
polygon = PoolVector2Array( -16, -8, -16, 8, 16, 8, 16, -8 )
__meta__ = {
"_edit_lock_": true
}
[node name="sprite" type="Sprite" parent="."]
material = SubResource( 1 )
texture = ExtResource( 2 )
__meta__ = {
"_edit_lock_": true
}
[node name="SuckArea" type="Area2D" parent="."]
script = ExtResource( 5 )
__meta__ = {
"_edit_lock_": true
}
[node name="Polygon2D" type="CollisionPolygon2D" parent="SuckArea"]
polygon = PoolVector2Array( -16, -12, 16, -12, 20, -8, 20, 8, 16, 12, -16, 12, -20, 8, -20, -8 )
__meta__ = {
"_edit_lock_": true
}

20
machines/text.gd 100644
View File

@ -0,0 +1,20 @@
extends Area2D
var font = preload("res://assets/UI_module_names.tres")
func _process(delta):
update()
func _draw():
if not $"..".was_started:
return
if $"..".working:
if $"..".num_inputs > 0:
draw_string(font, Vector2(5.25, -2.75), str($"..".num_inputs))
draw_rect(Rect2(6.5, -1, 1, 6), Color.black, true)
var progress = $"..".work_time/$"..".recipe.time
draw_rect(Rect2(6.5, 6*(1-progress)-1, 1, 6*progress), Color.green, true)
else:
var death_eta = max($"..".max_idle_time - $"..".idle_time, 0)
draw_string(font, Vector2(5.25, -2.75), '%.0f'%death_eta, Color.red)

View File

@ -8,7 +8,7 @@ var leaving_machine = null
var feed_position: Vector2
var held = false
var grabbed_vector = null
onready var beltmap = $"../BeltTiles"
onready var beltmap = $"/root/Main/TileMap/BeltTiles"
var dir_vectors = [Vector2(1,0), Vector2(0,-1), Vector2(-1,0), Vector2(0,1)]
@ -19,6 +19,7 @@ export var cy := 5.0 # offset for edge feet
var foot_vectors
var foot_weights
var total_weight
onready var rect = $sprite.get_rect()
#var stuck_vec = null
#var stuck_dir = -1 # For going off the end of belts
@ -51,10 +52,13 @@ func _physics_process(delta):
if entering_machine:
move_and_slide(position.direction_to(feed_position) * belt_speed)
if position.distance_to(feed_position) <= 1.0:
entering_machine.feed(self)
return
elif leaving_machine:
move_and_slide(feed_position.direction_to(position) * belt_speed)
if position.distance_to(feed_position) > $sprite.width/2:
var dir = feed_position.direction_to(position)
move_and_slide(dir * belt_speed)
if position.distance_to(feed_position) > rect.size.x/2 + 9:
remove_collision_exception_with(leaving_machine)
leaving_machine = null
return
@ -97,16 +101,18 @@ func _input(event):
if event is InputEventMouseButton:
if not event.pressed:
held = false
elif $sprite.get_rect().has_point(to_local(event.position)):
elif rect.has_point(to_local(event.position)) and event.button_mask & BUTTON_MASK_LEFT and $"/root/Main".p1_selection == 0:
held = true
grabbed_vector = to_local(event.position)
func enter_machine(machine):
func enter_machine(machine, feed_vec):
add_collision_exception_with(machine)
entering_machine = machine
self.feed_position = feed_vec
held = false
func leave_machine(machine):
func leave_machine(machine, feed_vec):
add_collision_exception_with(machine)
leaving_machine = machine
self.feed_position = feed_vec

View File

@ -0,0 +1,10 @@
extends Node2D
func _ready():
pass
func _process(delta):
# For now, just delete everything. EVERYTHING.
for object in $EatZone.get_overlapping_bodies():
object.get_parent().remove_child(object)
object.queue_free()

View File

@ -0,0 +1,17 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://portals/LadderEater.gd" type="Script" id=1]
[node name="LadderEater" type="Node2D"]
script = ExtResource( 1 )
[node name="EatZone" type="Area2D" parent="."]
__meta__ = {
"_edit_lock_": true
}
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="EatZone"]
polygon = PoolVector2Array( -7, 7, -7, -7, 7, -7, 7, 7 )
__meta__ = {
"_edit_lock_": true
}

View File

@ -0,0 +1,15 @@
extends Node2D
func _ready():
pass
func spawn_ore():
if len($DumpZone.get_overlapping_bodies()) <= 0:
var product = Constants.MATERIAL_SCENES[Constants.MATERIAL_TYPE.iORE].instance()
var outpos = position
product.position = outpos
$"/root/Main/TileMap/Objects".add_child(product)
func _on_Timer_timeout():
spawn_ore()

View File

@ -0,0 +1,22 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://portals/OreSpawner.gd" type="Script" id=1]
[node name="OreSpawner" type="Node2D"]
script = ExtResource( 1 )
[node name="Timer" type="Timer" parent="."]
wait_time = 4.0
autostart = true
[node name="DumpZone" type="Area2D" parent="."]
__meta__ = {
"_edit_lock_": true
}
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="DumpZone"]
polygon = PoolVector2Array( -3, 3, -3, -3, 3, -3, 3, 3 )
__meta__ = {
"_edit_lock_": true
}
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]