diff --git a/Tutorial-Proposals/Audio Series/Basic Audio Manipulation in Splashkit.md b/Tutorial-Proposals/Audio Series/Basic Audio Manipulation in Splashkit.md new file mode 100644 index 0000000..303f148 --- /dev/null +++ b/Tutorial-Proposals/Audio Series/Basic Audio Manipulation in Splashkit.md @@ -0,0 +1,72 @@ +# Title: Introduction to Splashkit Audio and Music Functions + +## Introduction + +In this tutorial, you will learn how to work with audio and music in the Splashkit framework. We +will explore various functions that allow you to load, play, pause, and control music tracks within +your Splashkit projects. By the end of this tutorial, you will have a solid understanding of how to +incorporate background music into your games or applications using Splashkit. + +## Prerequisites + +Before diving into this tutorial, it is essential to have the following prerequisites: + +1. **Basic Programming Knowledge:** Familiarity with programming concepts and a general + understanding of coding practices. +1. **C++/C# Programming Language:** Understanding of the C++ and/or C# programming languages, + including variables, functions, loops, and conditional statements. +1. **Integrated Development Environment (IDE):** An IDE set up for C++ development, such as + [Visual Studio Code](https://code.visualstudio.com/) +1. **Splashkit Framework:** Installation of the Splashkit framework on your system. You can find + installation instructions for your operating system on the + [Splashkit website](https://splashkit.io/articles/installation/). + +## Functions Used (Link to Splashkit documentation) + +1. [load_music](https://splashkit.io/api/audio/#load-music) +1. [music_filename](https://splashkit.io/api/audio/#music-filename) +1. [music_name](https://splashkit.io/api/audio/#music-name) +1. [music_named](https://splashkit.io/api/audio/#music-named) +1. [play_music](https://splashkit.io/api/audio/#group-play-music) +1. [pause_music](https://splashkit.io/api/audio/#pause-music) +1. [resume_music](https://splashkit.io/api/audio/#resume-music) +1. [stop_music](https://splashkit.io/api/audio/#stop-music) +1. [music_playing](https://splashkit.io/api/audio/#music-playing) +1. [music_volume](https://splashkit.io/api/audio/#music-volume) +1. [fade_music_in](https://splashkit.io/api/audio/#group-fade-music-in) +1. [fade_music_out](https://splashkit.io/api/audio/#fade-music-out) + +## Table of Contents + +1. **Introduction to Splashkit Audio and Music** +1. **Loading and Playing Music** + 1. Load music from file. + 1. Get music file name. + 1. Get music name by index. + 1. Play, pause, resume, and stop music. + 1. Check if music is currently playing. +1. **Controlling Music Volume** + 1. Adjusting the music volume. + 1. Fading music in and out. + +## Tutorial Details + +This tutorial is designed for beginners with a basic understanding of programming and the C++ +language. We will cover fundamental audio functions provided by Splashkit, focusing on loading and +playing music tracks. The tutorial will be presented in a step-by-step manner, providing clear +examples and explanations along the way. + +## Expected Learning Outcomes + +By the end of this tutorial, you will have gained the following skills: + +- Loading music tracks from files and accessing their information. +- Playing, pausing, resuming, and stopping music. +- Adjusting the volume of music. +- Fading music in and out for smooth transitions. + +## Conclusion + +Understanding how to work with audio and music is essential for creating engaging and immersive +experiences in your Splashkit projects. By mastering the functions covered in this tutorial, you +will be equipped to incorporate background music seamlessly into your games or applications. diff --git a/Tutorial-Proposals/Audio Series/Managing Audio Resources in Splashkit.md b/Tutorial-Proposals/Audio Series/Managing Audio Resources in Splashkit.md new file mode 100644 index 0000000..35a1d35 --- /dev/null +++ b/Tutorial-Proposals/Audio Series/Managing Audio Resources in Splashkit.md @@ -0,0 +1,73 @@ +## Tutorial Proposal: Managing Audio Resources in Splashkit + +### Introduction + +Welcome to Tutorial 3, where we will delve into the art of managing audio resources in Splashkit. In +this tutorial, you'll gain valuable insights into efficiently handling music and sound effects, +allowing you to create more immersive and engaging gaming experiences. + +### Prerequisites + +Before diving into this tutorial, you should have a basic understanding of programming concepts and +be familiar with working in a development environment. It will also be beneficial to have a grasp of +Splashkit's audio functionalities, as we'll be building upon those concepts. + +### Functions Used (Link to Splashkit Documentation) + +1. [`free_music`](https://splashkit.io/api/audio/#free-music) +2. [`free_all_music`](https://splashkit.io/api/audio/#free-all-music) +3. [`has_music`](https://splashkit.io/api/audio/#has-music) +4. [`free_sound_effect`](https://splashkit.io/api/audio/#free-sound-effect) +5. [`free_all_sound_effects`](https://splashkit.io/api/audio/#free-all-sound-effects) +6. [`has_sound_effect`](https://splashkit.io/api/audio/#has-sound-effect) +7. [`audio_ready`](https://splashkit.io/api/audio/#audio-ready) +8. [`open_audio`](https://splashkit.io/api/audio/#open-audio) +9. [`close_audio`](https://splashkit.io/api/audio/#close-audio) + +### Table of Contents + +1. **Introduction to Managing Audio Resources** + + - Importance of Efficient Audio Resource Management + - Benefits of Organizing Audio Assets + +2. **Freeing Music Resources** + + - Releasing Allocated Music Resources + - Freeing All Music Resources Simultaneously + - Checking for the Presence of Music + +3. **Freeing Sound Effect Resources** + + - Releasing Sound Effects Appropriately + - Freeing All Sound Effects + - Verifying the Existence of Sound Effects + +4. **Optimizing Audio Functionality** + - Ensuring Audio System Readiness + - Opening and Closing the Audio System + +### Tutorial Details + +This tutorial is geared toward individuals with intermediate-level programming knowledge, +particularly those who are working on game development projects using Splashkit. We will provide +step-by-step guidance with practical examples to solidify your understanding of managing audio +resources effectively. + +### Expected Learning Outcomes + +By completing this tutorial, you will achieve the following: + +- Master the techniques to properly release music and sound effect resources in Splashkit. +- Understand how to efficiently organize and manage audio assets within your game projects. +- Gain proficiency in verifying the availability of music and sound effects. +- Learn to optimize audio functionality by ensuring audio system readiness and appropriate system + opening and closing. + +### Conclusion + +Incorporating captivating audio resources is essential for creating memorable gaming experiences. +This tutorial has equipped you with the skills to efficiently manage audio assets in your Splashkit +projects. By following these best practices, you'll be better equipped to craft games that immerse +players in a world of captivating soundscapes. Start implementing your newfound knowledge to enhance +your game development endeavors! diff --git a/Tutorial-Proposals/Audio Series/Working with Sound Effects in Splashkit.md b/Tutorial-Proposals/Audio Series/Working with Sound Effects in Splashkit.md new file mode 100644 index 0000000..8b32e3f --- /dev/null +++ b/Tutorial-Proposals/Audio Series/Working with Sound Effects in Splashkit.md @@ -0,0 +1,70 @@ +## Tutorial Proposal: Working with Sound Effects in Splashkit + +### Introduction + +In this tutorial, we will delve into the world of sound effects in Splashkit, a library designed to +facilitate game development. By the end of this tutorial, you will have a solid understanding of how +to incorporate various sound effects into your game projects, enhancing the overall gaming +experience. + +### Prerequisites + +To make the most out of this tutorial, you should have a basic understanding of programming concepts +and familiarity with using libraries in your projects. It will also be helpful if you have worked +with Splashkit before, as this tutorial builds upon its audio functionalities. + +### Functions Used (Link to Splashkit Documentation) + +1. [`load_sound_effect`](https://splashkit.io/api/audio/#load-sound-effect) +2. [`sound_effect_filename`](https://splashkit.io/api/audio/#sound-effect-filename) +3. [`sound_effect_name`](https://splashkit.io/api/audio/#sound-effect-name) +4. [`sound_effect_named`](https://splashkit.io/api/audio/#sound-effect-named) +5. [`play_sound_effect`](https://splashkit.io/api/audio/#group-play-sound-effect) +6. [`sound_effect_playing`](https://splashkit.io/api/audio/#group-sound-effect-playing) +7. [`stop_sound_effect`](https://splashkit.io/api/audio/#group-stop-sound-effect) +8. [`sound_effect_playing`](https://splashkit.io/api/audio/#group-sound-effect-playing) +9. [`fade_sound_effect_out`](https://splashkit.io/api/audio/#fade-sound-effect-out) + +### Table of Contents + +1. **Introduction to Sound Effects in Splashkit** + + - What are Sound Effects? + - Importance of Sound Effects in Games + +2. **Loading and Naming Sound Effects** + + - Loading Sound Effects from Files + - Assigning Names to Sound Effects + +3. **Playing and Controlling Sound Effects** + + - Playing Sound Effects + - Checking if a Sound Effect is Playing + - Stopping Sound Effects + +4. **Enhancing Sound Effects** + - Fading Out Sound Effects + - Applying Sound Effects to Game Scenarios + +### Tutorial Details + +This tutorial is suitable for beginners and intermediate developers interested in game development +using Splashkit. We will guide you through each step with clear examples and explanations. The +tutorial content is structured to gradually build your knowledge from the ground up. + +### Expected Learning Outcomes + +Upon completing this tutorial, you will be able to: + +- Load various sound effects into your game projects using Splashkit. +- Play, pause, and stop sound effects to synchronize them with game events. +- Apply fading effects to smoothly transition sound effects. +- Incorporate sound effects to enhance user engagement and immersion in your games. + +### Conclusion + +This tutorial has equipped you with the essential knowledge to manipulate sound effects in your +Splashkit-based game development projects. By mastering these techniques, you can create more +dynamic and captivating games that leave a lasting impression on players. Embrace the power of sound +effects and take your games to the next level!s diff --git a/Tutorial-Proposals/Building the SplashKit Core Library with CMake.md b/Tutorial-Proposals/Building the SplashKit Core Library with CMake.md new file mode 100644 index 0000000..43a467a --- /dev/null +++ b/Tutorial-Proposals/Building the SplashKit Core Library with CMake.md @@ -0,0 +1,83 @@ +## Title: Understanding CMakeLists.txt for Building the SplashKit Core Library + +As a Splashkit developer I want to learn how the CMakeLists.txt file works for building the +SplashKit core library, So that I can effectively compile and link SplashKit on various platforms +for my game development and multimedia projects. + +### Introduction + +This tutorial aims to provide readers with a basic understanding of the CMakeLists.txt file used for +building the SplashKit core library. CMake is a powerful build system generator that simplifies the +process of compiling and linking projects across different platforms. By the end of this tutorial, +readers will have a solid grasp of how CMakeLists.txt works for building SplashKit and will be able +to modify it for their own projects. + +### Prerequisites + +Readers should have: + +- Basic knowledge of C++ programming language. +- Familiarity with CMake and its basic syntax. + +### Functions Used + +1. None + +### Table of Contents + +1. **Introduction to CMakeLists.txt** + + - Understanding the purpose of CMakeLists.txt. + - The role of CMakeLists.txt in building SplashKit. + - Basic CMake syntax. + +1. **Directory Setup and Platform Detection** + + - Setting up directories for the SplashKit project. + - Detecting the current platform (Windows, macOS, Linux). + +1. **Linking Libraries and Frameworks** + + - Configuring library and framework flags for different platforms. + - Linking SplashKit with external dependencies. + +1. **Source Files and Includes** + + - Organising source files for building the SplashKit core library. + - Including directories and header files. + +1. **Building the SplashKit Core Library** + + - Creating the SplashKit shared library. + - Compiling and linking on Windows (MINGW), macOS, and Linux. + +1. **Modifying CMakeLists.txt for Custom Projects** + - Adapting CMakeLists.txt for custom projects. + - Adding new source files and directories. + - Linking additional libraries. + +### Tutorial Details + +This tutorial will provide a comprehensive explanation of the CMakeLists.txt file used to build the +SplashKit core library. It will cover directory setup, platform detection, linking libraries, +handling source files, and compiling the shared library on different platforms. The tutorial is +aimed at computer science students and programmers who want to gain a deeper understanding of CMake +and learn to customise it for their projects. + +### Expected Learning Outcomes + +After completing this tutorial, readers will: + +- Understand the structure and purpose of CMakeLists.txt in building the SplashKit core library. +- Know how to configure CMake for different platforms (Windows, macOS, Linux). +- Be able to link libraries and frameworks with the SplashKit project. +- Learn how to organise source files and include directories effectively. +- Feel confident in modifying CMakeLists.txt for their own projects. + +### Conclusion + +Understanding CMakeLists.txt is a valuable skill for readers interested in managing complex build +processes. By mastering the concepts presented in this tutorial, readers will be well-equipped to +work with CMake and customise it according to the requirements of their projects. So, let's delve +into the world of CMake and unleash the full potential of SplashKit in game development and +multimedia applications! diff --git a/Tutorial-Proposals/Game Concept - Proposal (maybe).md b/Tutorial-Proposals/Game Concept - Proposal (maybe).md new file mode 100644 index 0000000..810423b --- /dev/null +++ b/Tutorial-Proposals/Game Concept - Proposal (maybe).md @@ -0,0 +1,102 @@ +--- +title: Game Concept Ideas +--- + +## Introduction + +This tutorial is to provide Splashkit Users a guide and tutorial on making a game within Splashkit's functionalities. This tutorial also allows users to work through multiple steps of game concept as well as the actual creation of a game. For this, the tutorial will provide simple instructions and examples with reference and links to other tutorials based on functions used, as well as: + +1. Choosing game mechanics and genre +2. Creating a compelling game narrative and characters +3. Mapping out game levels and progression +4. Art and audio direction for the game + +For this example, we can look at a simple side scroller platformer, like Super Mario, Luna Games and other popular side scrolling platforms. + +A basic, barebones game, and a starting point will be drawing in sprites, background, collision detection, jumping and movement animations. Progression can include items, enemies and multiple levels. + +## Prerequisites + +- Splashkit installed +- Chosen language (C++, C#, Pascal or Python) +- Assets (Whether pre-made from free to use packages or self made) +- basic programming skills +- documentation + +## Functions Used (Link to Splashkit documentation) + +- [Create and close window](https://splashkit.io/api/windows/) +- [Timer](https://splashkit.io/api/timers/) + +## Table of Contents + +1. **Before we code: Making a games foundation** + - Creating a plan - What game do you want to make? + - Game Mechanics, narrative, and characters + - Maps, level design and the visual/audio aides +2. **Getting our virtual hands dirty: Making the game come to life!** + - Basic and entry level functions + - Advanced functions (multiple levels, enemies, items) + - Expanding and going forward. (keyboard functions) + - Mouse control functions (Pause, resume, restart instead of using a keyboard button) + +## Tutorial Details + +This tutorial is suitable for all levels of experience. From beginners to experts, it's a guide on making a simple game that can be further expanded upon as you gain more confidence and skills with coding, and game design. +This tutorial will expand on the documentation and prepartion of the game, as well was providing coding examples for a basic side scrolling platformer. It will provide examples on how you can create your own assets, putting them into said game, and creating a 2D basic game. + +## Before We code: Making a Games foundation + +### *Create a plan* + +The most difficult part about any game creation is the planning. There are multiple avenues one can venture down into when creating a game in Splashkit; Metroidvania, Flappy Bird, racing, etc. One example of generating ideas is the site [firith.studio/game-idea-generator](https://firith.studio/game-idea-generator). This can generate a basic theme, genre and mechanic on what game you could create. + +![Game generation](/https://www.flickr.com/photos/198993917@N08/53111581748/in/dateposted-public/) + +Other ideas can be centred around pop culture references, personal favourite show or movie plots, or ideas from multiple games. Other common tropes used is the use of history and mythical folklore, or creating a new twist on a childish or simple game for a new challenge. Once your idea is decided upon, its time to plot out the entire game and its world. + +### *Game Mechanics* + +Game Mechanics are your different types of gameplay styles - Turn based RPGs, First Person shooters, top down or side on scrollers, visual novel based, or choose your own adventure. Its possible to achieve a 2D side scrolling Portal recreation game. + +### *Maps, levels and visual/audio aides* + +For a basic demo, or trial run of a game, you would primarily focus on only 1 level of a game. However, with any game, regardless of the number of levels, you need to design them. One way of designing your levels, and game, would be using a flowchart. This can be achieved through LucidChart, or other applications of chart design. A basic game design layout would use the waterfall methodology to create a linear path of your game. + +- Start menu -> Level Menu -> Gameplay -> exit. + +Maps and level designs can also follow a linear path of going left to right, or right to left. For a basic understanding of gameplay and levels, it is recommended to create a side scrolling game from left to right with few obstacles. More advanced features can include back tracking, or a circular path - Starting from the top, plummeting down, and climbing your way back up after completing the mission objective. + +Inspiration or ideas can be taken from retro games; Legend of Zelda's Majora's mask, Dead Cells, Metroid. You can start in a 'middle hub', where you begin, with various points of exits along a compass (North, South, East, West) to different areas of a map, or tombs or caverns. This means you can still create a 'linear' map, but have the option to venture to areas of your own accord as opposed to the game telling you where you must head next. + +Depending on your mechanics, and game plan, will depend on your visual and audible aides. You can base a game to be entirely terminal based with no visual or audible aides (leaving the player to imagine the scenarios through story telling), or look towards visual assets. The more detailed your assets become, the larger and potentially more difficult your game becomes. + +Visual assets can be one of the most vital and appealing aspects of a game, and it can sometimes be difficult finding the right assets. Free to use visual assets can be found at [opengameart.org](https://opengameart.org). For a personal touch, visual assets can be created with a number of programs, both free and paid versions. A personal favourite is a combination of Clip Studio Paint, Paint Tool SAI and ProCreate. These art programs can create a starting point for fine pixel or high quality sprites for any game, and use a multitude of brushes. Clip Studio Paint is one that works well for multiple reasons, including 3D poses and references to provide accurate human anatomy, and an animation function (PRO is limited in the number of frames, while EX is unlimited.). + +Audio Assets and music can be obtained using royalty free music, [kenney.nl/assets](https://kenney.nl/assets),or other applications for another personal touch; These can include Audacity, VOCALOID3/4/5/6, Incredibox and LMMS. + +### Expected Learning Outcomes + +By the end of this tutorial, you'll have made your first basic side scrolling platform game with collision detection, movement functions, audio and visual aides and the overall satisfaction of creating something from nothing. This allows you to scaffold your current project into multiple levels and create a fully fledged game with story and passion. + +You will gain skills in: + +- Planning and foundation of game creation in a 2D setting. +- Mapping, level design, and visual design - where to find assets and how to make assets from + scratch. +- Creating a window with assets +- animation functions +- loop functions +- collision detection +- platform generation +- camera movement +- background scrolling +- Game over and Victory conditions +- Input handling +- Pause, end, resume and restart. + +### Conclusion + +By following with this tutorial, you will not only gain the knowledge of game design via coding, but will learn fundamental skills in planning, design and avoid issues such as scope creep and poor organisation. This tutorial can also lead you to gaining new skills within art and audio manipulation, and new ways to design map layouts. You will have gained the skills of making a game with multiple functions, which they themselves hold multiple uses, and can create something not only teachable to others, but be made into something profitable and forever expandable. + +Having obtained the skills you know now, create yourself new games with new abilities, mechanics and assets. There are multiple ways to interpret a story. diff --git a/Tutorial-Proposals/Game-Car-Race/Step1-Starting Setup.md b/Tutorial-Proposals/Game-Car-Race/Step1-Starting Setup.md new file mode 100644 index 0000000..f284162 --- /dev/null +++ b/Tutorial-Proposals/Game-Car-Race/Step1-Starting Setup.md @@ -0,0 +1,48 @@ +--- +title: "Setting Up SplashKit for Car Race Game" +description: + Learn how to set up SplashKit for developing the Car Race Game. +author: Khushi Laddi +date: 2024-04-20 +tags: game development, programming, SplashKit, setup +sidebar: + label: " -Tutorial 1: Splashkit Setup" +--- + +## Introduction + +Welcome to the setup guide for SplashKit in preparation for developing the Car Race Game. SplashKit is a versatile game development toolkit that provides a wide range of features and functions to simplify the game development process. In this tutorial, we'll walk you through the steps to [install and configure SplashKit](https://splashkit.io/articles/installation/), set up your project, and get ready to start building your game. + +### Installing SplashKit + +To install SplashKit, follow these steps: + +1. Visit the [SplashKit website](https://splashkit.io/articles/installation/) and find the installation guide for your operating system (Windows, macOS, or Linux). +2. Follow the instructions provid ed in the installation guide to download and install SplashKit on your computer. +3. Make sure to install any additional programs or libraries required by SplashKit as indicated in the installation guide. + +### Creating Your Project + +After installing SplashKit, it's time to create your Car Race Game project: + +1. Create a new directory for your project on your computer. You can name it something like "CarRaceGame". +2. Use SplashKit Manager (SKM) to set up a new C++ project by running the command `skm new c++` in your project directory. This command initializes a new C++ project with SplashKit dependencies. +3. Generate resource folders for your project using the command `skm resources`. This command creates a "resources" folder where you can store game assets such as images, sounds, and fonts. +4. In this projet we have files car.cpp, game.cpp, car.h, game.h, and main program.cpp +5. The folder starting has libraries and then main files + +![image](images/folder1.png) +![image](images/Folder2.png) + +### Configuring Your IDE + +If you're using Visual Studio Code (VS Code) as your code editor: + +1. Open VS Code and navigate to your project directory. +2. Set up your project configuration and compile your code using SKM commands in the VS Code terminal. You can use commands like `skm clang++ *.cpp -0 output` to compile your project and `./output.exe` to execute it. + +## Conclusion + +You've completed the setup process for SplashKit in preparation for developing the Car Race Game. With SplashKit installed and your project set up, you're ready to start coding and building your game. Stay tuned for the next tutorial where we'll dive into game development with SplashKit! + +Happy coding!🚗💨 diff --git a/Tutorial-Proposals/Game-Car-Race/Step2-Game Development.md b/Tutorial-Proposals/Game-Car-Race/Step2-Game Development.md new file mode 100644 index 0000000..74dfe88 --- /dev/null +++ b/Tutorial-Proposals/Game-Car-Race/Step2-Game Development.md @@ -0,0 +1,143 @@ +--- +title: "C++ Programming Concepts Tutorial" +description: "Learn essential C++ programming concepts, including functions, structures, enums, conditional statements, loops, and standard library usage." +author: "Khushi Laddi" +date: "2024-04-20" +tags: C++, programming, basics +--- + +## Introduction + +Welcome to the C++ Programming Concepts tutorial. In this tutorial, we'll cover fundamental C++ programming concepts and techniques, including functions, structures, enums, conditional statements, loops, and the usage of the standard library. + +## Functions, Structures, and Enums + +1. **Functions**: + - Function is created and called as per the usage, here we have fucntions for every object and provide sample block of code for understanding. It performs specific task assigned. They ensure code reusability and organization + - First the fucntions have been declared in header files and then the main files + - Second we are using the fucntion and creating the car + + ```cpp + + // Function to get the bitmap for a car model + bitmap car_bitmap(car_model model) + + // Function to create a new car + car_data new_car(car_model model, double speed, double x, double y); + + // Function to switch the car's skin + void switch_car_skin(car_data &car) + + // Function to draw the car + void draw_car(car_data &car); + + // Function to update the car's position + void update_car(car_data &car) + + ``` + +2. **Structures**: + - Structures allow you to create custom data types that contain multiple variables. + - Example structure definition: + - Code for header files; + + ```cpp + struct car_data + { + sprite car_sprite; // Sprite representing the car + car_model model; // Model of the car + double speed; // Speed of the car + }; + + ``` + +3. **Enums**: + - Enums (enumerations) are user-defined data types consisting of named constants. + - Example enum declaration: + - These are also declared in header files + + ```cpp + enum Color { + RED, + GREEN, + BLUE + }; + ``` + +## Standard Library Usage + +1. **vector**: + - The `` header provides a dynamic array implementation in C++, allowing flexible storage and manipulation of elements. + - Example usage: + + ```cpp + #include + std::vector + ``` + +2. **splashkit.h**: + - Example usage: + + ```cpp + #include "splashkit.h" + ``` + +## Game Initialization + +Initializing the game environment involves setting up necessary resources, such as images, sounds, and initial game state: + +1. **Game State Setup**: + + Add the code to game.cpp file after handle user input + + - Create and initialize game data structures, such as player's car, obstacle cars, and score. + - Example code snippet: + + ```cpp + // Function to draw the game + void draw_game(game_data &game) + { + clear_screen(COLOR_GRAY); + + for (int i = 0; i < 6; i++) + { + draw_sprite(game.whitemarks[i]); + } + + for (int j = 0; j < game.cars.size(); j++) + { + draw_car(game.cars[j]); + } + + draw_bitmap("game", 0, 0, option_to_screen()); + + draw_text(to_string((int)game.score), COLOR_WHITE, "digi", 50, 650, 10, option_to_screen()); + draw_car(game.car); + } + ``` + +![image](images/game.png) + +## Bitmap Loading and Manipulation + +1. **Bitmap Loading**: + - Load bitmap images from files: + + ```cpp + // Used on many occassions + draw_bitmap("game", 0, 0, option_to_screen()); // used while drawing the game + bitmap default_bitmap = car_bitmap(model); // getting the car image + ``` + +2. **Bitmap Manipulation**: + - Modify bitmap properties such as size, color, and transparency: + + ```cpp + bitmap_set_cell_details(default_bitmap, 75, 120, 3, 1, 3); // setting the car position + ``` + +## Conclusion + +Congratulations! You've learned essential C++ programming concepts, including functions, structures, enums, conditional statements, loops, and standard library usage. These concepts are foundational to writing efficient and maintainable C++ code. + +Happy coding!🚗💨 diff --git a/Tutorial-Proposals/Game-Car-Race/Step3-Car Creation.md b/Tutorial-Proposals/Game-Car-Race/Step3-Car Creation.md new file mode 100644 index 0000000..afa5961 --- /dev/null +++ b/Tutorial-Proposals/Game-Car-Race/Step3-Car Creation.md @@ -0,0 +1,391 @@ +--- +title: "SplashKit Library Features Tutorial" +description: "Explore the features of the SplashKit library for game development, including sprite creation, drawing, animation, bitmap loading, manipulation, sound effect loading, and playback." +author: "Khushi Laddi" +date: "2024-04-21" +tags: SplashKit, game development, programming, basics +--- + +## Introduction + +Welcome to the SplashKit Library Features tutorial. In this tutorial, we'll dive into the features offered by the SplashKit library, a powerful toolkit for game development in C++. We'll cover sprite creation, drawing, animation, bitmap loading, manipulation, sound effect loading, and playback. + +## Sprite Creation, Drawing, and Animation + +1. **Sprite Creation**: + - Sprites are movable and animated images used to represent game objects. + - Here we created the sprite to change the color of car skin + - The code has been copied form car.cpp file for reference + - Create a sprite from a bitmap: + + ```cpp + void switch_car_skin(car_data &car) + { + bitmap other = car_bitmap(YELLOW); + bitmap_set_cell_details(other, 75, 120, 3, 1, 3); + sprite_add_layer(car.car_sprite, other, "YELLOW"); + sprite_hide_layer(car.car_sprite, 1); + + if (car.model == RED) + { + car.model = YELLOW; + sprite_hide_layer(car.car_sprite, 0); + sprite_show_layer(car.car_sprite, 1); + } + else if (car.model == YELLOW) + { + car.model = RED; + sprite_hide_layer(car.car_sprite, 1); + sprite_show_layer(car.car_sprite, 0); + } + } + ``` + +2. **Drawing Sprites**: + - The code has been copied form car.cpp file for reference + - Draw a sprite on the screen: + + ```cpp + // Function to draw the car + void draw_car(car_data &car) + { + draw_sprite(car.car_sprite); + } + ``` + +3. **Animation**: + - Animate a sprite by changing its position, rotation, and image frame over time: + - While creating new car we declared the animation of the car + + ```cpp + animation_script roadLineAnimation = load_animation_script("roadAnimation", "roadAnimation.txt"); + ``` + +## Car Models Creation + +Make a car.cpp file and car.h file where user will start with basic libraries #include "splashkit.h" # include vector # include "car.h" +using namespace std; and then start with code where first part is bitmap loading. + +1. **Car Bitmap Loading**: + - Load bitmap images for different car models: + - In this we made the fuction to call all the cars we are using in the game + + ```cpp + bitmap car_bitmap(car_model model) + { + switch (model) + { + case RED: + return bitmap_named("redcar"); + case YELLOW: + return bitmap_named("yellowcar"); + case BLACK: + return bitmap_named("blackcarsolo"); + case POLICE: + return bitmap_named("policecarsolo"); + default: + return bitmap_named("policecarsolo"); + } + } + ``` + +2. **Car Model Enumeration**: + + In header file user will start with basic libraries #ifndef CAR_RACE_CAR + #define CAR_RACE_CAR + + #include "splashkit.h" + #include vector and then start coding from enums + +- Define an enumeration for different car models: + + ```cpp + enum car_model { + RED, + YELLOW, + BLACK, + POLICE + }; + ``` + +## Drawing and Updating Car Position + + In the same header file after enums user will add the code for struct + +1. **Car Structure Definition**: + - Define a structure to store car data: + + ```cpp + struct car_data { + sprite car_sprite; // sprite representing the car + car_model model; // Model of the car + double speed; // Speed of the car + }; + ``` + +2. **Car Creation**: + + In the car.cpp file now add create the car code after bitmap loading + + - Create a new car with specified model, speed, and position: + + ```cpp + // Function to create a new car + car_data new_car(car_model model, double speed, double x, double y) + { + car_data result; + bitmap default_bitmap = car_bitmap(model); + + // Set cell details and animation script for RED and YELLOW cars + if (model == RED || model == YELLOW) + { + bitmap_set_cell_details(default_bitmap, 75, 120, 3, 1, 3); + animation_script carAnimation = load_animation_script("carAnimation", "carAnimation.txt"); + result.car_sprite = create_sprite(default_bitmap, carAnimation); + } + else + { + result.car_sprite = create_sprite(default_bitmap); + } + + result.speed = speed; + result.model = model; + + sprite_set_x(result.car_sprite, x); + sprite_set_y(result.car_sprite, y); + sprite_set_dy(result.car_sprite, result.speed); + + return result; + } + ``` + +3. **Drawing Car**: + + In the car.cpp file add the code after the switching car function + + - Draw the car sprite on the screen: + + ```cpp + void draw_car(car_data &car) + { + draw_sprite(car.car_sprite); + } + ``` + +4. **Updating Car Position**: + + In the car.cpp file add the code after the drawing car fucntion + - The image states the car is running and updating its position. + - Update the car's position based on its speed: + + ```cpp + void update_car(car_data &car) + { + update_sprite(car.car_sprite); + sprite_set_y(car.car_sprite, sprite_y(car.car_sprite) + car.speed); + } + ``` + + ![image](images/carrace-demo-01.png) + +## Switching Car Skin During Gameplay + + Add the code to car.cpp after create a car function + +1. **Switching Car Skin Function**: + - Implement a function to switch the car's skin during gameplay: + - The images are of the car which are used in code to change skin color of the car. + + ```cpp + // Function to switch the car's skin + void switch_car_skin(car_data &car) + { + bitmap other = car_bitmap(YELLOW); + bitmap_set_cell_details(other, 75, 120, 3, 1, 3); + sprite_add_layer(car.car_sprite, other, "YELLOW"); + sprite_hide_layer(car.car_sprite, 1); + + if (car.model == RED) + { + car.model = YELLOW; + sprite_hide_layer(car.car_sprite, 0); + sprite_show_layer(car.car_sprite, 1); + } + else if (car.model == YELLOW) + { + car.model = RED; + sprite_hide_layer(car.car_sprite, 1); + sprite_show_layer(car.car_sprite, 0); + } + } + ``` + + ![image](images/redcar.png) + ![image](images/yellowcar.png) + +2.**Handling User Input**: + + Add the code in gam.cpp file after randomly spawn obstacle cars + +- Handle user input in the fucntion: + + ```cpp + void handleInput(game_data &game) + { + if (key_down(A_KEY)) + { + sprite_set_x(game.car.car_sprite, sprite_x(game.car.car_sprite) - 5); + sprite_start_animation(game.car.car_sprite, "left"); + } + else if (key_down(D_KEY)) + { + sprite_set_x(game.car.car_sprite, sprite_x(game.car.car_sprite) + 5); + sprite_start_animation(game.car.car_sprite, "right"); + } + else if (key_typed(R_KEY)) + { + switch_car_skin(game.car); + } + else + { + sprite_start_animation(game.car.car_sprite, "straight"); + } + } + ``` + +## Final Code for car.cpp + +```cpp + #include "splashkit.h" + #include + #include "car.h" + using namespace std; + + // Function to get the bitmap for a car model + bitmap car_bitmap(car_model model) + { + switch (model) + { + case RED: + return bitmap_named("redcar"); + case YELLOW: + return bitmap_named("yellowcar"); + case BLACK: + return bitmap_named("blackcarsolo"); + case POLICE: + return bitmap_named("policecarsolo"); + default: + return bitmap_named("policecarsolo"); + } + } + + // Function to create a new car + car_data new_car(car_model model, double speed, double x, double y) + { + car_data result; + bitmap default_bitmap = car_bitmap(model); + + // Set cell details and animation script for RED and YELLOW cars + if (model == RED || model == YELLOW) + { + bitmap_set_cell_details(default_bitmap, 75, 120, 3, 1, 3); + animation_script carAnimation = load_animation_script("carAnimation", "carAnimation.txt"); + result.car_sprite = create_sprite(default_bitmap, carAnimation); + } + else + { + result.car_sprite = create_sprite(default_bitmap); + } + + result.speed = speed; + result.model = model; + + sprite_set_x(result.car_sprite, x); + sprite_set_y(result.car_sprite, y); + sprite_set_dy(result.car_sprite, result.speed); + + return result; + } + + // Function to switch the car's skin + void switch_car_skin(car_data &car) + { + bitmap other = car_bitmap(YELLOW); + bitmap_set_cell_details(other, 75, 120, 3, 1, 3); + sprite_add_layer(car.car_sprite, other, "YELLOW"); + sprite_hide_layer(car.car_sprite, 1); + + if (car.model == RED) + { + car.model = YELLOW; + sprite_hide_layer(car.car_sprite, 0); + sprite_show_layer(car.car_sprite, 1); + } + else if (car.model == YELLOW) + { + car.model = RED; + sprite_hide_layer(car.car_sprite, 1); + sprite_show_layer(car.car_sprite, 0); + } + } + + // Function to draw the car + void draw_car(car_data &car) + { + draw_sprite(car.car_sprite); + } + + // Function to update the car's position + void update_car(car_data &car) + { + update_sprite(car.car_sprite); + } + +``` + +## Final Code for car.h + +```cpp + #ifndef CAR_RACE_CAR + #define CAR_RACE_CAR + + #include "splashkit.h" + #include + + // Enumeration for different car models + enum car_model + { + RED, + YELLOW, + BLACK, + POLICE + }; + + // Structure to store car data + struct car_data + { + sprite car_sprite; // Sprite representing the car + car_model model; // Model of the car + double speed; // Speed of the car + }; + + // Function to create a new car + car_data new_car(car_model model, double speed, double x, double y); + + // Function to draw the car + void draw_car(car_data &car); + + // Function to switch the car's skin + void switch_car_skin(car_data &car); + + // Function to update the car's position + void update_car(car_data &car); + + #endif +``` + +## Conclusion + +Congratulations! You've explored the key features of the SplashKit library for game development. With SplashKit, you can create dynamic and engaging games with ease. Experiment with sprite creation, bitmap loading, sound effect playback, and more to bring your game ideas to life! + +Happy game development!🚗💨 diff --git a/Tutorial-Proposals/Game-Car-Race/Step4-Game Production.md b/Tutorial-Proposals/Game-Car-Race/Step4-Game Production.md new file mode 100644 index 0000000..a69ddb0 --- /dev/null +++ b/Tutorial-Proposals/Game-Car-Race/Step4-Game Production.md @@ -0,0 +1,388 @@ +--- +title: "Car Handling Tutorial with SplashKit" +description: "Learn how to handle cars in your game using the SplashKit library, including creation of different car models, drawing and updating car position, and switching car skin during gameplay." +author: "Khushi Laddi" +date: "2024-04-21" +tags: SplashKit, game development, programming, cars +--- + +## Introduction + +Welcome to the Car Handling tutorial with SplashKit. In this tutorial, we'll explore how to handle cars in your game using the features provided by the SplashKit library. We'll cover the creation of different car models, drawing and updating car positions, switching car skins and collision detection during gameplay. + +## Conditional Statements + +1. **If-Else Statements**: + - If-else statements are used to make decisions based on conditions. + - In the function we use if-else statements to keep the use under the control + - Example usage: + + ```cpp + // Function to check and limit the car's position within the screen + void input_check_positions(game_data &game) + { + if (sprite_x(game.car.car_sprite) <= 50) + { + sprite_set_x(game.car.car_sprite, 50); + } + else if (sprite_x(game.car.car_sprite) >= 650) + { + sprite_set_x(game.car.car_sprite, 650); + } + }; + ``` + +## Loops + +1. **For Loop**: + - For loops are used to iterate over a range of values or execute a block of code a specified number of times. + - Here in my code I used as in fucntion to showcase the game + - Example usage: + + ```cpp + // Function to draw the game + void draw_game(game_data &game) + { + clear_screen(COLOR_GRAY); + for (int i = 0; i < 6; i++) + { + draw_sprite(game.whitemarks[i]); + } + for (int j = 0; j < game.cars.size(); j++) + { + draw_car(game.cars[j]); + } + + draw_bitmap("game", 0, 0, option_to_screen()); + + draw_text(to_string((int)game.score), COLOR_WHITE, "digi", 50, 650, 10, option_to_screen()); + draw_car(game.car); + }; + ``` + +2. **While Loop**: + + Add the code to program.cpp in main file + + - While loops repeatedly execute a block of code as long as a specified condition is true. + - I used the while loop in my main file so that game could keep on running till the time user doesn't want to quit + - Example usage: + + ```cpp + int main() + { + open_window("Car Racing", 800, 600); + load_resources(); + bool game_started = false; + game_data game = new_game(); + while (not quit_requested()) + { + process_events(); + clear_screen(COLOR_GRAY); + if (!game_started) + { + // Draw buttons and home image + draw_bitmap("home", 0, 0, option_to_screen()); + refresh_screen(60); + // Set game_started to true when 'S' key is pressed + if (key_typed(S_KEY)) + { + game_started = true; + } + // quit game + if (key_typed(Q_KEY)) + { + exit(0); + } + } + else if (!game.game_over) + { + // Draw and update game + draw_game(game); + check_collisions(game); + out_range(game); + update_game(game); + } + else + { + // Game over screen + stop_sound_effect("carmotor"); + draw_bitmap("ending", 0, 0, option_to_screen()); + draw_text("Score: " + to_string((int)game.score), COLOR_WHITE, "digi", 70, 100, 400, option_to_screen()); + if (key_typed(RETURN_KEY)) + { + game = new_game(); + stop_sound_effect("endmusic"); + } + if (!musicplayed) + { + play_sound_effect("endmusic", 1); + musicplayed = true; + } + } + + refresh_screen(60); + } + } + ``` + +## Collision Detection + +Add the code to the game.cpp after function to remove cars that have gone out of range + +Collision detection is crucial for handling interactions between game objects: + +1. **Basic Collision Detection**: + - Detect collisions between sprites based on their bounding boxes or custom shapes. + - Example code snippet: + + ```cpp + void check_collisions(game_data &game) + { + for (int i = 0; i < game.cars.size(); i++) + { + if (sprite_collision(game.car.car_sprite, game.cars[i].car_sprite)) + { + play_sound_effect("carcrash", 1); + delay(400); + game.game_over = true; + } + } + } + ``` + +## Final Code for game.cpp + +```cpp +#include "splashkit.h" +#include "game.h" +#include +#include +// for the time functions, cars to spawn +#include +#include +using namespace std; +using std::vector; +#define MIN_SPEED 5.0 // min speed of obstacle car +#define MAX_SPEED 10.0 // max speed of obstacle car +#define CARS_COUNT 7 // total obstacle cars to be spwaned +#define CARS_SPAWN_DURATION 3 // Time between each car collection +void map_setup(game_data &game) +{ + int laneSpacing = 100; + int leftEdgePosition = screen_width() / 2 - laneSpacing * 7 / 2; + + bitmap roadEdge = create_bitmap("roadEdge", 10, screen_height()); + draw_line_on_bitmap(roadEdge, COLOR_WHITE, 0, 0, 0, screen_height(), option_line_width(10)); + setup_collision_mask(roadEdge); + + point_2d abc = point_at(leftEdgePosition, 0); + game.game_over = false; + abc = point_at(leftEdgePosition + (laneSpacing * 7) - 5, 0); + bitmap road = create_bitmap("roadmarkings", 10, screen_height()); + for (int i = 0; i < screen_height(); i += 20) + { + draw_line_on_bitmap(road, COLOR_WHITE, 1, i, 1, i + 10, option_line_width(8)); + } + + bitmap roadCells = create_bitmap("roadCells", 50, screen_height()); + for (int i = 0; i < 7; i++) + { + draw_bitmap_on_bitmap(roadCells, road, i * 10, i * 4); + } + + bitmap_set_cell_details(roadCells, 10, screen_height(), 5, 1, 5); + setup_collision_mask(roadCells); + animation_script roadLineAnimation = load_animation_script("roadAnimation", "roadAnimation.txt"); + for (int i = 0; i < 6; i++) + { + game.whitemarks[i] = create_sprite(roadCells, roadLineAnimation); + sprite_start_animation(game.whitemarks[i], "moving"); + abc = point_at(leftEdgePosition + (laneSpacing * (i + 1)), 0); + sprite_set_position(game.whitemarks[i], abc); + } +} + +double random_range(double min, double max) +{ + return min + (rand() / (RAND_MAX / (max - min))); +} +// Function to randomly spawn obstacle cars +void randomCars(game_data &game) +{ + int xLocations[] = {50, 150, 250, 350, 450, 550, 650}; // Array to store the x locations + car_model carModels[] = {POLICE, BLACK}; // Array of car models + + // Randomly select x locations for the cars + for (int i = 0; i < CARS_COUNT; i++) + { + int randomIndex = rand() % CARS_COUNT; // Generate a random index between 0 and 6 + int x = xLocations[randomIndex]; + car_model model = carModels[rand() % 2]; // Randomly select a car model + int speed = random_range(MIN_SPEED, MAX_SPEED); // Randomly select a speed + car_data laner_cars = new_car(model, speed, x, -300); // Create a car sprite at the selected x location + game.cars.push_back(laner_cars); // Add the car to the game's car vector + } +} +auto last_call_time = std::chrono::steady_clock::now(); // Track the last time the function was called +game_data new_game() +{ + game_data game; + game.car = new_car(RED, 0, screen_width() / 2, screen_height() - 200); + map_setup(game); + game.score = 0; + sprite_start_animation(game.car.car_sprite, "straight"); + play_sound_effect("carmotor", 1, 0.1); + return game; +} +// Function to handle user input +void handleInput(game_data &game) +{ + if (key_down(A_KEY)) + { + sprite_set_x(game.car.car_sprite, sprite_x(game.car.car_sprite) - 5); + sprite_start_animation(game.car.car_sprite, "left"); + } + else if (key_down(D_KEY)) + { + sprite_set_x(game.car.car_sprite, sprite_x(game.car.car_sprite) + 5); + sprite_start_animation(game.car.car_sprite, "right"); + } + else if (key_typed(R_KEY)) + { + switch_car_skin(game.car); + } + else + { + sprite_start_animation(game.car.car_sprite, "straight"); + } +} +// Function to draw the game +void draw_game(game_data &game) +{ + clear_screen(COLOR_GRAY); + + for (int i = 0; i < 6; i++) + { + draw_sprite(game.whitemarks[i]); + } + + for (int j = 0; j < game.cars.size(); j++) + { + draw_car(game.cars[j]); + } + + draw_bitmap("game", 0, 0, option_to_screen()); + + draw_text(to_string((int)game.score), COLOR_WHITE, "digi", 50, 650, 10, option_to_screen()); + draw_car(game.car); +} +// Function to check and limit the car's position within the screen +void input_check_positions(game_data &game) +{ + if (sprite_x(game.car.car_sprite) <= 50) + { + sprite_set_x(game.car.car_sprite, 50); + } + else if (sprite_x(game.car.car_sprite) >= 650) + { + sprite_set_x(game.car.car_sprite, 650); + } +} +// Function to remove cars that have gone out of range +void out_range(game_data &game) +{ + for (int j = 0; j < game.cars.size(); j++) + { + if (sprite_y(game.cars[j].car_sprite) > 600) + { + // remove the element from this vector + game.cars.erase(game.cars.begin() + j); + // Decrement j to account for the removed element + j--; + } + } +} +// Function to check for collisions between the player's car and obstacle cars +void check_collisions(game_data &game) +{ + for (int i = 0; i < game.cars.size(); i++) + { + if (sprite_collision(game.car.car_sprite, game.cars[i].car_sprite)) + { + play_sound_effect("carcrash", 1); + delay(1500); + game.game_over = true; + } + } +} +// Function to update the game state +void update_game(game_data &game) +{ + game.score += 0.3; + update_car(game.car); + for (int j = 0; j < game.cars.size(); j++) + { + update_car(game.cars[j]); + } + for (int i = 0; i < 6; i++) + { + update_sprite(game.whitemarks[i]); + } + + input_check_positions(game); + handleInput(game); + // Call the randomCars function every CARS_SPAWN_DURATION seconds + auto current_time = std::chrono::steady_clock::now(); + auto elapsed_time = std::chrono::duration_cast(current_time - last_call_time).count(); + if (elapsed_time >= CARS_SPAWN_DURATION) + { + randomCars(game); + last_call_time = current_time; + } +} +``` + +## Final Code for Game.h + +```cpp +#ifndef CAR_RACE_GAME +#define CAR_RACE_GAME + +#include "splashkit.h" +#include +#include "car.h" + +// Structure to store game data +struct game_data +{ + bool game_over; // Flag indicating if the game is over + sprite whitemarks[6]; // Array of sprites for white marks on the road + car_data car; // Player's car + vector cars; // Vector of obstacle cars + double score; // Current score +}; + +// Function to create a new game +game_data new_game(); + +// Function to draw the game +void draw_game(game_data &game); + +// Function to update the game state +void update_game(game_data &game); + +// Function to remove cars that have gone out of range +void out_range(game_data &game); + +// Function to check for collisions between the player's car and obstacle cars +void check_collisions(game_data &game); + +#endif +``` + +## Conclusion + +Congratulations! You've learned how to handle cars in your game using the SplashKit library. Experiment with different car models, customize their appearance, and enhance your gameplay experience. Keep practicing and exploring the possibilities to create amazing car-themed games! + +Happy game development!🚗💨 diff --git a/Tutorial-Proposals/Game-Car-Race/Step5-Game Completion.md b/Tutorial-Proposals/Game-Car-Race/Step5-Game Completion.md new file mode 100644 index 0000000..a6a7a12 --- /dev/null +++ b/Tutorial-Proposals/Game-Car-Race/Step5-Game Completion.md @@ -0,0 +1,207 @@ +--- +title: "Game Management with SplashKit" +description: "Learn how to manage game initialization, user input, obstacle spawning, score tracking, and game over conditions using SplashKit." +author: "Khushi Laddi" +date: "2024-04-21" +tags: game development, programming, SplashKit, management +--- + +## Introduction + +Welcome to the Game Management tutorial with SplashKit. In this tutorial, we'll cover essential concepts and techniques for managing game initialization, user input, obstacle spawning, score tracking, game over conditions, and audio features. + +## Obstacle Spawning and Updating the game state + +Spawn and update obstacle cars to create challenging gameplay: + +1. **Random Obstacle Spawning**: + + In game.cpp after map setup add the code + + - Randomly spawn obstacle cars at predefined intervals or positions. + - Example code snippet: + + ```cpp + // Function to randomly spawn obstacle cars + void randomCars(game_data &game) + { + int xLocations[] = {50, 150, 250, 350, 450, 550, 650}; // Array to store the x locations + car_model carModels[] = {POLICE, BLACK}; // Array of car models + + // Randomly select x locations for the cars + for (int i = 0; i < CARS_COUNT; i++) + { + int randomIndex = rand() % CARS_COUNT; // Generate a random index between 0 and 6 + int x = xLocations[randomIndex]; + car_model model = carModels[rand() % 2]; // Randomly select a car model + int speed = random_range(MIN_SPEED, MAX_SPEED); // Randomly select a speed + car_data laner_cars = new_car(model, speed, x, -300); // Create a car sprite at the selected x location + game.cars.push_back(laner_cars); // Add the car to the game's car vector + } + } + auto last_call_time = std::chrono::steady_clock::now(); // Track the last time the function was called + game_data new_game() + { + game_data game; + game.car = new_car(RED, 0, screen_width() / 2, screen_height() - 200); + map_setup(game); + game.score = 0; + sprite_start_animation(game.car.car_sprite, "straight"); + play_sound_effect("carmotor", 1, 0.1); + return game; + } + ``` + +2. **Updating game state**: + + At the end of the game.cpp file add the code + + - Update positions and states of obstacle cars based on game logic. + - Example code snippet: + + ```cpp + // Function to update the game state + void update_game(game_data &game) + { + game.score += 0.3; + update_car(game.car); + for (int j = 0; j < game.cars.size(); j++) + { + update_car(game.cars[j]); + } + for (int i = 0; i < 6; i++) + { + update_sprite(game.whitemarks[i]); + } + + input_check_positions(game); + handleInput(game); + // Call the randomCars function every CARS_SPAWN_DURATION seconds + auto current_time = std::chrono::steady_clock::now(); + auto elapsed_time = std::chrono::duration_cast(current_time - last_call_time).count(); + if (elapsed_time >= CARS_SPAWN_DURATION) + { + randomCars(game); + last_call_time = current_time; + } + } + ``` + +## Score Tracking and Game Over Conditions + +Add the code in program.cpp at the end in the else condition + +Track player's score and determine game over conditions for a satisfying gameplay experience: + +- Increment score based on game progress or achievements. +- The image says the score after the user get out. +- Example code snippet: + + ```cpp + { + // Game over screen + stop_sound_effect("carmotor"); + draw_bitmap("ending", 0, 0, option_to_screen()); + draw_text("Score: " + to_string((int)game.score), COLOR_WHITE, "digi", 70, 100, 400, option_to_screen()); + if (key_typed(RETURN_KEY)) + { + game = new_game(); + stop_sound_effect("endmusic"); + } + if (!musicplayed) + { + play_sound_effect("endmusic", 1); + musicplayed = true; + } + } + ``` + + ![image](images/carrace-gameover.png) + +## Playing Sound Effects + +Add the code to car.cpp wherever you want the sound effects and stop in program.cpp file in else condition + +1. **Sound Effect Loading**: + - Load sound effects for car movement and collisions: + + ```cpp + play_sound_effect("carmotor", 1, 0.1); + play_sound_effect("carcrash", 1); + stop_sound_effect("carmotor"); + ``` + +## Final Code for Program.cpp + +```cpp +/* +Run this by: +skm clang++ program.cpp car.cpp game.cpp -o output +./output +*/ + +#include "splashkit.h" +#include "game.h" +using std::vector; +using namespace std; + +/** + * Load the game images, sounds, etc. + */ +void load_resources() +{ + load_resource_bundle("game_bundle", "game_bundle.txt"); +} +bool musicplayed =false; +int main() +{ + + open_window("Car Racing", 800, 600); + load_resources(); + bool game_started = false; + game_data game = new_game(); + while (not quit_requested()) + { + process_events(); + clear_screen(COLOR_GRAY); + if (!game_started) + { + draw_bitmap("home", 0, 0, option_to_screen()); + refresh_screen(60); + delay(3000); + game_started = true; + } + if(!game.game_over) { + + draw_game(game); + check_collisions(game); + out_range(game); + update_game(game); + } else { + stop_sound_effect("carmotor"); + draw_bitmap("ending", 0, 0, option_to_screen()); + draw_text("Score: "+ to_string((int)game.score), COLOR_WHITE, "digi", 70, 100, 400, option_to_screen()); + if(key_typed(RETURN_KEY)) { + game = new_game(); + stop_sound_effect("endmusic"); + } + if(!musicplayed) { + play_sound_effect("endmusic", 1); + + musicplayed = true; + } + + } + refresh_screen(60); + } + + return 0; +} + +``` + +## Conclusion + +Congratulations! You've learned how to manage game initialization, user input, obstacle spawning, score tracking, and game over conditions using SplashKit. Apply these techniques to create engaging and challenging games. Happy coding! + +Happy game development!🚗💨 diff --git a/Tutorial-Proposals/Game-Car-Race/Step6-Visual Representation.md b/Tutorial-Proposals/Game-Car-Race/Step6-Visual Representation.md new file mode 100644 index 0000000..4356545 --- /dev/null +++ b/Tutorial-Proposals/Game-Car-Race/Step6-Visual Representation.md @@ -0,0 +1,46 @@ +--- +title: "Visual Representation Of Game" +description: "Lean How To play Game" +author: "Khushi Laddi" +date: "2024-04-22" +tags: game development, resource management, SplashKit +--- + +# Car Racing Game Controls and How to Play + +Welcome to the Car Racing Game! Here's how to play: + +[Watch the Tutorial Video](https://youtu.be/N5Oh1Wi7NlY?si=n4eeC2fmDwNi-HGC) + +## Controls + +- **Move Left**: Press the "A" key to move your car left. +- **Move Right**: Press the "D" key to move your car right. +- **Change Car Color**: Press the "R" key to switch between different car colors. + +## Gameplay + +1. **Starting the Game**: + - Open the game application by using command skm clang++ program.cpp car.cpp game.cpp -o output + - After the compilation is complete use ./output.exe and run the game successfully + - Click on the "Play" button to start the game. + +2. **Navigating the Race Track**: + - Use the "A" and "D" keys to steer your car left or right. + - Navigate through the race track and avoid collisions with other cars or obstacles. + +3. **Changing Car Color**: + - Press the "R" key to change the color of your car. Experiment with different colors to customize your ride! + +4. **Avoiding Collisions**: + - Be careful not to crash into other cars or obstacles on the track. Collisions may slow you down or even cause you to lose the race. + +5. **Scoring Points**: + - Earn points by playing as long as you can by avoiding obstacles. + +6. **Game Over**: + - The game ends when you complete the race or if your car crashes too many times. You can then view your race statistics. + +## Conclusion + +Now that you know the controls and how to play, it's time to rev up your engines and hit the race track! Compete against other drivers, set new records, and become the ultimate champion! diff --git a/Tutorial-Proposals/Game-Car-Race/Step7-Updates in Car-race.md b/Tutorial-Proposals/Game-Car-Race/Step7-Updates in Car-race.md new file mode 100644 index 0000000..f1ddb7a --- /dev/null +++ b/Tutorial-Proposals/Game-Car-Race/Step7-Updates in Car-race.md @@ -0,0 +1,677 @@ +# Tutorial for Updated Car Race + + Important Notice : The previous car-racing need to be compiled successfully and working + + [Watch the Tutorial Video Of Updated Game](https://youtu.be/eWJ1rshG5yE) + +## 1. New car.cpp + +**Additions for Two Player Mode:** This update adds functionality to support a two-player mode in the game. + +- **new_car function:** When creating a new car, it now also initializes a second player's car with a different color (YELLOW), positioned slightly to the right of the first player's car. + +- **update_car function:** Updates the position of both player 1 and player 2 cars. If the game is paused (`game.paused` is true), it skips updating the cars. + +```cpp +// Additions for Two Player Mode +car_data new_car(car_model model, double speed, double x, double y) { + // ... + result.secondPlayer = new_car(YELLOW, speed, x + 100, y); + result.twoPlayer = true; + // ... +} + +void update_car(car_data &car) { + // Pause the game if it's paused + if (game.paused) return; + + // Update player 1 car + update_sprite(car.car_sprite); + + // Update player 2 car + if (car.twoPlayer) { + update_sprite(car.secondPlayer.car_sprite); + } +} +``` + +![image](images/Two%20Playres%20together.png) + +## Final Updated Code for car.cpp file + +```cpp + #include "splashkit.h" + #include + #include "car.h" + using namespace std; + + // Function to get the bitmap for a car model + bitmap car_bitmap(car_model model) + { + switch (model) + { + case RED: + return bitmap_named("redcar"); + case YELLOW: + return bitmap_named("yellowcar"); + case BLACK: + return bitmap_named("blackcarsolo"); + case POLICE: + return bitmap_named("policecarsolo"); + default: + return bitmap_named("policecarsolo"); + } + } + + // Function to create a new car + car_data new_car(car_model model, double speed, double x, double y) + { + car_data result; + bitmap default_bitmap = car_bitmap(model); + + // Set cell details and animation script for RED and YELLOW cars + if (model == RED || model == YELLOW) + { + bitmap_set_cell_details(default_bitmap, 75, 120, 3, 1, 3); + animation_script carAnimation = load_animation_script("carAnimation", "carAnimation.txt"); + result.car_sprite = create_sprite(default_bitmap, carAnimation); + } + else + { + result.car_sprite = create_sprite(default_bitmap); + } + + result.speed = speed; + result.model = model; + + sprite_set_x(result.car_sprite, x); + sprite_set_y(result.car_sprite, y); + sprite_set_dy(result.car_sprite, result.speed); + + return result; + } + + // Function to switch the car's skin + void switch_car_skin(car_data &car) + { + bitmap other = car_bitmap(YELLOW); + bitmap_set_cell_details(other, 75, 120, 3, 1, 3); + sprite_add_layer(car.car_sprite, other, "YELLOW"); + sprite_hide_layer(car.car_sprite, 1); + + if (car.model == RED) + { + car.model = YELLOW; + sprite_hide_layer(car.car_sprite, 0); + sprite_show_layer(car.car_sprite, 1); + } + else if (car.model == YELLOW) + { + car.model = RED; + sprite_hide_layer(car.car_sprite, 1); + sprite_show_layer(car.car_sprite, 0); + } + } + + // Function to draw the car + void draw_car(car_data &car) + { + draw_sprite(car.car_sprite); + } + + // Function to update the car's position + void update_car(car_data &car) + { + update_sprite(car.car_sprite); + } + +``` +## 2. Updating game.h + +**Additions for Two Player Mode:** Extends the `game_data` structure to accommodate two-player mode. + +- **secondPlayer:** Stores the data for the second player's car. + +- **twoPlayer:** A boolean flag indicating whether the game is in two-player mode. + +- **paused:** A boolean flag indicating whether the game is currently paused. + +- **finished:** A boolean flag indicating whether the game has finished. + +- **finish_line:** Stores the sprite for the finish line. + +```cpp +// Additions for Two Player Mode +struct game_data { + // ... + car_data secondPlayer; + bool twoPlayer; + bool paused; + bool finished; + sprite finish_line; +}; +``` + +![image](images/game2.png) +![image](images/selectscreen.png) +![image](images/pause%20menu.png) +![image](images/levelup.png) + +## Final Code for game.h file + +```cpp + #ifndef CAR_RACE_GAME + #define CAR_RACE_GAME + + #include "splashkit.h" + #include + #include "car.h" + #include "powerup.h" + #include "barricade.h" + // Structure to store game data + struct game_data + { + bool game_over; // Flag indicating if the game is over + sprite whitemarks[6]; // Array of sprites for white marks on the road + car_data car; // Player's car + vector cars; // Vector of obstacle cars + double score; // Current score + vector powerups; // Vector of powerups + int level; // Current level + bool shield; // Flag indicating if the player has a shield + bool speed_boost; // Flag indicating if the player has a speed boost + vector barricades; // Vector of barricades + car_data secondPlayer; + bool twoPlayer; + bool paused; + bool finished; + sprite finish_line; + }; + + // Function to create a new game + game_data new_game(); + + // Function to draw the game + void draw_game(game_data &game); + + // Function to update the game state + void update_game(game_data &game); + + // Function to remove cars that have gone out of range + void out_range(game_data &game); + + // Function to check for collisions between the player's car and obstacle cars + void check_collisions(game_data &game); + + // check_collisions_barricade(game); + void check_collisions_barricade(game_data &game); + // check_collisions_powerup(game); + void check_collisions_powerup(game_data &game); + #endif + +``` + +## 3. New powerup.cpp + +- powerup_bitmap Function: This function takes a powerup_type enum as input and returns the corresponding bitmap for the given powerup type. It uses a switch statement to select the appropriate bitmap based on the powerup type. + +- new_powerup Function: This function creates a new powerup with the specified type, speed, and position (x, y). It initializes a sprite for the powerup using the powerup_bitmap function, sets its position, type, and speed, and returns the resulting powerup_data structure. + +- draw_powerup Function: This function draws the powerup sprite on the screen. + +- update_powerup Function: This function updates the position of the powerup sprite by moving it vertically downwards based on its speed. + +- out_range_powerup Function: This function removes powerups from the vector powerups that have gone out of the visible range of the screen. It iterates through the vector and checks the y-coordinate of each powerup sprite. If it exceeds a certain threshold (600 in this case), the powerup is removed from the vector. + +```cpp +#include "splashkit.h" +#include +#include "powerup.h" + +int main() +{ + // Initialize SplashKit + open_window("Powerup Demo", 800, 600); + load_resource_bundle("powerup_bundle", "powerup_bundle.txt"); + + // Create a vector to store powerups + std::vector powerups; + + // Add some powerups to the vector + powerups.push_back(new_powerup(SHIELD, 5, 100, 100)); + powerups.push_back(new_powerup(SPEED_BOOST, 3, 200, 200)); + powerups.push_back(new_powerup(COIN, 4, 300, 300)); + + // Main game loop + while (not quit_requested()) + { + // Update powerups + for (auto &powerup : powerups) + { + update_powerup(powerup); + } + + // Clear the screen + clear_screen(COLOR_WHITE); + + // Draw powerups + for (auto &powerup : powerups) + { + draw_powerup(powerup); + } + + // Remove out-of-range powerups + out_range_powerup(powerups); + + // Refresh the screen + refresh_screen(); + delay(17); // Cap the frame rate to approximately 60 frames per second + } + + // Close SplashKit + close_window("Powerup Demo"); + return 0; +} + +``` +![image](images/Powerups%20display.png) + +## Final Code for Powerup.cpp file + +```cpp + #include "splashkit.h" + #include + #include "powerup.h" + + + + bitmap powerup_bitmap(powerup_type type) + { + switch (type) + { + case SHIELD: + return bitmap_named("shield"); + case SPEED_BOOST: + return bitmap_named("speedup"); + case SLOW_DOWN: + return bitmap_named("slowdown"); + case COIN: + return bitmap_named("coin"); + default: + return bitmap_named("coin"); + } + + } + // Function to create a new powerup + powerup_data new_powerup(powerup_type type, double speed, double x, double y) + { + powerup_data result; + //random powerup + // powerup_type type = static_cast(rand() % 3); + result.powerup_sprite = create_sprite(powerup_bitmap(type)); + + sprite_set_x(result.powerup_sprite, x); + sprite_set_y(result.powerup_sprite, y); + result.type = type; + result.speed = speed; + return result; + } + + // Function to draw the powerup + void draw_powerup(powerup_data &powerup) + { + draw_sprite(powerup.powerup_sprite); + } + + // Function to update the powerup's position + void update_powerup(powerup_data &powerup) + { + sprite_set_y(powerup.powerup_sprite, sprite_y(powerup.powerup_sprite) + powerup.speed); + } + + // Function to remove powerups that have gone out of range + void out_range_powerup(std::vector &powerups) + { + for (int j = 0; j < powerups.size(); j++) + { + if (sprite_y(powerups[j].powerup_sprite) > 600) + { + // Remove the element from the vector + powerups.erase(powerups.begin() + j); + // Decrement j to account for the removed element + j--; + } + } + } +``` + +## 5. New powerup.h + +- The explanation of code as follows : +- powerup.h defines the structure and functions related to powerups in the game. +- powerup_data struct stores data for each powerup, including its sprite, type, and speed. +- The powerup_type enum lists different types of powerups available in the game. +- new_powerup function creates a new powerup with the specified type, speed, and position. +- draw_powerup function draws the powerup sprite on the screen. +- update_powerup function updates the powerup's position based on its speed. +- out_range_powerup function removes powerups that have gone out of range from the screen. + +```cpp +// Enumeration for different powerups +enum powerup_type +{ + SHIELD, + SPEED_BOOST, + SLOW_DOWN, + COIN +}; + +// Structure to store powerup data +struct powerup_data +{ + sprite powerup_sprite; // Sprite representing the powerup + powerup_type type; // Type of the powerup + double speed; // Speed of the powerup +}; + +// Function to create a new powerup +powerup_data new_powerup(powerup_type type, double speed, double x, double y); + +// Function to draw the powerup +void draw_powerup(powerup_data &powerup); + +// Function to update the powerup's position +void update_powerup(powerup_data &powerup); + +// Function to remove powerups that have gone out of range +void out_range_powerup(std::vector &powerups); + +#endif +``` +## Final Code for Powerup.h + +```cpp + #ifndef POWER_UP + #define POWER_UP + + #include "splashkit.h" + #include + + // Enumeration for different powerups + enum powerup_type + { + SHIELD, + SPEED_BOOST, + SLOW_DOWN, + COIN + }; + + // Structure to store powerup data + struct powerup_data + { + sprite powerup_sprite; // Sprite representing the powerup + powerup_type type; // Type of the powerup + double speed; // Speed of the powerup + }; + + // Function to create a new powerup + powerup_data new_powerup(powerup_type type, double speed, double x, double y); + + // Function to draw the powerup + void draw_powerup(powerup_data &powerup); + + // Function to update the powerup's position + void update_powerup(powerup_data &powerup); + + // Function to remove powerups that have gone out of range + void out_range_powerup(std::vector &powerups); + + #endif +``` + +## 6. New barricade.cpp + +- Header Inclusions: Includes necessary headers such as "splashkit.h" for SplashKit functionalities and vector for vector data structure. +- Constants and Variables: Defines constants like gap_size and an array gap_locations to store possible positions for gaps in the barricades. previous_gap_location is initialized to an invalid value to ensure that the first gap location is chosen randomly. +- get_new_gap_location Function: Generates a random index to select a gap location from the gap_locations array, ensuring that the same gap location is not chosen consecutively. +- barricade_bitmap Function: Creates a bitmap representing a barricade with a gap. It selects a random gap location, draws the left and right parts of the barricade around the gap, sets up collision masks, and returns the resulting bitmap. +- new_barricade Function: Creates a new barricade with the specified speed and y-coordinate. It initializes a sprite using the bitmap generated by barricade_bitmap and sets its position and speed. +- draw_barricade Function: Draws the barricade sprite on the screen. +- update_barricade Function: Updates the position of the barricade sprite. +- out_range_barricade Function: Removes barricades from the vector barricades that have gone out of the visible range of the screen. + +```cpp +// Define constants +#define gap_size 100 +double gap_locations[] = {250, 300, 350, 400, 450, 500, 550}; +double previous_gap_location = -1; + +// Function to get a new random gap location +double get_new_gap_location() +{ + int index; + do + { + index = rand() % 7; + } while (gap_locations[index] == previous_gap_location); + + previous_gap_location = gap_locations[index]; + return gap_locations[index]; +} + +// Function to create a bitmap for a barricade with a gap +bitmap barricade_bitmap() +{ + bitmap barricade_bitmap = create_bitmap("barricade3", 750, 40); + double gap_location = get_new_gap_location(); + + draw_bitmap_on_bitmap(barricade_bitmap, bitmap_named("barricade2"), 0, 0, option_part_bmp(0, 0, gap_location, 40)); + draw_bitmap_on_bitmap(barricade_bitmap, bitmap_named("barricade2"), gap_location + gap_size, 0, option_part_bmp(gap_location + gap_size, 0, 700 - gap_location - gap_size, 40)); + + setup_collision_mask(barricade_bitmap); + return barricade_bitmap; +} + +// Function to create a new barricade +barricade_data new_barricade(double speed, double y) +{ + barricade_data result; + result.barricade_sprite = create_sprite(barricade_bitmap()); + sprite_set_x(result.barricade_sprite, 50); + sprite_set_y(result.barricade_sprite, y); + sprite_set_dy(result.barricade_sprite, speed); + return result; +} + +// Function to draw the barricade +void draw_barricade(barricade_data &barricade) +{ + draw_sprite(barricade.barricade_sprite); +} + +// Function to update the barricade's position +void update_barricade(barricade_data &barricade) +{ + update_sprite(barricade.barricade_sprite); +} + +// Function to remove barricades that have gone out of range +void out_range_barricade(std::vector &barricades) +{ + for (int j = 0; j < barricades.size(); j++) + { + if (sprite_y(barricades[j].barricade_sprite) > 600) + { + barricades.erase(barricades.begin() + j); + j--; + } + } +} +``` +![image](images/barricade%20and%20level%20up.png) + +## Final Code for Baricade.cpp + +```cpp + #include "splashkit.h" + #include + #include "barricade.h" + + #define gap_size 150 + double gap_locations[] = {250, 300, 350, 400, 450, 500, 550}; + double previous_gap_location = -1; // Initialize to an invalid value + + double get_new_gap_location() + { + int index; + do + { + index = rand() % 7; // Generate a random index between 0 and 3 + } while (gap_locations[index] == previous_gap_location); + + previous_gap_location = gap_locations[index]; + return gap_locations[index]; + } + + // Function to get the bitmap for a barricade + bitmap barricade_bitmap() + { + // Adjust the gap size as needed + bitmap barricade_bitmap = create_bitmap("barricade3", 750, 40); // Adjust the size of the barricade as needed + + // get random location between 50 and 650 + + double gap_location = get_new_gap_location(); + // write_line("gap location: " + std::to_string(gap_location)); + // Draw the left part of the barricade + draw_bitmap_on_bitmap(barricade_bitmap, bitmap_named("barricade2"), 0, 0, option_part_bmp(0, 0, gap_location, 40)); + + // Draw the right part of the barricade + draw_bitmap_on_bitmap(barricade_bitmap, bitmap_named("barricade2"), gap_location + gap_size, 0, option_part_bmp(gap_location + gap_size, 0, 700 - gap_location - gap_size, 40)); + //setup_collision_mask(bitmap bmp) + setup_collision_mask(barricade_bitmap); + + // save_bitmap(barricade_bitmap, "barricade2"); + return barricade_bitmap; + } + + // Function to create a new barricade + barricade_data new_barricade(double speed, double y) + { + barricade_data result; + // bitmap bitmap_with_gap = barricade_bitmap(); + result.barricade_sprite = create_sprite(barricade_bitmap()); + sprite_set_x(result.barricade_sprite, 50); + sprite_set_y(result.barricade_sprite, y); + + result.speed = speed; + sprite_set_dy(result.barricade_sprite, speed); + return result; + } + + // Function to draw the barricade + void draw_barricade(barricade_data &barricade) + { + + draw_sprite(barricade.barricade_sprite); + } + + // Function to update the barricade's position + void update_barricade(barricade_data &barricade) + { + update_sprite(barricade.barricade_sprite); + } + + // Function to remove barricades that have gone out of range + void out_range_barricade(std::vector &barricades) + { + for (int j = 0; j < barricades.size(); j++) + { + if (sprite_y(barricades[j].barricade_sprite) > 600) + { + // Remove the element from the vector + barricades.erase(barricades.begin() + j); + // Decrement j to account for the removed element + j--; + } + } + } + // #endif +``` + +## 7. New barricade.h + +- The explanation of code as follows : +- barricade.h defines the structure and functions related to barricades in the game. +- barricade_data struct stores data for each barricade, including its sprite, speed, and gap location. +- new_barricade function creates a new barricade with the specified speed and initial position. +- draw_barricade function draws the barricade sprite on the screen. +- update_barricade function updates the barricade's position based on its speed. +- out_range_barricade function removes barricades that have gone out of range from the screen. + +```cpp +#ifndef BARRICADE +#define BARRICADE + +#include "splashkit.h" +#include + +// Structure to store barricade data +struct barricade_data +{ + sprite barricade_sprite; // Sprite representing the barricade + double speed; // Speed of the barricade + double gap_location; // Location of the gap in the barricade +}; + +// Function to create a new barricade +barricade_data new_barricade(double speed, double y); + +// Function to draw the barricade +void draw_barricade(barricade_data &barricade); + +// Function to update the barricade's position +void update_barricade(barricade_data &barricade); + +// Function to remove barricades that have gone out of range +void out_range_barricade(std::vector &barricades); + +#endif + +``` + +## Final Code for Barricade.h + +```cpp + #ifndef BARRICADE + #define BARRICADE + + #include "splashkit.h" + #include + + // Structure to store barricade data + struct barricade_data + { + sprite barricade_sprite; // Sprite representing the barricade + double speed; // Speed of the barricade + double gap_location; // Location of the gap in the barricade + }; + + // Function to create a new barricade + barricade_data new_barricade(double speed, double y); + + // Function to draw the barricade + void draw_barricade(barricade_data &barricade); + + // Function to update the barricade's position + void update_barricade(barricade_data &barricade); + + // Function to remove barricades that have gone out of range + void out_range_barricade(std::vector &barricades); + + #endif +``` + +## 8. Conclusion + +In conclusion, these code files provide a foundation for creating a dynamic and engaging car racing game with features such as multiple car models, powerups, obstacles, and two-player mode. By utilizing SplashKit's functionality and these code structures, developers can easily extend and customize the game to suit their preferences and requirements. diff --git a/Tutorial-Proposals/Game-Car-Race/images/Folder2.png b/Tutorial-Proposals/Game-Car-Race/images/Folder2.png new file mode 100644 index 0000000..8f7c170 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/Folder2.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/Powerups display.png b/Tutorial-Proposals/Game-Car-Race/images/Powerups display.png new file mode 100644 index 0000000..dc6e924 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/Powerups display.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/Two Playres together.png b/Tutorial-Proposals/Game-Car-Race/images/Two Playres together.png new file mode 100644 index 0000000..393a56f Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/Two Playres together.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/barricade and level up.png b/Tutorial-Proposals/Game-Car-Race/images/barricade and level up.png new file mode 100644 index 0000000..9d8b5f6 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/barricade and level up.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/carrace-demo-01.png b/Tutorial-Proposals/Game-Car-Race/images/carrace-demo-01.png new file mode 100644 index 0000000..1c9b149 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/carrace-demo-01.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/carrace-gameover.png b/Tutorial-Proposals/Game-Car-Race/images/carrace-gameover.png new file mode 100644 index 0000000..9e7d198 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/carrace-gameover.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/flowchart step 2.png b/Tutorial-Proposals/Game-Car-Race/images/flowchart step 2.png new file mode 100644 index 0000000..875e280 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/flowchart step 2.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/flowchart final.png b/Tutorial-Proposals/Game-Car-Race/images/flowchart final.png new file mode 100644 index 0000000..4588b75 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/flowchart final.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/flowchart step 3.png b/Tutorial-Proposals/Game-Car-Race/images/flowchart step 3.png new file mode 100644 index 0000000..fac5fc7 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/flowchart step 3.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/flowchart step 4.png b/Tutorial-Proposals/Game-Car-Race/images/flowchart step 4.png new file mode 100644 index 0000000..1a78e11 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/flowchart step 4.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/flowchart step 5.png b/Tutorial-Proposals/Game-Car-Race/images/flowchart step 5.png new file mode 100644 index 0000000..b2c8bda Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/flowchart step 5.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/folder1.png b/Tutorial-Proposals/Game-Car-Race/images/folder1.png new file mode 100644 index 0000000..1cf2752 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/folder1.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/game.png b/Tutorial-Proposals/Game-Car-Race/images/game.png new file mode 100644 index 0000000..45e6236 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/game.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/game2.png b/Tutorial-Proposals/Game-Car-Race/images/game2.png new file mode 100644 index 0000000..6afb392 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/game2.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/homescreen.png b/Tutorial-Proposals/Game-Car-Race/images/homescreen.png new file mode 100644 index 0000000..b5268e5 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/homescreen.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/levelup.png b/Tutorial-Proposals/Game-Car-Race/images/levelup.png new file mode 100644 index 0000000..53e83f5 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/levelup.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/pause menu.png b/Tutorial-Proposals/Game-Car-Race/images/pause menu.png new file mode 100644 index 0000000..53fae33 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/pause menu.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/redcar.png b/Tutorial-Proposals/Game-Car-Race/images/redcar.png new file mode 100644 index 0000000..1bb7e1d Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/redcar.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/selectscreen.png b/Tutorial-Proposals/Game-Car-Race/images/selectscreen.png new file mode 100644 index 0000000..67ef749 Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/selectscreen.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/updated flow chart.png b/Tutorial-Proposals/Game-Car-Race/images/updated flow chart.png new file mode 100644 index 0000000..545b26a Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/updated flow chart.png differ diff --git a/Tutorial-Proposals/Game-Car-Race/images/yellowcar.png b/Tutorial-Proposals/Game-Car-Race/images/yellowcar.png new file mode 100644 index 0000000..bcd211b Binary files /dev/null and b/Tutorial-Proposals/Game-Car-Race/images/yellowcar.png differ diff --git a/Tutorial-Proposals/Getting Started With Mouse Button and Inputs.md b/Tutorial-Proposals/Getting Started With Mouse Button and Inputs.md new file mode 100644 index 0000000..bc3263a --- /dev/null +++ b/Tutorial-Proposals/Getting Started With Mouse Button and Inputs.md @@ -0,0 +1,82 @@ +# Tutorial Proposal + +## Title: Getting Started With Mouse Button and Inputs + +### Introduction + +As a Splashkit developer, I want to learn how to use `Mouse Button` in Splashkit so that I can +identify which key triggers an event and handle it accordingly. + +### Prerequisites + +- Basic understanding of data types +- Basic understanding of at least one SplashKit supported programming languages + +### Functions Used (Link to Splashkit documentation) + +1. [Hide Mouse](https://splashkit.io/api/input/#hide-mouse) +1. [Mouse Clicked](https://splashkit.io/api/input/#mouse-clicked) +1. [Mouse Down](https://splashkit.io/api/input/#mouse-down) +1. [Mouse Movement](https://splashkit.io/api/input/#mouse-movement) +1. [Mouse Position](https://splashkit.io/api/input/#mouse-position) +1. [Mouse Position Vector](https://splashkit.io/api/input/#mouse-position-vector) +1. [Mouse Shown](https://splashkit.io/api/input/#mouse-shown) +1. [Mouse Up](https://splashkit.io/api/input/#mouse-up) +1. [Mouse Wheel Scroll](https://splashkit.io/api/input/#mouse-wheel-scroll) +1. [Mouse X](https://splashkit.io/api/input/#mouse-x) +1. [Mouse Y](https://splashkit.io/api/input/#mouse-y) +1. [Move Mouse](https://splashkit.io/api/input/#group-move-mouse) +1. [Show Mouse](https://splashkit.io/api/input/#group-show-mouse) + +### Table of Contents + +1. **Introduction to Mouse Button** + - What is `Mouse Button`? + - List of `Mouse Button` +1. **Mouse Button Inputs** + - Mouse Clicked + - Mouse Down + - Mouse Up + - Demonstration +1. **Read Mouse Movement** + - Mouse Movement + - Mouse Wheel Scroll + - Demonstration +1. **Mouse Position** + - Mouse Position + - Mouse Position Vector + - Mouse X + - Mouse Y + - Move Mouse + - Demonstration +1. **Mouse Visibility** + - Hide Mouse + - Show Mouse + - Mouse Shown + - Demonstration + +### Tutorial Details + +The tutorial will first introduce `Mouse Button` data type since an understanding of this is +important to be able to apply them to the functions that will also be discussed here. Next, each +section will explain all SplashKit functions to read and handle mouse inputs. Each function will be +given a description of its use and syntax, and at the end of each section there can be an example or +demonstration of how the functions are used. + +This tutorial is suitable for beginners wanting to learn how to handle mouse inputs. It is targetted +to people who are getting started on handling inputs for their SplashKit games and people who need a +list of `Mouse Button` and functions for syntax help. + +### Expected Learning Outcomes + +After completing this tutorial, readers will be able to: + +1. Understand what `Mouse Button` is and how to use it. +1. Know which `Mouse Button` to use to handle mouse inputs. +1. Understand and apply mouse input handling functions on SplashKit. + +### Conclusion + +This tutorial is beneficial for beginners who are wanting to start handling mouse inputs for their +SplashKit game. It is necessary to understand how to find which `Mouse Button` and functions to use +to implement them to their games. diff --git a/Tutorial-Proposals/Getting Started With Sprite Layering In Splashkit - C#.md b/Tutorial-Proposals/Getting Started With Sprite Layering In Splashkit - C#.md new file mode 100644 index 0000000..b2f34f8 --- /dev/null +++ b/Tutorial-Proposals/Getting Started With Sprite Layering In Splashkit - C#.md @@ -0,0 +1,62 @@ +# Tutorial Proposal + +## Title: Getting Started With Sprite Layering In Splashkit - C# + +### Introduction + +A brief introduction into managing sprite layers, understanding rendering order, and organization of +sprites to create visually appealing scenes without excess Sprite / Bitmap management. + +### Prerequisites + +- Basic Sprite handling knowledge as outlined in 'Getting Started With Sprites In Splashkit' +- Basic programming knowledge. Understand the process of declaring and assigning variables. + Understand what an overloaded method is. Understand argument passing and method constructing. +- Basic folder structure knowledge, at most understand how to point to a local file (for bitmap + purposes) + +### Functions Used (Link to Splashkit documentation) + +1. [Create Sprite](https://splashkit.io/api/sprites/#create-sprite) +2. [Sprite Add Layer](https://splashkit.io/api/sprites/#sprite-add-layer) +3. [Bring Layer Forward ](https://splashkit.io/api/sprites/#sprite-bring-layer-forward) +4. [Sprite Bring Layer To Front](https://splashkit.io/api/sprites/#sprite-bring-layer-to-front) +5. [Sprite Hide Layer](https://splashkit.io/api/sprites/#sprite-hide-layer-named) +6. [Sprite Toggle Layer Visible](https://splashkit.io/api/sprites/#sprite-toggle-layer-visible-named) + +### Table of Contents + +1. **[Creation of a layered Sprite]** + + - Small overview of a practical use-case that is referenced throughout tutorial (morning/night + background?) + - Declaration and instantiation of a layered Sprite + - Adding layers and hiding layers + +2. **[Creation of practical use case]** + + - Show practical instantiation of previously taught concepts for a more practical use case (maybe + for first section, use explicit sprites that are labelled for easier tutorial understanding, + one in the corner or information drawn onto the sprite for example) + - Highlight use cases for sprite layers (shifting background maybe) + +### Tutorial Details + +The structure of the tutorial will be a series of guided instructions with screenshots and code +snippets. It will be formatted in markdown for easier future porting to Docusaurus or other document +sharing services. + +### Expected Learning Outcomes + +The learning outcome that the reader can expect to have gained after completing this series of +tutorials is to have gained an understanding of Sprite Layering, including a theoretical +understanding of the concept including how Splashkit specifically interacts with layered sprites, as +well as a practical showcase of the concept + +### Conclusion + +The importance of this tutorial comes from the required ability to be able further interact with +Sprites as apart of the Splashkit library. Easing workflows and system process management via Sprite +layering rather than raw Sprite manipulation and management allows for a greater understanding of +the framework and concept as a whole and further entrenches students with the ability to use and +understand Sprites. diff --git a/Tutorial-Proposals/Getting Started With Sprites in Splashkit Outline - C#.md b/Tutorial-Proposals/Getting Started With Sprites in Splashkit Outline - C#.md new file mode 100644 index 0000000..4744884 --- /dev/null +++ b/Tutorial-Proposals/Getting Started With Sprites in Splashkit Outline - C#.md @@ -0,0 +1,61 @@ +# Tutorial Proposal + +## Title: Getting Started With Sprites in Splashkit Outline - C# + +### Introduction + +A brief introduction into handling Sprites - specifically X/Y positioning, with an initial beginner +focus on drawing a sprite to the screen, as well as accessing and modifying sprite positional data +based off of X and Y coordinates over time, with a section of general outline of Sprite handling +theory, methods, and modes of thinking in relation to Sprites in Splashkit. + +### Prerequisites + +- Basic programming knowledge. Understand the process of declaring and assigning variables. + Understand what an overloaded method is. Understand argument passing and method constructing. +- Basic folder structure knowledge, at most understand how to point to a local file (for bitmap + purposes) + +### Functions Used (Link to Splashkit documentation) + +1. [Create Sprite](https://splashkit.io/api/sprites/#create-sprite) +2. [Draw Sprite](https://splashkit.io/api/sprites/#group-draw-sprite) +3. [Move Sprite To](https://splashkit.io/api/sprites/#move-sprite-to) +4. [Sprite X](https://splashkit.io/api/sprites/#sprite-x) +5. [Sprite Y](https://splashkit.io/api/sprites/#sprite-y) + +### Table of Contents + +1. **[Understanding Sprites in Splashkit]** + + - Basic process of instantiating bitmap and sprite objects + - Understanding overloaded methods of above + +2. **[Placing Sprites into a Splashkit window]** + + - Using Create Sprite, Draw Sprite, and Move Sprite To to see our sprite and modify position + +3. **[Using Splashkit to move our Sprite around]** + + - Construction of some basic small program to showcase active runtime modification of Sprite + positioning and drawing. Maybe showcase multiple sprites, or maybe a random movement of a + single sprite. + +### Tutorial Details + +The structure of the tutorial will be a series of guided instructions with screenshots and code +snippets. It will be formatted in markdown for easier future porting to Docusaurus or other document +sharing services. + +### Expected Learning Outcomes + +The learning outcome that the reader can expect to have gained after completing this series of +tutorials is to have a basic understanding of Sprite assertion and manipulation, so as to be able to +use Sprites in their own projects. + +### Conclusion + +The importance of this tutorial comes from the almost ubiquitous required ability to be able to +interact with Sprites in the process of making games. Splashkit being a visual-focused and friendly +game making frontend, understanding how to interact with that visual medium via Sprites as a +baseline is important. diff --git a/Tutorial-Proposals/Getting Started in Splashkit Outline.md b/Tutorial-Proposals/Getting Started in Splashkit Outline.md new file mode 100644 index 0000000..3c08aef --- /dev/null +++ b/Tutorial-Proposals/Getting Started in Splashkit Outline.md @@ -0,0 +1,96 @@ +# Tutorial Proposal + +## Title: Getting Started: C++, C#, Python, and Pascal - Windows + +### Introduction + +A brief introduction into creating a splashkit project for all 4 supported languages, marked by +successful use of the `skm new` command on windows as well as a successful compile call. + +### Prerequisites + +- Basic computer knowledge. Ability to install files, run commands from a Command Line +- Basic troubleshooting abilities, PATH environment variable editing (will be covered in the + tutorial but useful to have pre-existing knowledge) + +### Functions Used (Link to Splashkit documentation) + +1. [Write](https://splashkit.io/api/terminal/#write) + +### Table of Contents + +1. **[Installing and compiling a C++ Splashkit programme on windows]** + + - Installation of the MSYS2 terminal + - Installation of the Splashkit SDK + - Installation of Visual Studio Code / Language Tools + - Hello World compile + +2. **[Installing and compiling a C# Splashkit programme on windows]** + + - Installation of the MSYS2 terminal + - Installation of the Splashkit SDK + - Installation of Visual Studio Code / Language Tools + - Hello World compile + +3. **[Installing and compiling a Python Splashkit programme on windows]** + + - Installation of the MSYS2 terminal + - Installation of the Splashkit SDK + - Installation of Visual Studio Code / Language Tools + - Hello World compile + +4. **[Installing and compiling a Pascal Splashkit programme on windows]** + + - Installation of the MSYS2 terminal + - Installation of the Splashkit SDK + - Installation of Visual Studio Code / Language Tools + - Hello World compile + + Maybe consolidate first two/three steps into a single tutorial, it would just be copy-pasting the + first parts of each to every other otherwise. Maybe that would be OK though, given that it's + meant to be beginner-focused, having copies of the same beginner friendly installation + instructions might not be that bad? + + ### Table of Contents. ALT + + 1. **[Installing MSYS2 and Splashkit SDK on windows]** + + - Installation of the MSYS2 terminal + - Installation of the Splashkit SDK + + 2. **[Installing Visual Studio Code / FreePascal(?) on windows]** + + - Installation of Visual Studio Code + - More research to be done on Pascal installation and compilation processes, have got every other + langauge down except this one, FreePascal is an IDE and Compiler, trying to see if it can be + rooted into VSCode, as well as how to get splashkit to be identified successfully without + compile errors + + 3. **[Hello Splashkit on windows]** + + - C++ Hello World compile tutorial + - C# Hello World compile tutorial + - Python Hello World compile tutorial + - Pascal Hello World compile tutorial + +### Tutorial Details + +The structure of the tutorial will be a series of guided instructions with screenshots and code +snippets. It will preferably be formatted in markdown, but further discussion regarding this has to +take place. The target audience will be absolute beginners, with little pre-knowledge outside of +general computer use expected. + +### Expected Learning Outcomes + +The learning outcome that the reader can expect to have gained after completing this series of +tutorials is to be able to go from nothing to be able to compile splashkit programmes with different +languages. This gives them the tools and abilities to compile files for later use in tutorials and +general overall use of the program, as well as facilitate different language usage and learning. + +### Conclusion + +The importance of this tutorial comes from the required ability to be able to install, as well as +compile splashkit programmes in multiple languages. This will benefit the readers by giving them the +necessary baseline to be able to learn more and facilitate real-world projects via installation of +the Splashkit SDK, IDEs and Language Tools, and a practical understanding of the compiling pipeline. diff --git a/Tutorial-Proposals/Introduction to Key Codes.md b/Tutorial-Proposals/Introduction to Key Codes.md new file mode 100644 index 0000000..d097378 --- /dev/null +++ b/Tutorial-Proposals/Introduction to Key Codes.md @@ -0,0 +1,56 @@ +# Tutorial Proposal + +## Title: Introduction to Key Codes + +### Introduction + +As a Splashkit developer, I want to learn how to use `Key Code` in Splashkit so that I can identify +which key triggers an event and handle it accordingly. + +### Prerequisites + +Readers should have: + +- Basic understanding of data types + +### Functions Used (Link to Splashkit documentation) + +1. [Key Name](https://splashkit.io/api/input/#key-name) + +### Table of Contents + +1. **Introduction to Key Codes** + - What are key codes? + - List of key codes + - How key codes are used +1. **Key Name** + - Syntax + - Usage and example + +### Tutorial Details + +The tutorial will first introduce the `Key Code` data type and how it is used. The list of key codes +are presented as a table, with the following collumns: Name, Description, Picture. The picture can +show an illustration of the associated key on a keyboard. The usage subtopic can briefly mention +some of the keyboard input functions that use `Key Code` as parameter, which links to the tutorials +for each of those functions. + +This tutorial is suitable for beginners as an introduction to keyboard inputs. It is targetted to +people who are getting started on handling inputs for their SplashKit games and people who need a +list of keyboard inputs and their associated `Key Code`. + +### Expected Learning Outcomes + +After completing this tutorial, readers will be able to: + +1. Understand what `Key Code` is and how to use it. +1. Know which `Key Code` to use to handle keyboard inputs. +1. Retrieve string name for a given `Key Code` by using the `Key Name` function. + +### Conclusion + +This tutorial is beneficial for beginners who are wanting to start handling keyboard inputs for +their SplashKit game. It is necessary to understand how to find which `Key Code` to use to swiftly +implement it to their games, instead of trying to find them through trial-and-error. This tutorial +can also provide base knowledge in understanding keyboard input functions that may be outlined in +another tutorial. diff --git a/Tutorial-Proposals/Proposal for SplashKit JSON Functionality Tutorial Series.md b/Tutorial-Proposals/Proposal for SplashKit JSON Functionality Tutorial Series.md new file mode 100644 index 0000000..9ec2474 --- /dev/null +++ b/Tutorial-Proposals/Proposal for SplashKit JSON Functionality Tutorial Series.md @@ -0,0 +1,312 @@ +# Proposal for SplashKit JSON Functionality Tutorial Series +## Overview +This proposal outlines a series of tutorials focused on the JSON functionality in SplashKit. While an existing tutorial introduces the basic concepts, there's a significant opportunity to expand this into a more comprehensive learning experience. This series will cater to both beginners and intermediate users, aiming to provide a thorough understanding of handling JSON in SplashKit. + +## Part 1: Introduction to JSON in SplashKit +### Introduction to JSON +JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write, and for machines to parse and generate. JSON is often used in various programming environments, including game development, for data storage and configuration. +In SplashKit, JSON functionality allows developers to efficiently manage game settings, level data, and more. This part of the tutorial introduces JSON and its basic structure, followed by an overview of its application in SplashKit. + +### What is JSON? +- **Format**: + JSON is a text format that is completely language-independent but uses conventions familiar to programmers of the C-family of languages, including C++, C#, Java, JavaScript, and many others. +- **Structure**: + JSON is built on two structures: + - A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array. + - An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence. + +### Basic Structure of a JSON File +A simple JSON file might look like this: +``` +{ + "gameTitle": "Metroidvania Adventures", + "screenSize": { + "width": 800, + "height": 600 + }, + "levels": ["level1", "level2", "level3"] +} +``` +In this example, **gameTitle** is a string, **screenSize** is an object with two numeric values (width and height), and levels is an array of strings. + +### Overview of JSON in SplashKit +SplashKit simplifies the process of working with JSON files in your games. Whether you need to load game configurations, save player progress, or manage game assets, SplashKit's JSON functionality makes these tasks straightforward. + +### Key Features: +- **Reading JSON**: SplashKit allows you to easily read values from a JSON file, helping you load configurations or game data. +- **Writing JSON**: You can also create and modify JSON data, then save it back to a file, which is useful for saving game states or player preferences. + +### Getting Started with JSON in SplashKit +To begin using JSON in SplashKit, you need to understand how to include the necessary SplashKit libraries in your project. Here's a simple way to start: +- 1. Include SplashKit Library: +`#include "splashkit.h"` +- 2. Load a JSON File: +`json game_data = load_json("game_data.json");` +- 3. Accessing Data: +``` +string title = json_read_string(game_data, "gameTitle"); +int width = json_read_int(game_data, "screenSize.width"); +``` +In the next part of this tutorial, we will delve deeper into reading JSON data, demonstrating how to navigate through JSON objects and arrays to extract various types of data. Stay tuned! + +## Part 2: Reading JSON Data in SplashKit +### Introduction to Reading JSON Data +After understanding the basics of JSON in SplashKit, this part of the tutorial focuses on how to read and parse JSON data. Reading JSON data is essential for game development tasks such as loading game settings, level configurations, or player data. + +### Loading a JSON File in SplashKit +To work with JSON in SplashKit, the first step is to load the JSON file. SplashKit provides functions to easily handle this. + +Example: Loading a JSON File +``` +#include "splashkit.h" + +int main() { + json game_data; + + // Load the JSON file + game_data = load_json("game_data.json"); + + // Ensure the JSON file is loaded + if (json_is_invalid(game_data)) { + write_line("Failed to load game data."); + return -1; + } + + // Proceed with reading data... +} +``` + +In this example, **load_json** is used to load the JSON file named **"game_data.json"**. After loading, it's good practice to check if the JSON data is valid using **json_is_invalid**. + +### Navigating Through JSON Objects and Arrays +JSON data is often structured as a combination of objects and arrays. Understanding how to navigate through this structure is key to effectively using JSON in your games. + +### Accessing Simple Values +To access simple values like strings, numbers, or booleans, you can use functions like **json_read_string**, **json_read_int**, or **json_read_bool**. +``` +string title = json_read_string(game_data, "gameTitle"); +int width = json_read_int(game_data, "screenSize.width"); +bool isFullScreen = json_read_bool(game_data, "fullScreenMode"); +``` + +### Working with JSON Arrays +If the data is an array, you can loop through the array using **json_read_array_length** and **json_read_string** (or other similar functions). +``` +int level_count = json_read_array_length(game_data, "levels"); +for (int i = 0; i < level_count; i++) { + string level_name = json_read_string(game_data, "levels[" + to_string(i) + "]"); + // Process each level name... +} +``` + +### Extracting Different Data Types +SplashKit's JSON functionality allows you to extract various types of data, including strings, integers, floats, booleans, and even nested JSON objects. + +Example: Extracting Nested Data +``` +json settings = json_read_object(game_data, "settings"); +int volume = json_read_int(settings, "volume"); +``` + +In this example, **json_read_object** is used to extract a nested JSON object, and then values are read from this nested object. + +### Conclusion +Reading JSON data with SplashKit is a straightforward process that can greatly enhance the flexibility and functionality of your game. It enables dynamic loading of game content and configurations, making your game more adaptable and easier to manage. + +In the next part of this tutorial, we will explore how to write and modify JSON data, allowing you to save game states, configurations, and player preferences. + +## Part 3: Writing JSON Data in SplashKit +### Introduction to Writing JSON Data +Having covered how to read JSON data in SplashKit, this part of the tutorial will focus on creating and writing data to JSON files. This functionality is crucial for features like saving game settings, player progress, or dynamically modifying game content. + +### Creating JSON Objects and Arrays +In SplashKit, you can programmatically create JSON objects and arrays, which then can be populated with data. + +Example: Creating a New JSON Object +``` +#include "splashkit.h" + +int main() { + // Create a new JSON object + json new_game_data = create_json(); + + // Add data to the JSON object + json_add_string(new_game_data, "gameTitle", "Metroidvania Adventure"); + json_add_number(new_game_data, "playerHealth", 100); + + // Create a JSON array + json levels_array = create_json_array(); + + // Add items to the JSON array + json_add_to_array(levels_array, create_json_string("level1")); + json_add_to_array(levels_array, create_json_string("level2")); + + // Add the array to the JSON object + json_add_array(new_game_data, "levels", levels_array); + + // Proceed with saving the JSON object... +} +``` +In this example, **create_json** is used to create a new JSON object, and **create_json_array** to create a new JSON array. Data is then added to these structures using functions like **json_add_string**, **json_add_number**, and **json_add_to_array**. + +### Writing JSON Data to a File +After creating and populating a JSON object or array, you can write the data to a file. This is useful for saving configurations or game states. + +Example: Saving JSON to a File +``` +// Save the JSON object to a file +save_json(new_game_data, "new_game_data.json"); + +// Free the JSON object +free_json(new_game_data); +``` +In this example, **save_json** is used to write the JSON data to a file named **"new_game_data.json"**. After saving, it's a good practice to free the JSON object from memory using **free_json**. + +### Modifying Existing JSON Data +You can also load an existing JSON file, modify its contents, and save the changes back to the file. + +Example: Modifying and Saving Existing JSON Data +``` +// Load existing JSON data +json existing_data = load_json("existing_game_data.json"); + +// Modify the data +json_add_number(existing_data, "playerScore", 500); // Add or update player score + +// Save the changes +save_json(existing_data, "existing_game_data.json"); + +// Free the JSON object +free_json(existing_data); +``` +In this example, an existing JSON file is loaded, modified, and then the changes are saved back to the same file. + +### Conclusion +Writing and modifying JSON data in SplashKit enables developers to manage dynamic game content efficiently. This powerful feature enhances the game's interactivity and provides a mechanism for storing player data and game settings. + +In the next part of this tutorial, we'll provide practical examples of using JSON in game development, such as managing game settings and player preferences. + +## Part 4: Practical Example - Game Settings Using JSON in SplashKit +### Introduction +This section of the tutorial will demonstrate a practical application of JSON in SplashKit for managing game settings. We'll create a simple system to load, modify, and save game settings, such as screen resolution, sound volume, and more. + +### Step 1: Creating the Game Settings JSON File +First, we'll create a JSON file named **game_settings.json** that contains some basic settings for the game. +``` +{ + "screen": { + "width": 800, + "height": 600, + "fullscreen": false + }, + "audio": { + "musicVolume": 70, + "sfxVolume": 80 + } +} +``` +This file includes settings for screen dimensions, fullscreen mode, and audio volumes. + +### Step 2: Reading Game Settings +Next, we'll write code to load these settings when the game starts. + +Example: Loading Game Settings +``` +#include "splashkit.h" + +json load_game_settings(const string &filename) { + json settings = load_json(filename); + if (json_is_invalid(settings)) { + write_line("Failed to load settings."); + exit(-1); + } + return settings; +} + +void apply_settings(const json &settings) { + // Apply screen settings + int width = json_read_int(settings, "screen.width"); + int height = json_read_int(settings, "screen.height"); + bool fullscreen = json_read_bool(settings, "screen.fullscreen"); + set_window_size(width, height); + set_window_fullscreen(fullscreen); + + // Apply audio settings + int musicVolume = json_read_int(settings, "audio.musicVolume"); + int sfxVolume = json_read_int(settings, "audio.sfxVolume"); + // Code to set audio levels... +} + +int main() { + open_window("Metroidvania Adventure", 800, 600); + json settings = load_game_settings("game_settings.json"); + apply_settings(settings); + // Rest of the game loop... +} +``` +In this example, the settings are loaded from **game_settings.json**, and then applied using **apply_settings**. + +### Step 3: Modifying and Saving Settings +Let's add the functionality to modify and save these settings, perhaps from an in-game settings menu. + +Example: Modifying and Saving Settings +``` +void update_and_save_settings(json &settings, const string &filename) { + // Update settings based on user input (e.g., from a settings menu) + json_write_number(settings, "audio.musicVolume", newMusicVolume); + json_write_number(settings, "audio.sfxVolume", newSfxVolume); + + // Save the updated settings + save_json(settings, filename); +} +``` +In this example, the **update_and_save_settings** function is used to update and save the settings, which can be triggered from an in-game settings menu. + +### Conclusion +Using JSON for game settings in SplashKit allows for a flexible and dynamic configuration system. By storing settings in a JSON file, they can be easily modified and persisted across game sessions, enhancing the user experience. + +In the final part of this tutorial, we will explore advanced JSON manipulation and use cases in game development. + +## Part 5: Part 5: Advanced Techniques with JSON in SplashKit +### Introduction +After exploring the basics of reading and writing JSON data, and a practical example of using JSON for game settings, this final part of the tutorial series delves into advanced techniques of JSON manipulation in SplashKit. These techniques can be invaluable for managing complex data structures in your game development process. + +### Working with Nested JSON Objects +Often, JSON data structures can be deeply nested. Understanding how to navigate and manipulate these nested structures is crucial for complex game development scenarios. + +Example: Accessing Nested Data +Consider a JSON structure representing a character with nested attributes: +``` +{ + "character": { + "name": "Hero", + "stats": { + "health": 100, + "mana": 50, + "strength": 75 + } + } +} +``` +Accessing nested attributes like the character's health can be done as follows: +``` +json game_data = load_json("game_data.json"); +int health = json_read_int(game_data, "character.stats.health"); +``` + +### Error Handling and Debugging JSON +Proper error handling is essential when working with JSON to ensure your game behaves as expected even when encountering malformed or unexpected data. + +Example: Robust JSON Reading +``` +if (json_has_key(game_data, "character.stats.health")) { + int health = json_read_int(game_data, "character.stats.health"); +} else { + write_line("Health data is missing"); +} +``` +Here, **json_has_key** is used to check if the health data is present before attempting to read it, preventing potential errors. + +### Conclusion +Mastering advanced JSON techniques in SplashKit opens up a myriad of possibilities for game development, enabling more dynamic, flexible, and complex game designs. This tutorial series has equipped you with the knowledge to effectively utilize JSON in your game projects, from basic operations to advanced applications. + diff --git a/Tutorial-Proposals/Splash World Adventures.md b/Tutorial-Proposals/Splash World Adventures.md new file mode 100644 index 0000000..60f39a7 --- /dev/null +++ b/Tutorial-Proposals/Splash World Adventures.md @@ -0,0 +1,249 @@ +## Software Requirements Specification for Mario-Like Game Tutorial Using Splashkit + +### 1. Purpose Description + +The purpose of this game tutorial is to create an engaging and educational Mario-like game that +utilizes various functionalities of Splashkit. + +The tutorial aims to teach users how to implement key game mechanics and features, such as character +movement, collision detection, sprite animation, and interactive gameplay. + +By building this game, users will gain hands-on experience with Splashkit's capabilities and learn +how to apply them effectively in real-world game development scenarios. + +### 2. Features + +The Mario-like game tutorial will include the following **features**: + +1. **Character Movement**: Implementing smooth movement for the main character using keyboard input. +1. **Collision Detection**: Handling collisions between the main character and other game objects, + such as obstacles and enemies. +1. **Sprite Animation**: Creating animations for the main character, enemies, and other in-game + elements using Splashkit's animation functionalities. +1. **Interactive Gameplay**: Designing interactive elements like collectible items, power-ups, and + enemies to provide an engaging gaming experience. +1. **Scoring System**: Implementing a scoring mechanism to track and display the player's progress. + _Stretch_: different scene via states system +1. **Audio Integration**: Incorporating sound effects and background music using Splashkit's audio + functionalities. +1. **Level Design**: Creating multiple levels with increasing difficulty and unique challenges. + +#### Stretch Features + +Menu system to start the game. Utilizes mouse input and States to change scenes using Splashkit game +engine. + +### 3. User Case + +As a user, I want to follow the Mario-like game tutorial to **learn how to develop** a game using +Splashkit's functionalities effectively. + +--- + +The tutorial should provide step-by-step instructions on implementing key game mechanics, including +character movement, collision detection, sprite animation, interactive gameplay, scoring system, +audio integration, and level design. By engaging in the tutorial, I aim to gain practical experience +in game development with Splashkit, understand its features, and apply the learned knowledge to +create my own games with similar functionalities. + +--- + +**Stretch User story** + +As a prospective Deakin University student, I want to play the Mario-like game developed using +Splashkit at the Deakin Arcade Showcase, so that I can experience and appreciate the programming +skills showcased at Deakin and get inspired to learn programming myself. + +### 4. Class Diagram + +This is a high-level plan of the game + +```mermaid +classDiagram + class Game { + -gameEngine: IGameEngine + } + class IRenderer { + <> + Init()*: void + Clear()*: void + RenderObject()*: void + Present()*: void + Shutdown()*: void + } + class SplashkitRenderer { + Init(): void + Clear(): void + RenderObject(): void + Present(): void + Shutdown(): void + } + + class ILogger { + <> + +Log(): void + +LogError(): void + +LogException(): void + +LogFormat(): void + +LogWarning(): void + } + + class SplashkitLogger { + +logEnabled: bool + +IsLogTypeAllowed(): bool + +Log(): void + +LogError(): void + +LogException(): void + +LogFormat(): void + +LogWarning(): void + } + + class IGameStateManager { + <> + -gameStates: stack[GameState] + +changeState()*: void + +getCurrentState()* : GameState* + +popState()* : void + +pushState()* : void + +render()* : void + +update()* : void + } + + class IGameEngine { + <> + #renderer: IRenderer + #gameStateManager: IGameStateManager + #logger: ILogger + +Start()*: void + +Update()*: void + +Draw()*: void + } + + class GameEngine { + #gameStateManager: IGameStateManager + #logger: ILogger + +Start(): void + +Update(): void + +Draw(): void + } + + class GameStateManager { + -gameStates: stack[GameState] + +changeState(): void + +getCurrentState() : GameState* + +popState() : void + +pushState() : void + +render() : void + +update() : void + } + + class IGameState { + <> + +update() + +draw() + } + + class MainMenuState { + +update() + +draw() + } + + class PlayGameState { + +Levels: Level + +update() + +draw() + } + + class IGameLevel { + <> + +gameObjects : vector~GameObject~ + +AddGameObject(GameObject gameObject)* + +RemoveGameObject(GameObject gameObject)* + } + + class GameObject { + <> + #name : str + #components : vector~IComponent~ + #transform: Transform + +GameObject(str name, vector~Icomponent~ components)* + +AddComponent(IComponent component)*: void + +GetComponent(str name)*: self + +RemoveComponent(IComponent component)*: void + +ToString()*: str + } + + class Component { + <> + #gameObject: GameObject + +parent: gameObject + +Awake() + +Start() + +Update() + } + + class Transform { + #gameObject: GameObject + +childCount: int + +hasChanged: bool + +localPosition: Vector2D + +parent: gameObject + +up: Vector2D + +forward: Vector2D + +hasChanged: bool + +Awake() + +Start() + +Update() + +Translate() + } + + Game *-- IGameEngine + IGameEngine <|-- GameEngine: Implements + IRenderer <|-- SplashkitRenderer: Implements + IGameEngine *-- IGameStateManager + IGameEngine *-- ILogger + IGameEngine *-- IRenderer + IGameStateManager <|.. GameStateManager: Implements + ILogger <|.. SplashkitLogger: Implements + PlayGameState o-- IGameLevel + GameStateManager --> IGameState + IGameState <|.. MainMenuState: Implements + IGameState <|.. PlayGameState: Implements + IGameLevel *-- GameObject + GameObject *--* Component + GameObject *-- Transform + Component <|.. Transform: Implements +``` + +### 5. Sequence Diagrams + +```mermaid +sequenceDiagram + participant g as Game + participant gsm as GameStateManager + participant gs as GameState + participant l as IGameLevel + participant go as GameObject + participant c as Component + + g->>gsm: start() + gsm->>gsm: GameStateManager() + gsm->>gs: pushState(MainMenuState) + gsm->>gs: getCurrentState() + Note over gsm,gs: Current state is now MainMenuState + + g->>gsm: update() + gsm->>gs: update() + Note over gsm,gs: MainMenuState update is called + + gsm->>gs: changeState(PlayGameState) + gsm->>gs: getCurrentState() + Note over gsm,gs: Current state is now PlayGameState + + g->>gsm: update() + gsm->>gs: update() + gs->>l: update() + l->>go: update() + go->>c: Update() + +``` diff --git a/Tutorial-Proposals/Sprite Pack Documentation.md b/Tutorial-Proposals/Sprite Pack Documentation.md new file mode 100644 index 0000000..57fea5e --- /dev/null +++ b/Tutorial-Proposals/Sprite Pack Documentation.md @@ -0,0 +1,103 @@ +# Sprite Pack Documentation + +## Introduction + +Sprite packs are a mechanism for managing and organizing sets of sprites within a game or +application. Sprites are visual elements that can be used to represent objects, characters, or other +graphics within the user interface. This documentation outlines the functions and concepts related +to sprite packs, including creating, updating, drawing, and selecting sprite packs. + +## Function Overview + +### `create_sprite_pack(const String &name)` + +- **Description:** Creates a new sprite pack with a given name. This pack can then be selected and + used to control which sprites are drawn/updated in the calls to `draw_all_sprites` and + `update_all_sprites`. +- **Parameters:** + - `name` (Type: `string`): The name of the new sprite pack. + +### `current_sprite_pack()` + +- **Description:** Returns the name of the currently selected sprite pack. +- **Return Type:** `string` +- **Signatures:** + + ```cpp + string current_sprite_pack(); + ``` + +### `draw_all_sprites()` + +- **Description:** Draws all of the sprites in the current sprite pack. Packs can be switched to + select between different sets of sprites. +- **Parameters:** None +- **Signatures:** + + ```cpp + void draw_all_sprites(); + ``` + +### `update_all_sprites()` + +- **Description:** Updates all sprites in the current sprite pack. +- **Parameters:** None +- **Signatures:** + + ```cpp + void update_all_sprites(); + ``` + +### `update_all_sprites(float pct)` + +- **Description:** Updates all sprites in the current sprite pack with a specified percentage. +- **Parameters:** + - `pct` (Type: `float`): The percentage of the update to apply. +- **Signatures:** + + ```cpp + void update_all_sprites(float pct); + ``` + +## Example Usage + +```cpp +create_sprite_pack("pack1"); +select_sprite_pack("pack1"); +draw_all_sprites(); +update_all_sprites(0.5); +free_sprite_pack("pack1"); +``` + +## Internal Functions + +### `_update_sprite_pct(void *s, Float pct)` + +- **Description:** Internal function for updating a sprite with a specified percentage. + +### `_draw_sprite(void *s)` + +- **Description:** Internal function for drawing a sprite. + +### `_free_sprite(void *s)` + +- **Description:** Internal function for freeing a sprite. + +### `_call_for_all_sprites(vector &sprites, sprite_function *fn)` + +- **Description:** Internal function for calling a sprite function on a vector of sprites. + +### `_call_for_all_sprites(vector &sprites, sprite_float_function *fn, Float val)` + +- **Description:** Internal function for calling a sprite function with a value on a vector of + sprites. + +## Internal Data and Structures + +### `_sprite_packs` + +- A map that stores sprite packs where keys are pack names and values are vectors of sprites. + +### `_current_pack` + +- A string representing the name of the currently selected sprite pack. diff --git a/Tutorial-Proposals/Understanding SplashKit Manager (SKM) Shell Commands.md b/Tutorial-Proposals/Understanding SplashKit Manager (SKM) Shell Commands.md new file mode 100644 index 0000000..9cf7f7a --- /dev/null +++ b/Tutorial-Proposals/Understanding SplashKit Manager (SKM) Shell Commands.md @@ -0,0 +1,82 @@ +## Title: Understanding SplashKit Manager (SKM) Shell Commands + +### Introduction + +This tutorial aims to provide a comprehensive understanding of the SplashKit Manager (SKM) shell +commands. SKM is a powerful command-line tool used for managing SplashKit projects and resources. By +the end of this tutorial, you will have a solid grasp of each SKM command, enabling you to +efficiently work with SplashKit projects and streamline your development process. + +### Prerequisites + +To make the most of this tutorial, you should have basic knowledge of programming and familiarity +with the command line. Prior experience with C++, Python, or Pascal will be beneficial but not +mandatory. + +### Functions Used + +1. `clang++` +1. `dotnet` +1. `fix` +1. `fpc` +1. `g++` +1. `help` +1. `linux` +1. `new` +1. `python3` +1. `resources` +1. `revert` +1. `uninstall` +1. `update` + +### Table of Contents + +1. **Introduction to SKM** + + - What is SplashKit Manager (SKM)? + - Installation and setup + +1. **Working with SKM Commands** + + - Overview of the SKM command structure + - Basic usage: `skm [command] [arguments]` + +1. **Understanding SKM Commands** + + - Detailed explanation of each command + - Examples of command usage + - Common use cases for each command + +1. **Integration with IDEs and build systems** + - Integrating SKM with IDEs and build systems + +### Tutorial Details + +This tutorial will be presented as a step-by-step guide with hands-on examples for each SKM command. +The tutorial will be suitable for intermediate-level programmers interested in game development and +working with the SplashKit library. Each command will be explained in a clear, concise manner, with +practical demonstrations to ensure a deep understanding of its functionality. + +### Expected Learning Outcomes + +After completing this tutorial, you will be able to: + +1. Install and set up SplashKit Manager (SKM) for your projects. +1. Execute various SKM commands and understand their purposes. +1. Compile and run SplashKit projects using different compilers (`clang++`, `g++`, `fpc`, `dotnet`, + `python3`). +1. Create new SplashKit projects and manage project resources. +1. Fix common path-related issues in SplashKit projects. +1. Upgrade or revert to different versions of SplashKit as needed. +1. Uninstall SKM when necessary. + +### Conclusion + +Upon completing the tutorial, readers will be equipped with the knowledge and skills to install and +set up SKM for their projects, execute different SKM commands, work with various compilers (e.g., +clang++, g++, fpc, dotnet, python3), create new SplashKit projects, manage project resources, +resolve path-related issues, update or revert to different versions of SplashKit, and uninstall SKM +when required. + +With this expertise, developers can streamline their workflow, leverage the full potential of +SplashKit, and efficiently create engaging and interactive projects. diff --git a/Tutorial-Proposals/kcb/2023-07-30-using-keycallbacks.html.md b/Tutorial-Proposals/kcb/2023-07-30-using-keycallbacks.html.md new file mode 100644 index 0000000..92d0622 --- /dev/null +++ b/Tutorial-Proposals/kcb/2023-07-30-using-keycallbacks.html.md @@ -0,0 +1,171 @@ +--- +title: Using Key Callbacks +date: 2023-07-30 06:21 UTC +author: Ro +author_url: +tags: Input +summary: | + Key Callbacks provide a method to indirectly run commands based on detected key events. + Instead of directly checking the state of a key press, process event will run the callback function + when it detects the event depending on the type it has been registered for. +related_funcs: + - register_callback_on_key_down + - register_callback_on_key_typed + - register_callback_on_key_up + - deregister_callback_on_key_down + - deregister_callback_on_key_typed + - deregister_callback_on_key_up +--- + +Key Callbacks are essentially function calls for when process event function detects any of the +three types of events. Using this object, we can avoid directly checking for key states every frame +ourselves. + +These are the three event types that are available for callback + +| Name | Trigger | +| ----- | -------------- | +| Down | Key is held | +| Typed | On key press | +| Up | On key release | + +Note that down has a small pause before continuous calling. Multiple held keys do not increase rate. +Depending on keyboard N-key rollover, it may also stop when a set of keys held, some are released. + +## Creating A Callback Function + +To start using key callbacks, we need a function that has the structure the object is expecting. + +This entails a single integer parameter and a void return type. + +```c# + + public void KeyEvent(int code) + { + // your code here + } + +``` + +## Selecting A Key + +The function when registered will run regardless of which key initiated the event. So it is +necessary to check what key the callback refers to, if your code is to change its behaviour based on +the key given. + +The integer "code" argument represents the key that triggered the event, and can be type casted into +KeyCode for direct comparisons to specific keys. + +```c# + + public void KeyEvent(int code) + { + if ((KeyCode)code == KeyCode.AKey) + { + // your code if A key here + } + } + +``` + +Alternatively, you can utilize collection objects to dynamically check if an entry exists for a +given code. In this C# example, a dictionary object is used as it cannot have entries with identical +keys and has try functions, that automatically retrieve the value into a variable while returning a +boolean if it was successful. + +```c# + + private Dictionary dict = new Dictionary + { + {114, Color.Red}, // 114 = R + {103, Color.Green}, // 103 = G + {98, Color.Blue} // 98 = B + }; + private Color clr; + + public void KeyEvent(int code) + { + + if (!dict.TryGetValue(code, out clr)) // clr will receive a default value, if code isn't found + { + clr = Color.White; // instead of default value, we change it to this + } + } + +``` + +The KeyCode enumerable can be used instead for the dictionary keys, and can help limit the key value +pairs. + +## Declaring And Initialising A KeyCallback object + +Once you have a function to be used for callbacks, a KeyCallback object is needed to refer to the +function and be registered for process event to be aware of. + +```C# + +public KeyCallback kcb; + +kcb = new KeyCallback(KeyEvent); // put the name of your function inside + +``` + +## Registering a Key Callback Object + +With an initialised Key Callback object, we need to register it for process event to use it. + +```c# + +Splashkit.RegisterCallbackOnKeyTyped(kcb); // call on press + +Splashkit.RegisterCallbackOnKeyDown(kcb); // call on hold + +Splashkit.registerCallbackOnKeyUp(kcb); // call on lift + +``` + +The above example, will start running the function kcb contains. The event typed specifies when any +key is initially pressed down, as shown in the table above. + +While you can register the same object for all three events, doing so may be at odds with its +design. As normally you would want different behaviours based on the different events. + +## Deregistering a Key Callback object + +When you want a callback to stop being called by process event, you need to run the deregister +function to do so. + +```c# + +Splashkit.DeregisterCallbackOnKeyTyped(kcb); // stop calling on press + +Splashkit.DeregisterCallbackOnKeyDown(kcb); // stop calling on hold + +Splashkit.DeregisterCallbackOnKeyUp(kcb); // stop calling on lift + +``` + +If you did register it for multiple event types, you need to run it for each type as well to +completely remove it from being called. + +Such examples of when this is necessary is if you were to switch between menus that have their own +behaviours. + +Deregister is important if you implement Key Callbacks in classes that are disposed of. As process +event will throw an error trying to reach the callback. + +## C# Demonstration Program + +A Splashkit Demo of Key Callbacks is available here LINK IT + +The code showcases the process event running the callback functions by displaying the last key +detected with its related integer code. The Down and Up callbacks are linked to a incrementing +counter based on how many callbacks for Down Event receive before any key is released. + +## Storing Key Codes outside of program + +If you want to store a keycode in JSON, an integer is recommended. Strings can still be used to +compare, but need extra work to be converted back into Key codes, since there isn't a Splashkit +function to convert string into key code, only from key code into string. + +A table to lookup the numeric value of a key can be found here LINK IT diff --git a/Tutorial-Proposals/kcb/kcb demo exe/KCB_test.deps.json b/Tutorial-Proposals/kcb/kcb demo exe/KCB_test.deps.json new file mode 100644 index 0000000..1ea709f --- /dev/null +++ b/Tutorial-Proposals/kcb/kcb demo exe/KCB_test.deps.json @@ -0,0 +1,23 @@ +{ + "runtimeTarget": { + "name": ".NETCoreApp,Version=v6.0", + "signature": "" + }, + "compilationOptions": {}, + "targets": { + ".NETCoreApp,Version=v6.0": { + "KCB_test/1.0.0": { + "runtime": { + "KCB_test.dll": {} + } + } + } + }, + "libraries": { + "KCB_test/1.0.0": { + "type": "project", + "serviceable": false, + "sha512": "" + } + } +} \ No newline at end of file diff --git a/Tutorial-Proposals/kcb/kcb demo exe/KCB_test.runtimeconfig.json b/Tutorial-Proposals/kcb/kcb demo exe/KCB_test.runtimeconfig.json new file mode 100644 index 0000000..4986d16 --- /dev/null +++ b/Tutorial-Proposals/kcb/kcb demo exe/KCB_test.runtimeconfig.json @@ -0,0 +1,9 @@ +{ + "runtimeOptions": { + "tfm": "net6.0", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "6.0.0" + } + } +} \ No newline at end of file diff --git a/Tutorial-Proposals/kcb/kcb demo exe/Resources/fonts/pdark.ttf b/Tutorial-Proposals/kcb/kcb demo exe/Resources/fonts/pdark.ttf new file mode 100644 index 0000000..0eace6e Binary files /dev/null and b/Tutorial-Proposals/kcb/kcb demo exe/Resources/fonts/pdark.ttf differ diff --git a/Tutorial-Proposals/kcb/kcb demo exe/Resources/fonts/pricedown_bl.otf b/Tutorial-Proposals/kcb/kcb demo exe/Resources/fonts/pricedown_bl.otf new file mode 100644 index 0000000..f06a2be Binary files /dev/null and b/Tutorial-Proposals/kcb/kcb demo exe/Resources/fonts/pricedown_bl.otf differ diff --git a/Tutorial-Proposals/kcb/kcb demo exe/Resources/fonts/readme.txt b/Tutorial-Proposals/kcb/kcb demo exe/Resources/fonts/readme.txt new file mode 100644 index 0000000..18d42aa --- /dev/null +++ b/Tutorial-Proposals/kcb/kcb demo exe/Resources/fonts/readme.txt @@ -0,0 +1 @@ +You can place fonts in this folder. Fonts can be otf or ttf files. diff --git a/Tutorial-Proposals/kcb/kcb demo exe/Resources/fonts/typodermic-eula-03-2020.pdf b/Tutorial-Proposals/kcb/kcb demo exe/Resources/fonts/typodermic-eula-03-2020.pdf new file mode 100644 index 0000000..845ff96 Binary files /dev/null and b/Tutorial-Proposals/kcb/kcb demo exe/Resources/fonts/typodermic-eula-03-2020.pdf differ diff --git a/Tutorial-Proposals/kcb/kcb demo src/Program.cs b/Tutorial-Proposals/kcb/kcb demo src/Program.cs new file mode 100644 index 0000000..68fffbc --- /dev/null +++ b/Tutorial-Proposals/kcb/kcb demo src/Program.cs @@ -0,0 +1,116 @@ +using System; +using SplashKitSDK; + + +// demonstration code for KeyCallback object +// +namespace KCB_test +{ + public class Program + { + private static KeyCallback kcb_Typed; // declare key callback object + private static KeyCallback kcb_Down; + private static KeyCallback kcb_Up; + private static String kcb_Typed_Keyname; // string object to hold the string name + private static int kcb_Typed_Code; + private static int kcb_Down_Held = 0; + private static Color textClr; + + // store colors related to keycode in dictionary object + private static Dictionary kcb_Color = new Dictionary + { + {114, Color.Red}, // 114 = R + {103, Color.Green}, // 103 = G + {98, Color.Blue} // 98 = B + }; + + private static Dictionary kcb_Up_Act = new Dictionary + { + {100, () => logging("sample text")} // 100 = D + }; + + + public static void Main() + { + Window programWindow = SplashKit.OpenWindow("KeyCallbacks", 640, 480); + Font f = new Font("pricedown_bl", "pricedown_bl.otf"); + + + // key callback initialized with function name + kcb_Typed = new KeyCallback(KeyEventTyped); // press + kcb_Down = new KeyCallback(KeyEventDown); // held + kcb_Up = new KeyCallback(KeyEventUp); // depress + + + kcb_Typed_Keyname = "N/A"; + textClr = Color.White; + + SplashKit.RegisterCallbackOnKeyTyped(kcb_Typed); // key callback is added to list to be called by process events + SplashKit.RegisterCallbackOnKeyDown(kcb_Down); + SplashKit.RegisterCallbackOnKeyUp(kcb_Up); + + while (!programWindow.CloseRequested) + { + SplashKit.ProcessEvents(); + + programWindow.Clear(Color.Black); + + programWindow.DrawText(kcb_Typed_Keyname, textClr, f, 40, 200, 200); // display the text name of the code from callback + programWindow.DrawText(kcb_Typed_Code.ToString(), textClr, f, 40, 200, 260); // display the code from callback + programWindow.DrawText("Held: " + kcb_Down_Held, textClr, f, 40, 200, 320); // display the callbacks from hold + + programWindow.Refresh(60); + } + + SplashKit.DeregisterCallbackOnKeyTyped(kcb_Typed); + SplashKit.DeregisterCallbackOnKeyDown(kcb_Down); + SplashKit.DeregisterCallbackOnKeyUp(kcb_Up); + // remove key callback from being called, not important here + // but if the object is located in an object that is disposed of + // it can throw an error + + programWindow.Close(); + } + + private static void KeyEventTyped(int code) // key pressed + { + kcb_Typed_Keyname = SplashKit.KeyName((KeyCode)code); + kcb_Typed_Code = code; + + // A dictionary can be used to avoid hardcoded specific code checks + // instead if the key exists in the dictionary, it will extract the value + if (!kcb_Color.TryGetValue(code, out textClr)) + { + textClr = Color.White; // if not found, set to white + } + + if (KeyCode.XKey == (KeyCode)code) // check if X key was pressed + { + // insert your code here + } + } + + private static void KeyEventDown(int code) // key held + { + kcb_Down_Held++; + } + + private static void KeyEventUp(int code) // key depressed + { + kcb_Down_Held = 0; + + Action a; + if (kcb_Up_Act.TryGetValue(code, out a)) // using an action, to retrieve code to run from dictionary + { + a(); + } + } + + private static void logging(String text) + { + Console.Out.WriteLine(text); + } + + + } +} diff --git a/Tutorial-Proposals/kcb/kcb demo src/Resources/fonts/pdark.ttf b/Tutorial-Proposals/kcb/kcb demo src/Resources/fonts/pdark.ttf new file mode 100644 index 0000000..0eace6e Binary files /dev/null and b/Tutorial-Proposals/kcb/kcb demo src/Resources/fonts/pdark.ttf differ diff --git a/Tutorial-Proposals/kcb/kcb demo src/Resources/fonts/pricedown_bl.otf b/Tutorial-Proposals/kcb/kcb demo src/Resources/fonts/pricedown_bl.otf new file mode 100644 index 0000000..f06a2be Binary files /dev/null and b/Tutorial-Proposals/kcb/kcb demo src/Resources/fonts/pricedown_bl.otf differ diff --git a/Tutorial-Proposals/kcb/kcb demo src/Resources/fonts/readme.txt b/Tutorial-Proposals/kcb/kcb demo src/Resources/fonts/readme.txt new file mode 100644 index 0000000..18d42aa --- /dev/null +++ b/Tutorial-Proposals/kcb/kcb demo src/Resources/fonts/readme.txt @@ -0,0 +1 @@ +You can place fonts in this folder. Fonts can be otf or ttf files. diff --git a/Tutorial-Proposals/kcb/kcb demo src/Resources/fonts/typodermic-eula-03-2020.pdf b/Tutorial-Proposals/kcb/kcb demo src/Resources/fonts/typodermic-eula-03-2020.pdf new file mode 100644 index 0000000..845ff96 Binary files /dev/null and b/Tutorial-Proposals/kcb/kcb demo src/Resources/fonts/typodermic-eula-03-2020.pdf differ diff --git a/Tutorials/Car-Race-Tutorial/Step1-Starting Setup.md b/Tutorials/Car-Race-Tutorial/Step1-Starting Setup.md new file mode 100644 index 0000000..0bd55e5 --- /dev/null +++ b/Tutorials/Car-Race-Tutorial/Step1-Starting Setup.md @@ -0,0 +1,53 @@ +--- +title: "Setting Up SplashKit for Car Race Game" +description: + Learn how to set up SplashKit for developing the Car Race Game. +author: Khushi Laddi +date: 2024-04-20 +tags: game development, programming, SplashKit, setup +sidebar: + label: " -Tutorial 1: Splashkit Setup" +--- + +## Introduction + +Welcome to the setup guide for SplashKit in preparation for developing the Car Race Game. SplashKit is a versatile game development toolkit that provides a wide range of features and functions to simplify the game development process. In this tutorial, we'll walk you through the steps to [install and configure SplashKit](https://splashkit.io/articles/installation/), set up your project, and get ready to start building your game. + +## Environment Setup + +Let's get started with setting up SplashKit for your Car Race Game project: + +### Installing SplashKit + +To install SplashKit, follow these steps: + +1. Visit the [SplashKit website](https://splashkit.io/articles/installation/) and find the installation guide for your operating system (Windows, macOS, or Linux). +2. Follow the instructions provid ed in the installation guide to download and install SplashKit on your computer. +3. Make sure to install any additional programs or libraries required by SplashKit as indicated in the installation guide. + +### Creating Your Project + +After installing SplashKit, it's time to create your Car Race Game project: + +1. Create a new directory for your project on your computer. You can name it something like "CarRaceGame". +2. Use SplashKit Manager (SKM) to set up a new C++ project by running the command `skm new c++` in your project directory. This command initializes a new C++ project with SplashKit dependencies. +3. Generate resource folders for your project using the command `skm resources`. This command creates a "resources" folder where you can store game assets such as images, sounds, and fonts. +4. In this projet we have files car.cpp, game.cpp, car.h, game.h, and main program.cpp +5. The folder starting has libraries and then main files + +![image](images/folder1.png) +![image](images/Folder2.png) + +### Configuring Your IDE + +If you're using Visual Studio Code (VS Code) as your code editor: + +1. Open VS Code and navigate to your project directory. +2. Set up your project configuration and compile your code using SKM commands in the VS Code terminal. You can use commands like `skm clang++ *.cpp -0 output` to compile your project and `./output.exe` to execute it. + + +## Conclusion + +You've completed the setup process for SplashKit in preparation for developing the Car Race Game. With SplashKit installed and your project set up, you're ready to start coding and building your game. Stay tuned for the next tutorial where we'll dive into game development with SplashKit! + +Happy coding!🚗💨 diff --git a/Tutorials/Car-Race-Tutorial/Step2-C++ Programing Concepts.md b/Tutorials/Car-Race-Tutorial/Step2-C++ Programing Concepts.md new file mode 100644 index 0000000..16b704e --- /dev/null +++ b/Tutorials/Car-Race-Tutorial/Step2-C++ Programing Concepts.md @@ -0,0 +1,226 @@ +--- +title: "C++ Programming Concepts Tutorial" +description: "Learn essential C++ programming concepts, including functions, structures, enums, conditional statements, loops, and standard library usage." +author: "Khushi Laddi" +date: "2024-04-20" +tags: C++, programming, basics +--- + +## Introduction + +Welcome to the C++ Programming Concepts tutorial. In this tutorial, we'll cover fundamental C++ programming concepts and techniques, including functions, structures, enums, conditional statements, loops, and the usage of the standard library. + +## Functions, Structures, and Enums + +1. **Functions**: + - Function is created and called as per the usage, here we have fucntions for every object and provide sample block of code for understanding. It performs specific task assigned. They ensure code reusability and organization + - First the fucntions have been declared in header files and then the main files + - Second we are using the fucntion and creating the car + ```cpp + // Function to create a new car + car_data new_car(car_model model, double speed, double x, double y); + + // Function to draw the car + void draw_car(car_data &car); + ``` + ```cpp + car_data new_car(car_model model, double speed, double x, double y) + { + car_data result; + bitmap default_bitmap = car_bitmap(model); + + // Set cell details and animation script for RED and YELLOW cars + if (model == RED || model == YELLOW) + { + bitmap_set_cell_details(default_bitmap, 75, 120, 3, 1, 3); + animation_script carAnimation = load_animation_script("carAnimation", "carAnimation.txt"); + result.car_sprite = create_sprite(default_bitmap, carAnimation); + } + else + { + result.car_sprite = create_sprite(default_bitmap); + } + + result.speed = speed; + result.model = model; + + sprite_set_x(result.car_sprite, x); + sprite_set_y(result.car_sprite, y); + sprite_set_dy(result.car_sprite, result.speed); + + return result; + } + ``` + +2. **Structures**: + - Structures allow you to create custom data types that contain multiple variables. + - Example structure definition: + - Code for header files; + ```cpp + struct car_data + { + sprite car_sprite; // Sprite representing the car + car_model model; // Model of the car + double speed; // Speed of the car + }; + + struct game_data + { + bool game_over; // Flag indicating if the game is over + sprite whitemarks[6]; // Array of sprites for white marks on the road + car_data car; // Player's car + vector cars; // Vector of obstacle cars + double score; // Current score + }; + struct button + { + const char* text; + rectangle bounds; + }; + ``` + +3. **Enums**: + - Enums (enumerations) are user-defined data types consisting of named constants. + - Example enum declaration: + - These are also declared in header files + ```cpp + enum Color { + RED, + GREEN, + BLUE + }; + ``` + +## Conditional Statements + +1. **If-Else Statements**: + - If-else statements are used to make decisions based on conditions. + - In the function we use if-else statements to keep the use under the control + - Example usage: + ```cpp + // Function to check and limit the car's position within the screen + void input_check_positions(game_data &game) + { + if (sprite_x(game.car.car_sprite) <= 50) + { + sprite_set_x(game.car.car_sprite, 50); + } + else if (sprite_x(game.car.car_sprite) >= 650) + { + sprite_set_x(game.car.car_sprite, 650); + } + }; + ``` + +## Loops + +1. **For Loop**: + - For loops are used to iterate over a range of values or execute a block of code a specified number of times. + - Here in my code I used as in fucntion to showcase the game + - Example usage: + ```cpp + // Function to draw the game + void draw_game(game_data &game) + { + clear_screen(COLOR_GRAY); + for (int i = 0; i < 6; i++) + { + draw_sprite(game.whitemarks[i]); + } + for (int j = 0; j < game.cars.size(); j++) + { + draw_car(game.cars[j]); + } + + draw_bitmap("game", 0, 0, option_to_screen()); + + draw_text(to_string((int)game.score), COLOR_WHITE, "digi", 50, 650, 10, option_to_screen()); + draw_car(game.car); + }; + ``` + +2. **While Loop**: + + Add the code to program.cpp in main file + + - While loops repeatedly execute a block of code as long as a specified condition is true. + - I used the while loop in my main file so that game could keep on running till the time user doesn't want to quit + - Example usage: + ```cpp + int main() + { + open_window("Car Racing", 800, 600); + load_resources(); + bool game_started = false; + game_data game = new_game(); + while (not quit_requested()) + { + process_events(); + clear_screen(COLOR_GRAY); + if (!game_started) + { + // Draw buttons and home image + draw_bitmap("home", 0, 0, option_to_screen()); + refresh_screen(60); + // Set game_started to true when 'S' key is pressed + if (key_typed(S_KEY)) + { + game_started = true; + } + // quit game + if (key_typed(Q_KEY)) + { + exit(0); + } + } + else if (!game.game_over) + { + // Draw and update game + draw_game(game); + check_collisions(game); + out_range(game); + update_game(game); + } + else + { + // Game over screen + stop_sound_effect("carmotor"); + draw_bitmap("ending", 0, 0, option_to_screen()); + draw_text("Score: " + to_string((int)game.score), COLOR_WHITE, "digi", 70, 100, 400, option_to_screen()); + if (key_typed(RETURN_KEY)) + { + game = new_game(); + stop_sound_effect("endmusic"); + } + if (!musicplayed) + { + play_sound_effect("endmusic", 1); + musicplayed = true; + } + } + + refresh_screen(60); + } + } + ``` + +## Standard Library Usage + +1. ****: + - The `` header provides a dynamic array implementation in C++, allowing flexible storage and manipulation of elements. + - Example usage: + ```cpp + #include + std::vector + ``` + +## Flow Chart + +![image](images/flowchart%20%20step%202.png) + +## Conclusion + +Congratulations! You've learned essential C++ programming concepts, including functions, structures, enums, conditional statements, loops, and standard library usage. These concepts are foundational to writing efficient and maintainable C++ code. + +Happy coding!🚗💨 + diff --git a/Tutorials/Car-Race-Tutorial/Step3-Splashkit Features.md b/Tutorials/Car-Race-Tutorial/Step3-Splashkit Features.md new file mode 100644 index 0000000..ad61df3 --- /dev/null +++ b/Tutorials/Car-Race-Tutorial/Step3-Splashkit Features.md @@ -0,0 +1,85 @@ +--- +title: "SplashKit Library Features Tutorial" +description: "Explore the features of the SplashKit library for game development, including sprite creation, drawing, animation, bitmap loading, manipulation, sound effect loading, and playback." +author: "Khushi Laddi" +date: "2024-04-21" +tags: SplashKit, game development, programming, basics +--- + +## Introduction + +Welcome to the SplashKit Library Features tutorial. In this tutorial, we'll dive into the features offered by the SplashKit library, a powerful toolkit for game development in C++. We'll cover sprite creation, drawing, animation, bitmap loading, manipulation, sound effect loading, and playback. + +## Sprite Creation, Drawing, and Animation + +1. **Sprite Creation**: + - Sprites are movable and animated images used to represent game objects. + - Here we created the sprite to change the color of car skin + - Create a sprite from a bitmap: + + ```cpp + void switch_car_skin(car_data &car) + { + bitmap other = car_bitmap(YELLOW); + bitmap_set_cell_details(other, 75, 120, 3, 1, 3); + sprite_add_layer(car.car_sprite, other, "YELLOW"); + sprite_hide_layer(car.car_sprite, 1); + + if (car.model == RED) + { + car.model = YELLOW; + sprite_hide_layer(car.car_sprite, 0); + sprite_show_layer(car.car_sprite, 1); + } + else if (car.model == YELLOW) + { + car.model = RED; + sprite_hide_layer(car.car_sprite, 1); + sprite_show_layer(car.car_sprite, 0); + } + } + ``` + +2. **Drawing Sprites**: + - Draw a sprite on the screen: + ```cpp + // Function to draw the car + void draw_car(car_data &car) + { + draw_sprite(car.car_sprite); + } + ``` + +3. **Animation**: + - Animate a sprite by changing its position, rotation, and image frame over time: + - While creating new car we declared the animation of the car + ```cpp + animation_script carAnimation = load_animation_script("carAnimation", "carAnimation.txt"); + ``` + +## Bitmap Loading and Manipulation + +1. **Bitmap Loading**: + - Load bitmap images from files: + ```cpp + // Used on many occassions + draw_bitmap("game", 0, 0, option_to_screen()); // used while drawing the game + bitmap default_bitmap = car_bitmap(model); // getting the car image + ``` + +2. **Bitmap Manipulation**: + - Modify bitmap properties such as size, color, and transparency: + ```cpp + bitmap_set_cell_details(default_bitmap, 75, 120, 3, 1, 3); // setting the car position + ``` + + +## Flow Chart + +![image](images/flowchart%20step%203.png) + +## Conclusion + +Congratulations! You've explored the key features of the SplashKit library for game development. With SplashKit, you can create dynamic and engaging games with ease. Experiment with sprite creation, bitmap loading, sound effect playback, and more to bring your game ideas to life! + +Happy game development!🚗💨 diff --git a/Tutorials/Car-Race-Tutorial/Step4-Car Handling.md b/Tutorials/Car-Race-Tutorial/Step4-Car Handling.md new file mode 100644 index 0000000..4bb89ff --- /dev/null +++ b/Tutorials/Car-Race-Tutorial/Step4-Car Handling.md @@ -0,0 +1,248 @@ +--- +title: "Car Handling Tutorial with SplashKit" +description: "Learn how to handle cars in your game using the SplashKit library, including creation of different car models, drawing and updating car position, and switching car skin during gameplay." +author: "Khushi Laddi" +date: "2024-04-21" +tags: SplashKit, game development, programming, cars +--- + +## Introduction + +Welcome to the Car Handling tutorial with SplashKit. In this tutorial, we'll explore how to handle cars in your game using the features provided by the SplashKit library. We'll cover the creation of different car models, drawing and updating car positions, switching car skins and collision detection during gameplay. + +## Car Models Creation + +Make a car.cpp file and car.h file where user will start with basic libraries #include "splashkit.h" +#include +#include "car.h" +using namespace std; and then start with code where first part is bitmap loading. + +1. **Car Bitmap Loading**: + - Load bitmap images for different car models: + - In this we made the fuction to call all the cars we are using in the game + ```cpp + bitmap car_bitmap(car_model model) + { + switch (model) + { + case RED: + return bitmap_named("redcar"); + case YELLOW: + return bitmap_named("yellowcar"); + case BLACK: + return bitmap_named("blackcarsolo"); + case POLICE: + return bitmap_named("policecarsolo"); + default: + return bitmap_named("policecarsolo"); + } + } + ``` + +2. **Car Model Enumeration**: + + In header file user will start with basic libraries #ifndef CAR_RACE_CAR + #define CAR_RACE_CAR + + #include "splashkit.h" + #include and then start coding from enums + + - Define an enumeration for different car models: + ```cpp + enum car_model { + RED, + YELLOW, + BLACK, + POLICE + }; + ``` + +## Drawing and Updating Car Position + + In the same header file after enums user will add the code for struct + +1. **Car Structure Definition**: + - Define a structure to store car data: + ```cpp + struct car_data { + sprite car_sprite; // sprite representing the car + car_model model; // Model of the car + double speed; // Speed of the car + }; + ``` + +2. **Car Creation**: + + In the car.cpp file now add create the car code after bitmap loading + + - Create a new car with specified model, speed, and position: + ```cpp + // Function to create a new car + car_data new_car(car_model model, double speed, double x, double y) + { + car_data result; + bitmap default_bitmap = car_bitmap(model); + + // Set cell details and animation script for RED and YELLOW cars + if (model == RED || model == YELLOW) + { + bitmap_set_cell_details(default_bitmap, 75, 120, 3, 1, 3); + animation_script carAnimation = load_animation_script("carAnimation", "carAnimation.txt"); + result.car_sprite = create_sprite(default_bitmap, carAnimation); + } + else + { + result.car_sprite = create_sprite(default_bitmap); + } + + result.speed = speed; + result.model = model; + + sprite_set_x(result.car_sprite, x); + sprite_set_y(result.car_sprite, y); + sprite_set_dy(result.car_sprite, result.speed); + + return result; + } + ``` + +3. **Drawing Car**: + + In the car.cpp file add the code after the switching car function + + - Draw the car sprite on the screen: + ```cpp + void draw_car(car_data &car) + { + draw_sprite(car.car_sprite); + } + ``` + +4. **Updating Car Position**: + + In the car.cpp file add the code after the drawing car fucntion + + - Update the car's position based on its speed: + ```cpp + void update_car(car_data &car) + { + update_sprite(car.car_sprite); + sprite_set_y(car.car_sprite, sprite_y(car.car_sprite) + car.speed); + } + ``` + +![image](images/carrace-demo-01.png) + +## Switching Car Skin During Gameplay + + Add the code to car.cpp after create a car function + +1. **Switching Car Skin Function**: + - Implement a function to switch the car's skin during gameplay: + ```cpp + // Function to switch the car's skin + void switch_car_skin(car_data &car) + { + bitmap other = car_bitmap(YELLOW); + bitmap_set_cell_details(other, 75, 120, 3, 1, 3); + sprite_add_layer(car.car_sprite, other, "YELLOW"); + sprite_hide_layer(car.car_sprite, 1); + + if (car.model == RED) + { + car.model = YELLOW; + sprite_hide_layer(car.car_sprite, 0); + sprite_show_layer(car.car_sprite, 1); + } + else if (car.model == YELLOW) + { + car.model = RED; + sprite_hide_layer(car.car_sprite, 1); + sprite_show_layer(car.car_sprite, 0); + } + } + ``` + +![image](images/redcar.png) +![image](images/yellowcar.png) + +2. **Handling User Input**: + + Add the code in gam.cpp file after randomly spawn obstacle cars + + - Handle user input in the fucntion: + ```cpp + void handleInput(game_data &game) + { + if (key_down(LEFT_KEY)) { + // Move car left + sprite_set_x(game.car.car_sprite, sprite_x(game.car.car_sprite) - 11); + sprite_start_animation(game.car.car_sprite, "left"); + } else if (key_down(RIGHT_KEY)) { + // Move car right + sprite_set_x(game.car.car_sprite, sprite_x(game.car.car_sprite) + 11); + sprite_start_animation(game.car.car_sprite, "right"); + } else if (key_down(UP_KEY)) { + game.car.speed -= 0.2; + // Enforce speed limit + if (game.car.speed > MAX_PLAYER_SPEED) { + game.car.speed = MAX_PLAYER_SPEED; + } + } else if (key_down(DOWN_KEY)) { + game.car.speed += 0.5; + // Enforce speed limit + if (game.car.speed > MAX_PLAYER_SPEED) { + game.car.speed = MAX_PLAYER_SPEED; + } + } else if (key_typed(R_KEY)) { + // Restart + game_started = false; // Assuming you have a 'game_started' flag + game = new_game(); // Reset the game + } else if (key_typed(Q_KEY)) { + // END PROGRAM + exit(0); + } else if (key_typed(C_KEY)) { + // Switch car skin + switch_car_skin(game.car); + } + { + + + sprite_start_animation(game.car.car_sprite, "straight"); + } + } + ``` + +## Collision Detection + +Add the code to the game.cpp after function to remove cars that have gone out of range + +Collision detection is crucial for handling interactions between game objects: + +1. **Basic Collision Detection**: + - Detect collisions between sprites based on their bounding boxes or custom shapes. + - Example code snippet: + ```cpp + void check_collisions(game_data &game) + { + for (int i = 0; i < game.cars.size(); i++) + { + if (sprite_collision(game.car.car_sprite, game.cars[i].car_sprite)) + { + play_sound_effect("carcrash", 1); + delay(400); + game.game_over = true; + } + } + } + ``` + +## Flow Chart + +![image](images/flowchart%20step%205.png) + +## Conclusion + +Congratulations! You've learned how to handle cars in your game using the SplashKit library. Experiment with different car models, customize their appearance, and enhance your gameplay experience. Keep practicing and exploring the possibilities to create amazing car-themed games! + +Happy game development!🚗💨 diff --git a/Tutorials/Car-Race-Tutorial/Step5-Game Management.md b/Tutorials/Car-Race-Tutorial/Step5-Game Management.md new file mode 100644 index 0000000..8287cdb --- /dev/null +++ b/Tutorials/Car-Race-Tutorial/Step5-Game Management.md @@ -0,0 +1,174 @@ +--- +title: "Game Management with SplashKit" +description: "Learn how to manage game initialization, user input, obstacle spawning, score tracking, and game over conditions using SplashKit." +author: "Khushi Laddi" +date: "2024-04-21" +tags: game development, programming, SplashKit, management +--- + +## Introduction + +Welcome to the Game Management tutorial with SplashKit. In this tutorial, we'll cover essential concepts and techniques for managing game initialization, user input, obstacle spawning, score tracking, game over conditions, and audio features. + +## Game Initialization + +Initializing the game environment involves setting up necessary resources, such as images, sounds, and initial game state: + +1. **Game State Setup**: + + Add the code to game.cpp file after handle user input + + - Create and initialize game data structures, such as player's car, obstacle cars, and score. + - Example code snippet: + ```cpp + // Function to draw the game + void draw_game(game_data &game) + { + clear_screen(COLOR_GRAY); + + for (int i = 0; i < 6; i++) + { + draw_sprite(game.whitemarks[i]); + } + + for (int j = 0; j < game.cars.size(); j++) + { + draw_car(game.cars[j]); + } + + draw_bitmap("game", 0, 0, option_to_screen()); + + draw_text(to_string((int)game.score), COLOR_WHITE, "digi", 50, 650, 10, option_to_screen()); + draw_car(game.car); + } + ``` + +![image](images/game.png) + +## Obstacle Spawning and Updating the game state + +Spawn and update obstacle cars to create challenging gameplay: + +1. **Random Obstacle Spawning**: + + In game.cpp after map setup add the code + + - Randomly spawn obstacle cars at predefined intervals or positions. + - Example code snippet: + ```cpp + // Function to randomly spawn obstacle cars + void randomCars(game_data &game) + { + int xLocations[] = {50, 150, 250, 350, 450, 550, 650}; // Array to store the x locations + car_model carModels[] = {POLICE, BLACK}; // Array of car models + + // Randomly select x locations for the cars + for (int i = 0; i < CARS_COUNT; i++) + { + int randomIndex = rand() % CARS_COUNT; // Generate a random index between 0 and 6 + int x = xLocations[randomIndex]; + car_model model = carModels[rand() % 2]; // Randomly select a car model + int speed = random_range(MIN_SPEED, MAX_SPEED); // Randomly select a speed + car_data laner_cars = new_car(model, speed, x, -300); // Create a car sprite at the selected x location + game.cars.push_back(laner_cars); // Add the car to the game's car vector + } + } + auto last_call_time = std::chrono::steady_clock::now(); // Track the last time the function was called + game_data new_game() + { + game_data game; + game.car = new_car(RED, 0, screen_width() / 2, screen_height() - 200); + map_setup(game); + game.score = 0; + sprite_start_animation(game.car.car_sprite, "straight"); + play_sound_effect("carmotor", 1, 0.1); + return game; + } + ``` + +2. **Updating game state**: + + At the end of the game.cpp file add the code + + - Update positions and states of obstacle cars based on game logic. + - Example code snippet: + ```cpp + // Function to update the game state + void update_game(game_data &game) + { + game.score += 0.3; + update_car(game.car); + for (int j = 0; j < game.cars.size(); j++) + { + update_car(game.cars[j]); + } + for (int i = 0; i < 6; i++) + { + update_sprite(game.whitemarks[i]); + } + + input_check_positions(game); + handleInput(game); + // Call the randomCars function every CARS_SPAWN_DURATION seconds + auto current_time = std::chrono::steady_clock::now(); + auto elapsed_time = std::chrono::duration_cast(current_time - last_call_time).count(); + if (elapsed_time >= CARS_SPAWN_DURATION) + { + randomCars(game); + last_call_time = current_time; + } + } + ``` + +## Score Tracking and Game Over Conditions + +Add the code in program.cpp at the end in the else condition + +Track player's score and determine game over conditions for a satisfying gameplay experience: + + - Increment score based on game progress or achievements. + - Example code snippet: + ```cpp + { + // Game over screen + stop_sound_effect("carmotor"); + draw_bitmap("ending", 0, 0, option_to_screen()); + draw_text("Score: " + to_string((int)game.score), COLOR_WHITE, "digi", 70, 100, 400, option_to_screen()); + if (key_typed(RETURN_KEY)) + { + game = new_game(); + stop_sound_effect("endmusic"); + } + if (!musicplayed) + { + play_sound_effect("endmusic", 1); + musicplayed = true; + } + } + ``` + +![image](images/carrace-gameover.png) + +## Playing Sound Effects + +Add the code to car.cpp wherever you want the sound effects and stop in program.cpp file in else condition + +1. **Sound Effect Loading**: + - Load sound effects for car movement and collisions: + ```cpp + play_sound_effect("carmotor", 1, 0.1); + play_sound_effect("carcrash", 1); + stop_sound_effect("carmotor"); + ``` + + +## Flow Chart + +![image](images/flowchart%20step%204.png) + +## Conclusion + +Congratulations! You've learned how to manage game initialization, user input, obstacle spawning, score tracking, and game over conditions using SplashKit. Apply these techniques to create engaging and challenging games. Happy coding! + + +Happy game development!🚗💨 diff --git a/Tutorials/Car-Race-Tutorial/Step6-Visual Representation.md b/Tutorials/Car-Race-Tutorial/Step6-Visual Representation.md new file mode 100644 index 0000000..6889e72 --- /dev/null +++ b/Tutorials/Car-Race-Tutorial/Step6-Visual Representation.md @@ -0,0 +1,47 @@ +--- +title: "Visual Representation Of Game" +description: "Lean How To play Game" +author: "Khushi Laddi" +date: "2024-04-22" +tags: game development, resource management, SplashKit +--- +# Car Racing Game Controls and How to Play + +Welcome to the Car Racing Game! Here's how to play: + +[Watch the Tutorial Video](https://youtu.be/N5Oh1Wi7NlY?si=n4eeC2fmDwNi-HGC) + +## Controls +- **Move Left**: Press the "A" key to move your car left. +- **Move Right**: Press the "D" key to move your car right. +- **Change Car Color**: Press the "R" key to switch between different car colors. + +## Gameplay +1. **Starting the Game**: + - Open the game application by using command skm clang++ program.cpp car.cpp game.cpp -o output + - After the compilation is complete use ./output.exe and run the game successfully + - Click on the "Play" button to start the game. + +2. **Navigating the Race Track**: + - Use the "A" and "D" keys to steer your car left or right. + - Navigate through the race track and avoid collisions with other cars or obstacles. + +3. **Changing Car Color**: + - Press the "R" key to change the color of your car. Experiment with different colors to customize your ride! + +4. **Avoiding Collisions**: + - Be careful not to crash into other cars or obstacles on the track. Collisions may slow you down or even cause you to lose the race. + +5. **Scoring Points**: + - Earn points by playing as long as you can by avoiding obstacles. + +6. **Game Over**: + - The game ends when you complete the race or if your car crashes too many times. You can then view your race statistics. + +## Conclusion +Now that you know the controls and how to play, it's time to rev up your engines and hit the race track! Compete against other drivers, set new records, and become the ultimate champion! + +## FInal Flow Chart + +![image](images/flowchart%20final.png) + diff --git a/Tutorials/Car-Race-Tutorial/Step7-Updates in Car-race.md b/Tutorials/Car-Race-Tutorial/Step7-Updates in Car-race.md new file mode 100644 index 0000000..f225b14 --- /dev/null +++ b/Tutorials/Car-Race-Tutorial/Step7-Updates in Car-race.md @@ -0,0 +1,331 @@ +# Tutorial for Updated Car Race + + Important Notice : The previous car-racing need to be compiled successfully and working + + [Watch the Tutorial Video Of Updated Game](https://youtu.be/eWJ1rshG5yE) + +## 1. Updating car.cpp + +**Additions for Two Player Mode:** This update adds functionality to support a two-player mode in the game. + +- **new_car function:** When creating a new car, it now also initializes a second player's car with a different color (YELLOW), positioned slightly to the right of the first player's car. + +- **update_car function:** Updates the position of both player 1 and player 2 cars. If the game is paused (`game.paused` is true), it skips updating the cars. + +```cpp +// Additions for Two Player Mode +car_data new_car(car_model model, double speed, double x, double y) { + // ... + result.secondPlayer = new_car(YELLOW, speed, x + 100, y); + result.twoPlayer = true; + // ... +} + +void update_car(car_data &car) { + // Pause the game if it's paused + if (game.paused) return; + + // Update player 1 car + update_sprite(car.car_sprite); + + // Update player 2 car + if (car.twoPlayer) { + update_sprite(car.secondPlayer.car_sprite); + } +} +``` +![image](images/Two%20Playres%20together.png) + +## 2. Updating car.h + +**Additions for Two Player Mode:** Extends the `car_data` structure to support two-player mode. + +- **secondPlayer:** Stores the data for the second player's car. + +- **twoPlayer:** A boolean flag indicating whether the car is controlled by the second player. +```cpp +// Additions for Two Player Mode +struct car_data { + // ... + car_data secondPlayer; + bool twoPlayer; + // ... +}; +``` + +## 3. Updating game.h + +**Additions for Two Player Mode:** Extends the `game_data` structure to accommodate two-player mode. + +- **secondPlayer:** Stores the data for the second player's car. + +- **twoPlayer:** A boolean flag indicating whether the game is in two-player mode. + +- **paused:** A boolean flag indicating whether the game is currently paused. + +- **finished:** A boolean flag indicating whether the game has finished. + +- **finish_line:** Stores the sprite for the finish line. +```cpp +// Additions for Two Player Mode +struct game_data { + // ... + car_data secondPlayer; + bool twoPlayer; + bool paused; + bool finished; + sprite finish_line; +}; +``` +![image](images/game2.png) +![image](images/selectscreen.png) +![image](images/pause%20menu.png) +![image](images/levelup.png) + +## 4. Updating powerup.cpp +- powerup_bitmap Function: This function takes a powerup_type enum as input and returns the corresponding bitmap for the given powerup type. It uses a switch statement to select the appropriate bitmap based on the powerup type. + +- new_powerup Function: This function creates a new powerup with the specified type, speed, and position (x, y). It initializes a sprite for the powerup using the powerup_bitmap function, sets its position, type, and speed, and returns the resulting powerup_data structure. + +- draw_powerup Function: This function draws the powerup sprite on the screen. + +- update_powerup Function: This function updates the position of the powerup sprite by moving it vertically downwards based on its speed. + +- out_range_powerup Function: This function removes powerups from the vector powerups that have gone out of the visible range of the screen. It iterates through the vector and checks the y-coordinate of each powerup sprite. If it exceeds a certain threshold (600 in this case), the powerup is removed from the vector. + +```cpp +#include "splashkit.h" +#include +#include "powerup.h" + +int main() +{ + // Initialize SplashKit + open_window("Powerup Demo", 800, 600); + load_resource_bundle("powerup_bundle", "powerup_bundle.txt"); + + // Create a vector to store powerups + std::vector powerups; + + // Add some powerups to the vector + powerups.push_back(new_powerup(SHIELD, 5, 100, 100)); + powerups.push_back(new_powerup(SPEED_BOOST, 3, 200, 200)); + powerups.push_back(new_powerup(COIN, 4, 300, 300)); + + // Main game loop + while (not quit_requested()) + { + // Update powerups + for (auto &powerup : powerups) + { + update_powerup(powerup); + } + + // Clear the screen + clear_screen(COLOR_WHITE); + + // Draw powerups + for (auto &powerup : powerups) + { + draw_powerup(powerup); + } + + // Remove out-of-range powerups + out_range_powerup(powerups); + + // Refresh the screen + refresh_screen(); + delay(17); // Cap the frame rate to approximately 60 frames per second + } + + // Close SplashKit + close_window("Powerup Demo"); + return 0; +} + +``` +![image](images/Powerups%20display.png) + +## 5. Updating powerup.h +- The explanation of code as follows : +- powerup.h defines the structure and functions related to powerups in the game. +- powerup_data struct stores data for each powerup, including its sprite, type, and speed. +- The powerup_type enum lists different types of powerups available in the game. +- new_powerup function creates a new powerup with the specified type, speed, and position. +- draw_powerup function draws the powerup sprite on the screen. +- update_powerup function updates the powerup's position based on its speed. +- out_range_powerup function removes powerups that have gone out of range from the screen. +```cpp +#ifndef POWER_UP +#define POWER_UP + +#include "splashkit.h" +#include + +// Enumeration for different powerups +enum powerup_type +{ + SHIELD, + SPEED_BOOST, + SLOW_DOWN, + COIN +}; + +// Structure to store powerup data +struct powerup_data +{ + sprite powerup_sprite; // Sprite representing the powerup + powerup_type type; // Type of the powerup + double speed; // Speed of the powerup +}; + +// Function to create a new powerup +powerup_data new_powerup(powerup_type type, double speed, double x, double y); + +// Function to draw the powerup +void draw_powerup(powerup_data &powerup); + +// Function to update the powerup's position +void update_powerup(powerup_data &powerup); + +// Function to remove powerups that have gone out of range +void out_range_powerup(std::vector &powerups); + +#endif + +``` + + +## 6. Updating barricade.cpp +- Header Inclusions: Includes necessary headers such as "splashkit.h" for SplashKit functionalities and for vector data structure. +- Constants and Variables: Defines constants like gap_size and an array gap_locations to store possible positions for gaps in the barricades. previous_gap_location is initialized to an invalid value to ensure that the first gap location is chosen randomly. +- get_new_gap_location Function: Generates a random index to select a gap location from the gap_locations array, ensuring that the same gap location is not chosen consecutively. +- barricade_bitmap Function: Creates a bitmap representing a barricade with a gap. It selects a random gap location, draws the left and right parts of the barricade around the gap, sets up collision masks, and returns the resulting bitmap. +- new_barricade Function: Creates a new barricade with the specified speed and y-coordinate. It initializes a sprite using the bitmap generated by barricade_bitmap and sets its position and speed. +- draw_barricade Function: Draws the barricade sprite on the screen. +- update_barricade Function: Updates the position of the barricade sprite. +- out_range_barricade Function: Removes barricades from the vector barricades that have gone out of the visible range of the screen. + +```cpp +#include "splashkit.h" +#include +#include "barricade.h" + +// Define constants +#define gap_size 100 +double gap_locations[] = {250, 300, 350, 400, 450, 500, 550}; +double previous_gap_location = -1; + +// Function to get a new random gap location +double get_new_gap_location() +{ + int index; + do + { + index = rand() % 7; + } while (gap_locations[index] == previous_gap_location); + + previous_gap_location = gap_locations[index]; + return gap_locations[index]; +} + +// Function to create a bitmap for a barricade with a gap +bitmap barricade_bitmap() +{ + bitmap barricade_bitmap = create_bitmap("barricade3", 750, 40); + double gap_location = get_new_gap_location(); + + draw_bitmap_on_bitmap(barricade_bitmap, bitmap_named("barricade2"), 0, 0, option_part_bmp(0, 0, gap_location, 40)); + draw_bitmap_on_bitmap(barricade_bitmap, bitmap_named("barricade2"), gap_location + gap_size, 0, option_part_bmp(gap_location + gap_size, 0, 700 - gap_location - gap_size, 40)); + + setup_collision_mask(barricade_bitmap); + return barricade_bitmap; +} + +// Function to create a new barricade +barricade_data new_barricade(double speed, double y) +{ + barricade_data result; + result.barricade_sprite = create_sprite(barricade_bitmap()); + sprite_set_x(result.barricade_sprite, 50); + sprite_set_y(result.barricade_sprite, y); + sprite_set_dy(result.barricade_sprite, speed); + return result; +} + +// Function to draw the barricade +void draw_barricade(barricade_data &barricade) +{ + draw_sprite(barricade.barricade_sprite); +} + +// Function to update the barricade's position +void update_barricade(barricade_data &barricade) +{ + update_sprite(barricade.barricade_sprite); +} + +// Function to remove barricades that have gone out of range +void out_range_barricade(std::vector &barricades) +{ + for (int j = 0; j < barricades.size(); j++) + { + if (sprite_y(barricades[j].barricade_sprite) > 600) + { + barricades.erase(barricades.begin() + j); + j--; + } + } +} + + +``` + +![image](images/barricade%20and%20level%20up.png) + +## 7. Updating barricade.h +- The explanation of code as follows : +- barricade.h defines the structure and functions related to barricades in the game. +- barricade_data struct stores data for each barricade, including its sprite, speed, and gap location. +- new_barricade function creates a new barricade with the specified speed and initial position. +- draw_barricade function draws the barricade sprite on the screen. +- update_barricade function updates the barricade's position based on its speed. +- out_range_barricade function removes barricades that have gone out of range from the screen. + +```cpp +#ifndef BARRICADE +#define BARRICADE + +#include "splashkit.h" +#include + +// Structure to store barricade data +struct barricade_data +{ + sprite barricade_sprite; // Sprite representing the barricade + double speed; // Speed of the barricade + double gap_location; // Location of the gap in the barricade +}; + +// Function to create a new barricade +barricade_data new_barricade(double speed, double y); + +// Function to draw the barricade +void draw_barricade(barricade_data &barricade); + +// Function to update the barricade's position +void update_barricade(barricade_data &barricade); + +// Function to remove barricades that have gone out of range +void out_range_barricade(std::vector &barricades); + +#endif + +``` +## FInal Flow Chart + +![image](images/updated%20flow%20chart.png) + + +## 8. Conclusion +In conclusion, these code files provide a foundation for creating a dynamic and engaging car racing game with features such as multiple car models, powerups, obstacles, and two-player mode. By utilizing SplashKit's functionality and these code structures, developers can easily extend and customize the game to suit their preferences and requirements. \ No newline at end of file diff --git a/Tutorials/Car-Race-Tutorial/images/Folder2.png b/Tutorials/Car-Race-Tutorial/images/Folder2.png new file mode 100644 index 0000000..8f7c170 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/Folder2.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/Powerups display.png b/Tutorials/Car-Race-Tutorial/images/Powerups display.png new file mode 100644 index 0000000..dc6e924 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/Powerups display.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/Two Playres together.png b/Tutorials/Car-Race-Tutorial/images/Two Playres together.png new file mode 100644 index 0000000..393a56f Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/Two Playres together.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/barricade and level up.png b/Tutorials/Car-Race-Tutorial/images/barricade and level up.png new file mode 100644 index 0000000..9d8b5f6 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/barricade and level up.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/carrace-demo-01.png b/Tutorials/Car-Race-Tutorial/images/carrace-demo-01.png new file mode 100644 index 0000000..1c9b149 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/carrace-demo-01.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/carrace-gameover.png b/Tutorials/Car-Race-Tutorial/images/carrace-gameover.png new file mode 100644 index 0000000..9e7d198 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/carrace-gameover.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/flowchart step 2.png b/Tutorials/Car-Race-Tutorial/images/flowchart step 2.png new file mode 100644 index 0000000..875e280 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/flowchart step 2.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/flowchart final.png b/Tutorials/Car-Race-Tutorial/images/flowchart final.png new file mode 100644 index 0000000..4588b75 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/flowchart final.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/flowchart step 3.png b/Tutorials/Car-Race-Tutorial/images/flowchart step 3.png new file mode 100644 index 0000000..fac5fc7 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/flowchart step 3.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/flowchart step 4.png b/Tutorials/Car-Race-Tutorial/images/flowchart step 4.png new file mode 100644 index 0000000..1a78e11 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/flowchart step 4.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/flowchart step 5.png b/Tutorials/Car-Race-Tutorial/images/flowchart step 5.png new file mode 100644 index 0000000..b2c8bda Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/flowchart step 5.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/folder1.png b/Tutorials/Car-Race-Tutorial/images/folder1.png new file mode 100644 index 0000000..1cf2752 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/folder1.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/game.png b/Tutorials/Car-Race-Tutorial/images/game.png new file mode 100644 index 0000000..45e6236 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/game.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/game2.png b/Tutorials/Car-Race-Tutorial/images/game2.png new file mode 100644 index 0000000..6afb392 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/game2.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/homescreen.png b/Tutorials/Car-Race-Tutorial/images/homescreen.png new file mode 100644 index 0000000..b5268e5 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/homescreen.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/levelup.png b/Tutorials/Car-Race-Tutorial/images/levelup.png new file mode 100644 index 0000000..53e83f5 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/levelup.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/pause menu.png b/Tutorials/Car-Race-Tutorial/images/pause menu.png new file mode 100644 index 0000000..53fae33 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/pause menu.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/redcar.png b/Tutorials/Car-Race-Tutorial/images/redcar.png new file mode 100644 index 0000000..1bb7e1d Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/redcar.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/selectscreen.png b/Tutorials/Car-Race-Tutorial/images/selectscreen.png new file mode 100644 index 0000000..67ef749 Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/selectscreen.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/updated flow chart.png b/Tutorials/Car-Race-Tutorial/images/updated flow chart.png new file mode 100644 index 0000000..545b26a Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/updated flow chart.png differ diff --git a/Tutorials/Car-Race-Tutorial/images/yellowcar.png b/Tutorials/Car-Race-Tutorial/images/yellowcar.png new file mode 100644 index 0000000..bcd211b Binary files /dev/null and b/Tutorials/Car-Race-Tutorial/images/yellowcar.png differ