Skip to content

Commit

Permalink
Level 3 progress, big level
Browse files Browse the repository at this point in the history
  • Loading branch information
tatjam committed Jul 10, 2022
1 parent 66b2770 commit 2245391
Show file tree
Hide file tree
Showing 32 changed files with 581 additions and 78 deletions.
Binary file added res/barrier/enemy_killer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions res/barrier/enemy_killer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sprite: res/barrier/enemy_killer.png
fx_sprite: res/barrier/enemy_killer.png
scale_origin: [0.0, 0.0]
animations:
- name: "idle"
loop: true
frames:
- clip: [0, 0, 20, 20]
duration: 0.1
- clip: [20, 0, 20, 20]
duration: 0.1
- clip: [40, 0, 20, 20]
duration: 0.1
Binary file added res/barrier/fry.mp3
Binary file not shown.
Binary file added res/deco/light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions res/deco/light.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sprite: res/deco/light.png
fx_sprite: res/deco/light_emit.png
scale_origin: [0.0, 0.0]
animations:
- name: "idle"
loop: true
frames:
- clip: [0, 0, 256, 256]
duration: 1.0
Binary file added res/deco/light_emit.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/spawner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions res/enemies/spawner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
sprite: res/enemies/spawner.png
fx_sprite: none
scale_origin: [16.0, 16.0]
animations:
- name: "idle"
loop: true
frames:
- clip: [0, 0, 40, 80]
duration: 1.0
- name: "spawn"
loop: false
frames:
- clip: [40, 0, 40, 80]
duration: 0.4
- clip: [80, 0, 40, 80]
duration: 0.4
- clip: [120, 0, 40, 80]
duration: 0.4
- clip: [80, 0, 40, 80]
duration: 0.4
- clip: [40, 0, 40, 80]
duration: 0.4
- clip: [0, 0, 40, 80]
duration: 0.4
Binary file modified res/level2/map.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 modified res/level2/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/level2/tutorial01.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/level3/back_metal.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/level3/back_metal1.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/level3/back_rock.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/level3/map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 94 additions & 0 deletions res/level3/map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
seed: 1234

images:
- res/level3/map.png
- res/level3/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: door
color: [0, 51, 255]

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

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

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

- name: rockman_spawner
color: [255, 0, 110]
Binary file added res/level3/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/level3/metal.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/level3/music.mp3
Binary file not shown.
Binary file added res/level3/rock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions res/shader/fullscreen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ void main()
vec2 off = (vec2(n, n) * 2.0 - 1.0) * 0.015 * fac;

vec2 fxcoord = coord + off;
fxcoord.x = max(min(fxcoord.x, 1.0), 0.0);
fxcoord.y = max(min(fxcoord.y, 1.0), 0.0);

// Effects, we do lighting
vec4 fx = texture(fxtex, fxcoord);
Expand Down
2 changes: 2 additions & 0 deletions src/engine/base/renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ proc resize(renderer: var Renderer, width: int, height: int) =

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST.GLint)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST.GLint)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP.GLint)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP.GLint)

glGenRenderbuffers(1, addr renderer.depth_buffer)
glBindRenderbuffer(GL_RENDERBUFFER, renderer.depth_buffer)
Expand Down
2 changes: 1 addition & 1 deletion src/engine/graphics/sprite.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Sprite* = ref object
layer*: int
# Position, to be used with the renderer
position*: Vec2f
rotation: float
rotation*: float
scale*: Vec2f
# Movement in pixels respect to the sprite top-left corner
# Also used for rotation
Expand Down
97 changes: 77 additions & 20 deletions src/game/entities/barrier.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,33 @@ import ../userdata
# Default is 0, so 42 is the answer to everything
const BARRIER_COLL = 42

type Barrier* = ref object
health*: float
hurt_wav: WavHandle
break_wav: WavHandle
sprites*: seq[AnimatedSprite]
broken*: bool
phys_shape*: Shape
phys_space: Space
user_data*: UserData
# via physical impact at speed
enemies_damage: bool
objects_damage: bool
min_energy: float

type
Barrier* = ref object
health*: float
hurt_wav: WavHandle
break_wav: WavHandle
sprites*: seq[AnimatedSprite]
broken*: bool
phys_shape*: Shape
phys_space: Space
user_data*: UserData
# via physical impact at speed
enemies_damage: bool
objects_damage: bool
sensor_data: SensorData

sensor: bool

# only for sensors
destroy_object: bool
destroy_enemy: bool

min_energy: float
SensorData = ref object
barriers: ptr seq[Barrier]
objects: ptr seq[PhysicalObject]
enemies: ptr seq[Enemy]

proc hurt(this: var Barrier, energy: float) =
discard this.hurt_wav.play_sound()
Expand All @@ -37,17 +51,37 @@ proc on_collide*(this: var Barrier, other: BodyKind, energy: float) =
this.hurt(energy)



proc barrier_handler(arb: Arbiter, sp: Space, data: pointer) {.cdecl.} =
var shape_other, shape_barrier: Shape
# In the order defined by the handler
shapes(arb, addr shape_other, addr shape_barrier)
let barriers = cast[ptr seq[Barrier]](data)
let barriers = cast[ptr SensorData](data)[].barriers
let budata = cast[ptr UserData](shape_barrier.userData)
let eng = arb.totalKE
if shape_other.userData != nil:
let udata = cast[ptr UserData](shape_other.userData)
barriers[budata.point].on_collide(udata.kind, eng)

proc sensor_barrier_handler(arb: Arbiter, sp: Space, data: pointer): bool {.cdecl.} =
var shape_other, shape_barrier: Shape
# In the order defined by the handler
shapes(arb, addr shape_other, addr shape_barrier)
let sdata = cast[ptr SensorData](data)
let budata = cast[ptr UserData](shape_barrier.userData)
if shape_other.userData != nil:
let udata = cast[ptr UserData](shape_other.userData)
let barrier = sdata.barriers[budata[].point]
if barrier.sensor:
if barrier.destroy_object and udata.kind == bkObject:
sdata.objects[udata.point].indirect_die()
discard barrier.break_wav.play_sound()
if barrier.destroy_enemy and udata.kind == bkEnemy:
sdata.enemies[udata.point].indirect_die()
discard barrier.break_wav.play_sound()

return true


proc create_barrier_segment(this: Barrier, sprite: string, pos: Vec2f, size: int, hor: bool, space: Space) =
var sprite = create_animated_sprite(sprite)
Expand All @@ -59,8 +93,10 @@ proc create_barrier_segment(this: Barrier, sprite: string, pos: Vec2f, size: int

this.sprites.add(sprite)

proc create_barrier(sprite: string, area: Vec4f, size: int, space: Space, id: int, barriers: ptr seq[Barrier]): Barrier =
proc create_barrier(sprite: string, area: Vec4f, size: int, space: Space, id: int, barriers: ptr seq[Barrier],
objects: ptr seq[PhysicalObject], enemies: ptr seq[Enemy], sensor: bool = false): Barrier =
result = new(Barrier)
result.sensor = sensor

if area.x == area.z:
# Vertical barrier
Expand All @@ -77,38 +113,59 @@ proc create_barrier(sprite: string, area: Vec4f, size: int, space: Space, id: in
# The collider is a simple static segment
let hs = size.toFloat * 0.5
result.phys_shape = newSegmentShape(space.staticBody, v(area.x + hs, area.y + hs), v(area.z + hs, area.w + hs), 8)
if sensor:
result.phys_shape.sensor = true
result.user_data = make_barrier_userdata(id)
result.phys_shape.userData = addr result.user_data
# We sign up for collision callbacks between everything and barriers
result.phys_shape.collisionType = cast[pointer](BARRIER_COLL)
let all_coll = cast[pointer](0)
var handler = space.addCollisionHandler(all_coll, cast[pointer](BARRIER_COLL))
result.sensor_data = new(SensorData)
result.sensor_data.barriers = barriers
result.sensor_data.objects = objects
result.sensor_data.enemies = enemies
# TODO: Assign it only for the very first time
handler.postSolveFunc = barrier_handler
handler.userData = barriers
handler.preSolveFunc = sensor_barrier_handler
handler.userData = addr result.sensor_data

result.phys_space = space

discard space.addShape(result.phys_shape)

proc create_wooden_barrier*(area: Vec4f, size: int, space: Space, id: int, barriers: ptr seq[Barrier]): Barrier =
result = create_barrier("res/level1/break_wood.yaml", area, size, space, id, barriers)
proc create_wooden_barrier*(area: Vec4f, size: int, space: Space, id: int, barriers: ptr seq[Barrier],
objects: ptr seq[PhysicalObject], enemies: ptr seq[Enemy]): Barrier =
result = create_barrier("res/level1/break_wood.yaml", area, size, space, id, barriers, objects, enemies)
result.health = 10.0
result.min_energy = 1000000.0
result.enemies_damage = true
result.objects_damage = true
result.hurt_wav = load_sound("res/barrier/wood_hurt.mp3")
result.break_wav = load_sound("res/barrier/wood_break.mp3")

proc create_gate*(area: Vec4f, size: int, space: Space, id: int, barriers: ptr seq[Barrier]): Barrier =
result = create_barrier("res/barrier/gate.yaml", area, size, space, id, barriers)
proc create_gate*(area: Vec4f, size: int, space: Space, id: int, barriers: ptr seq[Barrier],
objects: ptr seq[PhysicalObject], enemies: ptr seq[Enemy]): Barrier =
result = create_barrier("res/barrier/gate.yaml", area, size, space, id, barriers, objects, enemies)
result.health = 10.0
result.min_energy = 1000000000.0
result.enemies_damage = false
result.objects_damage = false
result.hurt_wav = load_sound("res/barrier/wood_hurt.mp3")
result.break_wav = load_sound("res/barrier/gate.mp3")

proc create_enemy_killer*(area: Vec4f, size: int, space: Space, id: int, barriers: ptr seq[Barrier],
objects: ptr seq[PhysicalObject], enemies: ptr seq[Enemy]): Barrier =
result = create_barrier("res/barrier/enemy_killer.yaml", area, size, space, id, barriers, objects, enemies, true)
result.health = 10.0
result.min_energy = 1000000000.0
result.enemies_damage = false
result.objects_damage = false
result.hurt_wav = load_sound("res/barrier/wood_hurt.mp3")
result.break_wav = load_sound("res/barrier/fry.mp3")
result.destroy_enemy = true
result.destroy_object = true

proc update*(this: var Barrier) =
for sprite in mitems(this.sprites):
sprite.animate(dt)
Expand Down
Loading

0 comments on commit 2245391

Please sign in to comment.