voltorb godot

This commit is contained in:
Junko 2024-01-18 14:12:42 +01:00
commit 5c73ea3a4e
23 changed files with 584 additions and 0 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Godot 4+ specific ignores
.godot/

24
card.gd Normal file
View File

@ -0,0 +1,24 @@
extends Sprite2D
@onready var value: int = 1
var flipped = false
var marked = false
func flip():
frame = value
Events.turn.emit(value)
func _input(event):
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_RIGHT:
if get_rect().has_point(to_local(event.position)):
if not flipped:
if not marked:
frame = 5
else:
frame = 4
marked = !marked
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
if get_rect().has_point(to_local(event.position)):
if not flipped:
flipped = true
flip()

21
card.tscn Normal file
View File

@ -0,0 +1,21 @@
[gd_scene load_steps=4 format=3 uid="uid://75dh4vq6py7c"]
[ext_resource type="Texture2D" uid="uid://0s1pbr2dehpj" path="res://sprites/cards.png" id="1_oqjnt"]
[ext_resource type="Script" path="res://card.gd" id="2_oclvx"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_pqyl8"]
size = Vector2(30, 30)
[node name="Card" type="Sprite2D"]
texture_filter = 1
texture = ExtResource("1_oqjnt")
hframes = 6
frame = 4
script = ExtResource("2_oclvx")
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
shape = SubResource("RectangleShape2D_pqyl8")
[connection signal="input_event" from="CharacterBody2D" to="." method="_on_character_body_2d_input_event"]

BIN
cards.aseprite Normal file

Binary file not shown.

3
events.gd Normal file
View File

@ -0,0 +1,3 @@
extends Node
signal turn(value)

221
game.gd Normal file
View File

@ -0,0 +1,221 @@
extends Node2D
@onready var card = preload("res://card.tscn")
var templates = [
[
[3,1,6],
[0,3,6],
[5,0,6],
[2,2,6],
[4,1,6],
],
[
[1,3,7],
[6,0,7],
[3,2,7],
[0,4,7],
[5,1,7],
],
[
[2,3,8],
[7,0,8],
[4,2,8],
[1,4,8],
[6,1,8],
],
[
[3,3,8],
[0,5,8],
[8,0,10],
[5,2,10],
[2,4,10],
],
[
[7,1,10],
[4,3,10],
[1,5,10],
[9,0,10],
[6,2,10],
],
[
[3,4,10],
[0,6,10],
[8,1,10],
[5,3,10],
[2,5,10],
],
[
[7,2,10],
[4,4,10],
[1,6,10],
[9,1,10],
[6,3,10],
],
[
[0,7,10],
[8,2,10],
[5,4,10],
[2,6,10],
[7,3,10],
]
]
var gameover = false
var win = false
var twoOpen = 0
var threeOpen = 0
var totalPoints = 0
var roundPoints = 0
var level = 1
var layout
var board = []
var labels = []
func _ready():
create_cards()
game()
func game():
while true:
setup_game(level)
while not gameover and not win:
handle(await Events.turn)
await get_tree().create_timer(1).timeout
if win:
level += 1
win = false
else:
level = 1
gameover = false
func setup_game(lvl):
$Level.text = "Level " + str(level)
if lvl == 1:
totalPoints = 0
else:
totalPoints += roundPoints
$tPoints.text = "Total points:\n" + str(totalPoints)
roundPoints = 0
$rPoints.text = "Round points:\n" + str(roundPoints)
twoOpen = 0
threeOpen = 0
clear_cards()
select_layout()
generate(0)
generate(2)
generate(3)
calculate()
func create_cards():
for i in range(0,5):
var subarray = []
for j in range(0,5):
var c = card.instantiate()
c.position.x = 60 + 32 * j
c.position.y = 60 + 32 * i
add_child(c)
subarray.append(c)
board.append(subarray)
func clear_cards():
for l in labels:
labels.erase(l)
l.queue_free()
for l in labels:
labels.erase(l)
l.queue_free()
for l in labels:
labels.erase(l)
l.queue_free()
for l in labels:
labels.erase(l)
l.queue_free()
for i in range(0,5):
for j in range(0,5):
board[i][j].frame = 4
board[i][j].value = 1
board[i][j].flipped = false
board[i][j].marked = false
func select_layout():
var selected = templates[level-1].pick_random()
layout = [selected[2], 0, selected[0], selected[1]]
func generate(layer):
var rng = RandomNumberGenerator.new()
for v in layout[layer]:
var flag = false
while not flag:
var x = rng.randi_range(0,4)
var y = rng.randi_range(0,4)
if board[x][y].value == 1:
board[x][y].value = layer
flag = true
func calculate():
# Horizontal
for i in range(0,5):
var p = 0
var v = 0
for j in range(0,5):
var val = board[i][j].value
p += val
if val == 0:
v += 1
var l = Label.new()
l.text = "P: " + str(p) + "\nV: " + str(v)
l.position.x = 80 + 32 * 4
l.position.y = 45 + 32 * i
l.label_settings = LabelSettings.new()
l.label_settings.font_size = 10
l.label_settings.line_spacing = 0
labels.append(l)
add_child(l)
# Vertical
for j in range(0,5):
var p = 0
var v = 0
for i in range(0,5):
var val = board[i][j].value
p += val
if val == 0:
v += 1
var l = Label.new()
l.text = "P: " + str(p) + "\nV: " + str(v)
l.position.y = 80 + 32 * 4
l.position.x = 45 + 32 * j
l.label_settings = LabelSettings.new()
l.label_settings.font_size = 10
l.label_settings.line_spacing = 0
labels.append(l)
add_child(l)
func handle(val):
if roundPoints == 0:
roundPoints += val
else:
roundPoints *= val
$rPoints.text = "Round points:\n" + str(roundPoints)
if val == 2:
twoOpen += 1
elif val == 3:
threeOpen += 1
elif val == 0:
gameover = true
print("LOST")
if twoOpen == layout[2] and threeOpen == layout[3]:
win = true
print("WON")

43
game.tscn Normal file
View File

@ -0,0 +1,43 @@
[gd_scene load_steps=3 format=3 uid="uid://diduxj855co8s"]
[ext_resource type="Script" path="res://game.gd" id="1_lgsuu"]
[sub_resource type="LabelSettings" id="LabelSettings_bopco"]
font_size = 8
[node name="Game" type="Node2D"]
script = ExtResource("1_lgsuu")
[node name="Level" type="Label" parent="."]
texture_filter = 1
offset_right = 54.0
offset_bottom = 23.0
text = "Level 1"
[node name="rPoints" type="Label" parent="."]
texture_filter = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = 97.0
offset_right = 151.0
offset_bottom = 23.0
grow_horizontal = 2
text = "Round points:
0"
label_settings = SubResource("LabelSettings_bopco")
horizontal_alignment = 1
[node name="tPoints" type="Label" parent="."]
texture_filter = 1
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = 194.0
offset_right = 248.0
offset_bottom = 27.0
grow_horizontal = 0
text = "Total points:
0"
label_settings = SubResource("LabelSettings_bopco")
horizontal_alignment = 1

1
icon.svg Normal file
View File

@ -0,0 +1 @@
<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="124" height="124" rx="14" fill="#363d52" stroke="#212532" stroke-width="4"/><g transform="scale(.101) translate(122 122)"><g fill="#fff"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 813 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H447l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c3 34 55 34 58 0v-86c-3-34-55-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></g></svg>

After

Width:  |  Height:  |  Size: 950 B

37
icon.svg.import Normal file
View File

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cd4ik7m3b761g"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

26
project.godot Normal file
View File

@ -0,0 +1,26 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=5
[application]
config/name="voltorb"
run/main_scene="res://game.tscn"
config/features=PackedStringArray("4.2", "Forward Plus")
config/icon="res://icon.svg"
[autoload]
Events="*res://events.gd"
[display]
window/size/viewport_width=248
window/size/viewport_height=248
window/stretch/mode="canvas_items"

BIN
sprites/cards.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 708 B

34
sprites/cards.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://0s1pbr2dehpj"
path="res://.godot/imported/cards.png-98810b7d009a629e440f1f0b52787060.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/cards.png"
dest_files=["res://.godot/imported/cards.png-98810b7d009a629e440f1f0b52787060.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
sprites/cards1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B

34
sprites/cards1.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://br8k8asy53pqc"
path="res://.godot/imported/cards1.png-7d0cccad9aced5e25fc4746473adccee.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/cards1.png"
dest_files=["res://.godot/imported/cards1.png-7d0cccad9aced5e25fc4746473adccee.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
sprites/cards2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

34
sprites/cards2.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b2gxq86nikovx"
path="res://.godot/imported/cards2.png-877a57ff447dead60564c584cf550b1e.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/cards2.png"
dest_files=["res://.godot/imported/cards2.png-877a57ff447dead60564c584cf550b1e.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
sprites/cards3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

34
sprites/cards3.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bn804ryp22s4"
path="res://.godot/imported/cards3.png-70332f2a730c41b1a3d03276447e25eb.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/cards3.png"
dest_files=["res://.godot/imported/cards3.png-70332f2a730c41b1a3d03276447e25eb.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
sprites/cards4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

34
sprites/cards4.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c2tu4rgvatod6"
path="res://.godot/imported/cards4.png-5e80e918105934048e3756e2c3a6d004.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/cards4.png"
dest_files=["res://.godot/imported/cards4.png-5e80e918105934048e3756e2c3a6d004.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
sprites/cards5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

34
sprites/cards5.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bp56jfak86kwd"
path="res://.godot/imported/cards5.png-f32d784378ed18c43d6e1f32f59b0272.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/cards5.png"
dest_files=["res://.godot/imported/cards5.png-f32d784378ed18c43d6e1f32f59b0272.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1