Skip to content

Commit

Permalink
Boy and girl villagers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey Tomes committed Dec 20, 2023
1 parent 99da861 commit 6158349
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 35 deletions.
3 changes: 1 addition & 2 deletions main.ms
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ drawHUD = function(display, player)
// display.color = color.white
// display.backColor = color.black

statusBar = "HP: {0} / {1} LVL: {2} XP: {3} / {4} world: {5}".fill([player.currentHP, player.maxHP, player.level, player.xp, player.xpToNextLevel, Service.world.currentLevel])
statusBar = "HP: {0}/{1} LVL: {2} XP: {3}/{4} world: {5}".fill([player.currentHP, player.maxHP, player.level, player.xp, player.xpToNextLevel, Service.world.currentLevel])
statusBar = statusBar + " " * (constants.UI_DISPLAY_WIDTH - statusBar.len)

display.print(statusBar, 0, constants.UI_DISPLAY_YMAX, color.white, color.black)
Expand Down Expand Up @@ -206,7 +206,6 @@ main = function()
Service.world.map.draw_v1(Display.map, Service.world.player, renderOffset)
drawEntities(Display.map, Service.world.map, renderOffset)
Display.map.flip
// Display.map.setCell 5, 5, "*", color.red, color.blue

drawHUD(Display.hud, Service.world.player)

Expand Down
22 changes: 22 additions & 0 deletions src/factories/entities.ms
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ makeSign = function(map, pnt, msg)
return e
end function

// Let's start with a villager that is basically a walking signpost.
makeSimpleVillager = function(map, pnt, msg)
if math.random(0, 100) < 50 then
name = names.boy
t = tile.make(268, Color.blue.lighter, true, false)
else
name = names.girl
t = tile.make(268, Color.pink.lighter, true, false)
end if
e = (new entity.Entity).init(t, races.npc, classes.classless, pnt)
e.name = name.str()
e.fullName = name
e.description = "{0}: ""{1}""".fill([e.name, msg])
e.canBeAttacked = false
e.describe = function(display, bounds)
end function
e.behaviors.push(behaviors.makeWander())
return e
end function
makeRat = function(map)
t = tile.make("r", Color.gray, Color.black, true, false)
e = (new entity.Entity).init(t, races.rat, classes.classless, map.findHiddenSpawnPoint())
Expand Down
108 changes: 75 additions & 33 deletions src/townGenerator.ms
Original file line number Diff line number Diff line change
Expand Up @@ -267,47 +267,89 @@ generateCavernLevel = function(mapgen, map)
end for
// Place the stairs down.
foundSpot = false
while not foundSpot
x = math.random(0, map.width - 1)
y = math.random(0, map.height - 2)
if not map.blocksMovement(x, y) then
map.tiles[y][x] = tiles.makeStairsDown()
map.stairsDown = point.make(x, y)
foundSpot = true
end if
end while
pnt = findSpawnPoint(map)
map.tiles[pnt.y][pnt.x] = tiles.makeStairsDown()
map.stairsDown = pnt
// foundSpot = false
// while not foundSpot
// x = math.random(0, map.width - 1)
// y = math.random(0, map.height - 2)
// if not map.blocksMovement(x, y) then
// map.tiles[y][x] = tiles.makeStairsDown()
// map.stairsDown = point.make(x, y)
// foundSpot = true
// end if
// end while
// Place the player spawn near the stairs down.
foundSpot = false
while not foundSpot
// Put the spawn point near the stairs down.
x = math.random(map.stairsDown.x - 5, map.stairsDown.x + 5)
y = math.random(map.stairsDown.y - 5, map.stairsDown.y + 5)
if not map.blocksMovement(x, y) and not pnt.equals(map.stairsDown) then
// We need the stairsUp point for spawning, but there is no level < 0.
//map.tiles[y][x] = tiles.makeStairsUp()
map.stairsUp = point.make(x, y)
foundSpot = true
pnt = findSpawnPointInRadius(map, map.stairsDown, 5)
map.stairsUp = pnt
// foundSpot = false
// while not foundSpot
// // Put the spawn point near the stairs down.
// x = math.random(map.stairsDown.x - 5, map.stairsDown.x + 5)
// y = math.random(map.stairsDown.y - 5, map.stairsDown.y + 5)
// if not map.blocksMovement(x, y) and not pnt.equals(map.stairsDown) then
// // We need the stairsUp point for spawning, but there is no level < 0.
// //map.tiles[y][x] = tiles.makeStairsUp()
// map.stairsUp = point.make(x, y)
// foundSpot = true
// end if
// end while
// Place a sign post.
pnt = findSpawnPointInRadius(map, map.stairsDown, 5)
e = entities.makeSign(map, pnt, "Under construction, please come back later!")
map.entities.push(e)
// foundSpot = false
// while not foundSpot
// // Put the spawn point near the stairs down.
// x = math.random(map.stairsDown.x - 5, map.stairsDown.x + 5)
// y = math.random(map.stairsDown.y - 5, map.stairsDown.y + 5)
// pnt = point.make(x, y)
// if not map.blocksMovement(x, y) and not map.isEntityAt(pnt) and not pnt.equals(map.stairsDown) then
// e = entities.makeSign(map, pnt, "Under construction, please come back later!")
// map.entities.push(e)
// foundSpot = true
// end if
// end while
// pnt = findSpawnPointInRadius(map, map.stairsDown, 20)
// e = entities.makeSimpleVillager(map, pnt, "Welcome to Village!")
// map.entities.push(e)
for n in range(10)
pnt = findSpawnPointInRadius(map, map.stairsDown, 20)
e = entities.makeSimpleVillager(map, pnt, "Welcome to Village!")
map.entities.push(e)
end for
return map
end function
findSpawnPoint = function(map)
while true
sx = math.random(0, map.width - 1)
sy = math.random(0, map.height - 1)
if not map.blocksMovement(sx, sy) then
return point.make(sx, sy)
end if
end while
end function
// Place a sign post.
foundSpot = false
while not foundSpot
findSpawnPointInRadius = function(map, pnt, radius)
while true
// Put the spawn point near the stairs down.
x = math.random(map.stairsDown.x - 5, map.stairsDown.x + 5)
y = math.random(map.stairsDown.y - 5, map.stairsDown.y + 5)
pnt = point.make(x, y)
if not map.blocksMovement(x, y) and not map.isEntityAt(pnt) and not pnt.equals(map.stairsDown) then
e = entities.makeSign(map, pnt, "Under construction, please come back later!")
map.entities.push(e)
foundSpot = true
sx = math.random(pnt.x - radius, pnt.x + radius)
sy = math.random(pnt.y - radius, pnt.y + radius)
sp = point.make(sx, sy)
if not map.blocksMovement(sx, sy) and not map.isEntityAt(sp) and not sp.equals(map.stairsDown) then
return sp
end if
end while
return map
end function
build = function(mapgen, map)
Expand Down

0 comments on commit 6158349

Please sign in to comment.