Skip to content

Commit

Permalink
ALMSOT DONE
Browse files Browse the repository at this point in the history
  • Loading branch information
tatjam committed Jul 11, 2022
1 parent 160a3ca commit 767c3e3
Show file tree
Hide file tree
Showing 33 changed files with 271 additions and 66 deletions.
Binary file modified res/barrier/fry.mp3
Binary file not shown.
Binary file added res/blood0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/blood1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/blood2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/clip3/backdrop0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/clip3/backdrop1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/clip3/backdrop2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/clip3/backdrop3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/clip3/bigboi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/clip3/sky0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/clip3/sky1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/clip3/sky2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/clip3/smallboi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/clip3/sun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/enemies/metalhurt.mp3
Binary file not shown.
Binary file added res/final/finalboss.mp3
Binary file not shown.
Binary file added res/final/roar1.mp3
Binary file not shown.
Binary file added res/final/roar2.mp3
Binary file not shown.
Binary file added res/level4/backdrop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/level4/map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 103 additions & 0 deletions res/level4/map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
seed: 1234

images:
- res/level4/map.png
- res/level4/map_ent.png

tiles:
- class: ground
texture: res/level1/ground.png
noise: 1.0
color: [0, 0, 0]

- class: ground
texture: res/level1/wood.png
noise: 0.0
color: [101, 101, 101]

- class: ground
texture: res/level1/sand.png
noise: 3.0
color: [200, 200, 200]

- class: ground
texture: res/level3/rock.png
noise: 0.7
color: [75, 50, 50]

- class: B@back
texture: res/level1/back.png
noise: 1.0
color: [240, 240, 240]

- class: B@backwood
texture: res/level1/wood_back.png
noise: 0.0
color: [160, 160, 160]

- class: B@back
texture: res/level3/back_metal.png
noise: 0.0
color: [210, 140, 140]

- class: B@back
texture: res/level3/back_metal1.png
noise: 0.0
color: [210, 145, 145]

- class: B@back
texture: res/level3/back_rock.png
noise: 1.5
color: [220, 220, 220]

areas:
- name: water
color: [0, 0, 255]
- name: break_wood
color: [0, 255, 150]
- name: gate
color: [100, 255, 150]
- name: enemy_killer
color: [255, 240, 0]
- name: kill
color: [255, 0, 0]

points:
- name: rock
color: [140, 140, 200]

- name: magmarock
color: [140, 175, 200]

- name: box
color: [255, 140, 200]

- name: player
color: [100, 255, 50]

- name: rockman
color: [255, 100, 50]

- name: bird
color: [60, 160, 60]

- name: door
color: [0, 51, 255]

- name: button0
color: [255, 0, 255]

- name: button1
color: [255, 10, 255]

- name: button2
color: [255, 20, 255]

- name: light1l
color: [255, 190, 0]

- name: light
color: [100, 0, 0]

- name: rockman_spawner
color: [255, 0, 110]
Binary file added res/level4/map_ent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/level4/music.mp3
Binary file not shown.
2 changes: 2 additions & 0 deletions src/game/entities/barrier.nim
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ proc create_barrier_segment(this: Barrier, sprite: string, pos: Vec2f, size: int

# Center barriers
sprite.position = pos + vec2f(size.toFloat * 0.5, size.toFloat * 0.5)
if hor:
sprite.position = vec2f(sprite.position.x + size.toFloat, sprite.position.y)

this.sprites.add(sprite)

Expand Down
17 changes: 11 additions & 6 deletions src/game/entities/enemy.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import sequtils
import ../userdata

type
EnemyKind = enum
EnemyKind* = enum
ekRockman,
ekRockmanSpawner,
ekBird

Enemy* = ref object
case kind: EnemyKind
case kind*: EnemyKind
of ekRockman:
retreat_timer: float
retreat_goal: float
Expand All @@ -24,6 +24,7 @@ type
dumb: int
of ekRockmanSpawner:
spawn_timer: float
spawn_timer_def*: float
children: seq[Enemy]
max_children: int
of ekBird:
Expand Down Expand Up @@ -71,13 +72,14 @@ proc create_rockman_spawner*(pos: Vec2f, space: Space, id: int): Enemy =
result.phys_shape.friction = 1.0
result.phys_body.position = v(pos.x, pos.y - 40.0)

result.hurt_wav = load_sound("res/enemies/rockman_hurt.mp3")
result.hurt_wav = load_sound("res/enemies/metalhurt.mp3")
result.user_data = make_enemy_userdata(id)
result.phys_shape.userData = addr result.user_data

result.health = 6.0
result.spawn_timer = 0.0
result.max_children = 5
result.spawn_timer_def = 15.0

proc create_bird*(pos: Vec2f, space: Space, id: int): Enemy =
result = base_create(ekBird)
Expand All @@ -90,7 +92,7 @@ proc create_bird*(pos: Vec2f, space: Space, id: int): Enemy =
result.phys_shape.friction = 0.3
result.phys_body.position = v(pos.x, pos.y - 10.0)

result.hurt_wav = load_sound("res/enemies/rockman_hurt.mp3")
result.hurt_wav = load_sound("res/enemies/metalhurt.mp3")
result.user_data = make_enemy_userdata(id)
result.phys_shape.userData = addr result.user_data

Expand Down Expand Up @@ -156,7 +158,7 @@ proc update*(this: var Enemy, player: Player, objects: var seq[PhysicalObject],
elif this.spawn_timer < 5.0:
this.sprite.start_anim("idle")
if this.spawn_timer < 0.0 and this.children.len < this.max_children:
this.spawn_timer = 15.0
this.spawn_timer = this.spawn_timer_def
var pos = vec2f(this.sprite.center_position.x - 40.0, this.sprite.center_position.y)
var dumb = -1
if this.sprite.scale.x < 0.0:
Expand All @@ -180,14 +182,17 @@ proc update*(this: var Enemy, player: Player, objects: var seq[PhysicalObject],
(scale.x > 0.0 and player_dir.x > 0.0):
# Player walked into our attack!
this.turn_timer = 0.0
elif player_dist < 150.0:
elif player_dist < 190.0:
# Move quickly towards the player, but with turn-around inertia
if (scale.x < 0.0 and player_dir.x > 0.0) or
(scale.x > 0.0 and player_dir.x < 0.0):
# we are looking one way, but must go the other, start timer
this.turn_timer = 3.0
else:
this.phys_body.velocity = v(player_dir.x * 120.0, this.phys_body.velocity.y)
if player_dist < 75.0 and player_dir.y < -0.5:
if player.try_hurt():
this.sprite.start_anim("bloody")

else:
this.toss_timer -= dt
Expand Down
11 changes: 7 additions & 4 deletions src/game/entities/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ type Platform* = ref object
track_body*: Body
track_shape*: Shape
spring*: Constraint
speed: float
speed*: float
distt: float

progress: float
p0: Vect
Expand Down Expand Up @@ -63,7 +64,8 @@ proc create_platform*(p0: Vect, p1: Vect, lanchor0: Vec2f, lanchor1: Vec2f, spac
result.p0 = p0
result.p1 = p1

result.speed = 50.0 / vdist(result.p0, result.p1)
result.distt = vdist(result.p0, result.p1)
result.speed = 50.0

var points: seq[Vec2f]
points.add(lanchor0)
Expand Down Expand Up @@ -107,10 +109,11 @@ proc update*(this: var Platform, player: Player, control_platform: Option[Platfo
player.phys_body.position = v(-100.0, -100.0)
player.fall_sound.pause()
player.step_sound.pause()
let mspeed = this.speed / this.distt
if glfw_window.getKey(GLFWKey.A) == GLFW_PRESS:
this.progress -= dt * this.speed
this.progress -= dt * mspeed
elif glfw_window.getKey(GLFWKey.D) == GLFW_PRESS:
this.progress += dt * this.speed
this.progress += dt * mspeed

# Stop controlling
if glfw_window.getKey(GLFWKey.E) == GLFW_PRESS and not this.just_hopped:
Expand Down
40 changes: 38 additions & 2 deletions src/game/entities/player.nim
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ type Player* = ref object
step_sound*: AudioHandle
fall_sound*: AudioHandle

blood0: Sprite
blood1: Sprite
blood2: Sprite

health*: float
hurt_timer: float


proc try_hurt*(this: Player): bool =
if this.hurt_timer < 0.0:
this.health -= 1.0
this.hurt_timer = 2.0
this.phys_body.applyImpulseAtWorldPoint(v(0.0, -8000.0), this.phys_body.position)
return true

# This must be here to avoid circular dependency hell
import enemy
Expand Down Expand Up @@ -70,10 +84,17 @@ proc create_player*(pos: Vec2f, space: Space): Player =
result.step_sound = create_sound(result.step_wav, true)
result.fall_sound = create_sound(result.fall_wav, true)

let points = @[vec2f(0.0, 0.0), vec2f(20.0, 0.0), vec2f(15.0, 5.0), vec2f(15.0, -5.0)]
result.ind_line = create_line(points, 4.0)
result.blood0 = create_sprite("res/blood0.png")
result.blood0.clear_fx = false
result.blood1 = create_sprite("res/blood1.png")
result.blood1.clear_fx = false
result.blood2 = create_sprite("res/blood2.png")
result.blood2.clear_fx = false

result.health = 5.0

let points = @[vec2f(0.0, 0.0), vec2f(20.0, 0.0), vec2f(15.0, 5.0), vec2f(20.0, 0.0), vec2f(15.0, -5.0)]
result.ind_line = create_line(points, 4.0)

proc ground_query_foot(sh: Shape, p: Vect, n: Vect, a: Float, data: pointer) {.cdecl.} =
if sh.userData == nil:
Expand Down Expand Up @@ -103,6 +124,10 @@ proc query_hit(sh: Shape, p: Vect, n: Vect, a: Float, data: pointer) {.cdecl.} =
hurt(datac[].enemies[enemy_idx], p)


proc deinit*(this: Player) =
this.step_sound.pause()
this.fall_sound.pause()

proc hit(this: Player, enemies: seq[Enemy]): bool =
let rays = this.phys_body.position + v(0.0, 0.0)
var raye = this.phys_body.position + v(34.0, 23.0)
Expand Down Expand Up @@ -212,6 +237,7 @@ proc toss(this: Player, enemies: seq[Enemy], objects: seq[PhysicalObject]) =
segmentQuery(this.phys_space, rays, raye2, Float(14.0), filter, query_toss, addr query_data)

proc update*(this: var Player, enemies: seq[Enemy], objects: seq[PhysicalObject]) =
this.hurt_timer -= dt
# Ground check
let rfootp = this.phys_body.position + v(34.0, 25.0)
let lfootp = this.phys_body.position + v(-34.0, 25.0)
Expand Down Expand Up @@ -361,3 +387,13 @@ proc draw_fx*(this: var Player) =
renderer.draw(this.lantern)
if this.in_toss:
renderer.draw(this.ind_line)

this.blood0.center_position = renderer.camera.center
this.blood1.center_position = renderer.camera.center
this.blood2.center_position = renderer.camera.center
if this.health < 2.0:
renderer.draw(this.blood2)
elif this.health < 3.0:
renderer.draw(this.blood1)
elif this.health < 4.0:
renderer.draw(this.blood0)
17 changes: 12 additions & 5 deletions src/game/scenes/level.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Level* = ref object
physics_space*: Space
physical_objects*: seq[PhysicalObject]
barriers*: seq[Barrier]
enemies: seq[Enemy]
enemies*: seq[Enemy]
# Must be manually created
platforms*: seq[Platform]
doors: seq[Door]
Expand Down Expand Up @@ -84,7 +84,7 @@ proc init_no_map(this: var Level, scale: int) =
let point = this.map.points[str][0]
this.physical_objects.add(create_button(point, this.physics_space, this.physical_objects.len,
addr this.physical_objects))
this.buttons_idx[0] = this.physical_objects.len - 1
this.buttons_idx[i] = this.physical_objects.len - 1


# Load barriers
Expand Down Expand Up @@ -128,8 +128,9 @@ proc init_no_map(this: var Level, scale: int) =
# Removes all physical objects EXCEPT the world, and reinits
proc restart(this: var Level) =
for obj in this.physical_objects:
this.physics_space.removeBody(obj.phys_body)
this.physics_space.removeShape(obj.phys_shape)
if not obj.dead:
this.physics_space.removeBody(obj.phys_body)
this.physics_space.removeShape(obj.phys_shape)
for barrier in this.barriers:
if not barrier.broken:
this.physics_space.removeShape(barrier.phys_shape)
Expand All @@ -138,6 +139,8 @@ proc restart(this: var Level) =
this.physics_space.removeBody(enemy.phys_body)
this.physics_space.removeShape(enemy.phys_shape)


this.player.deinit()
this.physics_space.removeBody(this.player.phys_body)
this.physics_space.removeShape(this.player.phys_shape)

Expand Down Expand Up @@ -225,6 +228,7 @@ proc update*(this: var Level): bool =
exit = exit or door.update(this.player)

if exit:
this.player.deinit()
return true


Expand Down Expand Up @@ -252,8 +256,11 @@ proc update*(this: var Level): bool =
# Check die areas
for area in this.kill:
let pos = this.player.sprite.position
if pos.x > area.x and pos.y > area.y and pos.x < area.x + area.z and pos.y < area.y + area.w:
if pos.x > area.x and pos.y > area.y and pos.x < area.z and pos.y < area.w:
this.die()

if this.player.health < 0.0:
this.die()

if this.die_timer > 0.0:
this.die_timer -= dt
Expand Down
6 changes: 4 additions & 2 deletions src/game/scenes/level1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import cutsc1

type Level1Scene* = ref object of Scene
music: WavHandle
musich: AudioHandle
level: Level
tut: seq[Sprite]

method init(this: Level1Scene) =
echo "Init!"
this.music = load_sound("res/level1/music.mp3")
discard play_sound(this.music, true)
this.musich = play_sound(this.music, true)

this.level.init("res/level1/map.yaml", "res/level1/backdrop.png", "none", 20)
this.tut.add(create_sprite("res/tutorial/tut000.png"))
Expand All @@ -36,7 +37,8 @@ method init(this: Level1Scene) =

method update(this: Level1Scene) =
if this.level.update():
goto_scene(CutScene1)
this.musich.pause()
goto_scene(CutScene1())
method render(this: Level1Scene) =
this.level.draw()
for tut in this.tut:
Expand Down
Loading

0 comments on commit 767c3e3

Please sign in to comment.