Skip to content

xinchengo/GameDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twisty Snake & Wavy Fish(蛇卷卷和鱼摆摆)

简体中文

This game was developed for the C2 assignment for the Computer Programming A class I took.

Important Note: The game is currently available exclusively in Chinese. If you're interested in the concept, feel free to open an issue, and I will be happy to create an English version.

Theme

Game Play

The player controls a snake using the mouse cursor (the snake heads towards the direction of the mouse cursor). The goal is to eat all the fish. If the snake eats any of the green circles, the player loses the game.

Etymology

Twisty Snake & Wavy Fish is an oblique translation of the Chinese name of the game “蛇卷卷和鱼摆摆” (lit. snake twist-twist and fish swing-swing), where “卷” refers to “内卷” (lit. inward spiral), an informal term for a competitive rat race, and “摆” is an abbreviation of “摆烂” (lit. swing rotten), referring to giving up or slacking off. These terms describe common phenomena in Chinese schools and universities, where grades are of utmost importance.

“鱼摆摆” is also a term in the Sichuanese dialect of Mandarin, simply meaning 'fish,' but the additional characters are used to make it sound cuter.

Green circles(绿色圆圈) is a joke related to USTC (University of Science and Technology of China). The story goes that a student once asked the cafeteria staff what the green circles in the dishes were. They were just ordinary green peppers, but the student didn’t know this. This story reflects the student's lack of basic life knowledge, which is a common situation in universities like USTC, where students focus heavily on academics while neglecting other life skills.

Compilation & Installation

For Windows users, pre-compiled portable executables are available as Snake-x.x-win64.zip on the Releases page. The code is theoretically cross-platform, but since I only use a Windows machine, only the Windows executable is pre-compiled.

To compile the game yourself, you can refer to my GitHub Actions Workflow or follow the instructions below:

Step 1: Install vcpkg

git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install

Step 2: Install required libraries (for Linux, using Ubuntu as an example)

sudo apt update
sudo apt install autoconf libtool
sudo apt install libx11-dev libxrandr-dev libxcursor-dev libxi-dev libudev-dev libgl1-mesa-dev

Step 3: Use vcpkg to install necessary libraries

./vcpkg install sfml nlohmann-json clipper2 jhasse-poly2tri

Step 4: Build the project

Finally, enter the project directory and run the following commands to configure CMake and compile the game:

cmake -B ./build -DCMAKE_BUILD_TYPE="Release" -DVCPKG_ROOT="/path/to/vcpkg" -DCMAKE_TOOLCHAIN_FILE="/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake"
cmake --build ./build --config Release

Configurations

Configurations are stored in assets/config.json. It should look like this:

{
    "game": {},
    "swarm": {},
    "snake": {},
    "greenCircle": {}
}

Game Section

  • framerateLimit: The frame rate limit of the game.
  • pauseKey: The key to toggle between the pause and play states of the game.
  • delayWhenGameIsOver: Time to delay before the game-over (or win) screen appears, in seconds.
  • windowWidth, windowHeight: The width and height of the initial window of the game (in virtual pixels, i.e., physical pixels multiplied by scale).
  • scale, applyScaleInJSON: The game automatically scales the window, but users can specify a specific scale in config.json if desired.
  • toggleFullScreenKey: Key to toggle full screen.

Swarm Section

  • separationFactor, alignmentFactor, cohesionFactor, turnFactor, predatorRepulsionFactor, visualRange, avoidThresholdRange, edgeRange: These parameters control the Boids Simulation Model. You can refer to Swarm.cpp for more details.
  • speedLimit: The speed limit for the fish, in pixels per second.
  • disappearTimeAfterEaten: Time a fish remains on the screen after being eaten, turning white before disappearing.
  • fishColor: The color of the fish, in 0xRRGGBBAA format converted to decimal.

Snake Section

  • speed: Speed of the snake, in pixels per second.
  • circleSize: Radius of the snake's circle segments.
  • segmentSpacing: Distance between the centers of neighboring snake segments.
  • growthPerFish: Snake growth after eating a single fish, in segments.
  • maxTurnAngle: Maximum angle the snake can turn in one second, in radians.
  • coefficientOfPredatorMode: Maximum ratio of the distance between the first and last segment of the snake relative to the total length of the snake for the snake to eat a fish enclosed by its body and the line segment connecting its head and tail.
  • polygonIndicatorColor: The color of the indicator, in 0xRRGGBBAA format converted to decimal. This indicator shows the area within which a fish or green circle is eaten by the snake.

Green Circle Section

  • speedMin, speedMax: Minimum and maximum speed of the green circle.
  • radius: Radius of the green circle.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

This project uses the following open-source libraries:

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published