Skip to content

Commit

Permalink
Progress and more progress
Browse files Browse the repository at this point in the history
  • Loading branch information
tatjam committed Jul 10, 2022
1 parent 354c879 commit 66b2770
Show file tree
Hide file tree
Showing 47 changed files with 641 additions and 67 deletions.
Binary file added res/barrier/electric_door.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/barrier/electric_door_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/barrier/gate.mp3
Binary file not shown.
9 changes: 9 additions & 0 deletions res/barrier/gate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sprite: res/barrier/electric_door.png
fx_sprite: res/barrier/electric_door_emit.png
scale_origin: [0.0, 0.0]
animations:
- name: "idle"
loop: true
frames:
- clip: [0, 0, 20, 20]
duration: 1.0
Binary file added res/clip1/back.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/clip1/eldritch.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/clip1/music.mp3
Binary file not shown.
Binary file added res/clip1/text0.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/clip1/text1.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/clip1/text2.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/deco/light1.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/light1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sprite: res/deco/light1.png
fx_sprite: res/deco/light1_emit.png
scale_origin: [0.0, 0.0]
animations:
- name: "idle"
loop: true
frames:
- clip: [0, 0, 60, 100]
duration: 1.0
Binary file added res/deco/light1_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/level1/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/level2/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/level2/backdrop_fx.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/map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions res/level2/map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
seed: 1234

images:
- res/level2/map.png
- res/level2/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: 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]

areas:
- name: water
color: [0, 0, 255]
- name: break_wood
color: [0, 255, 150]
- name: gate
color: [100, 255, 150]
- 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]
Binary file added 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/tutorial00.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/objects/box.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/objects/box.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sprite: res/objects/box.png
fx_sprite: none
scale_origin: [30.0, 30.0]
animations:
- name: "idle"
loop: true
frames:
- clip: [0, 0, 60, 60]
duration: 1.0
Binary file added res/objects/button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions res/objects/button.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sprite: res/objects/button.png
fx_sprite: res/objects/button_emit.png
scale_origin: [20.0, 20.0]
animations:
- name: "off"
loop: true
frames:
- clip: [0, 0, 40, 40]
duration: 1.0
- name: "on"
loop: true
frames:
- clip: [40, 0, 40, 40]
duration: 1.0
Binary file added res/objects/button_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/perish.mp3
Binary file not shown.
Binary file added res/perish.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/platform/emit_base.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/platform/emit_cabin.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/platform/platform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions res/shader/line.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 330
layout(location = 0) out vec4 color;
layout(location = 1) out vec4 effect;

uniform vec4 tint;
uniform vec4 fx_tint;

void main()
{
color = tint;
effect = fx_tint;
}
10 changes: 10 additions & 0 deletions res/shader/line.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 330
layout (location = 0) in vec3 aPos;

uniform mat4 tform;
uniform mat4 subtform;

void main()
{
gl_Position = tform * subtform * vec4(aPos.x, aPos.y, aPos.z, 1.0);
}
10 changes: 9 additions & 1 deletion res/shader/sprite.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ uniform sampler2D tex;
uniform int has_fx;

uniform vec4 tint;
uniform int clear_fx;

// Contains (x, y) = lower bound (z, w) = size
uniform vec4 clip;
Expand All @@ -25,6 +26,13 @@ void main()
else
{
color = texture(tex, coord) * tint;
effect = vec4(0, 0, 0, 0);
if(clear_fx == 1 && color.a != 0)
{
effect = vec4(0, 0, 0, 1);
}
else
{
effect = vec4(0, 0, 0, 0);
}
}
}
1 change: 1 addition & 0 deletions src/engine/base.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import launcher
import base/scene_manager
import graphics/sprite
import graphics/line
import graphics/camera
import globals
import base/renderer as rnd
Expand Down
54 changes: 54 additions & 0 deletions src/engine/graphics/line.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import nimgl/opengl
import glm
import shader

# Draws a connected line, with width
type Line* = ref object
vbo: GLuint
vao: GLuint
width*: float
shader*: Shader
position*: Vec2f
rotation*: float
scale*: Vec2f
points: int
layer*: int

color*: Vec4f
fx_color*: Vec4f

proc create_line*(points: seq[Vec2f], width: float = 1.0): Line =
let shader = load_shader("res/shader/line")
var verts: seq[float32]
for point in points:
verts.add(point.x)
verts.add(point.y)
verts.add(0.0)

var vao: GLuint
var vbo: GLuint
glGenVertexArrays(1, addr vao)
glGenBuffers(1, addr vbo)

glBindVertexArray(vao)

glBindBuffer(GL_ARRAY_BUFFER, vbo)
glBufferData(GL_ARRAY_BUFFER, verts.len * sizeof(float32), unsafeAddr verts[0], GL_STATIC_DRAW)

# position attribute
glVertexAttribPointer(0'u32, 3'i32, EGL_FLOAT, false, 3 * float32.sizeof, cast[pointer](0))
glEnableVertexAttribArray(0)

return Line(width: width, shader: shader, vbo: vbo, points: points.len,
fx_color: vec4f(0, 0, 0, 0), color: vec4f(1, 1, 1, 1), vao: vao, scale: vec2f(1.0, 1.0))

proc do_draw*(line: Line) =
var subtform = mat4f(1.0)
subtform = subtform.rotate(line.rotation, 0, 0, 1).scale(line.scale.x, line.scale.y, 1.0)
line.shader.set_mat4("subtform", subtform)
line.shader.set_vec4("tint", line.color)
line.shader.set_vec4("fx_tint", line.fx_color)

glLineWidth(1.0)
glBindVertexArray(line.vao)
glDrawArrays(GL_LINE_STRIP, 0.GLint, line.points.GLsizei)
24 changes: 14 additions & 10 deletions src/engine/graphics/sprite.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Sprite* = ref object
texture_width*, texture_height*: int
# In UV coordinates
clip*: Vec4f
clear_fx*: bool
# Tint color
tint*: Vec4f
flip_h*, flip_v*: bool
Expand All @@ -31,7 +32,8 @@ type Sprite* = ref object
proc create_sprite*(image: GLuint, fx_image: GLuint, width: int, height: int): Sprite =
return Sprite(texture_id: image, fx_texture_id: fx_image, texture_width: width, texture_height: height,
clip: vec4f(0, 0, 1, 1), tint: vec4f(1.0, 1.0, 1.0, 1.0),
shader: load_shader("res/shader/sprite"), scale: vec2f(1.0, 1.0))
shader: load_shader("res/shader/sprite"), scale: vec2f(1.0, 1.0),
clear_fx: true)

proc create_sprite*(image: string): Sprite =
var width, height, nCh : int
Expand Down Expand Up @@ -73,8 +75,8 @@ proc create_fx_sprite*(image: string): Sprite =

proc create_sprite*(image: string, fx_image: string): Sprite =
var width, height, nCh, fxwidth, fxheight : int
var data = stbi.load(image, width, height, nCh, 0)
var fxdata = stbi.load(fx_image, fxwidth, fxheight, nCh, 0)
var data = stbi.load(image, width, height, nCh, 4)
var fxdata = stbi.load(fx_image, fxwidth, fxheight, nCh, 4)
assert fxwidth == width and fxheight == height

var tex, fxtex: Gluint
Expand Down Expand Up @@ -124,20 +126,22 @@ proc do_draw*(sprite: Sprite) =
.rotate(sprite.rotation, 0, 0, 1)
.translate(-sprite.scale_origin.x, -sprite.scale_origin.y, 0.0)
sprite.shader.set_mat4("sprite_tform", stform)

if sprite.fx_texture_id != 0:
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, sprite.fx_texture_id)
sprite.shader.set_int("has_fx", 1)
glDepthMask(false)
draw_rectangle()
sprite.shader.set_int("clear_fx",
if (sprite.texture_id != 0) and sprite.clear_fx: 1 else: 0)

if sprite.texture_id != 0:
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, sprite.texture_id)
sprite.shader.set_int("has_fx", 0)
glDepthMask(true)
draw_rectangle()

if sprite.fx_texture_id != 0:
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, sprite.fx_texture_id)
sprite.shader.set_int("has_fx", 1)
glDepthMask(false)
draw_rectangle()


proc `center_position=`*(sprite: Sprite, pos: Vec2f) =
Expand Down
4 changes: 3 additions & 1 deletion src/engine/map/map_loader.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type Map* = ref object
points*: Table[string, seq[Vec2f]]
# Only bounding boxes
areas*: Table[string, seq[Vec4f]]
size*: Vec2f

proc hash(x: Vec3i): Hash =
return x.x.hash !& x.y.hash !& x.z.hash
Expand Down Expand Up @@ -592,7 +593,8 @@ proc load_map*(map: string, scale: int, space: Space): Map =


let drawer = create_map_drawer(ground_tiles)
return Map(drawer: drawer, segments: segments, points: points, areas: areas)
let size = vec2f((images[0].width * scale).toFloat, (images[0].height * scale).toFloat)
return Map(drawer: drawer, segments: segments, points: points, areas: areas, size: size)



13 changes: 11 additions & 2 deletions src/game/entities/barrier.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ../userdata
const BARRIER_COLL = 42

type Barrier* = ref object
health: float
health*: float
hurt_wav: WavHandle
break_wav: WavHandle
sprites*: seq[AnimatedSprite]
Expand Down Expand Up @@ -100,10 +100,19 @@ proc create_wooden_barrier*(area: Vec4f, size: int, space: Space, id: int, barri
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)
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 update*(this: var Barrier) =
for sprite in mitems(this.sprites):
sprite.animate(dt)
if this.health < 0.0:
if this.health <= 0.0:
discard this.break_wav.play_sound()
this.phys_space.removeShape(this.phys_shape)
this.broken = true
Expand Down
Loading

0 comments on commit 66b2770

Please sign in to comment.