Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: TomK32/Rogue-Beach-CA
base: 94ef3236ae
...
head fork: TomK32/Rogue-Beach-CA
compare: 3409fdfa73
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
View
15 entities/beach.lua
@@ -6,12 +6,15 @@ function Beach:initialize(position, tiles)
end
function Beach:draw()
- for x = 1, #self.tiles do
- for y = 1, #self.tiles[x] do
- c = self.tiles[x][y]
- print(c)
- self.map.view.rectangle('fill', {255, 255, c, 255}, x, y)
- self.map.view.print('.', {255, 255, 200, 240}, x, y)
+ love.graphics.push()
+ for x, row in pairs(self.tiles) do
+ for y, c in pairs(row) do
+ game.renderer:rectangle('fill', {255, 255, c, 255}, x-1, y-1)
+ game.renderer:print('.', {55, 55, 0, 240}, x-1, y-1)
end
end
+ love.graphics.pop()
+end
+
+function Beach:update()
end
View
44 entities/wave.lua
@@ -0,0 +1,44 @@
+
+Wave = class("Wave", Entity)
+function Wave:initialize(position, tiles)
+ self.position = position
+ self.tiles = tiles
+ self.dt = 0
+ self.dead = false
+end
+
+function Wave:draw()
+ love.graphics.push()
+ game.renderer:translate(self.position.x, self.position.y)
+ for x, row in pairs(self.tiles) do
+ for y, c in pairs(row) do
+ game.renderer:rectangle('fill', {0, 0, 255-c, 155}, x-1, y-1)
+ game.renderer:print('~', {2200, 200, 255-c, 255}, x-1, y-1)
+ end
+ end
+ love.graphics.pop()
+end
+
+
+function Wave:update(dt)
+ self.dead = false
+ self.dt = self.dt + dt * 3
+ if self.dt > 1 then
+ local new_tiles = {}
+ self.dt = 0
+ self.position.y = self.position.y - 1
+ if self.position.y < 1 then
+ self.position.y = 1
+ table.remove(self.tiles, 0)
+ end
+ for x, row in pairs(self.tiles) do
+ new_tiles[x] = {}
+ -- remove wave if it is very small
+ for y, c in pairs(row) do
+ new_tiles[x][y-1] = c
+ end
+ end
+ if self.position.y == 2 then self.dead = true end
+ self.tiles = new_tiles
+ end
+end
View
1  game.lua
@@ -5,6 +5,7 @@ game = {
mode = { height = love.graphics.getHeight(), width = love.graphics.getWidth() }
},
fonts = {},
+ renderer = require('renderers/ascii')
}
function game:createFonts(offset)
View
11 game_states/map_state.lua
@@ -6,15 +6,24 @@ require 'views/map_view'
require 'entities/entity'
require 'entities/beach'
+require 'entities/wave'
MapState = class("MapState", GameState)
function MapState:initialize()
self.level = Level(1, 1)
- self.view = MapView(self, self.level.map)
+ self.view = MapView(self.level.map)
+ game.renderer.map_view = self.view
+ self.view:update()
self.view.map = self.level.map
end
function MapState:draw()
self.view:draw()
+
+ love.graphics.print("FPS: "..love.timer.getFPS(), 10, 20)
end
+function MapState:update(dt)
+ self.level:update(dt)
+ self.view:update()
+end
View
64 generators/map_generator.lua
@@ -3,15 +3,33 @@ LuaBit = require("lib/LuaBit")
MapGenerator = class("MapGenerator")
-function MapGenerator:initialize(seed, map)
+function MapGenerator:initialize(seed)
self.seed = seed
- self.map = map
+ self:incrementSeed(0)
+ self.dt = { wave = 0 }
+end
+
+function MapGenerator:incrementSeed(dt)
+ self.seed = self.seed + dt
SimplexNoise.seedP(self.seed)
end
-- fill a whole map
function MapGenerator:randomize()
- self:newBeach()
+ self:newBeach(1, 1/4)
+ self:newWave(1)
+ self:newWave(2)
+ self:newWave(3)
+ self:newBeach(3, 1/7)
+end
+
+function MapGenerator:update(dt)
+ self.dt.wave = self.dt.wave + dt
+ if self.dt.wave > 0.7 then
+ self:incrementSeed(1)
+ self.dt.wave = 0
+ self:newWave(1)
+ end
end
-- int, int, 0..1, 0..1, int, int
@@ -26,19 +44,37 @@ function MapGenerator:seedPosition(seed_x,seed_y, scale_x, scale_y, offset_x, of
}
end
-function MapGenerator:newBeach()
- local tiles = {}
- for x=1, self.map.width do
- tiles[x] = {}
- for y=1, self.map.height/4 do
- tiles[x][y] = math.floor((SimplexNoise.Noise2D(x*0.1, y*0.1) + 1) * 120) % 255
+function MapGenerator:newWave(offset_y)
+ print('Add wave')
+ wave_factor = 6
+
+ local tiles = self:fillTiles(1, 1, self.map.width, wave_factor,
+ function(x,y)
+ local w = math.floor(SimplexNoise.Noise2D(x*0.002, y*0.03)*200) % (60+offset_y)
+ if y == wave_factor / 2 then
+ return w * 3
+ else
+ return w
+ end
end
- end
- local beach = Beach({x = 1, y = 1, z = 1}, tiles)
- beach.map = self.map
- return map:addEntity(beach)
+ )
+ return self.map:addEntity(Wave({x = 0, y = self.map.height - offset_y + wave_factor, z = 2, speed = 1 }, tiles))
end
-function MapGenerator:randomizeBeach()
+function MapGenerator:newBeach(z, depth)
+ local tiles = self:fillTiles(1, 1, self.map.width, self.map.height * depth,
+ function(x,y) return math.floor((SimplexNoise.Noise2D(x*0.1, y*0.1) + 1) * 120) % 255 end
+ )
+ return self.map:addEntity(Beach({x = 0, y = 0, z = z}, tiles))
end
+function MapGenerator:fillTiles(x1, y1, x2, y2, callback)
+ local tiles = {}
+ for x=math.floor(x1), math.floor(x2-x1+1) do
+ tiles[x] = {}
+ for y=math.floor(y1), math.abs(math.floor(y2-y1+1)) do
+ tiles[x][y] = callback(x,y)
+ end
+ end
+ return tiles
+end
View
15 level.lua
@@ -8,13 +8,24 @@ function Level:initialize(level, seed)
self.seed = self.seed + self.level
- self.map = Map(200,200)
+ self.generator = MapGenerator(self.seed)
+ self.map = Map(40,30, self.generator)
- self.generator = MapGenerator(self.seed, self.map)
end
function Level:update(dt)
self.dt = self.dt + dt
+ for layer, entities in pairs(self.map.layers) do
+ for i, entity in pairs(entities) do
+ entity:update(dt)
+ if entity.dead == true then
+ print("Removing", entity.position.y)
+ table.remove(self.map.layers[layer], i)
+ end
+ end
+ --print(layer, #self.map.layers[layer])
+ end
+ self.generator:update(dt)
end
View
7 map.lua
@@ -9,14 +9,17 @@
-- and update and draw functions
Map = class("Map")
-function Map:initialize(width, height)
+function Map:initialize(width, height, generator)
self.width = width
self.height = height
self.layers = {} -- here the entities are stuffed into
self.map = {}
+ self.generator = generator
+ self.generator.map = self
+ self.generator:randomize()
end
-function Map:place(entity)
+function Map:addEntity(entity)
entity.map = self
if not self.layers[entity.position.z] then
self.layers[entity.position.z] = {}
View
34 renderers/ascii.lua
@@ -0,0 +1,34 @@
+
+-- Handles how things are being draw. tiles, colours, text
+--
+
+local AsciiRenderer = class("AsciiRenderer")
+AsciiRenderer.map_view = nil
+
+function AsciiRenderer:translate(x, y)
+ love.graphics.translate(self:scaledXY(x,y))
+end
+function AsciiRenderer:rectangle(style, color, x, y, tiles_x, tiles_y)
+ if not self.map_view then return end
+ love.graphics.setColor(unpack(color))
+ love.graphics.rectangle(style,
+ self:scaledX(x), self:scaledY(y),
+ (tiles_x or 1) * self.map_view.scale.x, (tiles_y or 1) * self.map_view.scale.y
+ )
+end
+
+function AsciiRenderer:print(text, color, x, y)
+ love.graphics.setColor(unpack(color))
+ love.graphics.print(text, self:scaledXY(x, y))
+end
+function AsciiRenderer:scaledXY(x, y)
+ return self:scaledX(x), self:scaledY(y)
+end
+function AsciiRenderer:scaledX(x)
+ return x * self.map_view.scale.x
+end
+function AsciiRenderer:scaledY(y)
+ return y * self.map_view.scale.y
+end
+return AsciiRenderer
+
View
28 views/map_view.lua
@@ -3,7 +3,7 @@ MapView = class("MapView", View)
MapView:include({
map = nil,
top_left = { x = 0, y = 0 }, -- offset
- scale = { x = 10, y = 10 },
+ scale = { x = 16, y = 16 },
canvas = nil,
})
@@ -12,39 +12,35 @@ function MapView:initialize(map)
self:updateDisplay()
self.draw_cursor = false
self.canvas = love.graphics.newCanvas(self.display.width, self.display.height)
- self:update()
end
function MapView:updateDisplay()
self.display = {
x = 10,
y = 10,
- width = game.graphics.mode.width - 20,
- height = game.graphics.mode.height - 20
+ width = math.min(self.map.width * self.scale.x, game.graphics.mode.width) - 20,
+ height = math.min(self.map.height * self.scale.y, game.graphics.mode.height) - 20
}
end
function MapView:drawContent()
if self.canvas then
- love.graphics.setColor(255,255,255,255)
+ love.graphics.setColor(255,255,255,155)
love.graphics.draw(self.canvas, 0, 0)
end
end
-function MapView:rectangle(style, colour, x, y)
- love.graphics.setColor(unpack(colour))
- love.graphics.rectangle(style, x * self.scale.x, y * self.scale.y, self.scale.x, self.scale.y)
-end
-
-function MapView:print(text, colour, x, y)
- love.graphics.setColor(unpack(colour))
- love.graphics.print(text, x * self.scale.x, y * self.scale.y)
-end
-
function MapView:update()
love.graphics.setCanvas(self.canvas)
- love.graphics.setColor(255,255,255,255)
+ love.graphics.setColor(55,55,55,255)
love.graphics.rectangle('fill', 0,0,game.graphics.mode.width, game.graphics.mode.height)
+ for layer, entities in pairs(self.map.layers) do
+ for i,entity in ipairs(entities) do
+ love.graphics.push()
+ entity:draw()
+ love.graphics.pop()
+ end
+ end
love.graphics.setCanvas()
return self.canvas
end

No commit comments for this range

Something went wrong with that request. Please try again.