Skip to content

Commit

Permalink
Add power_ups to bounce super high
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicfreeston committed May 14, 2023
1 parent c77f561 commit 9eaad80
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions mygame/app/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ def reset_level
vel: {x: 0, y: 0,},
}

state.platforms = generate_level
state.platforms = generate_platforms
state.broken_platforms = []
state.power_ups = (generate_power_ups state.platforms)

state.goal = {
x: grid.center.x,
Expand All @@ -149,7 +150,7 @@ def reset_level
@setup = true
end

def generate_level
def generate_platforms
[
# floor
{
Expand Down Expand Up @@ -190,6 +191,21 @@ def generate_level
].flatten
end

def generate_power_ups platforms
platforms.filter do |p|
(!p.breakable) && (p.vel&.x == 0) && (rand > 0.8)
end.map do |p|
{
x: p.x,
y: p.top,
w: 30,
h: 10,
anchor_x: 0.5,
anchor_y: 0,
}
end
end

def wraparound! entity
if entity.right < 0
entity.left = grid.w
Expand Down Expand Up @@ -244,7 +260,7 @@ def update
player.vel.x = (player.vel.x + acc)
.clamp(-MAX_MOVE_SPEED, MAX_MOVE_SPEED)
player.vel.y = (player.vel.y - controls_settings.gravity)
.clamp(-controls_settings.max_fall_speed, controls_settings.bounce_up_speed)
.clamp(-controls_settings.max_fall_speed, controls_settings.bounce_up_speed * 4)

# player.squish = (player.bounce_at.ease 15, :flip) if player.bounce_at else 0

Expand All @@ -256,6 +272,10 @@ def update
if plat
player.bottom = plat.top
player.vel.y = controls_settings.bounce_up_speed

if geometry.find_intersect_rect player, state.power_ups
player.vel.y += controls_settings.bounce_up_speed
end
player.bounce_at = state.tick_count

if lr != 0 && lr != player.vel.x.sign
Expand Down Expand Up @@ -338,6 +358,12 @@ def render
p.angle = 45 * (p.flip_horizontally ? -1 : 1)
p
end

outputs.primitives << state.power_ups.map do |p|
p = p.dup
p.y -= state.camera
p.solid
end

outputs.primitives << [state.goal].map do |p|
p = p.dup
Expand Down

0 comments on commit 9eaad80

Please sign in to comment.