Map & mapgen updates.

- More textures, more transition textures.
  - Old ImageLoader removed.
  - Number of tiles displayed reduced for more realistic benchmarking.
    Also makes running tests a bit faster.
master
Luka Vandervelden 2018-11-05 00:21:56 +09:00
parent 9b33e7cbb5
commit 1c454fd523
29 changed files with 48 additions and 76 deletions

BIN
assets/flowers-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

BIN
assets/haunted---bl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/haunted--rb-.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/haunted--rbl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/haunted-t--l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/haunted-t-bl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/haunted-tr--.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/haunted-tr-l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/haunted-trb-.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/haunted-tree.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/sand-----.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/sand----l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
assets/sand---b-.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/sand---bl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
assets/sand--r--.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
assets/sand--r-l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/sand--rb-.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/sand--rbl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
assets/sand-t---.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/sand-t--l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
assets/sand-t-b-.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/sand-t-bl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
assets/sand-tr--.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
assets/sand-tr-l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
assets/sand-trb-.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
assets/tree-cut.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

@ -3,49 +3,25 @@ require "json"
require "./naka.cr"
class ImagesLoader
getter stone : SDL::Texture
getter tree : SDL::Texture
getter pine : SDL::Texture
getter flowers : SDL::Texture
getter sand : SDL::Texture
getter water : SDL::Texture
getter haunted : SDL::Texture
getter rocks : SDL::Texture
def initialize(window)
@stone = window.newImage "assets/stone.png"
@tree = window.newImage "assets/tree.png"
@flowers = window.newImage "assets/flowers.png"
@sand = window.newImage "assets/sand.png"
@water = window.newImage "assets/water.png"
@haunted = window.newImage "assets/haunted.png"
@pine = window.newImage "assets/tree_pine.png"
@rocks = window.newImage "assets/rocks.png"
end
end
Naka.init
window = Naka::Window.new "Test", 16*128, 16*128, flags: LibSDL::WindowFlags::RESIZABLE | LibSDL::WindowFlags::SHOWN | LibSDL::WindowFlags::OPENGL
images = ImagesLoader.new window
connection_font = window.newFont "assets/connection.otf", 30.5
window.set_font connection_font
def simple_tile_drawer(window : Naka::Window, tile_path : String)
texture = window.newImage tile_path
texture_height = texture.height
->(map : Naka::Map, x : Int32, y : Int32, z : Int32, tile : Naka::Map::Tile, object : Naka::Map::Object, draw_x : Int32, draw_y : Int32, zoom : Float64){
window.draw texture, draw_x, draw_y, scale_x: zoom, scale_y: zoom
window.draw texture, draw_x, (draw_y + (16 - texture_height) * zoom).to_i, scale_x: zoom, scale_y: zoom
nil
}
end
def bordered_tile_drawer(window : Naka::Window, base_tile_path : String)
# FIXME: Both excessive, insufficient, and broken.
mod = [
"trbl",
"-rbl",
@ -119,27 +95,42 @@ dirt = Naka::Map::ObjectReference.new(
)
sand = Naka::Map::ObjectReference.new(
name: "Sand",
walkable: true
walkable: true,
drawer: bordered_tile_drawer window, "assets/sand{}.png"
)
water = Naka::Map::ObjectReference.new(
name: "Water"
name: "Water",
drawer: simple_tile_drawer window, "assets/water.png"
)
flowers = Naka::Map::ObjectReference.new(
name: "Flowers",
walkable: true
walkable: true,
drawer: simple_tile_drawer window, "assets/flowers.png"
)
haunted = Naka::Map::ObjectReference.new(
name: "Haunted",
walkable: true
walkable: true,
drawer: bordered_tile_drawer window, "assets/haunted{}.png"
)
haunted_tree = Naka::Map::ObjectReference.new(
name: "Tree (Haunted)",
drawer: simple_tile_drawer window, "assets/haunted-tree.png"
)
tree_cut = Naka::Map::ObjectReference.new(
name: "Tree (Cut)",
drawer: simple_tile_drawer window, "assets/tree-cut.png"
)
tree = Naka::Map::ObjectReference.new(
name: "Tree"
name: "Tree",
drawer: simple_tile_drawer window, "assets/tree.png"
)
pine = Naka::Map::ObjectReference.new(
name: "Pine Tree"
name: "Pine Tree",
drawer: simple_tile_drawer window, "assets/tree_pine.png"
)
rocks = Naka::Map::ObjectReference.new(
name: "Rocks"
name: "Rocks",
drawer: simple_tile_drawer window, "assets/rocks.png"
)
altitude_noise = Naka::Noise2D.new.tap do |a|
@ -178,18 +169,24 @@ map = Naka::Map.new stone, "map-test-01" do |tile, x, y|
tile << Naka::Map::Object.new stone
end
if altitude < 0.25
if altitude > 0.175
if humidity < 0.33
if altitude < 0.75
if altitude < 0.175
next
end
tile << Naka::Map::Object.new sand
else
tile << Naka::Map::Object.new dirt
if humidity < 0.225
next
end
end
elsif altitude < 0.75
tile << Naka::Map::Object.new dirt
if evil > 0.5
if altitude < 0.275
next
end
if evil > 0.4
tile << Naka::Map::Object.new haunted
else
tile << Naka::Map::Object.new grass
@ -197,7 +194,9 @@ map = Naka::Map.new stone, "map-test-01" do |tile, x, y|
if altitude > 0.35 && altitude < 0.65
if humidity > 0.4
if humidity > 0.8
if evil > 0.4
tile << Naka::Map::Object.new haunted_tree
elsif humidity > 0.8
tile << Naka::Map::Object.new tree
elsif humidity < 0.6
tile << Naka::Map::Object.new pine
@ -228,51 +227,24 @@ Naka::Event.loop window do |event|
when Naka::Event::Quit
next Naka::Event::Quit
when Naka::Event::Update
p "FPS: #{(1000f64 / event.dt)}"
when Naka::Event::Draw
zoom_level = 4.0
128.times do |x|
128.times do |y|
64.times do |x|
32.times do |y|
tile = map.get x, y
# FIXME:
# - Please dont draw more than one layer of ground…
# - Transitions. (eg. between dirt and grass)
tile.each_with_index do |object, z|
image = case object.reference.name.downcase
when "tree"
images.tree
when "pine tree"
images.pine
when "flowers"
images.flowers
when "water"
images.water
when "haunted"
images.haunted
when "sand"
images.sand
when "rocks"
images.rocks
else
images.stone
end
draw_x = (x * 16 * zoom_level).to_i
draw_y = (y * 16 * zoom_level - (image.height - 16) * zoom_level).to_i
draw_y = (y * 16 * zoom_level).to_i
drawer = object.reference.drawer
if drawer.nil?
window.draw(
image,
x: draw_x,
y: draw_y,
scale_x: zoom_level,
scale_y: zoom_level
)
next
end
next if drawer.nil? # FIXME: Maybe print a warning.
drawer.call map, x, y, z, tile, object, draw_x, draw_y, zoom_level
end