Giter Site home page Giter Site logo

cs141-functional-onaf's Introduction

One Night at Freddy's

This is the skeleton code for the second coursework in the 2022 iteration of CS141 Functional Programming at the University of Warwick. This is built on a haskell Stack framework, and uses the Gloss library that haskell supports. This is an implementation of one night from the game Five Nights at Freddy's. This program was the final task of my functional programming module at Warwick University, and achieved 100%!

As you will have seen from looking at the code, there is a large facet of different areas and files that all contribute in different ways towards game. These can be broken down into the main sections of the primary monadic interface used: Gloss; specifically their play function. Play is broken down into several arguments: → Color : Background color → Int : Frames per second (fps) → world : Initial GameState → (world → picture) : Render function → Event → world → world : Input handler → (Float → world → world) : GameState Update The ones that really matter to us are the render function, the input handler and the GameState update. Starting with the render function, this takes all of our assets, and uses the current GameState to convert it into an image that reflects what we want to see on screen. This includes displaying the office, the content on the cameras, the jumpscares, and any other images present throughout FNAF. The assets used were taken straight from the original game, with the link to the assets and the game being in the resources. Next, we have the input handler, and this is how we tackle inputs such as clicking on different cameras, or opening and closing the doors using buttons. This made use of the Event handler built into gloss, allowing us to find where the mouse was on the screen, and if it was clicking. Additionally, the cameras were implemented such that you bring up the monitor by pressing the space key. Finally, there is the update function, which is the most important as it explores how we change our game every single frame. This made heavy use of the State monad, in which it was used not only to parse changes on to the GameState in a way reminiscent to an imperative language; but it also allowed us to return useful data and update 1 the GameState simultaneously. The most prominent example of this how the State monad enables randomness, by updating the random seed each call of random, whilst returning the random value. Currently to the point it is at, the features of: a fully functioning office, cameras, time and battery system, with Bonnie and Chica fully implemented, Freddy mostly implemented, and a plenty of ways to win and to lose the game!

The way that the game was designed hence, was that the animatronics would operate as close as they would in the original game, their AI being found and explained in the video ‘Ruining FNaF by Dissecting the Animatronics’ AI — Tech Rules, https://www.youtube.com/watch?v=ujg0Y5IziiY. A graph of data would hold the directions to which an animatronic could traverse too, and every set number of frames, the animatronic would make an attempt to move. This move is dependent on a random generator, compared the aggression level of the animatronic. Bonnie and Chica would roam freely, and if coming close, would try to get into your office, whilst Freddy would always be heading in your direction, and the only way to stop him is to look at him on the cameras. Unfortunately, due to how different Foxy was, I was unable to implement them, similar to Golden Freddy; however, the basis and their set up for their existence is there. The other mechanics then to implement were the in-game time progressing, as well as the power. The way FNAF power consumption works is that every 9.6 seconds you are guaranteed to lose 1% of your power. However, if you have one door close, then its every 4.8 seconds; another door, halves the time again to 2.4 seconds, and so on. If the usage is four, you will roughly lose power once every second, and when you run out, you enter blackout mode, where everything will go dark, you cannot pull up the cameras, all you can do is wait before Freddy jumpscares you.

cs141-functional-onaf's People

Contributors

illuminarchie66 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.