diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b1d6220 --- /dev/null +++ b/.gitignore @@ -0,0 +1,968 @@ +# Created by https://www.toptal.com/developers/gitignore/api/vim,node,data,emacs,python,pycharm,executable,sublimetext,visualstudio,visualstudiocode +# Edit at https://www.toptal.com/developers/gitignore?templates=vim,node,data,emacs,python,pycharm,executable,sublimetext,visualstudio,visualstudiocode + +### Data ### +*.csv +*.dat +*.efx +*.gbr +*.key +*.pps +*.ppt +*.pptx +*.sdf +*.tax2010 +*.vcf +*.xml + +### Emacs ### +# -*- mode: gitignore; -*- +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# flymake-mode +*_flymake.* + +# eshell files +/eshell/history +/eshell/lastdir + +# elpa packages +/elpa/ + +# reftex files +*.rel + +# AUCTeX auto folder +/auto/ + +# cask packages +.cask/ +dist/ + +# Flycheck +flycheck_*.el + +# server auth directory +/server/ + +# projectiles files +.projectile + +# directory configuration +.dir-locals.el + +# network security +/network-security.data + + +### Executable ### +*.app +*.bat +*.cgi +*.com +*.exe +*.gadget +*.jar +*.pif +*.vb +*.wsf + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +### Node Patch ### +# Serverless Webpack directories +.webpack/ + +# Optional stylelint cache + +# SvelteKit build / generate output +.svelte-kit + +### PyCharm ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### PyCharm Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# Azure Toolkit for IntelliJ plugin +# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij +.idea/**/azureSettings.xml + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +### Python Patch ### +# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration +poetry.toml + +# ruff +.ruff_cache/ + +### SublimeText ### +# Cache files for Sublime Text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# Workspace files are user-specific +*.sublime-workspace + +# Project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using Sublime Text +# *.sublime-project + +# SFTP configuration file +sftp-config.json +sftp-config-alt*.json + +# Package control specific files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +Package Control.merged-ca-bundle +Package Control.user-ca-bundle +oscrypto-ca-bundle.crt +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +*.code-workspace + +# Local History for Visual Studio Code + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + +### VisualStudio Patch ### +# Additional files built by Visual Studio + +# End of https://www.toptal.com/developers/gitignore/api/vim,node,data,emacs,python,pycharm,executable,sublimetext,visualstudio,visualstudiocode +.markata.cache +cave_survival/__pycache__ +cave_survival/__pycache__ +cave_survival/__pycache__ +cave_survival/__pycache__ +cave_survival/__pycache__ +cave_survival/__pycache__/run.cpython-310.pyc diff --git a/axe.png b/axe.png new file mode 100644 index 0000000..84a3f7f Binary files /dev/null and b/axe.png differ diff --git a/background.png b/background.png new file mode 100644 index 0000000..cd5cf58 Binary files /dev/null and b/background.png differ diff --git a/bluedot.png b/bluedot.png new file mode 100644 index 0000000..3abc07a Binary files /dev/null and b/bluedot.png differ diff --git a/cave_survival/__pycache__/run.cpython-310.pyc b/cave_survival/__pycache__/run.cpython-310.pyc index bdf7bbc..13f33f4 100644 Binary files a/cave_survival/__pycache__/run.cpython-310.pyc and b/cave_survival/__pycache__/run.cpython-310.pyc differ diff --git a/cave_survival/map.py b/cave_survival/map.py new file mode 100644 index 0000000..541cf81 --- /dev/null +++ b/cave_survival/map.py @@ -0,0 +1,90 @@ +from noise import snoise2 +import pydantic +import pygame +from rich.console import Console + +console = Console() + +# Generate the map using perlin noise + +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +GREY = (128, 128, 128) +RED = (255, 128, 128) + + +class Point(pydantic.BaseModel): + x: int + y: int + + +class Map: + def __init__(self): + self.resolution = 32 + self.scale = 0.1 # Determines the "smoothness" of the terrain + self.offset = Point(x=0, y=0) + self.last_offset = self.offset + # self.width = int(screen_width / self.resolution) + # self.height = int(screen_height / self.resolution) + self.screen_width = 800 + self.screen_height = 600 + self.octaves = 6 # Number of layers of noise to combine + self.persistence = 0.5 # Amplitude of each octave + self.lacunarity = 2.0 # Frequency of each octave + self.thresh = 128 + self.surf = pygame.Surface( + (self.screen_width / self.resolution, self.screen_height / self.resolution) + ) + self.pre_draw() + + # self.noise_map = self.generate_noise_map() + + # def generate_noise_map(self): + + # noise_map = [ + # [self.get_noise(x, y) for x in range(self.width)] + # for y in range(self.height) + # ] + # return noise_map + + def get_noise(self, x, y): + value = snoise2( + (x + self.offset.x) * self.scale, + (y + self.offset.y) * self.scale, + self.octaves, + self.persistence, + self.lacunarity, + ) + value = (value + 1) / 2 * 255 + return value + + def draw(self, screen): + # if self.last_offset != self.offset: + # self.last_offset = self.offset + screen.blit( + pygame.transform.scale(self.surf, (self.screen_width, self.screen_height)), + (0, 0), + ) + + def point_check_collision(self, x, y): + return self.get_noise(x / self.resolution, y / self.resolution) < self.thresh + + def pre_draw(self): + console.log("drawing") + self.surf = pygame.Surface((self.screen_width, self.screen_height)) + for x in range(self.screen_width): + for y in range(self.screen_height): + if not self.point_check_collision(x, y): + pygame.draw.rect( + self.surf, + WHITE, + ( + x, + y, + 1, + 1, + # self.resolution, + # self.resolution, + ), + ) + pygame.image.save(self.surf, "map.png") diff --git a/cave_survival/run.py b/cave_survival/run.py index aa5e0c9..db2ee10 100644 --- a/cave_survival/run.py +++ b/cave_survival/run.py @@ -1,78 +1,2 @@ -import pygame - - def run(): - # Initialize Pygame - pygame.init() - - # Set the window size and caption - size = (700, 500) - caption = "Pygame Image Movement" - screen = pygame.display.set_mode(size) - pygame.display.set_caption(caption) - - # Load an image and get its rectangle - image1 = pygame.image.load("cave_survival/assets/stev/1.png") - image2 = pygame.image.load("cave_survival/assets/stev/2.png") - image_rect = image1.get_rect() - - # Set the initial position of the image - image_rect.x = 350 - image_rect.y = 250 - movement_speed = 0.5 - - # Set the animation speed - animation_speed = 0.005 - - # Set the animation frame - animation_frame = 0 - - # Set the movement speed - movement_speed = 0.5 - - # Main game loop - running = True - while running: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - running = False - - # Get the current key presses - pressed = pygame.key.get_pressed() - - # Move the image based on the key presses - if pressed[pygame.K_w]: - image_rect.y -= movement_speed - if pressed[pygame.K_a]: - image_rect.x -= movement_speed - if pressed[pygame.K_s]: - image_rect.y += movement_speed - if pressed[pygame.K_d]: - image_rect.x += movement_speed - - # Animate the image if the player is moving - if ( - pressed[pygame.K_w] - or pressed[pygame.K_a] - or pressed[pygame.K_s] - or pressed[pygame.K_d] - ): - animation_frame += animation_speed - if animation_frame >= 2: - animation_frame = 0 - - image_rect.x += movement_speed - - # Draw the image on the screen - screen.fill((0, 0, 0)) - if animation_frame < 1: - screen.blit(image1, image_rect) - else: - screen.blit(image2, image_rect) - else: - screen.fill((0, 0, 0)) - screen.blit(image1, image_rect) - pygame.display.flip() - - # Clean up - pygame.quit() + from cave_survival import underground diff --git a/cave_survival/underground.py b/cave_survival/underground.py new file mode 100644 index 0000000..b3173b8 --- /dev/null +++ b/cave_survival/underground.py @@ -0,0 +1,266 @@ +from pydantic import BaseModel +import pygame +from rich.console import Console + +from cave_survival.map import Map, Point + +console = Console() + +# Initialize pygame +pygame.init() + +# Set up the display +screen_width = 800 +screen_height = 600 +screen = pygame.display.set_mode((screen_width, screen_height)) +pygame.display.set_caption("Underground Survival") + +# Set up the clock +clock = pygame.time.Clock() + +# Set up the colors +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +GREY = (128, 128, 128) +RED = (255, 128, 128) + +# Set up the player + + +class Collisions(BaseModel): + top: bool = False + right: bool = False + bottom: bool = False + left: bool = False + + +class Player: + def __init__(self): + self.width = 16 + self.height = 16 + self.x = screen_width / 2 + self.y = screen_height / 2 + self.speed = 5 + self.image = pygame.image.load("player.png").convert_alpha() + self.x_last = self.x + self.y_last = self.y + self.hitbox_surface = pygame.Surface((self.width, self.height)) + self.hitbox_surface.fill(WHITE) + pygame.draw.rect( + self.hitbox_surface, (255, 0, 0), (0, 0, self.width, self.height), 1 + ) + self.hitbox_surface.set_alpha(0) + + def draw(self, surface, offset): + surface.blit( + pygame.transform.scale(self.image, (16, 16)), + (self.x - 8 - offset.x, self.y - 8 - offset.y), + ) + + +# def generate_perlin_noise(width, height, scale): +# map.noise_map = [[0 for y in range(height)] for x in range(width)] +# for i in range(width): +# for j in range(height): +# map.noise_map[i][j] = noise.pnoise2( +# i / float(scale), +# j / float(scale), +# octaves=6, +# persistence=0.5, +# lacunarity=2.0, +# repeatx=1024, +# repeaty=1024, +# base=0, +# ) +# return map.noise_map + + +player = Player() + +# Set up the enemies +enemy_width = 32 +enemy_height = 32 +enemy_speed = 2 +enemy_image = pygame.image.load("enemy.png").convert_alpha() + +# Set up the items +item_width = 32 +item_height = 32 +item_image = pygame.image.load("item.png").convert_alpha() + +# Set up the day/night cycle +day_length = 60 * 60 # 60 seconds * 60 frames +day_timer = 0 + +# Set up the inventory +inventory = ["sword", "pickaxe", "axe"] + +# Set up the map + +map = Map() +map_image = pygame.image.load("map.png").convert_alpha() + +# Set up the inventory surface +inventory_surface = pygame.Surface((len(inventory) * 32, 32)) +inventory_surface.fill(GREY) + +# Generate the map using perlin noise +# map.noise_map = [[0 for x in range(map.width)] for y in range(map.height)] +# map.noise_map = generate_perlin_noise(map.width, map.height, map.scale) +# for x in range(map.width): +# for y in range(map.height): +# map.noise_map[x][y] = random.randint(0, 255) + +# Make sure the player starts on a white block +# while ( +# map.noise_map[int(player.x / map.resolution)][int(player.y / map.resolution)] +# < map.thresh +# ): + +# while map.point_check_collision(player.pos.x, player.pos.y): +# player.x += 1 +# player.y += 1 +# player.x -= 1 +# player.y -= 1 + +# Main game loop +running = True +while running: + # Handle events + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + # Update the day/night cycle + day_timer += 1 + if day_timer > day_length: + day_timer = 0 + + # Update the player + keys = pygame.key.get_pressed() + if keys[pygame.K_w]: + player.y -= player.speed + if keys[pygame.K_s]: + player.y += player.speed + if keys[pygame.K_a]: + player.x -= player.speed + if keys[pygame.K_d]: + player.x += player.speed + + # Check for player collisions with the walls and the black tiles on the map + collisions = Collisions() + if player.x < 0: + player.x = 0 + collisions.left = True + if player.x > screen_width - player.width: + player.x = screen_width - player.width + collisions.right = True + if player.y < 0: + player.y = 0 + collisions.top = True + if player.y > screen_height - player.height: + player.y = screen_height - player.height + collisions.bottom = True + + player.pos = pygame.math.Vector2(player.x, player.y) + + if map.point_check_collision(player.pos.x, player.pos.y): + + start_pos = pygame.math.Vector2(player.x_last, player.y_last) + end_pos = pygame.math.Vector2(player.x, player.y) + movement_vector = end_pos - start_pos + try: + movement_direction = movement_vector.normalize() + except: + end_pos = pygame.math.Vector2(player.x + 128, player.y + 128) + movement_vector = end_pos - start_pos + movement_direction = movement_vector.normalize() + movement_speed = 0.05 + + player.x = player.x_last + player.y = player.y_last + + player.pos = pygame.math.Vector2(start_pos) + + while map.point_check_collision(player.pos.x, player.pos.y): + # map.noise_map[int(player.pos.x / map.resolution)][ + # int(player.pos.y / map.resolution) + # ] < + # map.thresh + # ): + print("moving") + print(movement_speed) + print(movement_direction) + + player.pos += movement_speed * movement_direction + player.x = player.pos.x + player.y = player.pos.y + + player.pos -= movement_speed * movement_direction + player.x = player.pos.x + player.y = player.pos.y + + player.x_last = player.x + player.y_last = player.y + + # Update the enemies + # for enemy in enemies: + # enemy_x += enemy_speed + # enemy_y += enemy_speed + + # Draw the screen + screen.fill(BLACK) + + # Draw the map + map.offset = Point(x=player.x, y=player.y) + map.offset = Point(x=0, y=0) + map.draw(screen) + + # Draw the player + player.draw(screen, offset=map.offset) + + # Draw the enemies + # for enemy in enemies: + # screen.blit(enemy_image, (enemy_x, enemy_y)) + + # Draw the items + # for item in items: + # screen.blit(item_image, (item_x, item_y)) + + # Draw the inventory + for i, item_name in enumerate(inventory): + inventory_surface.blit( + pygame.image.load(item_name + ".png").convert_alpha(), (i * 32, 0) + ) + screen.blit( + inventory_surface, + ( + screen_width / 2 - inventory_surface.get_width() / 2, + screen_height - inventory_surface.get_height(), + ), + ) + + # Draw the day/night cycle + pygame.draw.rect(screen, GREY, (0, 0, day_timer / day_length * screen_width, 10)) + + # collision debug + # top + + # pygame.draw.rect(screen, RED, (0, 0, screen_width, 5)) + # # bottom + # pygame.draw.rect(screen, RED, (0, screen_height - 5, screen_width, 5)) + # # left + # pygame.draw.rect(screen, RED, (0, 0, 5, screen_height)) + # # right + # pygame.draw.rect(screen, RED, (screen_width - 5, 0, 5, screen_height)) + + # Update the display + pygame.display.flip() + + # Limit the framerate + clock.tick(60) + # console.log(clock.get_fps()) + + +# Quit pygame +pygame.quit() diff --git a/enemy.png b/enemy.png new file mode 100644 index 0000000..c221f10 Binary files /dev/null and b/enemy.png differ diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..1037a77 Binary files /dev/null and b/icon.png differ diff --git a/item.png b/item.png new file mode 100644 index 0000000..3abc07a Binary files /dev/null and b/item.png differ diff --git a/map.png b/map.png new file mode 100644 index 0000000..86e6fa2 Binary files /dev/null and b/map.png differ diff --git a/move_along_line.py b/move_along_line.py new file mode 100644 index 0000000..062f1cd --- /dev/null +++ b/move_along_line.py @@ -0,0 +1,108 @@ +import pygame + +# Initialize Pygame +pygame.init() + +clock = pygame.time.Clock() +# Set the window size and caption +WINDOW_SIZE = (500, 500) +screen = pygame.display.set_mode(WINDOW_SIZE) +pygame.display.set_caption("Moving circle along a line") + +# Define some colors +WHITE = (255, 255, 255) +BLACK = (0, 0, 0) + +# Set up the starting position and ending position of the line +start_pos = (50, 300) +end_pos = (400, 400) + +end_pos = (50, 300) +start_pos = (400, 400) + +# Set up the circle's initial position and movement speed +circle_pos = start_pos +circle_radius = 20 +movement_speed = 5 + +# # Game loop +# running = True +# while running: +# # Handle events +# for event in pygame.event.get(): +# if event.type == pygame.QUIT: +# running = False + +# # Clear the screen +# screen.fill(WHITE) + +# # Draw the line +# pygame.draw.line(screen, BLACK, start_pos, end_pos) + +# # Draw the circle at its current position +# pygame.draw.circle(screen, BLACK, circle_pos, circle_radius) + +# # Move the circle along the line +# movement_vector = pygame.math.Vector2( +# end_pos[0] - start_pos[0], end_pos[1] - start_pos[1] +# ) +# movement_direction = movement_vector.normalize() +# circle_pos = ( +# circle_pos[0] + movement_speed * movement_direction.x, +# circle_pos[1] + movement_speed * movement_direction.y, +# ) + +# # Check if the circle has reached the end of the line +# if circle_pos.distance_to(end_pos) < movement_speed: +# circle_pos = end_pos +# running = False +# # Update the display +# pygame.display.update() + +# clock.tick(60) + +# # Quit Pygame +# pygame.quit() + +# Set up the starting position and ending position of the line +start_pos = pygame.math.Vector2(50, 50) +end_pos = pygame.math.Vector2(400, 400) + +# Set up the circle's initial position +circle_pos = pygame.math.Vector2(start_pos) + +# Game loop +running = True +while running: + # Handle events + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + # Clear the screen + screen.fill(WHITE) + + # Draw the line + pygame.draw.line(screen, BLACK, start_pos, end_pos) + + # Draw the circle at its current position + pygame.draw.circle( + screen, BLACK, [int(circle_pos.x), int(circle_pos.y)], circle_radius + ) + + # Move the circle along the line + movement_vector = end_pos - start_pos + movement_direction = movement_vector.normalize() + circle_pos += movement_speed * movement_direction + + # Check if the circle has reached the end of the line + if circle_pos.distance_to(end_pos) < movement_speed: + circle_pos = end_pos + running = False + + # Update the display + pygame.display.update() + clock.tick(60) + +# Quit Pygame +pygame.quit() diff --git a/pickaxe.png b/pickaxe.png new file mode 100644 index 0000000..930e0ad Binary files /dev/null and b/pickaxe.png differ diff --git a/player.png b/player.png new file mode 100644 index 0000000..0d4b500 Binary files /dev/null and b/player.png differ diff --git a/pyproject.toml b/pyproject.toml index 4b3ac5c..581d051 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,8 @@ dependencies = [ "pygame", "typer", "rich", + "pydantic", + 'noise', ] dynamic = ["version"] diff --git a/sword.png b/sword.png new file mode 100644 index 0000000..c2ee937 Binary files /dev/null and b/sword.png differ diff --git a/unnamed.png b/unnamed.png new file mode 100644 index 0000000..930e0ad Binary files /dev/null and b/unnamed.png differ