Render HP
This commit is contained in:
		
							parent
							
								
									d0302c3156
								
							
						
					
					
						commit
						1dc8aac4c7
					
				
					 5 changed files with 31 additions and 12 deletions
				
			
		|  | @ -42,14 +42,19 @@ allItems = [ | |||
|     ("key",    "key.png"   ) | ||||
|     ] | ||||
| 
 | ||||
| allGui :: [(String, FilePath)] | ||||
| allGui = [ | ||||
|     ("health", "health.png") | ||||
|     ] | ||||
| 
 | ||||
| -- Map of all renders | ||||
| library :: [(String, Picture)] | ||||
| library = unknown:entities ++ environment ++ gui ++ items | ||||
|     where unknown     = ("unknown", renderPNG (assetsFolder ++ unknownImage)) | ||||
|           entities    = map (\(f, s) -> (f, renderPNG (assetsFolder ++ "entities/" ++ s))) allEntities | ||||
|           entities    = map (\(f, s) -> (f, renderPNG (assetsFolder ++ "entities/"    ++ s))) allEntities | ||||
|           environment = map (\(f, s) -> (f, renderPNG (assetsFolder ++ "environment/" ++ s))) allEnvironment | ||||
|           gui         = [] | ||||
|           items       = map (\(f, s) -> (f, renderPNG (assetsFolder ++ "items/" ++ s))) allItems | ||||
|           gui         = map (\(f, s) -> (f, renderPNG (assetsFolder ++ "gui/"         ++ s))) allGui | ||||
|           items       = map (\(f, s) -> (f, renderPNG (assetsFolder ++ "items/"       ++ s))) allItems | ||||
| 
 | ||||
| ------------------------------ Exported ------------------------------ | ||||
| 
 | ||||
|  |  | |||
|  | @ -5,8 +5,9 @@ module RPGEngine.Render.Playing | |||
| import RPGEngine.Render.Core (Renderer, getRender, setRenderPos, overlay) | ||||
| 
 | ||||
| import RPGEngine.Config (resolution, zoom, uizoom) | ||||
| import RPGEngine.Data (State(..), Player (..), Game (..), Level (..), Layout, Physical (..), Item (..), Entity (..)) | ||||
| import RPGEngine.Data (State(..), Player (..), Game (..), Level (..), Layout, Physical (..), Item (..), Entity (..), HP) | ||||
| 
 | ||||
| import Data.Maybe ( fromJust ) | ||||
| import Graphics.Gloss ( pictures, Picture, translate, white ) | ||||
| import Graphics.Gloss.Data.Picture ( blank, text, color, scale ) | ||||
| 
 | ||||
|  | @ -23,9 +24,9 @@ renderPlaying _ = blank | |||
| ------------------------------- Player ------------------------------- | ||||
| 
 | ||||
| renderPlayer :: Renderer Player | ||||
| renderPlayer Player{ position = (x, y) } = move picture | ||||
|     where move    = setRenderPos x y | ||||
|           picture = getRender "player" | ||||
| renderPlayer Player{ position = (x, y), playerHp = playerHp } = move picture | ||||
|     where move      = setRenderPos x y | ||||
|           picture   = withHealthBar playerHp $ getRender "player" | ||||
| 
 | ||||
| -- Center the player in the middle of the screen. | ||||
| -- Not in use at the moment, might be useful later. | ||||
|  | @ -83,8 +84,8 @@ renderEntities :: [Entity] -> Picture | |||
| renderEntities list = pictures $ map renderEntity list | ||||
| 
 | ||||
| renderEntity :: Entity -> Picture | ||||
| renderEntity Entity{ entityId = id, entityX = x, entityY = y} = setRenderPos x y image | ||||
|     where image = getRender id | ||||
| renderEntity Entity{ entityId = id, entityX = x, entityY = y, entityHp = hp} = setRenderPos x y image | ||||
|     where image = withHealthBar hp $ getRender id | ||||
| 
 | ||||
| renderInventory :: Player -> Picture | ||||
| renderInventory Player{ showInventory = False } = blank | ||||
|  | @ -92,4 +93,19 @@ renderInventory Player{ inventory = list } = pictures [overlay, title, items] | |||
|     where title = translate 0 (offset (-1)) $ scale uizoom uizoom $ color white $ text "Inventory" | ||||
|           items = pictures $ map move $ zip [0::Int ..] (map (getRender . itemId) list) | ||||
|           move (i, pic) = translate 0 (offset i) pic | ||||
|           offset i      = negate (zoom * resolution * fromIntegral i) | ||||
|           offset i      = negate (zoom * resolution * fromIntegral i) | ||||
| 
 | ||||
| withHealthBar :: HP -> Picture -> Picture | ||||
| withHealthBar (Nothing) renderedEntity = renderedEntity | ||||
| withHealthBar (Just hp) renderedEntity = pictures [renderedEntity, positionedBar] | ||||
|     where positionedBar = scale smaller smaller $ translate left up renderedBar | ||||
|           renderedBar   = pictures [heart, counter] | ||||
|           heart         = scale by by $ getRender "health" | ||||
|           counter       = translate right down $ scale scaler scaler $ color white $ text $ show hp | ||||
|           left          = negate $ uizoom * resolution * scaler | ||||
|           right         = uizoom * resolution * 0.05 | ||||
|           up            = uizoom * resolution | ||||
|           down          = negate $ resolution * uizoom * 0.15 | ||||
|           smaller       = resolution * uizoom | ||||
|           by            = uizoom * 0.1 | ||||
|           scaler        = by * 0.5 | ||||
		Reference in a new issue