Skip to content

Commit

Permalink
Particles use TileDisplay.
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey Tomes committed Dec 19, 2023
1 parent b1ffe3d commit d7f6d94
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 72 deletions.
59 changes: 12 additions & 47 deletions main.ms
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ Display = {}
Display.initialize = function()
MapDisplay = require("MapDisplay")

HUD = 0
HUD_BACK = 1
PARTICLES_0 = 2
PARTICLES_1 = 3
MAP_0 = 4
MAP_1 = 5
// HUD = 0
// HUD_BACK = 1
// PARTICLES_0 = 2
// PARTICLES_1 = 3
// MAP_0 = 4
// MAP_1 = 5

activate = function(n)
display(n).mode = displayMode.text
Expand All @@ -99,48 +99,16 @@ Display.initialize = function()
return display(n)
end function

Display.hud = ui.HeadsUpDisplay.init(HUD, HUD_BACK)
Display.hud = ui.HeadsUpDisplay.make(0, 1)

Display.particles = activate(PARTICLES_0)
deactivate(PARTICLES_0)
activate(PARTICLES_1)

Display.particles = display(PARTICLES_0)
Display.flipParticles = function()
if display(PARTICLES_0).mode == displayMode.off then
display(PARTICLES_0).mode = displayMode.text
display(PARTICLES_1).mode = displayMode.text
Display.particles = display(PARTICLES_1)
display(PARTICLES_1).mode = displayMode.off
else
display(PARTICLES_0).mode = displayMode.text
display(PARTICLES_1).mode = displayMode.text
Display.particles = display(PARTICLES_0)
display(PARTICLES_0).mode = displayMode.off
end if
end function
Display.particles = MapDisplay.make(2, 3)

Display.map = MapDisplay.init(MAP_0, MAP_1)
Display.map = MapDisplay.make(4, 5)
end function

Display.clear = function()
Display.hud.backColor = color.clear
Display.hud.clear()
Display.flipParticles()

Display.particles.backColor = color.clear
Display.particles.clear()
Display.flipParticles()
Display.particles.backColor = color.clear
Display.particles.clear()
Display.flipParticles()

//Display.map.backColor = color.clear
//Display.map.clear()
//Display.map.flip
//Display.map.backColor = color.clear
//Display.map.clear()
//Display.map.flip
end function

Service = {}
Expand Down Expand Up @@ -184,8 +152,7 @@ updateParticles = function(deltaTime, map, renderOffset)
if Service.fountains.len > 0 then
n = 0

Display.particles.backColor = color.clear
Display.particles.clear()
Display.particles.clear color.clear

while n < Service.fountains.len
f = Service.fountains[n]
Expand All @@ -197,7 +164,7 @@ updateParticles = function(deltaTime, map, renderOffset)
end if
end while

Display.flipParticles()
Display.particles.flip
end if
end function

Expand Down Expand Up @@ -245,10 +212,9 @@ main = function()
while isRunning
frameStart = time * 1000

// updateParticles(deltaTime, Service.world.map, renderOffset) // TODO
updateParticles(deltaTime, Service.world.map, renderOffset)

// The next step in the game occurs when the player presses a key.
// Service.messages.report("move?")
if key.available then
map = Service.world.map

Expand Down Expand Up @@ -280,7 +246,6 @@ main = function()
Service.messages.report("YOU ARE DEAD!")
end if

// Service.messages.report("move")
Service.world.map.draw_v1(Display.map, Service.world.player, renderOffset)
drawEntities(Display.map, Service.world.map, renderOffset)
Display.map.flip
Expand Down
33 changes: 17 additions & 16 deletions src/MapDisplay.ms
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,27 @@ MapDisplay.initTiles = function(displayNumber)
return dsp
end function

MapDisplay.init = function(displayNumberFront, displayNumberBack)
self.isActive = false
MapDisplay.make = function(displayNumberFront, displayNumberBack)
dsp = new MapDisplay
dsp.isActive = false

self.displayNumberFront = displayNumberFront
self.displayNumberBack = displayNumberBack
dsp.displayNumberFront = displayNumberFront
dsp.displayNumberBack = displayNumberBack

self.activeDisplay = 0
dsp.activeDisplay = 0

self.display0 = self.initTiles(displayNumberFront)
self.display0Back = self.initTiles(displayNumberBack)
dsp.display0 = dsp.initTiles(displayNumberFront)
dsp.display0Back = dsp.initTiles(displayNumberBack)

self.display1 = self.initTiles(displayNumberFront)
self.display1Back = self.initTiles(displayNumberBack)
dsp.display1 = dsp.initTiles(displayNumberFront)
dsp.display1Back = dsp.initTiles(displayNumberBack)

self.display = self.display0
self.displayBack = self.display0Back
self.display.install self.displayNumberFront
self.displayBack.install self.displayNumberBack
dsp.display = dsp.display0
dsp.displayBack = dsp.display0Back
dsp.display.install dsp.displayNumberFront
dsp.displayBack.install dsp.displayNumberBack

return self
return dsp
end function

MapDisplay.flip = function()
Expand Down Expand Up @@ -77,10 +78,10 @@ MapDisplay.setCell = function(x, y, tile, color="#FFFFFF", backColor = "#0000000
self.setCellBackColor x, y, backColor
end function

MapDisplay.clear = function()
MapDisplay.clear = function(fg="#000000", bg="#00000000")
for y in range(0, constants.TILE_DISPLAY_YMAX)
for x in range(0, constants.TILE_DISPLAY_XMAX)
self.setCell x, y, 0, color.black, color.clear
self.setCell x, y, 0, fg, bg
end for
end for
end function
Expand Down
6 changes: 1 addition & 5 deletions src/particle.ms
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ Particle.draw = function(dsp, renderOffset)
y = floor(renderOffset.y + self.y)

if 0 <= x and x <= SCREEN_MAX_X and 0 <= y and y <= SCREEN_MAX_Y then
dsp.row = floor(renderOffset.y + self.y)
dsp.column = floor(renderOffset.x + self.x)
dsp.color = self.foregroundColor.str()
dsp.backColor = self.backgroundColor.str()
dsp.print(self.text)
dsp.setCell x, y, self.text, self.foregroundColor, self.backgroundColor
end if
end function

Expand Down
9 changes: 5 additions & 4 deletions src/ui/HeadsUpDisplay.ms
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ HeadsUpDisplay.initTiles = function(displayNumber)
return display(displayNumber)
end function

HeadsUpDisplay.init = function(displayNumberFront, displayNumberBack)
self.display = self.initTiles(displayNumberFront)
self.displayBack = self.initTiles(displayNumberBack)
return self
HeadsUpDisplay.make = function(displayNumberFront, displayNumberBack)
dsp = new HeadsUpDisplay
dsp.display = dsp.initTiles(displayNumberFront)
dsp.displayBack = dsp.initTiles(displayNumberBack)
return dsp
end function

HeadsUpDisplay.setCellBackColor = function(x, y, backColor)
Expand Down

0 comments on commit d7f6d94

Please sign in to comment.