Skip to content

Commit

Permalink
part 08 difficulty curve
Browse files Browse the repository at this point in the history
  • Loading branch information
cbscribe committed May 28, 2019
1 parent 0655e42 commit 202b260
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func spawn_circle(_position=null):
var c = Circle.instance()
if !_position:
var x = rand_range(-150, 150)
var y = rand_range(-500, -400)
var y = rand_range(-550, -450)
_position = player.target.position + Vector2(x, y)
add_child(c)
c.init(_position)
c.init(_position, level)

func _on_Jumper_captured(object):
$Camera2D.position = object.position
Expand Down
47 changes: 47 additions & 0 deletions ProgressionTester.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
extends Node2D

var Circle = preload("res://objects/Circle.tscn")
var font = preload("res://assets/fonts/xolonium_64.tres")
var level
var last_circle_position
var level_markers = []

func _ready():
randomize()
last_circle_position = $Camera2D.position
level = 0
for i in 100:
if i % 5 == 0:
level += 1
level_markers.append(last_circle_position)
spawn_circle()
update()

func _process(delta):
if Input.is_action_pressed("ui_up"):
$Camera2D.position.y -= 15
if Input.is_action_pressed("ui_down"):
$Camera2D.position.y += 15
if Input.is_action_pressed("ui_left"):
$Camera2D.position.x -= 15
if Input.is_action_pressed("ui_right"):
$Camera2D.position.x += 15

func spawn_circle(_position=null):
var c = Circle.instance()
if !_position:
var x = rand_range(-150, 150)
var y = rand_range(-500, -400)
_position = last_circle_position + Vector2(x, y)
add_child(c)
c.init(_position, level)
last_circle_position = _position

func _draw():
var l = 1
for pos in level_markers:
var s = Vector2(pos.x-480, pos.y-200)
var e = Vector2(pos.x-80, pos.y-200)
draw_line(s, e, Color(1, 1, 1), 15)
draw_string(font, s - Vector2(0, 50), str(l), Color(1, 1, 1))
l += 1
15 changes: 11 additions & 4 deletions objects/Circle.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ enum MODES {STATIC, LIMITED}
var radius = 100
var rotation_speed = PI
var mode = MODES.STATIC
var move_range = 100
var move_speed = 1.0
var move_range = 0
var move_speed = 2.0
var num_orbits = 3
var current_orbits = 0
var orbit_start = null
var jumper = null

func init(_position, _radius=radius, _mode=MODES.LIMITED):
func init(_position, level=1):
var _mode = settings.rand_weighted([10, level-1])
set_mode(_mode)
position = _position
radius = _radius
var move_chance = clamp(level-10, 0, 9) / 10.0
if randf() < move_chance:
move_range = max(25, 100 * rand_range(0.75, 1.25) * move_chance) * pow(-1, randi() % 2)
move_speed = max(2.5 - ceil(level/5) * 0.25, 0.75)
var small_chance = min(0.9, max(0, (level-10) / 20.0))
if randf() < small_chance:
radius = max(50, radius - level * rand_range(0.75, 1.25))
$Sprite.material = $Sprite.material.duplicate()
$SpriteEffect.material = $Sprite.material
$CollisionShape2D.shape = $CollisionShape2D.shape.duplicate()
Expand Down
6 changes: 4 additions & 2 deletions objects/Jumper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ var trail_length = 25

func _ready():
$Sprite.material.set_shader_param("color", settings.theme["player_body"])
$Trail/Points.default_color = settings.theme["player_trail"]

var trail_color = settings.theme["player_trail"]
trail.gradient.set_color(1, trail_color)
trail_color.a = 0
trail.gradient.set_color(0, trail_color)

func _unhandled_input(event):
if target and event is InputEventScreenTouch and event.pressed:
Expand Down
18 changes: 18 additions & 0 deletions settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,21 @@ var color_schemes = {
}

var theme = color_schemes["NEON1"]

static func rand_weighted(weights):
var sum = 0
for weight in weights:
sum += weight
var num = rand_range(0, sum)
for i in weights.size():
if num < weights[i]:
return i
num -= weights[i]








11 changes: 11 additions & 0 deletions tests/ProgressionTester.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[gd_scene load_steps=2 format=2]

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

[node name="ProgressionTester" type="Node2D"]
script = ExtResource( 1 )

[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2( 240, 428.122 )
current = true
zoom = Vector2( 4, 4 )

0 comments on commit 202b260

Please sign in to comment.