Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Initial version for the Seoul Maker Festival 2022
  • Loading branch information
egwkim committed Oct 14, 2022
0 parents commit bbaad13
Show file tree
Hide file tree
Showing 30 changed files with 997 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.cpp text
*.c text
*.h text
*.gd text
*.cs text

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Godot-specific ignores
.import/
export.cfg
export_presets.cfg

# Imported translations (automatically generated from CSV files)
*.translation

# Mono-specific ignores
.mono/
data_*/

# Godot git plugin
addons/godot-git-plugin/

# Exported binary
export/
98 changes: 98 additions & 0 deletions Game.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
extends Node

export(PackedScene) var obstacle1_scene
export(PackedScene) var obstacle2_scene

onready var player = get_node("Player")

const gravity:float = 6.0
const power:float = 6.0
const vx:float = 200.0
const max_vy:float = 200.0
const min_vy:float = - 200.0
const sensitivity:float = 1.5

var score:int = 0
var vy:float = 0


func _ready():
randomize()
$MessageLabel.text = "READY"
$MessageLabel.show()
$SceneTimer.wait_time = 1
$SceneTimer.start()
$ScoreTimer.connect("timeout", self, "_on_ScoreTimer_timeout")
$ScoreLabel.hide()
player.position = Vector2(360, 540)


func _process(delta):
if Global.playing:
if Input.is_action_pressed("move"):
# Accelerate upwards
if (vy > min_vy):
vy -= min(1, sensitivity * (vy - min_vy) / (-min_vy)) * power
else:
# Accelerate downwards
if (vy < max_vy):
vy += min(1, sensitivity * (max_vy - vy) / max_vy) * gravity

player.rotation = atan2(vy, vx)

player.position.y += vy * delta


func _on_SceneTimer_timeout():
if $MessageLabel.text == "READY":
$MessageLabel.text = "GO!"
$SceneTimer.wait_time = 0.5
$SceneTimer.start()
elif $MessageLabel.text == "GO!":
$MessageLabel.text = ""
$MessageLabel.hide()
Global.playing = true
$ScoreTimer.start()
$ScoreLabel.text = "Score: %d" % score
$ScoreLabel.show()
$ObstacleTimer.start()
else:
# Game over
get_tree().change_scene("res://Title.tscn")


func _on_ScoreTimer_timeout():
score += 1
$ScoreLabel.text = "Score: %d" % score


func _on_ObstacleTimer_timeout():
$ObstacleTimer.wait_time = rand_range(1.4 - Global.difficulty * 0.2, 5.0 - Global.difficulty)
$ObstacleTimer.start()

var obstacle = obstacle1_scene.instance()

var spawn_location = get_node("ObstaclePath/ObstacleSpawnLocation")
spawn_location.offset = randi()

var direction = atan3(player.position - spawn_location.position) + rand_range(-PI / 8, PI / 8)

obstacle.position = spawn_location.position
obstacle.rotation = direction + PI

var velocity = Vector2(rand_range(240, 500), 0)
obstacle.linear_velocity = velocity.rotated(direction)

add_child(obstacle)


func game_over():
Global.playing = false
$ScoreTimer.stop()
$ObstacleTimer.stop()
$SceneTimer.wait_time = 3
$SceneTimer.start()


func atan3(v:Vector2):
return atan2(v.y, v.x)
95 changes: 95 additions & 0 deletions Game.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
[gd_scene load_steps=9 format=2]

[ext_resource path="res://fonts/Roboto-Regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://Game.gd" type="Script" id=2]
[ext_resource path="res://sprites/Player.tscn" type="PackedScene" id=3]
[ext_resource path="res://sprites/Obstacle1.tscn" type="PackedScene" id=4]
[ext_resource path="res://sprites/Obstacle2.tscn" type="PackedScene" id=5]

[sub_resource type="DynamicFont" id=3]
size = 120
use_mipmaps = true
use_filter = true
font_data = ExtResource( 1 )

[sub_resource type="DynamicFont" id=1]
size = 96
outline_size = 1
use_filter = true
font_data = ExtResource( 1 )

[sub_resource type="Curve2D" id=4]
_data = {
"points": PoolVector2Array( 0, 0, 0, 0, 1600, 0, 0, 0, 0, 0, 1920, 0, 0, 0, 0, 0, 1920, 1080, 0, 0, 0, 0, 1600, 1080 )
}

[node name="Game1" type="Node"]
script = ExtResource( 2 )
obstacle1_scene = ExtResource( 4 )
obstacle2_scene = ExtResource( 5 )

[node name="Background" type="TextureRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_group_": true,
"_edit_lock_": true
}

[node name="ColorBackground" type="ColorRect" parent="Background"]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0, 0, 0, 1 )

[node name="MessageLabel" type="Label" parent="."]
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
margin_top = -100.0
margin_bottom = 100.0
custom_fonts/font = SubResource( 3 )
text = "Ready"
align = 1
valign = 1
__meta__ = {
"_edit_lock_": true
}

[node name="ScoreLabel" type="Label" parent="."]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -450.0
margin_top = 50.0
margin_right = -50.0
margin_bottom = 150.0
custom_fonts/font = SubResource( 1 )
align = 2
valign = 1
__meta__ = {
"_edit_lock_": true
}

[node name="Player" parent="." instance=ExtResource( 3 )]
position = Vector2( 360, 540 )
scale = Vector2( 0.7, 0.7 )
__meta__ = {
"_edit_lock_": true
}

[node name="SceneTimer" type="Timer" parent="."]
one_shot = true

[node name="ObstacleTimer" type="Timer" parent="."]
one_shot = true

[node name="ScoreTimer" type="Timer" parent="."]

[node name="ObstaclePath" type="Path2D" parent="."]
curve = SubResource( 4 )

[node name="ObstacleSpawnLocation" type="PathFollow2D" parent="ObstaclePath"]
position = Vector2( 1600, 0 )

[connection signal="hit" from="Player" to="." method="game_over"]
[connection signal="timeout" from="SceneTimer" to="." method="_on_SceneTimer_timeout"]
[connection signal="timeout" from="ObstacleTimer" to="." method="_on_ObstacleTimer_timeout"]
45 changes: 45 additions & 0 deletions GameSelectionRect.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
extends ReferenceRect

signal game_selected(difficulty)

onready var progress_bar = $GameSelectionProgress
onready var timer = $GameSelectionTimer

var screen_width = 1920
var speed:float = 4
var selection_delay:float = 2
var progress_id:int = 0

func _ready():
progress_bar.value = 0
timer.connect("timeout", self, "_on_timer_timeout")


func _process(_delta):
if (Input.is_action_pressed("move")):
rect_position.x += speed
if (rect_position.x > screen_width + border_width):
rect_position.x -= screen_width + border_width*2 + rect_size.x

progress_id = 0
for i in range(1,4):
if (abs((rect_position.x + rect_size.x/2) - (3*i-1) * 0.1 * screen_width) < border_width + 40):
progress_id = i
break

if progress_id:
border_color = Color(1, 1, 0, 0.75)
if timer.is_stopped():
timer.start(selection_delay)
$SelectionSFX.play()
progress_bar.value = 100 * (selection_delay - timer.time_left) / selection_delay
else:
progress_bar.value = 0
border_color = Color(1, 1, 0, 0.25)
timer.stop()
$SelectionSFX.stop()


func _on_timer_timeout():
# Emit signal to start selected game
emit_signal("game_selected", progress_id)
16 changes: 16 additions & 0 deletions Global.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extends Node

var difficulty:int = 0
var playing:bool = false


func _ready():
OS.window_fullscreen = false
OS.window_maximized = true


func _process(_delta):
if Input.is_action_just_pressed("toggle_fullscreen"):
OS.window_fullscreen = !OS.window_fullscreen
if Input.is_action_just_released("exit_game"):
get_tree().quit()
6 changes: 6 additions & 0 deletions Global.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://Global.gd" type="Script" id=1]

[node name="Global" type="Node"]
script = ExtResource( 1 )
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Bicycle game

2022 서울 메이커축제 출품작
10 changes: 10 additions & 0 deletions Title.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends Node


func _ready():
var selectionRect = get_node("GameSelection/GameSelectionRect")
selectionRect.connect("game_selected", self, "_on_game_selected")

func _on_game_selected(difficulty):
Global.difficulty = difficulty
get_tree().change_scene("res://Game.tscn")
Loading

0 comments on commit bbaad13

Please sign in to comment.