AWS Logo
Menu
Building a Sprite-Based Snake Xenzia Game with Amazon Q CLI

Building a Sprite-Based Snake Xenzia Game with Amazon Q CLI

This blog is about using Amazon Q CLI to build Snake Xenzia game using pygame library with multiple game elements

Published May 29, 2025
Introduction:
Welcome to a nostalgic trip down memory lane! Inspired by the vibrant AWS community and brilliant LinkedIn posts from Shafraz Rahim, Omshree Butani, and Srinivasan Chinnachamy, I embarked on a fun journey to recreate the iconic Snake Xenzia for the AWS Game Builder Challenge (https://lnkd.in/gn6_6mgs). Using the power of Amazon Q CLI, I built a sprite-based game with Python and Pygame, featuring a neon-green snake, glowing gold food, and classic gameplay that echoes the Nokia phone era. With simple prompts like q "Create a Pygame Snake game with sprite visuals and highlighted food", I crafted a retro masterpiece in hours, complete with smooth controls and score tracking. A huge shoutout to the AWS community for sparking this idea! Join me as I dive into how Amazon Q CLI made this retro adventure a reality—read on to explore the code, prompts, and nostalgic fun!
Coding
coding
GAMING:
The Snake Xenzia game environment, built with Python and Pygame using Amazon Q CLI, transports players back to the pixelated charm of Nokia phones. Designed to evoke nostalgia while showcasing modern development ease, this sprite-based game creates a simple yet captivating world. Let’s break down the key components of the game environment as crafted from the code, highlighting how Amazon Q CLI brought this retro adventure to life.

1. Display and Dimensions

The game runs on a 640x480 pixel window, mimicking the compact screens of early mobile phones. This resolution, set with pygame.display.set_mode((WIDTH, HEIGHT)), strikes a balance between retro aesthetics and modern playability. The window, titled “Sprite Theme Snake Game with Highlighted Food,” sets the stage for a nostalgic experience. The environment operates on a 20x20 pixel grid (derived from WIDTH//20 and HEIGHT//20 for food spawning), ensuring the snake and food snap to discrete positions for that classic, blocky feel.

2. Visual Aesthetics

The game’s visual environment is defined by its sprite-based elements, created using Pygame surfaces to emulate pixel-art graphics:
  • Snake: The snake is rendered as a series of neon-green squares (snake_sprite = create_surface((0, 255, 0), (20, 20))), giving it a vibrant, retro look reminiscent of early arcade games. Each segment is a 20x20 pixel sprite, drawn at positions stored in snake_body (initially [[100, 50], [80, 50], [60, 50]]).
  • Food: The food appears as a red square sprite (food_sprite = create_surface((255, 0, 0), (20, 20))), enhanced by a glowing gold outline (HIGHLIGHT = (255, 215, 0)). This outline, drawn as a 26x26 pixel rectangle (highlight_rect) with a 3-pixel border, makes the food pop against the black background, adding visual flair.
  • Background: The screen is filled with black (screen.fill((0, 0, 0))), creating a stark, high-contrast canvas that emphasizes the neon sprites, much like the monochromatic displays of old Nokia phones.
These visuals, generated with the prompt q "Create a Pygame Snake game with sprite visuals and highlighted food", capture the essence of Snake Xenzia’s simplicity while adding a modern sprite-based twist.

3. Gameplay Mechanics

The game environment is governed by classic Snake mechanics, enhanced by sprite visuals and smooth controls:
  • Snake Movement: The snake starts at position [100, 50] and moves in 20-pixel increments based on arrow key inputs (pygame.KEYDOWN events). The direction variable (RIGHT initially) ensures the snake moves only up, down, left, or right, with restrictions to prevent reversing (e.g., can’t move DOWN if going UP).
  • Food Spawning: Food spawns randomly on the grid (random.randrange(1, WIDTH//20) * 20), ensuring alignment with the snake’s movement. When the snake’s head (snake_pos) matches the food’s position (food_pos), the score increases, and new food appears without the snake losing a segment.
  • Growth and Collision: The snake grows by adding a new head segment (snake_body.insert(0, list(snake_pos))) when eating food, while non-food moves remove the tail (snake_body.pop()). Collisions with walls (snake_pos[0] < 0 or snake_pos[0] >= WIDTH) or the snake’s body (for block in snake_body[1:]) trigger a game-over, exiting via pygame.quit().
  • Speed: The game runs at 10 frames per second (clock.tick(FPS)), providing a deliberate, nostalgic pace akin to early mobile games.

4. User Interface

The environment includes a minimal but effective UI:
  • Score Display: A score (score += 1 per food eaten) is shown in the top-left corner using an Arial font (font = pygame.font.SysFont('Arial', 24)), rendered in white (score_surface). This keeps players engaged without cluttering the screen.
  • Controls: Arrow keys control the snake’s direction, detected via pygame.KEYDOWN events, offering intuitive gameplay familiar to Snake fans.

5. Amazon Q CLI’s Role

The environment was shaped by Amazon Q CLI’s generative AI, turning prompts into functional code. For example:
  • q "Write a Pygame Snake game with sprite visuals and highlighted food" generated the core game loop, sprite surfaces, and glowing food effect.
  • If issues arose, such as food spawning on the snake, a prompt like q "Ensure food doesn’t spawn on the snake in my Pygame Snake game" could refine the logic (though not implemented in the provided code).
This streamlined development, making it accessible for cloud engineers and game enthusiasts alike, as noted in my journey inspired by the AWS Game Builder Challenge.

6. Potential Enhancements

While the current environment is a polished single-level game, I envisioned adding features from my original plan (inspired by the AWS community):
  • Difficulty Levels: Easy, medium, and hard modes with varying FPS (e.g., 8, 10, 15).
  • Obstacles: L-shaped corner obstacles or rectangular barriers, as mentioned in my document, using prompts like q "Add L-shaped obstacles to my Pygame Snake game".
  • Bonus Food: Timed bonus food with higher points, inspired by Nokia 1100’s special items.
  • Web Adaptation: To align with the title’s “web adventure,” the game could be ported to JavaScript/HTML5 Canvas for browser play, using a prompt like q "Convert my Pygame Snake game to JavaScript with sprite visuals".

7. Retro Charm and Future Vision

The game environment captures the essence of Snake Xenzia with its neon-green snake and glowing food against a stark black backdrop, evoking Nokia phone memories. Hosted on a GitHub repo (https://github.com/Gowtham280103/SnakeXenzia-QCLI
), it’s ready for forking and customization. Future plans include deploying a web version on AWS Amplify and adding a DynamoDB leaderboard, showcasing Amazon Q CLI’s versatility beyond game development.
GAME LOOK AND OUTPUT DATAS:
PROMPTS USED:
  1. "Write a Pygame Snake game with sprite visuals and highlighted food"
  2. "Could you save this program to a file in documents folder on my machine?"
  3. "Ensure food doesn’t spawn on the snake in my Pygame Snake game"
  4. "Add a score display in the top-left corner of my Pygame Snake game using Arial font"
  5. "Make the food in my Pygame Snake game have a glowing gold outline"
  6. "Set the snake to move in 20-pixel increments on a grid in my Pygame Snake game"
  7. "Add collision detection for walls and the snake’s body in my Pygame Snake game"
CONCLUSION:
Creating this sprite-based Snake Xenzia game with Amazon Q CLI was a thrilling blend of nostalgia and modern tech! Simple prompts brought a neon-green snake and glowing gold food to life, capturing the classic Nokia vibe in just a few hours. The AWS Game Builder Challenge inspired this project, and I’m grateful for the spark from the AWS community. Fork the code at https://github.com/Gowtham280103/SnakeXenzia-QCLI, play the game, and share your high scores! This is just the beginning—future plans include a web version and more features. Keep exploring, coding, and gaming! 🐍
 

Comments