188 lines
3.9 KiB
Plaintext
188 lines
3.9 KiB
Plaintext
log.console("test_tilemap starting")
|
|
|
|
var time = use('time')
|
|
|
|
var core = use('core')
|
|
var tilemap2d = use('tilemap2d')
|
|
var text2d = use('text2d')
|
|
var compositor = use('compositor')
|
|
var film2d = use('film2d')
|
|
var math = use('math/radians')
|
|
|
|
var tilemaps = []
|
|
var labels = []
|
|
var t = 0
|
|
|
|
var camera = {
|
|
pos: {x: 250, y: 250},
|
|
width: 500,
|
|
height: 500,
|
|
anchor: {x: 0.5, y: 0.5}
|
|
}
|
|
|
|
var compositor_config = {
|
|
clear: {r: 0.05, g: 0.05, b: 0.1, a: 1},
|
|
planes: [
|
|
{
|
|
name: 'main',
|
|
plane: 'main',
|
|
camera: camera,
|
|
resolution: {width: 500, height: 500},
|
|
presentation: 'stretch',
|
|
clear: {r: 0.05, g: 0.05, b: 0.1, a: 1}
|
|
}
|
|
]
|
|
}
|
|
|
|
function make_grid(w, h, img) {
|
|
var tiles = []
|
|
var x = 0
|
|
var y = 0
|
|
for (x = 0; x < w; x++) {
|
|
tiles[x] = []
|
|
for (y = 0; y < h; y++) {
|
|
tiles[x][y] = img
|
|
}
|
|
}
|
|
return tiles
|
|
}
|
|
|
|
function init() {
|
|
// Tilemap 1: Normal (top-left)
|
|
tilemaps[] = tilemap2d({
|
|
plane: 'main',
|
|
layer: 0,
|
|
tiles: make_grid(4, 4, 'examples/tiles/terrain_dirt_cloud'),
|
|
tile_width: 25,
|
|
tile_height: 25,
|
|
offset_x: 0,
|
|
offset_y: 14
|
|
})
|
|
labels[] = text2d({
|
|
plane: 'main',
|
|
layer: 10,
|
|
text: "Normal",
|
|
pos: {x: 50, y: 480},
|
|
font: 'examples/fonts/dos',
|
|
size: 14,
|
|
color: {r: 1, g: 1, b: 1, a: 1}
|
|
})
|
|
|
|
// Tilemap 2: Opacity 0.5 (top-right)
|
|
tilemaps[] = tilemap2d({
|
|
plane: 'main',
|
|
layer: 0,
|
|
tiles: make_grid(4, 4, 'examples/tiles/terrain_dirt_cloud'),
|
|
tile_width: 25,
|
|
tile_height: 25,
|
|
offset_x: 10,
|
|
offset_y: 14,
|
|
opacity: 0.5
|
|
})
|
|
labels[] = text2d({
|
|
plane: 'main',
|
|
layer: 10,
|
|
text: "Opacity 0.5",
|
|
pos: {x: 280, y: 480},
|
|
font: 'examples/fonts/dos',
|
|
size: 14,
|
|
color: {r: 1, g: 1, b: 1, a: 1}
|
|
})
|
|
|
|
// Tilemap 3: Red tint (bottom-left)
|
|
tilemaps[] = tilemap2d({
|
|
plane: 'main',
|
|
layer: 0,
|
|
tiles: make_grid(4, 4, 'examples/tiles/terrain_dirt_cloud'),
|
|
tile_width: 25,
|
|
tile_height: 25,
|
|
offset_x: 0,
|
|
offset_y: 4,
|
|
tint: {r: 1, g: 0.3, b: 0.3, a: 1}
|
|
})
|
|
labels[] = text2d({
|
|
plane: 'main',
|
|
layer: 10,
|
|
text: "Red Tint",
|
|
pos: {x: 50, y: 230},
|
|
font: 'examples/fonts/dos',
|
|
size: 14,
|
|
color: {r: 1, g: 1, b: 1, a: 1}
|
|
})
|
|
|
|
// Tilemap 4: Green tint (bottom-right)
|
|
tilemaps[] = tilemap2d({
|
|
plane: 'main',
|
|
layer: 0,
|
|
tiles: make_grid(4, 4, 'examples/tiles/terrain_dirt_cloud'),
|
|
tile_width: 25,
|
|
tile_height: 25,
|
|
offset_x: 10,
|
|
offset_y: 4,
|
|
tint: {r: 0.3, g: 1, b: 0.3, a: 1}
|
|
})
|
|
labels[] = text2d({
|
|
plane: 'main',
|
|
layer: 10,
|
|
text: "Green Tint",
|
|
pos: {x: 280, y: 230},
|
|
font: 'examples/fonts/dos',
|
|
size: 14,
|
|
color: {r: 1, g: 1, b: 1, a: 1}
|
|
})
|
|
|
|
// Tilemap 5: Animated opacity (center bottom)
|
|
tilemaps[] = tilemap2d({
|
|
plane: 'main',
|
|
layer: 0,
|
|
tiles: make_grid(3, 3, 'examples/tiles/terrain_dirt_cloud'),
|
|
tile_width: 30,
|
|
tile_height: 30,
|
|
offset_x: 6,
|
|
offset_y: 0,
|
|
opacity: 1
|
|
})
|
|
labels[] = text2d({
|
|
plane: 'main',
|
|
layer: 10,
|
|
text: "Animated Opacity",
|
|
pos: {x: 180, y: 20},
|
|
font: 'examples/fonts/dos',
|
|
size: 14,
|
|
color: {r: 1, g: 1, b: 0, a: 1}
|
|
})
|
|
|
|
log.console("test_tilemap initialized with " + text(length(tilemaps)) + " tilemaps")
|
|
}
|
|
|
|
function update(dt) {
|
|
t += dt
|
|
|
|
// Animate opacity on the center tilemap
|
|
var animated_tilemap = tilemaps[4]
|
|
animated_tilemap.opacity = 0.3 + 0.7 * abs(math.sine(t * 1.5))
|
|
|
|
// Animate tint on the red tilemap (pulse)
|
|
var red_tilemap = tilemaps[2]
|
|
var pulse = 0.5 + 0.5 * math.sine(t * 2)
|
|
red_tilemap.tint.r = 0.5 + 0.5 * pulse
|
|
red_tilemap.tint.g = 0.2 * pulse
|
|
red_tilemap.tint.b = 0.2 * pulse
|
|
}
|
|
|
|
function render() {
|
|
var plan = compositor.compile(compositor_config)
|
|
return compositor.execute(plan)
|
|
}
|
|
|
|
init()
|
|
|
|
core.start({
|
|
width: 500,
|
|
height: 500,
|
|
title: "Test Tilemap Features",
|
|
framerate: 60,
|
|
update: update,
|
|
render: render
|
|
})
|