From 60b23279098cb71c4f3ef28ea1aa46feab7aa319 Mon Sep 17 00:00:00 2001 From: jgk Date: Thu, 22 Apr 2021 10:11:26 +0200 Subject: [PATCH] Fix new game resize bug --- data/music/firstCompo.mid | Bin 8950 -> 9125 bytes src/Dodge/Event/Menu.hs | 14 ++++++++------ src/Dodge/Item/Weapon.hs | 2 +- src/Dodge/Layout/Tree/Annotate.hs | 9 ++++++++- src/Dodge/Layout/Tree/Either.hs | 11 +++++++++++ src/Dodge/Room.hs | 5 ++++- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/data/music/firstCompo.mid b/data/music/firstCompo.mid index bad3e62be1d8903b69165a6845c71934f46c3776..556ac1f749aa45a562dd8f65f16d449aae28c32c 100644 GIT binary patch delta 1050 zcmd^;KTASU7>9r7CKjS`!K{l7UJXJ5^=fEGxX5vkXb81jBBF-2h9GDt0+A5fPkn^8 zhTtmH&{VC_5Pbui8l#rT-t=&Th8!E3emv*A=e!T+&ui&){`}D!O;noY1eir(xuFJo z;k*sgQ1L7r=@XMX(Y@2`o>M|2g20LNAKZyN3mX6Q9=^YX zFM!eRiUz>h1FkD@5c;i7!UPflvvHXZ+}&hq&Cy+ delta 787 zcmdVYO-lkn7zglY7PAm44J%m*)&zS&a5Y~uNZZ}&B31+u8hR)QIs{!L2qeTy9f$k| z9iw2>FVM@eLx-+)>DDpoXwU3y81@Oe?2nme|IhHu?&Zp-ar12VCD!Ws1du2a1)?G< zkl&l^%l>Yc`iksrP?p&B&=O%;SDjQFS)*Jr;B3Yy3bq6rCVH--V@+Qb=z>KPZN8#m zO^XRsK`@P*d)ky(O$sIi9)TMnoe< case scode of ScancodeEscape -> Nothing ScancodeR -> return $ fromMaybe w $ _storedLevel w - ScancodeN -> Just $ putSound $ generateLevel 1 - $ initialWorld {_randGen = _randGen w} + ScancodeN -> startNewGame ScancodeO -> goToOptionMenu w ScancodeC -> goToControls w _ -> unpause w GameOverMenu -> case scode of ScancodeEscape -> Nothing ScancodeR -> Just $ fromMaybe w $ _storedLevel w - ScancodeN -> Just $ putSound $ generateLevel 1 - $ initialWorld - {_randGen = _randGen w} + ScancodeN -> startNewGame ScancodeO -> goToOptionMenu w ScancodeC -> goToControls w _ -> Just w @@ -52,12 +50,16 @@ handlePressedKeyInMenu mState scode w = case mState of unpause w' = Just . resumeSound $ w' {_menuLayers = []} startLevel = unpause . storeLevel - putSound = id -- set loadedSounds (_loadedSounds w) dec x = max 0 (x - 0.1) inc x = min 1 (x + 0.1) goToOptionMenu w = Just $ w & menuLayers %~ (OptionMenu :) goToControls w = Just $ w & menuLayers %~ (ControlList :) sw = w & sideEffects %~ (setVol (_config w) : ) + startNewGame = Just $ generateFromList levx + $ initialWorld + & randGen .~ _randGen w + & windowX .~ _windowX w + & windowY .~ _windowY w storeLevel :: World -> World storeLevel w = case _storedLevel w of diff --git a/src/Dodge/Item/Weapon.hs b/src/Dodge/Item/Weapon.hs index d43799a3b..5284e8e57 100644 --- a/src/Dodge/Item/Weapon.hs +++ b/src/Dodge/Item/Weapon.hs @@ -454,7 +454,7 @@ ltAutoGun = defaultAutoGun , _wpReloadState = 0 , _wpFireRate = 4 , _wpFireState = 0 - , _wpFire = shootWithSound 0 . withRandomDir 0.3 + , _wpFire = shootWithSound 0 . withRandomDir 0.3 . withSidePush 50 . withMuzFlare $ withVelWthHiteff (30,0) 2 bulletEffect' , _wpSpread = 0.5 , _wpRange = 20 diff --git a/src/Dodge/Layout/Tree/Annotate.hs b/src/Dodge/Layout/Tree/Annotate.hs index ea68ee88d..ef7fe56ba 100644 --- a/src/Dodge/Layout/Tree/Annotate.hs +++ b/src/Dodge/Layout/Tree/Annotate.hs @@ -5,6 +5,7 @@ module Dodge.Layout.Tree.Annotate where import Dodge.RandomHelp import Dodge.Layout.Tree.Polymorphic +import Dodge.Layout.Tree.Either import Dodge.Room.Procedural import Dodge.Room.Link import Dodge.Room.Data @@ -38,7 +39,13 @@ randomPadCorridors (Node x xs) = do annoToRoomTree :: RandomGen g => [Annotation] -> State g (Tree (Either Room Room)) annoToRoomTree [Corridor] = fmap (pure . Right) $ randomiseOutLinks corridor -annoToRoomTree [FirstWeapon] = weaponRoom +annoToRoomTree [FirstWeapon] = do + --firstWeapon <- takeOne $ [[branchRectWith weaponRoom,blockedCorridor]] ++ replicate 5 [weaponRoom] + branchWP <- branchRectWith weaponRoom + blockedC <- blockedCorridor + firstWeapon <- takeOne $ [return $ appendEitherTree branchWP [blockedC]] ++ replicate 5 weaponRoom + --firstWeapon <- takeOne $ replicate 5 weaponRoom + firstWeapon annoToRoomTree _ = do w <- state $ randomR (100,400) h <- state $ randomR (200,400) diff --git a/src/Dodge/Layout/Tree/Either.hs b/src/Dodge/Layout/Tree/Either.hs index b0a61a7e4..cb60bbc57 100644 --- a/src/Dodge/Layout/Tree/Either.hs +++ b/src/Dodge/Layout/Tree/Either.hs @@ -3,6 +3,7 @@ Combining and composing trees with 'Either' nodes. -} module Dodge.Layout.Tree.Either ( expandTreeBy + , appendEitherTree , connectRoom , deadRoom ) where @@ -20,6 +21,16 @@ expandTreeBy f (Node x xs) = appendAndRemove $ f x appendAndRemove (Node (Left y) ys) = Node y (map appendAndRemove ys) appendAndRemove (Node (Right y) _ ) = Node y (map (expandTreeBy f) xs) +-- | Appends a second either forest at the 'Right' elements of a first either +-- tree. +-- Makes such 'Right' elements into 'Left's. +appendEitherTree + :: Tree (Either a a) -- ^ The first tree + -> [Tree (Either a a)] -- ^ The forest to append + -> Tree (Either a a) +appendEitherTree (Node (Left x) ts) ts' = Node (Left x) $ map (flip appendEitherTree ts') ts +appendEitherTree (Node (Right x) ts) ts' = Node (Left x) ts' + removeEither (Left y) = y removeEither (Right y) = y diff --git a/src/Dodge/Room.hs b/src/Dodge/Room.hs index 708480580..a89902762 100644 --- a/src/Dodge/Room.hs +++ b/src/Dodge/Room.hs @@ -392,6 +392,7 @@ blockedCorridor = do n <- state $ randomR (0,3) let plmnts = [PS (20,40) r $ PutBlock [5,5,5] (150/256, 75/256, 0, 250/256) $ reverse $ rectNSWE 10 (-10) (-10) 10 + ,PS (20,15) 0 $ putLamp ] sequence $ treePost (replicate n $ fmap Left $ randomiseOutLinks corridor) $ fmap Right $ return $ set rmPS plmnts corridor @@ -430,7 +431,9 @@ deadEndRoom = Room where lnks = [((0,30) ,0) ] - +{- +A random Either tree with a weapon and melee monster challenge. +-} weaponRoom :: RandomGen g => State g (Tree (Either Room Room)) weaponRoom = do x <- takeOne [ weaponEmptyRoom