Git Product home page Git Product logo

cppnd-capstone-snake-game's Introduction

CPPND: Capstone Snake Game Example

This is a starter repo for the Capstone project in the Udacity C++ Nanodegree Program. The code for this repo was inspired by this excellent StackOverflow post and set of responses.

The Capstone Project gives you a chance to integrate what you've learned throughout this program. This project will become an important part of your portfolio to share with current and future colleagues and employers.

In this project, you can build your own C++ application or extend this Snake game, following the principles you have learned throughout this Nanodegree Program. This project will demonstrate that you can independently create applications using a wide range of C++ features.

Dependencies for Running Locally

Basic Build Instructions

  1. Clone this repo.
  2. Make a build directory in the top level directory: mkdir build && cd build
  3. Compile: cmake .. && make
  4. Run it: ./SnakeGame.

CC Attribution-ShareAlike 4.0 International

Shield: CC BY-SA 4.0

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

CC BY-SA 4.0

cppnd-capstone-snake-game's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cppnd-capstone-snake-game's Issues

A complement project to this project

Hello, I notice that this project just uses SDL2 library, but SDL2_Image and SDL2_ttf are also important in reality. So I create a new project using SDL2, SDL2_Image, and SDL2_ttf to improve the ability of this project by adding some game UI. I try to make my project simple enough so that any beginner can learn how to SDL2, SDL2_Image, and SDL2_ttf libraries to write some simple projects just like me. And as a beginner, my project must have some bugs, any suggestions are welcome. The address of my project is here.
Thank you!

C++ standard not specified in CMakeLists.txt

Had a minor issue building this project.

Adding the following to CMakeLists.txt solved the issue:
set (CMAKE_CXX_STANDARD 17)

Perhaps just an issue with my default setting but might be worth considering for ease of use.

Game::PlaceFood infinite loop

If the snake fills the entire screen upon eating the last food item (in other words, winning the game), Game::PlaceFood will run forever as it attempts to find an x and y value that aren't occupied by the snake.

Game::Game random_w & random_h has bug

Your random_w should be 0 to screen_width/grid_width and random_h should be 0 to
screen_height/grid_height. Otherwise, you will place food out of screen sometimes.

  random_w(0, static_cast<int>(screen_width/grid_width)),
  random_h(0, static_cast<int>(screen_width/grid_height)

Missing include SDL2 lib; also linker flag is missing

scenario 1; not included SDL2 dir;

fatal error: SDL.h: No such file or directory
    5 | #include "SDL.h"
      |          ^~~~~~~
compilation terminated.

scenario 2; included SDL2 dir but still linker error

fatal error: SDL.h: No such file or directory
    5 | #include "SDL.h"
      |          ^~~~~~~
compilation terminated.

game.cpp:(.text+0x12a): undefined reference to SDL_GetTicks' /usr/bin/ld: game.cpp:(.text+0x149): undefined reference to SDL_GetTicks'
/usr/bin/ld: game.cpp:(.text+0x1c3): undefined reference to SDL_GetTicks' /usr/bin/ld: game.cpp:(.text+0x22f): undefined reference to SDL_Delay'
/usr/bin/ld: CMakeFiles/SnakeGame.dir/src/controller.cpp.o: in function `Controller::HandleInput(bool&, Snake&) const':
...


Fixed by adding to CmakeLists.txt
`
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/include/SDL2")`

SDL_Error: Couldn't find matching render driver

After building the clean and untouched project using:
cmake .. && make
I received the following error:
Renderer could not be created. SDL_Error: Couldn't find matching render driver

I ran everything on the provided workspace with GPU enabled in the browser editor. I get the same error in the VS Code Terminal.

Does anyone have an idea what's going on?

Thanks for the feedback!

Compile on M1 Mac

hey guys!
Is there anyway to compile and run this repo on M1 Pro?
I keep running into issues when I attempt to do that.

Recommend Projects

  • React photo React

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

  • Vue.js photo Vue.js

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

  • Typescript photo Typescript

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

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

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

  • web

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

  • server

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

  • Machine learning

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

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

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

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.