diff --git a/assignment/assignment.cpp b/assignment/assignment.cpp deleted file mode 100644 index 9fd4408758284990fc2fc9c406bf436245cc5fa2..0000000000000000000000000000000000000000 --- a/assignment/assignment.cpp +++ /dev/null @@ -1,264 +0,0 @@ -// MARKING SCHEME (included for reference): -// - Implement a simple example program using the framework provided : 30 marks -// - Your program supports interaction and state, e.g. allows the user to draw sprites, these sprites, can be saved, and restored: 20 Marks -// - Your programs demonstrates a complex application, e.g. it might be 2D game, such as 2048 or a simple Space Invaders: 20 Marks -// - Your program is well structured, using multiple include files, and is documented, including source comments and a readme.md: 30 Marks - -// PLEASE READ -// How to play: -// - Use W/A/S/D to move your character (red square) -// - Collect cubes by touching them with your character, this increases your score -// - Your score is displayed in the top left -// - Collect as many points as you can before time runs out -// - Player character is blue, cubes are red -// NOTE: -// - Cube collection is very wonky, make sure you cover the cube entirely to collect it. -// - Also, I was originally intending to make this a sprite editor, so sorry if there are any left-over bits of that. - -#include <iostream> -// Import used for input/output. - -#include <iomanip> -// Import used to manipulate the visual output of the program. - -#include <vector> -// Import used for creating vectors -- vectors are arrays that can dynamically change -// their size. - -#include <stdlib.h> -// For randomly generating the cube location. - -#include <cstring> -// Import used to manipulate C++ output. - -#include <tuple> -// Import used for creating tuples -- tuples are finite ordered lists of elements. - -#include <context.hpp> -// Import - -#include <app.hpp> -// Import used for app code. - -using namespace std; - -const int width = 1024; -// Defines the variable 'width' as a constant integer of 1024. - -const int height = 640; -// Defines the variable 'height' as a constant integer of 640. - -class MyApp: public uwe::App { - // Creates public class referred to as 'MyApp' - -private: - // Private: cannot be accessed by any other function. - - - -public: - // Public: can be accessed by any other function. - - MyApp(int width, int height, std::string title); - ~MyApp(); - - void begin() override; - // Declares begin() function. This function will be used for program set-up. - - void update() override; - // Declares update() function. This function will be used to update the rendered frame to show the intended contents. - - void draw() override; - // Declares draw() function. This function will be used to actually draw the contents of the frame. - - void key_pressed(uwe::Scancode scancode, bool repeat) override; - // Declares key_pressed() function. This function will be used when any key is pressed by the user. - - void mouse_pressed(int x, int y, uwe::Button button) override; - // Declares mouse_pressed() function. This function will be used when any mouse button is pressed. - // Receives input of X/Y location of mouse cursor, and of what button was pressed. - - void mouse_released(int x, int y, uwe::Button button) override; - // Declares mouse_released() function. This function will be used when any mouse button is released. - // Receives input of X/Y location of mouse cursor, and of what button was released. - - void mouse_moved(int x, int y) override; - // Declares mouse_moved() function. This function will be used when the mouse is moved. - // Receives input of X/Y location of mouse cursor. - - int player_x = 64; - int player_y = 64; - // Player co-ordinates defaults - - int cube_x = 256; - int cube_y = 256; - // Cube co-ordinates defaults - - int player_score = 0; - // Player score - - int time_remaining_seconds = 60; - // 60 seconds per round, before score resets - - bool player_takes_cube = false; - // If player has taken cube , then a new one will be spawned elsewhere. - -}; - -MyApp::MyApp(int width, int height, std::string title) { - init(width, height, title); -} - -MyApp::~MyApp() { - -} - -void MyApp::begin() { - // Function called when the framework is initialised. Can be used for set-up. - - app_font = create_font("../assets/fonts/FreeSans.ttf", 8, uwe::Colour::black()); - // Declares the font details of app_font. Font size of 8, colour black. -} - -void MyApp::update() { - // Function called per frame rendered. Updates the program as to what should be drawn in the frame, so it knows what to draw. - - time_remaining_seconds = time_remaining_seconds - 1; - // Every second, the remaining time in seconds is reduced by one second. This remaining time will be drawn on screen by another function. - - if(time_remaining_seconds <= 0) - // If the player runs out of time, reset their score to zero, and reset their time to sixty seconds. - { - player_score = 0; - time_remaining_seconds = 60; - } - else - { - break; - } - - if(player_x == cube_x && player_y == cube_y) - // If player is touching a red cube, increase their score. - { - player_score = player_score + 1; - player_takes_cube = true; - } - else - { - break; - } - - if(player_takes_orb == true) - // If player has touched a red cube, change the cube's location. - { - cube_x = rand() % 512 + 128; - cube_y = rand() % 512 + 128; - player_takes_orb = false; - } - else - { - break; - } - -} - -void MyApp::key_pressed(uwe::Scancode scancode, bool repeat) -{ - // When a key is pressed, this function is performed. - // Used for the player movement implementation. - - switch (scancode) - { - case uwe::Scancode::A: - // If player presses 'a' key, the player character moves 'left'. - { - player_x = player_x - 1; - } - case uwe::Scancode::W: - // If player presses 'w' key, the player character moves 'up'. - { - player_y = player_y - 1; - } - case uwe::Scancode::S: - // If player presses 's' key, the player character moves 'down'. - { - player_y = player_y + 1; - } - case uwe::Scancode::D: - // If player presses 'd' key, the player character moves 'right'. - { - player_x = player_x + 1 - } - - default: - { - // If no key has been pressed, this function does nothing. - break; - } - } -} - -void MyApp::mouse_pressed(int x, int y, uwe::Button button) { - // Function called when a mouse button is pressed. - -} - -void MyApp::mouse_released(int x, int y, uwe::Button button) { - // Function called when a mouse button is released. - // Receives input of X/Y location of mouse cursor, and of what button was released. -} - -void MyApp::mouse_moved(int x, int y) { - // Function called when the mouse is moved. - // Receives input of X/Y location of mouse cursor. -} - -void MyApp::draw() { - // Function used to render the contents of the window as an image (frame). How often this occurs is - // dictated by the FPS, or 'Frames per Second'. For example, an FPS of 60 means that sixty 'frames' are - // drawn/rendered per second. This 'frame' is then output to be displayed to the user. - - // Note: - // My intention with this section is to create a sprite editor with the option to change RGB value of the brush to any value, thus - // allowing for any colour to be used. I have no idea how to create a slider, so I'll be using a button based system, which is - // slow and inefficient, but it does work. The < and > text will be used as button 'indicators'. - // - // Also, the buttons are probably going to be extremely wonky. Sorry about that. - - clear(uwe::Colour::white()); - // Clears the frame by covering it with white (255, 255, 255, RGB). - - draw_font(app_font, std::string player_score, 10, 10); - // Draws the player's score in the frame - - draw_font(app_font, std::string time_remaining_seconds, 10, 20); - // Draws how long the player has left this round - - set_draw_color(uwe::Colour::blue); - // Changes pen draw colour to blue - - draw_rect_fill(player_x, player_y, 32, 32); - // Draws player character - - set_draw_color(uwe::Colour::red); - // Changes pen draw colour to red - - draw_rect_fill(orb_x, orb_y, 16, 16); - // Draw the cube - - // If this works, it should display the score, timer, player, and cube. - - break; -} -int main(int argc, char *argv[]) { - uwe::App* app = new MyApp{width, height, "GARETH CHAPPELL: C++ ASSIGNMENT, COLLECT CUBES GAME"}; - // Creates new window with width of variable 'width' (640), height of variable 'height' (480), and a window - // header title of "GARETH CHAPPELL: C++ ASSIGNMENT". - - srand (time(0)); - // Uses the current time to generate the random location of the orb - - app->run(); - - return 0; -}