Updated and reformatted README
This commit is contained in:
1 parent
9b776f1ec9
commit
17b109e98e
3 files changed
+36
-18
No files matched your search
@@ -4,11 +4,12 @@ This is my attempt at building Conway's game of life in multiple languages.
|
|||||||
|
|
||||||
My first attempt is to do it in Python using Pygame and other libraries. I do plan on showcasing these on my website.
|
My first attempt is to do it in Python using Pygame and other libraries. I do plan on showcasing these on my website.
|
||||||
|
|
||||||
## Running with Python
|
## Setting up Python
|
||||||
|
|
||||||
To run the Python version I recommend that you set up a python virtual environment, you can do this with the following command
|
To run the Python version of this program, I recommend that you set up a python virtual environment. The current recommended Python version is Python 3.13 by Pygame. You can set up the virtual environment with the following command:
|
||||||
|
|
||||||
|
`python3.13 -m venv /path/to/virtual/environment`
|
||||||
|
|
||||||
`python<version> -m venv /path/to/virtual/environment`
|
|
||||||
|
|
||||||
After that you can use it to run the program and pip installs to get the libraries.
|
After that you can use it to run the program and pip installs to get the libraries.
|
||||||
|
|
||||||
@@ -16,16 +17,30 @@ After that you can use it to run the program and pip installs to get the librari
|
|||||||
|
|
||||||
The following commands should install any dependencies and ensure you are ready to run the program.
|
The following commands should install any dependencies and ensure you are ready to run the program.
|
||||||
|
|
||||||
`pip install --upgrade pip` - This will update pip to the version compatible with the virtual environment.
|
`pip install --upgrade pip`
|
||||||
|
- This will update pip to the version compatible with the virtual environment.
|
||||||
|
|
||||||
`pip install pygame pygame-menu pygbag numpy importlib` - This will install the dependencies needed for the project.
|
`pip install pygame pygame-menu numpy`
|
||||||
|
- This will install the dependencies needed for the project.
|
||||||
|
|
||||||
### Running the program
|
### Running the program
|
||||||
|
|
||||||
Running the program is fairly simple.
|
Running the program is fairly simple. Starting the program can be done with the following command:
|
||||||
|
|
||||||
Starting the program can be done with the following command:
|
`python -m src.main`
|
||||||
|
|
||||||
`python<version> -m src.main`
|
|
||||||
|
|
||||||
Once running the menu is fairly simple and some parts do not work at the moment. However once in game the right mouse will remove a cell and a left click will create a cell. To start the simulation you press the return button, this will prevent you from making new cells. the same button will stop the simulation in place. To clear the screen and stop the simulation if running simply press C. Escape will pause the game but the simulation will not stop. To exit press escape and follow prompts to quit the game.
|
### Basic Controls
|
||||||
|
|
||||||
|
Once running, the menu is fairly simple and some parts are still a work in progress. This can be navagated by using the Left mouse and clicking on the buttons on-screen to navigate.
|
||||||
|
|
||||||
|
Once in the game:
|
||||||
|
|
||||||
|
- Use Right mouse will remove a cell
|
||||||
|
- Use Left mouse will create a cell.
|
||||||
|
- Use Return/ Enter to start/stop the simulation
|
||||||
|
- NOTE: This will prevent you from making new cells while the simulation is running.
|
||||||
|
- Use C to clear the screen and stop the simulation.
|
||||||
|
- Use Escape to pause the game
|
||||||
|
- NOTE: The simulation will not stop.
|
||||||
|
- To exit press escape and follow prompts to quit the game.
|
||||||
Binary file not shown.
+12
-9
@@ -1,14 +1,13 @@
|
|||||||
import sys
|
import sys
|
||||||
import pygame
|
import pygame
|
||||||
#import pygbag used for serving on a website would need to change the code
|
|
||||||
import os
|
import os
|
||||||
import pygame_menu
|
import pygame_menu
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import math
|
import math
|
||||||
import random as rand
|
import random as rand
|
||||||
|
|
||||||
SCREEN_X = 1280
|
SCREEN_X = 1920
|
||||||
SCREEN_Y = 720
|
SCREEN_Y = 1080
|
||||||
SCREEN = None
|
SCREEN = None
|
||||||
MENU_X = 1
|
MENU_X = 1
|
||||||
MENU_Y = 1
|
MENU_Y = 1
|
||||||
@@ -54,16 +53,17 @@ def updateGame():
|
|||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
def drawRect(x,y, color):
|
def drawRect(x,y, color):
|
||||||
global CELL_SIZE
|
|
||||||
#Draw the rectangle
|
#Draw the rectangle
|
||||||
square = pygame.Rect((x,y, CELL_SIZE, CELL_SIZE))
|
square = pygame.Rect((x,y, CELL_SIZE, CELL_SIZE))
|
||||||
pygame.draw.rect(SCREEN, color, square)
|
pygame.draw.rect(SCREEN, color, square)
|
||||||
|
|
||||||
def drawGrid():
|
def drawGrid():
|
||||||
# Draw the grid lines only
|
# Draw the grid lines
|
||||||
for x in range(0, SCREEN.get_width(), 100):
|
gridOffset = CELL_SIZE * 10
|
||||||
|
for x in range(0, SCREEN.get_width(), gridOffset):
|
||||||
|
#(display,color, start, end)
|
||||||
pygame.draw.line(SCREEN, (0, 0, 60), (x, 0), (x, SCREEN.get_height()))
|
pygame.draw.line(SCREEN, (0, 0, 60), (x, 0), (x, SCREEN.get_height()))
|
||||||
for y in range(0, SCREEN.get_height(), 100):
|
for y in range(0, SCREEN.get_height(), gridOffset):
|
||||||
pygame.draw.line(SCREEN, (0, 0, 60), (0, y), (SCREEN.get_width(), y))
|
pygame.draw.line(SCREEN, (0, 0, 60), (0, y), (SCREEN.get_width(), y))
|
||||||
|
|
||||||
def displayMenu():
|
def displayMenu():
|
||||||
@@ -79,7 +79,10 @@ def displayMenu():
|
|||||||
def controlsMenu():
|
def controlsMenu():
|
||||||
SCREEN.fill((0, 0, 0))
|
SCREEN.fill((0, 0, 0))
|
||||||
menu = pygame_menu.Menu('Controls', MENU_X, MENU_Y, theme=MENU_THEME)
|
menu = pygame_menu.Menu('Controls', MENU_X, MENU_Y, theme=MENU_THEME)
|
||||||
menu.add.label('Controls coming soon')
|
menu.add.label('Esc - Goes to the settings / options menu')
|
||||||
|
menu.add.label('C - Clears the screen while in the game')
|
||||||
|
menu.add.label('Left mouse - Adds a cell to the screen while in the game')
|
||||||
|
menu.add.label('Right mouse - Removes a cell from the screen while in the game')
|
||||||
menu.add.button('Back', settingsMenu)
|
menu.add.button('Back', settingsMenu)
|
||||||
|
|
||||||
menu.mainloop(SCREEN)
|
menu.mainloop(SCREEN)
|
||||||
@@ -248,7 +251,7 @@ def main():
|
|||||||
pygame.init()
|
pygame.init()
|
||||||
try:
|
try:
|
||||||
#initialize the screen and set the height and widths
|
#initialize the screen and set the height and widths
|
||||||
SCREEN = pygame.display.set_mode((1920,1080), pygame.RESIZABLE | pygame.SCALED)
|
SCREEN = pygame.display.set_mode((SCREEN_X,SCREEN_Y), pygame.RESIZABLE | pygame.SCALED)
|
||||||
SCREEN_X, SCREEN_Y = SCREEN.get_size()
|
SCREEN_X, SCREEN_Y = SCREEN.get_size()
|
||||||
|
|
||||||
MENU_Y = .9 * SCREEN_Y
|
MENU_Y = .9 * SCREEN_Y
|
||||||
|
|||||||
Reference in new issue
Block a user