diff options
| -rw-r--r-- | data_src/characters/Top-Down_Shooter_v2_1.psd | bin | 0 -> 3485605 bytes | |||
| -rw-r--r-- | data_src/darkseed-16-1x.png | bin | 0 -> 119 bytes | |||
| -rw-r--r-- | data_src/oil-6-1x.png | bin | 0 -> 93 bytes | |||
| -rw-r--r-- | data_src/vanilla-milkshake-1x.png | bin | 0 -> 5733 bytes | |||
| -rw-r--r-- | ideas.txt | 27 | ||||
| -rw-r--r-- | notes/lake.png | bin | 0 -> 17617 bytes | |||
| -rw-r--r-- | src/controllers/mouse_keyboard.moon | 55 | ||||
| -rw-r--r-- | src/islandgen.moon | 118 | ||||
| -rw-r--r-- | src/menu/input.moon | 30 | ||||
| -rw-r--r-- | src/menu/main.moon | 67 | ||||
| -rw-r--r-- | src/menu/playername.moon | 23 | ||||
| m--------- | src/party/hc | 0 | ||||
| -rw-r--r-- | src/player.moon | 145 | ||||
| -rw-r--r-- | src/prefab/hall.moon | 21 | ||||
| -rw-r--r-- | src/prefab/room.moon | 10 | ||||
| -rw-r--r-- | src/prefab/spawn.moon | 3 | ||||
| -rw-r--r-- | src/prefab/worldgen.moon | 58 | ||||
| -rw-r--r-- | src/shaders/lake.frag | 5 | ||||
| -rw-r--r-- | src/shaders/lake.moon | 29 | ||||
| -rw-r--r-- | src/shaders/lake.vert | 13 | ||||
| -rw-r--r-- | src/shaders/land.frag | 50 | ||||
| -rw-r--r-- | src/shaders/land.vert | 14 | ||||
| -rw-r--r-- | src/shaders/player.frag | 14 | ||||
| -rw-r--r-- | src/shaders/player.vert | 23 | ||||
| -rw-r--r-- | src/worldgen.moon | 17 |
25 files changed, 722 insertions, 0 deletions
diff --git a/data_src/characters/Top-Down_Shooter_v2_1.psd b/data_src/characters/Top-Down_Shooter_v2_1.psd Binary files differnew file mode 100644 index 0000000..91ac9af --- /dev/null +++ b/data_src/characters/Top-Down_Shooter_v2_1.psd diff --git a/data_src/darkseed-16-1x.png b/data_src/darkseed-16-1x.png Binary files differnew file mode 100644 index 0000000..fdeb8f8 --- /dev/null +++ b/data_src/darkseed-16-1x.png diff --git a/data_src/oil-6-1x.png b/data_src/oil-6-1x.png Binary files differnew file mode 100644 index 0000000..a509776 --- /dev/null +++ b/data_src/oil-6-1x.png diff --git a/data_src/vanilla-milkshake-1x.png b/data_src/vanilla-milkshake-1x.png Binary files differnew file mode 100644 index 0000000..9ac3b48 --- /dev/null +++ b/data_src/vanilla-milkshake-1x.png diff --git a/ideas.txt b/ideas.txt new file mode 100644 index 0000000..16dabc0 --- /dev/null +++ b/ideas.txt @@ -0,0 +1,27 @@ +* Game where you and friends have to brew potions - potion shop +* game where you and friends fish in a swamp +* magnum opus clone? potion craft clone? + +A bunch of recipies in the form a op b -> c + +* A game where you go fishing at night, and have to bring a lantern so you can look for bubbles in the water +* You catch all sorts of stuff, a trader comes by boat during the day to buy your fish and sell you lamp oil +* You can catch monsters that attack you +* You can catch monsters that defend you +* player can go a little into the water + +Must have assets: +* reel in sound effect +* bubbles in the water +* fishing minigame +* character controller, aim and cast line + +should have: +* multiplayer +* inventory +* things to buy +* fish have different reel-in patterns +* ripples in the water +* trees on the island +* a dock where the trader comes by in the morning +* a way to tell day from night diff --git a/notes/lake.png b/notes/lake.png Binary files differnew file mode 100644 index 0000000..1cb9c15 --- /dev/null +++ b/notes/lake.png diff --git a/src/controllers/mouse_keyboard.moon b/src/controllers/mouse_keyboard.moon new file mode 100644 index 0000000..b0b63b6 --- /dev/null +++ b/src/controllers/mouse_keyboard.moon @@ -0,0 +1,55 @@ +ecs = require("ecs") +win = require("window") +world = require("world") +controller = {} + +class MouseKeyboardControllerComponent extends ecs.Component + new: (id, properties) => + @text_size = 1 + super(id, properties) + join: (ent) => + graphic = ent\get("graphic") + @node = am.group! + graphic.properties.node\append(@node) + net_component = ent\get("net") + pred_component = ent\get("pred") + bind_node = graphic.properties.node("bind") + @node\action(() => + x,y = 0,0 + accel = {x:0,y:0} -- x,y + if win\key_down("w") + y += 0.001 + if win\key_down("s") + y -= 0.001 + if win\key_down("a") + x -= 0.001 + if win\key_down("d") + x += 0.001 + mouse_loc = win\mouse_position! + angle = -math.atan(mouse_loc.x / mouse_loc.y) + if mouse_loc.y > 0 + angle = angle + math.pi + graphic\face(angle) + --print("angle is:", angle) + should_update = false + -- Need to update net component somehow + final_accel = vec2(x, y) + if net_component.properties.accel ~= final_accel + net_component.properties.accel = final_accel + net_component.properties.last_update = am.current_time! + --net_component.properties.vel = vec2(0,0) + --should_update = true + --print("Mouse keyboard action") + pred_loc = pred_component.properties.pos + world.world_x = pred_loc.x + world.world_y = pred_loc.y + bind_node.world_x = pred_loc.x + bind_node.world_y = pred_loc.y + + ) + +controller.text_size = 1 +controller.Controller = MouseKeyboardControllerComponent + +controller + diff --git a/src/islandgen.moon b/src/islandgen.moon new file mode 100644 index 0000000..95e8b07 --- /dev/null +++ b/src/islandgen.moon @@ -0,0 +1,118 @@ +rng = require("rng") +shim = require("shader_shim") +world = require("world") +color = require("color") +win = require("window") +gen = {} + +-- Generate roughly rectangular islands +-- Stategy: generate a series of points, if we're in the first 1/4, go roughly right, +-- in the second 1/4, roughtly up, in the 3rd 1/4 roughly left, and in the 4th quarter roughtly down, finally joining up at the end +-- We find the smallest aabb box in this line, and use points on this box as the other side for triangles. + +n_points = 100 +point_distance = 1 +sides = 4 + +gen.generate = (seed) -> + rg = rng.generator(seed) + normal = (avg, std) -> + print("normal with", avg, std) + rg1, rg2 = rg(),rg() + print("rgs:",rg1, rg2) + -- Box-Muller transform + bm = math.sqrt(-2 * math.log(rg1)) * math.cos(2 * math.pi * rg2) + print("bm was:",bm) + -- Box-Muller gives us std = e^-0.5 , avg = 0 + ((bm / math.exp(-1/2)) * std) + avg + shoreline = {} + shoreline[1] = vec2(0,0) + aabb_sides = { + {"y",math.max,"b"}, + {"x",math.min,"r"}, + {"y",math.min,"t",}, + {"x",math.max,"l"} + } + aabb = { + b: n_points * point_distance + r: n_points * point_distance + t: -n_points * point_distance + l: -n_points * point_distance + } + z = 0 + for i = 1, sides + for j = 1, n_points / sides + -- remap i (1->4) to (0 -> 2pi) + avg_direction = ((i-1)/sides) * (2 * math.pi) + std_direction = math.pi / 6 + rng_direction = normal(avg_direction, std_direction) + print("rng_direction ended up being:", rng_direction) + point = shoreline[#shoreline] + vec2(math.cos(rng_direction) * point_distance, math.sin(rng_direction) * point_distance) + shoreline[#shoreline + 1] = point + print("point:", point) + print("prev:",aabb[aabb_sides[i][3]]) + aabb[aabb_sides[i][3]] = aabb_sides[i][2](aabb[aabb_sides[i][3]],point[aabb_sides[i][1]]) + + print("Generated shoreline:",shoreline) + print("And aabb box:" ,aabb) + -- Now that we have the shorline, generate the geometry + -- every point after the first needs to generate 2 triangles, 6 vertexes, each vertex is a vec3, 3 floats, 4 bytes per float + geom = am.buffer(((n_points * 2) - 4) * 6 * 3 * 4) -- 4 corners only get 1 triangle + gview = geom\view("vec3") + gview[1] = vec3(shoreline[1].x, shoreline[1].y,z) + gview[2] = vec3(aabb.l, aabb.b,z) + gview[3] = vec3(shoreline[npoints - 1].x, shoreline[npoints - 1].y, z) + gi = 4 + only1 = {[25]: true, [50]: true, [75]: true} + for i = 2, npoints + gview[gi] = vec3(shoreline[i].x, shoreline[i].y, z) + if i < 25 + gview[gi+1] = 1 + +gen.protogen = (seed) -> + geom = am.buffer(6 * 3 * 4) + gview = geom\view("vec3") + z = 0 + gview[1] = vec3(-10,-10,z) + gview[2] = vec3(-10,10,z) + gview[3] = vec3(10,10,z) + gview[4] = vec3(10,10,z) + gview[5] = vec3(10,-10,z) + gview[6] = vec3(-10,-10,z) + aspect = win.width / win.height + s_mv = mat4( + 1, 0, 0, 0, + 0, aspect, 0, 0, + 0, 0, 1, 0, + -0.5, 0.5, 0, 4 + ) + node = shim.land\append(am.depth_test("less")\append(am.bind({ + MV: s_mv + P: mat4(1) + land: gview + lamp1: vec4(0,0,0,0.1) + lamp2: vec4(0,0,0,0) + lamp3: vec4(0,0,0,0) + time: am.current_time! + background: color.am_color.background + shadow: color.am_color.shadow + midground: color.am_color.midground + foreground: color.am_color.foreground + highlight: color.am_color.highlight + outline: color.am_color.outline + black: color.am_color.black + world_x: 5 + world_y: 5 + })\append(am.draw("triangles")))) + node\action(() => + bind = self("bind") + bind.time = am.current_time! + bind.world_x = world.world_x + bind.world_y = world.world_y + print(world.world_x, world.world_y) + bind.lamp1 = vec4(math.sin(am.current_time!), 0, 0, math.cos(am.current_time! * 3) + math.pi) + ) + + node + +gen diff --git a/src/menu/input.moon b/src/menu/input.moon new file mode 100644 index 0000000..eb3cffe --- /dev/null +++ b/src/menu/input.moon @@ -0,0 +1,30 @@ +ui = require("ui") +world = require("world") +main_menu = require("menu.main") +input = {} + +buttons = {} +input.initalize = () -> + button_mk = ui.button(-630,-100,300,200,"Mouse\nand\nKeyboard") + button_touch = ui.button(-300,-250,500,500,"Touch") + button_controller = ui.button(250,-64,380,128,"Controller") + button_touch.on = () => + world.controller = require("controllers.touch") + input.remove! + button_mk.on = () => + print("setting mk controller") + world.controller = require("controllers.mouse_keyboard") + input.remove! + require("menu.main").initalize! + button_controller.on = () => + world.controller = require("controllers.controller") + input.remove! + buttons = {button_mk, button_touch, button_controller} + +input.remove = () -> + print("Removing buttons", buttons) + for button in *buttons + print("Deleting button",button) + ui.delete(button) + +input diff --git a/src/menu/main.moon b/src/menu/main.moon new file mode 100644 index 0000000..764ce28 --- /dev/null +++ b/src/menu/main.moon @@ -0,0 +1,67 @@ +ui = require("ui") +router = require("router") +world = require("world") +menu = {} + +buttons = {} +buttons_data = { + { + text: "Settings" + on: () => + menu.destroy! + require("menu.settings").initalize! + } + { + text: "Join" + on: () => + menu.destroy! + require("menu.join").initalize! + } + { + text: "Host" + on: () => + print("Setting co...") + if not @node.co + @node.co = coroutine.create(() -> + server = router.Router! + server\initalize! + server + ) + button = @ + @node\action(() => + print("In coroutine, menu is", menu) + if @co and coroutine.status(@co) ~= "dead" + succ, val = coroutine.resume(@co) + if not succ + error(debug.traceback(@co,val)) + if type(val) == "string" + print("Setting text", val) + button.text.text = val + else + print("Returned router") + world.router = val + menu.destroy! + require("menu.playername").initalize(true) + ) + } + { + text: "Tutorial" + on: () => + menu.destroy! + print("Load tutorial level") + } +} +menu.initalize = () -> + starty = -200 + for i = starty, ((#buttons_data-1) * (64 + 32)) + starty, 64 + 32 + print("making button", #buttons + 1) + buttons[#buttons + 1] = ui.button(-100,i,200,64,buttons_data[#buttons + 1].text) + buttons[#buttons].on = buttons_data[#buttons].on + + print("intalize") + +menu.destroy = () -> + for button in *buttons + ui.delete(button) + +menu diff --git a/src/menu/playername.moon b/src/menu/playername.moon new file mode 100644 index 0000000..afcddd0 --- /dev/null +++ b/src/menu/playername.moon @@ -0,0 +1,23 @@ +ui = require("ui") +world = require("world") + +menu = {} + +buttons = {} +menu.initalize = (is_host) -> + text = ui.textbox(-100,16,200,32) + submit = ui.button(-100,-16,200,32,"Use alias") + submit.on = () => + menu.destroy! + print("Got name:", text.text.text) -- <textbox class>.<am.text node>.<actual text lookup> + if is_host + require("worldgen") + print("Building player with", world.router, world.controller, text.text.text) + player = require("player").Player(world.router, world.controller ,text.text.text) + buttons = {text, submit} + +menu.destroy = () -> + for button in *buttons + ui.delete(button) + +menu diff --git a/src/party/hc b/src/party/hc new file mode 160000 +Subproject eb1f285cb1cc4d951d90c92b64a4fc85e7ed06b diff --git a/src/player.moon b/src/player.moon new file mode 100644 index 0000000..fcd624b --- /dev/null +++ b/src/player.moon @@ -0,0 +1,145 @@ +ecs = require("ecs") +shim = require("shader_shim") +win = require("window") +sprites = require("world.sprites") +world = require("world") +aspect = win.width / win.height +player_tiny = 6 +s_mv = mat4( + 1, 0, 0, 0, + 0, aspect, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, player_tiny + ) +class Player extends ecs.Entity + new: (router, controller, alias) => + @router = router + @controller = controller + if @router.state == "elected" -- We're the host player + @alias = alias + else + error("Implement other players") + +class PlayerGraphicComponent extends world.GraphicsComponent + @player_size = 1 + @static = true + new: (name, properties) => + properties = properties or {} + buf = am.buffer(6 * 3 * 4) + buf.usage = "dynamic" + @playerbuf = buf\view("vec3") + @playerbuf[1] = vec3(0,0,0) + @playerbuf[2] = vec3(0,@@player_size,0) + @playerbuf[3] = vec3(@@player_size,@@player_size,0) + @playerbuf[4] = vec3(@@player_size,@@player_size,0) + @playerbuf[5] = vec3(@@player_size,0,0) + @playerbuf[6] = vec3(0,0,0) + properties.node = shim.player\append(am.depth_test("less")\append(am.bind({ + MV: s_mv + P: mat4(1) + world_x: 0, + world_y: 0, + player: @playerbuf + texuv: am.vec2_array({ + vec2(0,0), + vec2(0,1), + vec2(1,1), + vec2(1,1), + vec2(1,0), + vec2(0,0) + }) + dir: 0 + textures: sprites.guy_diffuse.texture + })\append(am.draw("triangles")))) + properties.node\action(() => + --print("Player graphic action") + ) + --print("Properties node is:", properties.node) + super(name, properties) + --print("finished init") + @ + move: (x,y) => + assert(x, "x required") + assert(y, "y required") + h = @@player_size / 2 + @playerbuf[1] = vec3(x-h,y-h,0) + @playerbuf[2] = vec3(x-h,y+h,0) + @playerbuf[3] = vec3(x+h,y+h,0) + @playerbuf[4] = vec3(x+h,y+h,0) + @playerbuf[5] = vec3(x+h,y-h,0) + @playerbuf[6] = vec3(x-h,y-h,0) + --print("Move called", @playerbuf[1]) + face: (direction) => + print("direction",direction) + @properties.node("bind").dir = (direction ) % (math.pi * 2) + --@properties.node("bind").MV = + + +-- In a normal simulation, velocity adds acceleration * delta time every tick, minus some friction coefficient * current velocity +-- i.e. velocity = (acceleration * delta) - (friction * velocity) +-- every tick +-- velocity[tick] = (acceleration * delta[tick]) - (friction * velocity[tick - 1]) +-- velocity[4] = (acceleration * delta[4]) - (friction * velocity[3]) +-- = (acceleration * delta[4]) - (friction * ((acceleration * delta[3]) - (friction * velocity[2]))) +-- = (acceleration * delta[4]) - (friction * ((acceleration * delta[3]) - (friction * ((acceleration * delta[2]) - (friction * velocity[inital]))))) +-- = (acceleration * delta[4]) - (friction * ((acceleration * delta[3]) - ((friction * acceleration * delta[2]) - (friction * friction * velocity[inital])))) +-- = (acceleration * delta[4]) - (friciton * ((acceleration * delta[3]) - (friction * acceleration * delta[2]) + (friction^2 * velocity[inital]))) +-- = (acceleration * delta[4]) - ((friction * acceleration * delta[3]) - (friction * friction * acceleration * delta[2]) + (friction^3 * velocity[inital])) +-- = (acceleration * delta[4]) - (friction * acceleration * delta[3]) + (friction^2 * acceleration * delta[2]) - (friction^3 * velocity[inital]) +-- as delta approaches 0 (high fidelity simulation), the middle components become e^(-friction * delta), and acceleration needs to be divided by friction +-- Position is a second layer on top +-- position[tick] = position[tick-1] + velocity[tick] +-- position[2] = position[inital] + velocity[2] +-- = position[inital] + (acceleration * delta[2]) - (friction * velocity[inital]) +-- position[delta] = (delta * (acceleration / friction) ) - ((1 / friction) * (velocity[inital] - (acceleratin / friction)) * e^(-friction * delta) + position[inital] + +-- velocity = (acceleration * delta) - ( +-- we want to find the location based on inital velocity and position, constant acceleration, and delta time + +friction = 0.1 +class PlayerPredictedComponent extends ecs.PredictedComponent + new: (name) => + super(name, {vel: vec2(0,0), pos:vec2(0,0), accel: vec2(0,0)}, "net", { + accel:() => + vec2(@net.properties.accel) + vel: () => + --print("Net is ", @net.properties) + delta = world.sync_time! - @net.properties.last_update + (@net.properties.accel / friction) + ((@net.properties.vel - (@net.properties.accel / friction)) * math.exp(-friction * delta)) + pos: () => + delta = world.sync_time! - @net.properties.last_update + friction_loss = @net.properties.accel / friction + -- when delta = 0 (up to date) + -- pos = (1/friction) * (velocity - friction_loss) * 1 + position + -- = 2 * (2 - 2) * 1 + position + -- = position + (friction_loss * delta) - ((1/friction) * (@net.properties.vel - friction_loss) * (math.exp(-friction * delta))) + @properties.pos + }) + print("Right after creation, properties is",@properties) + @node = am.group! + join: (entity) => + @gc = entity\get("graphic") + @net = entity\get("net") + @gc.properties.node\append(@node) + s = @ + @node\action(() => + s\forward! + ) + forward: () => + --print("Forward called", @properties) + super! + @gc\move(@properties.pos.x, @properties.pos.y) + + + +class ProtoPlayer extends ecs.Entity + new: () => + @controller = require("controllers.mouse_keyboard") + cc = require("controllers.mouse_keyboard").Controller() + gc = PlayerGraphicComponent("graphic") + pc = PlayerPredictedComponent("pred") + nc = ecs.NetworkedComponent("net",{accel: vec2(0,0), vel: vec2(0,0), pos: vec2(0,0), name: "test", last_update: 0, dir: 0}) + print("Protoplayer created") + super("test",{graphic:gc,net:nc,controller:cc,pred:pc}) + +{:Player, :ProtoPlayer} diff --git a/src/prefab/hall.moon b/src/prefab/hall.moon new file mode 100644 index 0000000..59dbea0 --- /dev/null +++ b/src/prefab/hall.moon @@ -0,0 +1,21 @@ +util = require("util") + +-- Halls run from one point to another, the start and end points are in the +-- middle of the hallway. +-- "floor_gen" can be a string (the sprites texture to use)a +-- or a function (passed the "Hall" object to generate the texture for that segment. +class Hall + new: (tbl) => + util.typecheck(tbl, + "startx", "number", + "starty", "number", + "endx", "number", + "endy", "number", + "width", "number" + ) + assert(tbl.floor_gen, "Hall requires a 'floor_gen' attribute") + if type(tbl.floor_gen) == "function" + @floor_gen = tbl.floor_gen + elseif type(tbl.floor_gen) == "string" + @floor_gen = () => + tbl.floor_gen diff --git a/src/prefab/room.moon b/src/prefab/room.moon new file mode 100644 index 0000000..c041bb8 --- /dev/null +++ b/src/prefab/room.moon @@ -0,0 +1,10 @@ + + +class Room + new: (x,y,width,height) => + @x = x + @y = y + @width = width + @height = height + @hallways = {} + diff --git a/src/prefab/spawn.moon b/src/prefab/spawn.moon new file mode 100644 index 0000000..516c72a --- /dev/null +++ b/src/prefab/spawn.moon @@ -0,0 +1,3 @@ +-- Spawnpoint? + +class Spawnpoint extends Room diff --git a/src/prefab/worldgen.moon b/src/prefab/worldgen.moon new file mode 100644 index 0000000..846067e --- /dev/null +++ b/src/prefab/worldgen.moon @@ -0,0 +1,58 @@ +args = {...} +require("rng") +self = args[1] + +gen = {} + +-- Logical worldgen +-- Strategy: splatter some rooms on a canvas +-- rooms are {location, width, height, specialty} +-- splatter some large rooms first, in a mostly-straight line, +-- then some medium rooms with a larger spread +-- then a bunch of small rooms with a large spread +-- then connect each room with nearby neighbors + +room_sizes = { + -- avgx, stdx, avgy, stdy + large: { + avg_w: 40 + std_w: 10 + avg_l: 40 + std_l: 10 + } + medium: { + avg_w: 20 + std_w: 5 + avg_l: 20 + std_l: 5 + } + small: { + avg_w: 8 + std_w: 3 + avg_l: 8 + std_l: 3 + } +} +level = { + avg_w: 1000 + std_w: 200 + avg_h: 1000 + std_h: 200 +} +gen.level = (seed) -> + random_gen = rng.generator(seed) + normal = (avg, std, gen) => + -- Box-Muller transform + bm = math.sqrt(-2 * math.log(gen())) * math.cos(2 * math.pi * gen()) + -- Box-Muller gives us std = e^-0.5 , avg = 0 + ((bm / math.exp(-1/2)) * std) + avg + width = random_gen(avg_w, std_w, random_gen) + height = random_gen(avg_h, std_h, random_gen) + rooms = {} + -- Pick a a direction to splatter + direction = random_gen() * 2 * math.pi + rooms[0] = + + + +gen diff --git a/src/shaders/lake.frag b/src/shaders/lake.frag new file mode 100644 index 0000000..d45917e --- /dev/null +++ b/src/shaders/lake.frag @@ -0,0 +1,5 @@ +precision mediump float; +uniform vec4 color; +void main() { + gl_FragColor = color; +} diff --git a/src/shaders/lake.moon b/src/shaders/lake.moon new file mode 100644 index 0000000..bac2c42 --- /dev/null +++ b/src/shaders/lake.moon @@ -0,0 +1,29 @@ + +shader_shim = require("shader_shim") +win = require("window") +world = require("world") + +node = shader_shim.lake\append(am.bind({ + MV: mat4( + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + (-win.width / 2), (-win.height/2), 0, 1 + ), + P: mat4(1) + lake: am.vec3_array({}) + light1: am.vec4_array({}) + light2: am.vec4_array({}) + light3: am.vec4_array({}) + world_x: 0 + world_y: 0 + time: am.current_time() +}))\append(am.draw("triangles")) + +node\action((self) -> + self("bind").time = am.current_time! + self("bind").world_x = world.world_x + self("bind").world_y = world.world_y +) + +node diff --git a/src/shaders/lake.vert b/src/shaders/lake.vert new file mode 100644 index 0000000..2745cf9 --- /dev/null +++ b/src/shaders/lake.vert @@ -0,0 +1,13 @@ +precision highp float; +attribute vec3 lake; +attribute vec4 lamp1; //position, strength +attribute vec4 lamp2; +attribute vec4 lamp3; // max 3 lamps per shaded vertex +uniform float time; //used for noise +uniform float world_x; +uniform float world_y; +uniform mat4 MV; +uniform mat4 P; +void main() { + gl_Position = P * MV * vec4(lake.x - world_x, lake.y - world_y, 0., 1.0); +} diff --git a/src/shaders/land.frag b/src/shaders/land.frag new file mode 100644 index 0000000..3c23990 --- /dev/null +++ b/src/shaders/land.frag @@ -0,0 +1,50 @@ +precision mediump float; +uniform vec4 black; +uniform vec4 outline; +uniform vec4 highlight; +uniform vec4 foreground; +uniform vec4 midground; +uniform vec4 shadow; +uniform vec4 background; +uniform vec4 lamp1; //vec3 position, float strength +uniform vec4 lamp2; +uniform vec4 lamp3; // max 3 lamps per shaded vertex +varying vec2 worldxy; +varying mat4 pre; + +// Author @patriciogv - 2015 +float random (vec2 st) { + return fract( + sin( + dot(st.xy,vec2(12.9898,78.233)) + ) * + 43758.5453123 + ); +} + +void main() { + vec4 coord = gl_FragCoord + vec4(worldxy * 256., 0, 0); + /* + coord.x -= worldxy.x; + coord.y -= worldxy.y; + */ + //coord = coord / 1000.; + float color = 0.; + vec2 lamppos = (lamp1.xy * 256.) - (worldxy * 1.); + color += (lamp1.w * 256.) - distance((lamp1.xy * 256.) - worldxy, coord.xy); + /* + if(color > 1.) + gl_FragColor = highlight; + else if(color > 0.8) + gl_FragColor = foreground; + else if(color > 0.6) + gl_FragColor = midground; + else if(color > 0.4) + gl_FragColor = background; + else if(color > 0.2) + gl_FragColor = shadow; + else + gl_FragColor = black; + */ + gl_FragColor = vec4(color / (256. * lamp1.w), color / (256. * lamp1.w), color / (256. * lamp1.w),1.); +} diff --git a/src/shaders/land.vert b/src/shaders/land.vert new file mode 100644 index 0000000..2004ab3 --- /dev/null +++ b/src/shaders/land.vert @@ -0,0 +1,14 @@ +precision highp float; +attribute vec3 land; +uniform float time; //used for noise +uniform float world_x; +uniform float world_y; +uniform mat4 MV; +uniform mat4 P; +varying vec2 worldxy; +varying mat4 pre; +void main() { + worldxy = vec2(world_x, world_y); + pre = P * MV; + gl_Position = P * MV * vec4(land.x - world_x, land.y - world_y, 0., 1.0); +} diff --git a/src/shaders/player.frag b/src/shaders/player.frag new file mode 100644 index 0000000..5d329fa --- /dev/null +++ b/src/shaders/player.frag @@ -0,0 +1,14 @@ +precision mediump float; +varying vec2 textureuv; // uv +uniform sampler2D textures; +uniform sampler2D emissives; +uniform sampler2D normals; +varying mat3 light1; // position, color, intensity-fadetime-? +varying vec4 v_color; +void main() { + vec2 uv = textureuv; + //gl_FragColor = texture2D(textures,uv);// + vec4(uv.xy / 4.,0.,1.); + gl_FragColor = vec4(uv.xy / 1., 0., max(uv.x, uv.y)); + //gl_FragColor = texture2D(textures,screen_intersection.xy); + +} diff --git a/src/shaders/player.vert b/src/shaders/player.vert new file mode 100644 index 0000000..ce53bf5 --- /dev/null +++ b/src/shaders/player.vert @@ -0,0 +1,23 @@ +precision highp float; +attribute vec3 player; +attribute vec2 texuv; +varying vec2 textureuv; +attribute vec4 lamp1; //vec3 position, float strength +attribute vec4 lamp2; +attribute vec4 lamp3; // max 3 lamps per shaded player +uniform float time; //used for noise +uniform float world_x; +uniform float world_y; +uniform float dir; +uniform mat4 MV; +uniform mat4 P; +void main() { + textureuv=texuv; + mat2 rotate = mat2( + cos(dir), -sin(dir), + sin(dir), cos(dir) + ); + vec2 world = vec2(world_x, world_y); + vec2 local = (player.xy - world) * rotate; + gl_Position = P * MV * vec4(local.xy, -2, 1.0); +} diff --git a/src/worldgen.moon b/src/worldgen.moon new file mode 100644 index 0000000..5fcefaf --- /dev/null +++ b/src/worldgen.moon @@ -0,0 +1,17 @@ +player = require("player") +world = require("world") +net = require("net") +router = require("router") +ecs = require("ecs") +island = require("islandgen") + + +--Check for setup +--char = player.Player(world.router, world.controller ,text.text.text) +--level = island.generate(1234) +level = island.protogen(1234) +world.node\append(level) +--world.controller = require("controllers.mouse_keyboard") +--world.node\append(world.controller.node) +char = player.ProtoPlayer() +gc = char\get("graphic") |
