search
HomeWeb Front-endJS TutorialDyson Swarm: How I built a hard science fiction game with AWS services

A Hard Sci-Fi Clicker Game: Dyson Swarm

I'm a passionate science fiction enthusiast, having even run a sci-fi magazine for five years. This love led me to create a series of short games explaining complex sci-fi concepts in an engaging way. My first creation, Dyson Swarm, emerged during the AWS Game Builder Challenge.

Dyson Swarm is an incremental (clicker) game where players dismantle the solar system to construct a Dyson swarm – a megastructure encompassing the sun. Starting as a game developer, you gradually accumulate resources and advance through stages.

I initially estimated 10-20 hours of development, but the project expanded significantly, ultimately consuming around 70 hours (mostly late at night!). This highlights the challenge of accurate software development estimations.

You can play the game here: Dyson Swarm

AWS Architecture

Dyson Swarm: How I built a hard science fiction game with AWS services

The game uses client-side Javascript and runs entirely in the browser. Hosting is achieved using an S3 static site bucket, enhanced by CloudFront CDN for global, high-speed delivery. CloudFront handles TLS termination, simplifying the process.

Anonymous gameplay metrics (player count and progress) are stored in an RDS Postgres database. Data transmission uses a serverless API built with API Gateway and Lambda. While I used an existing RDS instance, serverless RDS would be equally suitable.

Deployment leveraged the AWS console for S3 and CloudFront, and an AWS CDK stack (Python) for the serverless metrics Lambda.

The CDK Stack

The CDK stack for the serverless metrics Lambda is concise:

from aws_cdk import (
    aws_lambda as lambda_,
    aws_apigateway as apigw,
    aws_ecr as ecr,
    aws_certificatemanager as acm,
    aws_route53 as route53,
    Duration,
    Stack)
from constructs import Construct
import os

class DysonSwarmStack(Stack):
    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        repo = ecr.Repository.from_repository_name(self, "dysonSwarmRepo", "gamesapi")

        dyson_swarm_lambda = lambda_.DockerImageFunction(self,
            "dysonSwarmLambda",
            code=lambda_.DockerImageCode.from_ecr(
                repository=repo,
                tag=os.environ["CDK_DOCKER_TAG"]
            ),
            memory_size=256,
            timeout=Duration.seconds(60),
            architecture=lambda_.Architecture.ARM_64
        )

        # do auth inside lambda
        api = apigw.LambdaRestApi(self,
            "dysonSwarm-endpoint",
            handler=dyson_swarm_lambda,
            default_cors_preflight_options=apigw.CorsOptions(allow_origins=["*"])
        )

        custom_domain = apigw.DomainName(
            self,
            "custom-domain",
            domain_name="gameapi.compellingsciencefiction.com",
            certificate=acm.Certificate.from_certificate_arn(self,'cert',"[cert ARN here]"),
            endpoint_type=apigw.EndpointType.EDGE
        )

        apigw.BasePathMapping(
            self,
            "base-path-mapping",
            domain_name=custom_domain,
            rest_api=api
        )

        hosted_zone = route53.HostedZone.from_hosted_zone_attributes(
            self,
            "hosted-zone",
            hosted_zone_id="[zone id here]",
            zone_name="compellingsciencefiction.com"
        )

        route53.CnameRecord(
            self,
            "cname",
            zone=hosted_zone,
            record_name="gameapi",
            domain_name=custom_domain.domain_name_alias_domain_name
        )

It leverages an existing ECR repository (containing the Lambda container image) and Route 53 hosted zone (for the custom domain). Essentially, it creates an API Gateway endpoint backed by a Lambda function. The full code is available at: dyson_swarm_stack.py

The Code

The complete game source code is on GitHub: Dyson Swarm GitHub Repo

The main game loop, found in dysonswarm.html, uses a 100-millisecond interval. Local browser storage (localStorage) handles game state persistence. Button functions (56 in total) are managed in buttonFunctions.js. Game animations, initially SVG, were transitioned to Canvas for better performance with a large number of elements. Thorough testing and iterative improvements addressed various edge cases in game logic.

Using AWS Q Developer

The AWS Game Builder Challenge encouraged using AWS Q Developer. I found it helpful:

Pros:

  • Intuitive chat interface for quick answers.
  • /dev feature generates and applies code diffs, streamlining development.
  • Effective at replicating code patterns.

Cons:

  • /dev feature can be slow due to multiple LLM calls.
  • /dev sometimes creates new files instead of in-line code additions. Careful prompt engineering is crucial.
  • Room for improvement, but shows significant potential.

Open-Source Game

The game's source code is available under the MIT license. Feel free to use it as a foundation for your projects. I welcome hearing about your game creations!

The above is the detailed content of Dyson Swarm: How I built a hard science fiction game with AWS services. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
JavaScript Comments: A Guide to Using // and /* */JavaScript Comments: A Guide to Using // and /* */May 13, 2025 pm 03:49 PM

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

Python vs. JavaScript: A Comparative Analysis for DevelopersPython vs. JavaScript: A Comparative Analysis for DevelopersMay 09, 2025 am 12:22 AM

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Python vs. JavaScript: Choosing the Right Tool for the JobPython vs. JavaScript: Choosing the Right Tool for the JobMay 08, 2025 am 12:10 AM

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript: Understanding the Strengths of EachPython and JavaScript: Understanding the Strengths of EachMay 06, 2025 am 12:15 AM

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScript's Core: Is It Built on C or C  ?JavaScript's Core: Is It Built on C or C ?May 05, 2025 am 12:07 AM

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript Applications: From Front-End to Back-EndJavaScript Applications: From Front-End to Back-EndMay 04, 2025 am 12:12 AM

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Python vs. JavaScript: Which Language Should You Learn?Python vs. JavaScript: Which Language Should You Learn?May 03, 2025 am 12:10 AM

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

JavaScript Frameworks: Powering Modern Web DevelopmentJavaScript Frameworks: Powering Modern Web DevelopmentMay 02, 2025 am 12:04 AM

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor