From: Skullheadx <94652084+Skullheadx@users.noreply.github.com>
Date: Wed, 5 Jul 2023 00:31:27 +0000 (-0400)
Subject: remove unnecessary
X-Git-Tag: game
X-Git-Url: http://git.skullheadx.com/about.html?a=commitdiff_plain;h=e406bdea89bc23e4f9490be1a1b8a89feba4499e;p=fruit-ninja.git
remove unnecessary
---
diff --git a/.gitattributes b/.gitattributes
deleted file mode 100644
index dfe0770..0000000
--- a/.gitattributes
+++ /dev/null
@@ -1,2 +0,0 @@
-# Auto detect text files and perform LF normalization
-* text=auto
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 3eb56cb..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,152 +0,0 @@
-# Byte-compiled / optimized / DLL files
-__pycache__/
-*.py[cod]
-*$py.class
-
-# C extensions
-*.so
-
-# Distribution / packaging
-.Python
-build/
-develop-eggs/
-dist/
-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.*
-.cache
-nosetests.xml
-coverage.xml
-*.cover
-*.py,cover
-.hypothesis/
-.pytest_cache/
-cover/
-
-# Translations
-*.mo
-*.pot
-
-# Django stuff:
-*.log
-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
-
-# PEP 582; used by e.g. github.com/David-OConnor/pyflow
-__pypackages__/
-
-# Celery stuff
-celerybeat-schedule
-celerybeat.pid
-
-# SageMath parsed files
-*.sage.py
-
-# Environments
-.env
-.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 maintainted 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/
diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 13566b8..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
diff --git a/.idea/fruit-ninja.iml b/.idea/fruit-ninja.iml
deleted file mode 100644
index 74d515a..0000000
--- a/.idea/fruit-ninja.iml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
deleted file mode 100644
index 105ce2d..0000000
--- a/.idea/inspectionProfiles/profiles_settings.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 74740ed..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 8571d5f..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 35eb1dd..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/__pycache__/bomb.cpython-310.pyc b/__pycache__/bomb.cpython-310.pyc
deleted file mode 100644
index 92b9456..0000000
Binary files a/__pycache__/bomb.cpython-310.pyc and /dev/null differ
diff --git a/__pycache__/combo_counter.cpython-310.pyc b/__pycache__/combo_counter.cpython-310.pyc
deleted file mode 100644
index 130fbfe..0000000
Binary files a/__pycache__/combo_counter.cpython-310.pyc and /dev/null differ
diff --git a/__pycache__/effect.cpython-310.pyc b/__pycache__/effect.cpython-310.pyc
deleted file mode 100644
index 63a96c4..0000000
Binary files a/__pycache__/effect.cpython-310.pyc and /dev/null differ
diff --git a/__pycache__/fruit.cpython-310.pyc b/__pycache__/fruit.cpython-310.pyc
deleted file mode 100644
index fc2ac08..0000000
Binary files a/__pycache__/fruit.cpython-310.pyc and /dev/null differ
diff --git a/__pycache__/game.cpython-310.pyc b/__pycache__/game.cpython-310.pyc
deleted file mode 100644
index d748347..0000000
Binary files a/__pycache__/game.cpython-310.pyc and /dev/null differ
diff --git a/__pycache__/menu.cpython-310.pyc b/__pycache__/menu.cpython-310.pyc
deleted file mode 100644
index 6c7e77d..0000000
Binary files a/__pycache__/menu.cpython-310.pyc and /dev/null differ
diff --git a/__pycache__/player.cpython-310.pyc b/__pycache__/player.cpython-310.pyc
deleted file mode 100644
index 24a73e2..0000000
Binary files a/__pycache__/player.cpython-310.pyc and /dev/null differ
diff --git a/__pycache__/setup.cpython-310.pyc b/__pycache__/setup.cpython-310.pyc
deleted file mode 100644
index fcb1cda..0000000
Binary files a/__pycache__/setup.cpython-310.pyc and /dev/null differ
diff --git a/bomb.py b/bomb.py
deleted file mode 100644
index 133934e..0000000
--- a/bomb.py
+++ /dev/null
@@ -1,108 +0,0 @@
-from fruit import Fruit
-from setup import *
-
-
-class Bomb(Fruit):
- RADIUS = 100 * SCALE.x
-
- EXPLOSION_RADIUS = RADIUS * 10
- POWER = 75
-
- BOMB_IMAGE = pygame.image.load("assets/bomb.png").convert_alpha()
- BOMB_TXT = Texture.from_surface(renderer, BOMB_IMAGE)
-
- RADIUS_FACTOR = 1.75
-
- EXPLOSIONS = [
- [
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch1/File1.png")),
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch1/File2.png")),
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch1/File3.png")),
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch1/File4.png")),
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch1/File5.png")),
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch1/File6.png"))
- ],
- [
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch2/File1.png")),
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch2/File2.png")),
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch2/File3.png")),
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch2/File4.png")),
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch2/File5.png")),
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch2/File6.png"))
- ],
- [
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch2/File1.png")),
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch2/File2.png")),
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch2/File3.png")),
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch2/File4.png")),
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch2/File5.png")),
- Texture.from_surface(renderer, pygame.image.load(f"assets/explosion/Punch2/File6.png"))
- ],
- ]
-
- EXPLOSION_TIME = 500
-
- explosion_sound_effects = [
- pygame.mixer.Sound("assets/sounds/hq-explosion-6288.wav"),
- pygame.mixer.Sound("assets/sounds/medium-explosion-40472.wav"),
- ]
-
- def __init__(self):
- super().__init__()
- self.radius = self.RADIUS
- self.image = self.BOMB_IMAGE
- self.exploded = False
-
- self.exploded_frame_timer = 0
- self.explosion_frame = 0
-
- self.explosion_txt = random.choice(self.EXPLOSIONS)
-
- circle = pygame.Surface((self.radius * 2, self.radius * 2), pygame.SRCALPHA)
- pygame.draw.circle(circle, (255, 255, 255, 255), (self.radius, self.radius), self.radius)
- self.circle = Texture.from_surface(renderer, circle)
-
- def update(self, delta):
- super().update(delta)
- if self.exploded:
- self.exploded_frame_timer += delta
- if self.exploded_frame_timer >= self.EXPLOSION_TIME / len(self.explosion_txt):
- self.exploded_frame_timer = 0
- self.explosion_frame = min(len(self.explosion_txt) - 1, self.explosion_frame + 1)
- if self.explosion_frame == len(self.explosion_txt) - 1:
- return True
-
- def explode(self, fruits, bombs, effects, depth=0):
- if self in bombs:
- if not self.exploded:
- self.image = self.explosion_txt[0]
- if depth == 0:
- pygame.mixer.Sound.play(random.choice(self.explosion_sound_effects))
- self.exploded = True
- self.velocity = pygame.Vector2(0, 0)
- self.acceleration = pygame.Vector2(0, 0)
-
- for fruit in fruits:
- fruit.velocity += (fruit.position - self.position).normalize() * self.POWER
- for effect in effects:
- effect.velocity += (effect.position - self.position).normalize() * self.POWER
-
- for bomb in bombs:
- if not bomb.exploded:
- bomb.explode(fruits, bombs, effects, depth + 1)
-
- def draw(self):
- if self.exploded:
- self.explosion_txt[self.explosion_frame].draw(None, pygame.Rect(self.position.x - self.EXPLOSION_RADIUS,
- self.position.y - self.EXPLOSION_RADIUS,
- self.EXPLOSION_RADIUS * 2,
- self.EXPLOSION_RADIUS * 2))
- else:
- # self.circle.draw(None, pygame.Rect(self.position.x - self.RADIUS, self.position.y - self.RADIUS,
- # self.RADIUS * 2, self.RADIUS * 2))
-
- self.BOMB_TXT.draw(None, pygame.Rect(self.position.x - self.radius * self.RADIUS_FACTOR,
- self.position.y - self.radius * self.RADIUS_FACTOR,
- self.radius * 2 * self.RADIUS_FACTOR,
- self.radius * 2 * self.RADIUS_FACTOR),
- self.angle, (self.radius * self.RADIUS_FACTOR, self.radius * self.RADIUS_FACTOR))
diff --git a/combo_counter.py b/combo_counter.py
deleted file mode 100644
index f697d50..0000000
--- a/combo_counter.py
+++ /dev/null
@@ -1,23 +0,0 @@
-from setup import *
-
-
-class ComboCounter:
- LIFE_TIME = 1000
-
- def __init__(self, position, combo):
- self.position = pygame.Vector2(position)
- self.velocity = pygame.Vector2(0, -100)
- self.time = self.LIFE_TIME
- self.combo = f"x{combo}"
- self.text_surface = font_large.render(self.combo, True, DARK_GRAY)
- self.text_txt = Texture.from_surface(renderer, self.text_surface)
-
- def update(self, delta):
- self.position += self.velocity * delta / 1000
- self.time -= delta
- if self.time <= 0:
- return True
-
- def draw(self):
- self.text_txt.draw(None, self.position - pygame.Vector2(self.text_surface.get_width() / 2,
- self.text_surface.get_height() / 2))
diff --git a/effect.py b/effect.py
deleted file mode 100644
index 3a7ce26..0000000
--- a/effect.py
+++ /dev/null
@@ -1,301 +0,0 @@
-from setup import *
-
-
-class BloodEffect:
- LIFE_TIME = 1000
- SPEED_RANGE = [250, 350]
- RADIUS_RANGE = [3, 3.75]
- blood_frames = [
- [pygame.image.load(f"assets/effects/blood1/{i}.png").convert_alpha() for i in range(16)],
- [pygame.image.load(f"assets/effects/blood2/{i}.png").convert_alpha() for i in range(16)],
- [pygame.image.load(f"assets/effects/blood3/{i}.png").convert_alpha() for i in range(16)]
- ]
-
- def __init__(self, position, radius, color=None):
- self.position = pygame.Vector2(position)
-
- self.radius = radius * lerp(self.RADIUS_RANGE[0], self.RADIUS_RANGE[1], random.random())
-
- self.life_time = 0
- self.current_frame = 0
-
- self.surf_frames = random.choice(self.blood_frames)
-
- if color is None:
- color = random.choice(EFFECT_COLORS)
-
- for frame in self.surf_frames:
- px_array = pygame.PixelArray(frame)
- px_array.replace(pygame.Color(250, 3, 35), pygame.Color(color))
- px_array.close()
-
- self.frame_txt = [Texture.from_surface(renderer, frame) for frame in self.surf_frames]
-
- def update(self, delta):
- self.life_time += delta
-
- if self.life_time >= self.LIFE_TIME / len(self.surf_frames) * (self.current_frame + 1):
- self.current_frame += 1
-
- if self.life_time >= self.LIFE_TIME:
- return True
-
- def draw(self):
- if self.life_time < self.LIFE_TIME:
- self.frame_txt[self.current_frame].draw(None, pygame.Rect(self.position.x - self.radius,
- self.position.y - self.radius,
- self.radius * 2, self.radius * 2))
-
-
-class BloodSplatter:
- LIFE_TIME = 4000
- FADE_TIME = 1000
- RADIUS_RANGE = [2, 2.75]
- ANGLE_OFFSET = 35
- blood_frames = [
- pygame.image.load("assets/effects/splatter/bloodslash1.png").convert_alpha(),
- pygame.image.load("assets/effects/splatter/bloodslash2.png").convert_alpha()
- ]
-
- LIGHT_COLOR1 = pygame.Color(110, 110, 110)
- DARK_COLOR1 = pygame.Color(84, 84, 84)
- LIGHT_COLOR2 = pygame.Color(83, 83, 83)
- DARK_COLOR2 = pygame.Color(74, 74, 74)
-
- color_frames = [dict(), dict()]
- for c in EFFECT_COLORS:
- for i, f in enumerate(blood_frames):
- c_f = f.copy()
- px_array = pygame.PixelArray(c_f)
- px_array.replace(LIGHT_COLOR1 if i == 0 else LIGHT_COLOR2, pygame.Color(c))
- px_array.replace(DARK_COLOR1 if i == 0 else DARK_COLOR2, pygame.Color(darken(c, 0.875)))
- px_array.close()
- color_frames[i][c] = c_f
-
- def __init__(self, position, radius, angle, color=None):
- self.position = pygame.Vector2(position)
-
- self.radius = radius * lerp(self.RADIUS_RANGE[0], self.RADIUS_RANGE[1], random.random())
- self.angle = angle
-
- self.life_time = self.LIFE_TIME
- self.fade_time = self.FADE_TIME
-
- img_index = random.randint(0, len(self.blood_frames) - 1)
- self.alpha = 255
-
- if color is None:
- color = random.choice(EFFECT_COLORS)
-
- self.frame = Texture.from_surface(renderer, self.color_frames[img_index][color])
-
- def update(self, delta):
- if self.life_time > 0:
- self.life_time -= delta
- else:
- self.fade_time -= delta
-
- if self.fade_time <= 0 and self.life_time <= 0:
- return True
-
- if self.life_time <= 0:
- self.alpha = int(lerp(0, 255, self.fade_time / self.FADE_TIME))
- self.frame.alpha = self.alpha
-
- def draw(self):
- self.frame.draw(None, pygame.Rect(self.position.x - self.radius,
- self.position.y - self.radius,
- self.radius * 2, self.radius * 2),
- self.angle + self.ANGLE_OFFSET, origin=(self.radius, self.radius))
-
-
-class SplitEffect:
- SPEED_PERCENT_RANGE = [65, 85]
- gravity = 275
-
- def __init__(self, position, frame, fruit_velocity, normal_velocity):
- self.position = pygame.Vector2(position)
- self.velocity = pygame.Vector2(fruit_velocity) * lerp(self.SPEED_PERCENT_RANGE[0], self.SPEED_PERCENT_RANGE[1],
- random.random()) / 100 + pygame.Vector2(normal_velocity)
- self.acceleration = pygame.Vector2(0, self.gravity)
-
- self.angle = frame.angle
- self.direction = random.choice([-1, 1])
-
-
- self.frame = frame
- self.width, self.height = self.frame.get_rect().width, self.frame.get_rect().height
-
- def update(self, delta):
- self.velocity += self.acceleration * delta / 1000
- self.position += self.velocity * delta / 1000
-
- self.angle += 360 * delta / 1000 / 10 * self.direction
-
- if self.position.y - self.height / 2 > HEIGHT:
- return True
-
- def draw(self):
- self.frame.angle = self.angle
- # print(self.position)
- self.frame.draw(None, pygame.Rect(self.position.x - self.width / 2,
- self.position.y - self.height / 2,
- self.width, self.height))
- self.width, self.height = self.frame.get_rect().width, self.frame.get_rect().height
-
- @staticmethod
- def find_normals(v):
- return pygame.Vector2(-v.y, v.x), pygame.Vector2(v.y, -v.x)
-
- @staticmethod
- def should_split(texture, angle, image_position, mouse_position, mouse_direction, radius):
- if mouse_direction.x == 0:
- mouse_direction.x += 0.0001
-
- a = math.degrees(math.atan(mouse_direction.y / mouse_direction.x))
- diagonal = math.sqrt(2 * ((radius * 2) ** 2))
- txt = Texture(renderer, (diagonal, diagonal), target=True)
- txt.blend_mode = pygame.BLEND_ADD
- renderer.target = txt
- texture.draw(None, pygame.Rect((diagonal - radius * 2) / 2, (diagonal - radius * 2) / 2, radius * 2,
- radius * 2), angle - a, origin=(radius, radius))
- renderer.target = None
-
- img_size = pygame.Vector2(diagonal, diagonal)
- center = img_size / 2
-
- # finding end and start points of the splitting line
- # [x,y] = mouse_position + t * mouse_direction # vector equation
- # x = mouse_position.x + t * mouse_direction.x
- # y = mouse_position.y + t * mouse_direction.y
-
- mp = mouse_position - image_position + center
-
- t1 = (- mp.x) / mouse_direction.x
- p1 = mp + t1 * mouse_direction
-
- p3 = (p1 - center).rotate(-a) + center
-
- MIN_SPLIT = 0.25
- slice_percent = clamp(p3.y, 0, img_size.y) / img_size.y
- if MIN_SPLIT < slice_percent < 1 - MIN_SPLIT:
- return True
- return False
-
- @staticmethod
- def split_image(texture, angle, image_position, mouse_position, mouse_direction, radius):
- if mouse_direction.x == 0:
- mouse_direction.x += 0.0001
-
- a = math.degrees(math.atan(mouse_direction.y / mouse_direction.x))
- diagonal = math.sqrt(2 * ((radius * 2) ** 2))
- txt = Texture(renderer, (diagonal, diagonal), target=True)
- txt.blend_mode = pygame.BLEND_ADD
- renderer.target = txt
- texture.draw(None, pygame.Rect((diagonal - radius * 2) / 2, (diagonal - radius * 2) / 2, radius * 2,
- radius * 2), angle - a, origin=(radius, radius))
- renderer.target = None
-
- img_size = pygame.Vector2(diagonal, diagonal)
- center = img_size / 2
-
- # finding end and start points of the splitting line
- # [x,y] = mouse_position + t * mouse_direction # vector equation
- # x = mouse_position.x + t * mouse_direction.x
- # y = mouse_position.y + t * mouse_direction.y
-
- mp = mouse_position - image_position + center
-
- t1 = (- mp.x) / mouse_direction.x
- p1 = mp + t1 * mouse_direction
-
- p3 = (p1 - center).rotate(-a) + center
-
- half1 = Image(txt, pygame.Rect(0, 0, img_size.x, clamp(p3.y, 0, img_size.y)))
- half2 = Image(txt,
- pygame.Rect(0, clamp(p3.y, 0, img_size.y), img_size.x, clamp(img_size.y - p3.y, 0, img_size.y)))
-
- p5 = half1.get_rect().center - center
- pos1 = p5.rotate(a) + image_position
-
- p6 = half2.get_rect().center - center
- pos2 = p6.rotate(a) + image_position
-
- half1.angle = a
- half2.angle = a
-
- return half1, half2, pos1, pos2
-
-
-class SlashEffect:
- SLASH_SURFS = [pygame.image.load(f"assets/effects/sword_slashes/File{i}.png").convert_alpha()
- for i in range(1, 7)]
- LIFETIME = 600
-
- def __init__(self, position, angle):
- self.position = pygame.Vector2(position)
- self.angle = angle
-
- self.time = 0
- self.current_frame = 0
-
- self.slash_frames = [Texture.from_surface(renderer, frame) for frame in self.SLASH_SURFS]
-
- def update(self, delta):
- self.time += delta
- if self.time >= self.LIFETIME / len(self.SLASH_SURFS):
- self.time = 0
- self.current_frame += 1
- if self.current_frame >= len(self.SLASH_SURFS):
- return True
-
- def draw(self):
- frame = self.slash_frames[self.current_frame]
- frame.draw(None, self.position - pygame.Vector2(frame.width, frame.height) / 2, self.angle)
-
-
-class FadeInEffect:
-
- def __init__(self, fade_time=500):
- self.fade_time = fade_time
- self.surf = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA)
- self.surf.fill(BLACK)
- self.time = self.fade_time
- self.alpha = 255
-
- self.txt = Texture.from_surface(renderer, self.surf)
-
- def update(self, delta):
- self.time -= delta
-
- if self.time <= 0:
- return True
- self.alpha = int(lerp(0, 255, self.time / self.fade_time))
-
- def draw(self):
- self.txt.alpha = self.alpha
- self.txt.draw(None, (0, 0))
-
-
-class FadeOutEffect:
-
- def __init__(self, fade_time=500, max_alpha=255):
- self.fade_time = fade_time
- self.max_alpha = max_alpha
-
- self.surf = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA)
- self.surf.fill(BLACK)
- self.time = 0
- self.alpha = 0
-
- self.txt = Texture.from_surface(renderer, self.surf)
-
- def update(self, delta):
- self.time += delta
- if self.time >= self.fade_time:
- return True
- self.alpha = int(lerp(0, self.max_alpha, self.time / self.fade_time))
-
- def draw(self):
- self.txt.alpha = self.alpha
- self.txt.draw(None, (0, 0))
diff --git a/fruit.py b/fruit.py
deleted file mode 100644
index 37a9df3..0000000
--- a/fruit.py
+++ /dev/null
@@ -1,53 +0,0 @@
-from setup import *
-
-
-class Fruit:
- RADIUS_RANGE = [60 * SCALE.x, 100 * SCALE.x]
-
- HORIZONTAL_SPAWN_RANGE = [max(RADIUS_RANGE), WIDTH - max(RADIUS_RANGE)]
- VERTICAL_SPAWN_RANGE = [HEIGHT + max(RADIUS_RANGE), HEIGHT * 2 + max(RADIUS_RANGE)]
-
- VERTICAL_TARGET_RANGE = [max(RADIUS_RANGE), HEIGHT * 3.5 / 5]
- HORIZONTAL_TARGET_RANGE = [WIDTH / 5.5, WIDTH * 4.5 / 5.5]
-
- GRAVITY = 275 * SCALE.y
- FRUITS = [
- pygame.image.load(f"assets/fruits/{file}").convert_alpha() for file in os.listdir('assets/fruits/')
- ]
-
- def __init__(self):
- self.radius = lerp(self.RADIUS_RANGE[0], self.RADIUS_RANGE[1], random.random())
-
- self.target = pygame.Vector2(
- lerp(self.HORIZONTAL_TARGET_RANGE[0], self.HORIZONTAL_TARGET_RANGE[1], random.random()),
- lerp(self.VERTICAL_TARGET_RANGE[0], self.VERTICAL_TARGET_RANGE[1], random.random()))
- self.position = pygame.Vector2(
- lerp(self.HORIZONTAL_SPAWN_RANGE[0], self.HORIZONTAL_SPAWN_RANGE[1], random.random()),
- lerp(self.VERTICAL_SPAWN_RANGE[0], self.VERTICAL_SPAWN_RANGE[1], random.random()))
-
- self.acceleration = pygame.Vector2(0, self.GRAVITY)
-
- dy = self.target.y - self.position.y
- dx = self.target.x - self.position.x
- t = (-2 / self.GRAVITY * dy) ** 0.5
- self.velocity = pygame.Vector2(dx / t, -(-2 * self.GRAVITY * dy) ** 0.5)
-
- self.angle = lerp(0, 360, random.random())
- self.direction = random.choice([-1, 1])
-
- self.width, self.height = (self.radius * 2, self.radius * 2)
-
- self.image = random.choice(self.FRUITS)
- self.fruit_txt = Texture.from_surface(renderer, self.image)
-
- def update(self, delta):
- self.velocity += self.acceleration * delta / 1000
- self.position += self.velocity * delta / 1000
-
- self.angle += 360 * delta / 1000 / 10 * self.direction
-
- def draw(self):
- if self.position.y - self.radius <= HEIGHT:
- self.fruit_txt.draw(None, pygame.Rect(self.position - pygame.Vector2(self.radius, self.radius),
- (self.radius * 2, self.radius * 2)),
- angle=self.angle, origin=(self.radius, self.radius))
diff --git a/game.py b/game.py
deleted file mode 100644
index b07d96c..0000000
--- a/game.py
+++ /dev/null
@@ -1,295 +0,0 @@
-from player import Player
-from fruit import Fruit
-from effect import BloodEffect, SplitEffect, SlashEffect, FadeInEffect, FadeOutEffect, BloodSplatter
-from combo_counter import ComboCounter
-from bomb import Bomb
-from rect import Rect
-from setup import *
-
-
-class Game:
- BOMB_CHANCE = 0.1
-
- COMBO_TIME = 250
- GAME_OVER_TIME = 2000
- WAVE_COOLDOWN = 500
-
- BACKGROUND = pygame.Surface((WIDTH, HEIGHT))
- tile_cols = 4
- tile_rows = 4
- background_tile = pygame.transform.scale(pygame.image.load("assets/background.png"),
- (WIDTH / tile_cols, HEIGHT / tile_rows)).convert()
- dark_background_tile = pygame.transform.scale(pygame.image.load("assets/dark_background.png"),
- (WIDTH / tile_cols, HEIGHT / tile_rows)).convert()
- for x in range(tile_cols):
- for y in range(tile_rows):
- if y == 0:
- BACKGROUND.blit(dark_background_tile, (x * WIDTH / tile_cols, y * HEIGHT / tile_rows))
- else:
- BACKGROUND.blit(background_tile, (x * WIDTH / tile_cols, y * HEIGHT / tile_rows))
- BACKGROUND = Texture.from_surface(renderer, BACKGROUND)
-
- bass_sound_effect = pygame.mixer.Sound("assets/sounds/sub-bass-4-secondsssss-6241.wav")
- bass_sound_effect.set_volume(0.1)
- slash_sounds = [pygame.mixer.Sound(f"assets/sounds/Swishes/long-medium-swish-44324.wav"),
- pygame.mixer.Sound(f"assets/sounds/Swishes/swing-6045.wav"),
- pygame.mixer.Sound(f"assets/sounds/Swishes/swish-sound-94707.wav"),
- ]
-
- HIGH_SCORE_FILE = "high_score.txt"
-
- def __init__(self):
- self.player = Player()
-
- self.fruits = [Fruit()]
- self.bombs = []
-
- self.effects = [
- [], # Blood splatter
- [], # Blood splash
- [], # Split Effect
- [], # slash effect
- [FadeInEffect(fade_time=1000)] # Fade in/fade out effects
- ]
-
- self.combo_counters = []
-
- self.score = 0
-
- self.time_since_last_hit = 0
- self.current_combo = 0
-
- self.wave = 1
- self.cleared_wave = True
- self.wave_cooldown_timer = 0
-
- self.game_over = False
- self.game_over_time = 0
-
- try:
- with open(self.HIGH_SCORE_FILE, "r") as f:
- self.high_score = int(f.read())
- except:
- self.high_score = 0
-
- self.music_started = False
- if pygame.mixer.music.get_busy():
- pygame.mixer.music.fadeout(500)
- pygame.mixer.music.load("assets/sounds/Of Far Different Nature - Friendly Trap (CC-BY).ogg")
- pygame.mixer.music.set_volume(0.25)
- pygame.mixer.music.play(-1)
- self.music_started = True
-
- self.score_surf = font.render(f"SCORE {self.score}", True, WHITE)
- self.score_txt = Texture.from_surface(renderer, self.score_surf)
-
- self.combo_surf = font.render(f"COMBO x{max(1,self.current_combo)}", True, WHITE)
- self.combo_txt = Texture.from_surface(renderer, self.combo_surf)
-
- self.high_score_surf = font.render(f"BEST {self.high_score}", True, WHITE)
- self.high_score_txt = Texture.from_surface(renderer, self.high_score_surf)
-
- self.title_surf = font_large.render("GAME OVER", True, WHITE)
-
- self.subtitle_surf = font.render(f"HIGH SCORE {self.high_score}", True, WHITE)
-
- self.game_over_surf = pygame.Surface((max(self.title_surf.get_width(), self.subtitle_surf.get_width()),
- self.title_surf.get_height() + self.subtitle_surf.get_height()))
- self.game_over_surf.fill(GRAY)
- self.game_over_surf.blit(self.title_surf, self.title_surf.get_rect(
- center=(self.game_over_surf.get_width() / 2, self.title_surf.get_height() / 2)))
- self.game_over_surf.blit(self.subtitle_surf, self.subtitle_surf.get_rect(
- center=(
- self.game_over_surf.get_width() / 2,
- self.title_surf.get_height() + self.subtitle_surf.get_height() / 2)))
- self.game_over_txt = Texture.from_surface(renderer, self.game_over_surf)
-
- self.r1 = Rect(self.game_over_surf.get_rect(center=(WIDTH / 2, HEIGHT / 2)).inflate(50, 50), GRAY, 10)
- self.r2 = Rect(self.game_over_surf.get_rect(center=(WIDTH / 2, HEIGHT / 2)).inflate(50, 50), BLACK, 10, 5)
-
- def update(self, delta):
- for event in pygame.event.get():
- if event.type == pygame.QUIT or (event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE):
- if self.score >= self.high_score:
- self.high_score = self.score
- with open(self.HIGH_SCORE_FILE, "w") as f:
- f.write(str(self.high_score))
- return COMMAND_EXIT
- elif event.type == pygame.KEYUP:
- if event.key == pygame.K_m:
- if pygame.mixer.music.get_busy():
- pygame.mixer.music.pause()
- else:
- pygame.mixer.music.unpause()
- if not self.music_started:
- pygame.mixer.music.load("assets/sounds/Of Far Different Nature - Friendly Trap (CC-BY).ogg")
- pygame.mixer.music.set_volume(0.25)
- pygame.mixer.music.play(-1)
- self.music_started = True
-
- if not self.game_over:
- self.player.update(delta)
- else:
- self.game_over_time += delta
- if self.game_over_time > self.GAME_OVER_TIME:
- return COMMAND_START
-
- hits = []
- for fruit in self.fruits:
- fruit.update(delta)
-
- hit_status = self.player.hits(fruit)
- if hit_status and SplitEffect.should_split(fruit.fruit_txt, fruit.angle, fruit.position,
- self.player.previous_mouse_pos,
- self.player.mouse_direction, fruit.radius):
- hits.append((fruit, self.player.mouse_direction, self.player.previous_mouse_pos))
-
- if (((not -fruit.radius * 2 < fruit.position.x < WIDTH + fruit.radius * 2) or
- fruit.position.y - fruit.radius * 2 > HEIGHT) and fruit.velocity.y > 0):
- self.fruits.remove(fruit)
- self.cleared_wave = False
-
- self.time_since_last_hit += delta
-
- if self.time_since_last_hit < self.COMBO_TIME:
- self.score += self.current_combo
- self.high_score = max(self.score, self.high_score)
- self.score_surf = font.render(f"SCORE {self.score}", True, WHITE)
- self.score_txt = Texture.from_surface(renderer, self.score_surf)
- self.high_score_surf = font.render(f"BEST {self.high_score}", True, WHITE)
- self.high_score_txt = Texture.from_surface(renderer, self.high_score_surf)
- else:
- self.current_combo = 0
- self.combo_surf = font.render(f"COMBO x{max(1,self.current_combo)}", True, WHITE)
- self.combo_txt = Texture.from_surface(renderer, self.combo_surf)
-
- for hit, mouse_direction, mouse_position in hits:
- color = random.choice(EFFECT_COLORS)
- self.effects[0].append(BloodSplatter(hit.position, hit.radius,
- determine_angle(hit.position, hit.position + mouse_direction),
- color))
- self.effects[1].append(BloodEffect(hit.position, hit.radius, lighten(color, 0.15)))
-
- half1, half2, pos1, pos2 = SplitEffect.split_image(hit.fruit_txt, hit.angle, hit.position, mouse_position,
- mouse_direction, hit.radius)
-
- n1, n2 = SplitEffect.find_normals(mouse_direction.normalize() * 5)
- self.effects[2].append(SplitEffect(pos1, half1, hit.velocity, n1))
- self.effects[2].append(SplitEffect(pos2, half2, hit.velocity, n2))
-
- pygame.mixer.Sound.play(random.choice(self.slash_sounds))
-
- self.score += 1
- self.high_score = max(self.score, self.high_score)
- self.score_surf = font.render(f"SCORE {self.score}", True, WHITE)
- self.score_txt = Texture.from_surface(renderer, self.score_surf)
- self.high_score_surf = font.render(f"BEST {self.high_score}", True, WHITE)
- self.high_score_txt = Texture.from_surface(renderer, self.high_score_surf)
-
- if self.time_since_last_hit < self.COMBO_TIME:
- self.current_combo += 1
- self.combo_surf = font.render(f"COMBO x{max(1,self.current_combo)}", True, WHITE)
- self.combo_txt = Texture.from_surface(renderer, self.combo_surf)
- if self.current_combo > 1:
- self.combo_counters.append(ComboCounter(hit.position, self.current_combo + 1))
-
- self.effects[3].append(SlashEffect(hit.position, hit.angle))
- self.time_since_last_hit = 0
-
- if hit in self.fruits:
- self.fruits.remove(hit)
-
- for layer in self.effects:
- for effect in layer:
- effect_status = effect.update(delta)
- if effect_status:
- layer.remove(effect)
-
- for combo in self.combo_counters:
- combo_status = combo.update(delta)
- if combo_status:
- self.combo_counters.remove(combo)
-
- for bomb in self.bombs:
- bomb_status = bomb.update(delta)
- if self.player.hits(bomb):
- bomb.explode(self.fruits, self.bombs, self.effects[2])
- self.set_game_over()
-
- if bomb_status:
- self.bombs.remove(bomb)
- continue
- if (((not -bomb.radius * 2 < bomb.position.x < WIDTH + bomb.radius * 2) or
- bomb.position.y - bomb.radius * 2 * bomb.RADIUS_FACTOR > HEIGHT) and bomb.velocity.y > 0):
- self.bombs.remove(bomb)
-
- if len(self.fruits) == 0 and len(self.bombs) == 0 and not self.game_over:
- self.wave_cooldown_timer += delta
- if self.wave_cooldown_timer >= self.WAVE_COOLDOWN:
- if self.cleared_wave:
- self.wave_cooldown_timer = 0
- self.wave += 1
- self.cleared_wave = True
- for i in range(self.wave):
- if random.random() < self.BOMB_CHANCE:
- self.bombs.append(Bomb())
- else:
- self.fruits.append(Fruit())
-
- def set_game_over(self):
- self.game_over = True
-
- self.player.sliced_points.clear()
- pygame.mixer.Sound.play(self.bass_sound_effect)
- self.effects[4].append(FadeOutEffect(fade_time=self.GAME_OVER_TIME, max_alpha=20))
-
- if self.score >= self.high_score:
- self.high_score = self.score
- with open(self.HIGH_SCORE_FILE, "w") as f:
- f.write(str(self.high_score))
-
- self.title_surf = font_large.render("GAME OVER", True, WHITE)
-
- self.subtitle_surf = font.render(f"HIGH SCORE {self.high_score}", True, WHITE)
-
- self.game_over_surf = pygame.Surface((max(self.title_surf.get_width(), self.subtitle_surf.get_width()),
- self.title_surf.get_height() + self.subtitle_surf.get_height()))
- self.game_over_surf.fill(GRAY)
- self.game_over_surf.blit(self.title_surf, self.title_surf.get_rect(
- center=(self.game_over_surf.get_width() / 2, self.title_surf.get_height() / 2)))
- self.game_over_surf.blit(self.subtitle_surf, self.subtitle_surf.get_rect(
- center=(
- self.game_over_surf.get_width() / 2,
- self.title_surf.get_height() + self.subtitle_surf.get_height() / 2)))
- self.game_over_txt = Texture.from_surface(renderer, self.game_over_surf)
-
- def draw(self):
- self.BACKGROUND.draw(None, (0, 0))
-
- self.score_txt.draw(None, (7, 0))
- self.combo_txt.draw(None, (WIDTH / 2 - self.combo_txt.width / 2, 0))
- self.high_score_txt.draw(None, (WIDTH - self.high_score_txt.width - 7, 0))
-
- for effect in self.effects[0]:
- effect.draw()
- for effect in self.effects[1]:
- effect.draw()
- for bomb in self.bombs:
- bomb.draw()
- for effect in self.effects[2]:
- effect.draw()
- for fruit in self.fruits:
- fruit.draw()
- for effect in self.effects[3]:
- effect.draw()
- for combo in self.combo_counters:
- combo.draw()
- for effect in self.effects[4]:
- effect.draw()
-
- if self.game_over:
- self.r1.draw()
- self.r2.draw()
- self.game_over_txt.draw(None, (
- WIDTH / 2 - self.game_over_txt.width / 2, HEIGHT / 2 - self.game_over_txt.height / 2))
- self.player.draw()
diff --git a/main.py b/main.py
deleted file mode 100644
index 2053bfe..0000000
--- a/main.py
+++ /dev/null
@@ -1,31 +0,0 @@
-from game import Game
-from menu import Menu
-from setup import *
-
-FPS = 60
-clock = pygame.time.Clock()
-
-scene = Menu()
-
-is_running = True
-while is_running:
- delta = clock.tick(FPS)
- renderer.clear()
-
- status = scene.update(delta)
- scene.draw()
-
- # fps_text = font_small.render(f"FPS: {clock.get_fps():.0f}", True, DARK_GRAY)
- # fps_txt = Texture.from_surface(renderer, fps_text)
- # fps_txt.draw(None, pygame.Vector2(10, 75))
-
- renderer.present()
-
- if status == COMMAND_EXIT:
- is_running = False
- elif status == COMMAND_START:
- scene = Game()
- elif status == COMMAND_MENU:
- scene = Menu()
-
-pygame.quit()
diff --git a/menu.py b/menu.py
deleted file mode 100644
index 21ac97b..0000000
--- a/menu.py
+++ /dev/null
@@ -1,149 +0,0 @@
-from setup import *
-from player import Player
-from fruit import Fruit
-from effect import SlashEffect, SplitEffect, BloodEffect, FadeOutEffect, BloodSplatter
-from rect import Rect
-
-
-class Menu:
- # Creating background image
- background = pygame.Surface((WIDTH, HEIGHT))
- tile_cols = 4
- tile_rows = 4
- background_tile = pygame.transform.scale(pygame.image.load("assets/background.png"),
- (WIDTH / tile_cols, HEIGHT / tile_rows)).convert()
- for x in range(tile_cols):
- for y in range(tile_rows):
- background.blit(background_tile, (x * WIDTH / tile_cols, y * HEIGHT / tile_rows))
- bg_txt = Texture.from_surface(renderer, background)
-
- # Slash sound effects
- slash_sounds = [
- pygame.mixer.Sound(f"assets/sounds/Swishes/long-medium-swish-44324.wav"),
- pygame.mixer.Sound(f"assets/sounds/Swishes/swing-6045.wav"),
- pygame.mixer.Sound(f"assets/sounds/Swishes/swish-sound-94707.wav"),
- ]
-
- def __init__(self):
- # Music
- pygame.mixer.music.load("assets/sounds/Of Far Different Nature - Ethnic Beat (CC-BY).ogg")
- pygame.mixer.music.set_volume(0.5)
- pygame.mixer.music.play(-1)
- pygame.mixer.music.pause()
-
- # Player
- self.player = Player()
-
- # Fruit
- self.fruit = Fruit()
- self.fruit.position = pygame.Vector2(WIDTH / 2, HEIGHT * 1.5 / 2.5)
- self.fruit.angle = 0
- self.fruit.image = pygame.image.load("assets/fruits/58.png")
- self.fruit.fruit_txt = Texture.from_surface(renderer, self.fruit.image)
-
- # Effects
- self.effects = []
-
- # Text surfaces
- self.title_surface = font_large.render("Fruit Shinobi", True, WHITE)
- self.tutorial_surface = font.render("Drag to slice the fruit", True, WHITE)
- self.controls_surface = font_small.render("Press M to unmute music", True, WHITE)
- self.credit_surface = font_small.render("Made by: Skullheadx", True, WHITE)
-
- self.title_txt = Texture.from_surface(renderer, self.title_surface)
- self.tutorial_txt = Texture.from_surface(renderer, self.tutorial_surface)
- self.controls_txt = Texture.from_surface(renderer, self.controls_surface)
- self.credit_txt = Texture.from_surface(renderer, self.credit_surface)
-
- # Rect textures
- self.tutorial_surface_pos = (
- WIDTH / 2, HEIGHT * 2 / 3 + self.tutorial_surface.get_height() / 2 + self.fruit.radius + 30)
-
- self.r1 = Rect(self.tutorial_surface.get_rect(center=self.tutorial_surface_pos).inflate(25, 25), DARK_GRAY, 10)
- self.r2 = Rect(self.tutorial_surface.get_rect(center=self.tutorial_surface_pos).inflate(25, 25), BLACK, 10, 5)
-
- self.r3 = Rect(self.title_surface.get_rect(center=(WIDTH / 2, HEIGHT / 3)).inflate(50, 50), GRAY, 10)
- self.r4 = Rect(self.title_surface.get_rect(center=(WIDTH / 2, HEIGHT / 3)).inflate(50, 50), BLACK, 10, 5)
-
- # blacked out
- self.blacked_out = False
-
- def update(self, delta):
- # Event handling
- for event in pygame.event.get():
- if event.type == pygame.QUIT or (event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE):
- pygame.mixer.music.stop()
- return COMMAND_EXIT
- if event.type == pygame.KEYUP:
- if event.key == pygame.K_m:
- if pygame.mixer.music.get_busy():
- pygame.mixer.music.pause()
- else:
- pygame.mixer.music.unpause()
-
- # Update player
- self.player.update(delta)
-
- # Update fruit
- if not self.blacked_out:
- hit_status = self.player.hits(self.fruit) # Check if player hits fruit
- # Check if fruit should split
- if hit_status and SplitEffect.should_split(self.fruit.fruit_txt, self.fruit.angle, self.fruit.position,
- self.player.previous_mouse_pos, self.player.mouse_direction,
- self.fruit.radius):
- # Split fruit
- color = random.choice(EFFECT_COLORS)
- n1, n2 = SplitEffect.find_normals(self.player.mouse_direction.normalize() * 5)
-
- self.effects.append(BloodSplatter(self.fruit.position, self.fruit.radius,
- determine_angle(self.fruit.position,
- self.fruit.position + self.player.mouse_direction),
- color))
- self.effects.append(BloodEffect(self.fruit.position, self.fruit.radius, lighten(color, 0.15)))
- half1, half2, pos1, pos2 = SplitEffect.split_image(self.fruit.fruit_txt, self.fruit.angle,
- self.fruit.position, self.player.previous_mouse_pos,
- self.player.mouse_direction, self.fruit.radius)
-
- self.effects.append(SplitEffect(pos1, half1, pygame.Vector2(0, 0), n1))
- self.effects.append(SplitEffect(pos2, half2, pygame.Vector2(0, 0), n2))
- self.effects.append(SlashEffect(self.fruit.position, self.fruit.angle))
-
- # Play slash sound
- pygame.mixer.Sound.play(random.choice(self.slash_sounds))
-
- # cue fadeout
- self.blacked_out = True
- self.effects.append(FadeOutEffect())
-
- # Update effects
- for effect in self.effects:
- effect_status = effect.update(delta)
- if effect_status:
- if isinstance(effect, FadeOutEffect):
- return COMMAND_START
- self.effects.remove(effect)
-
- def draw(self):
- self.bg_txt.draw(None, (0, 0))
-
- if not self.blacked_out:
- self.fruit.draw()
-
- self.r1.draw()
- self.r2.draw()
-
- self.tutorial_txt.draw(None, self.tutorial_surface.get_rect(
- center=self.tutorial_surface_pos))
-
- self.r3.draw()
- self.r4.draw()
-
- self.title_txt.draw(None, self.title_surface.get_rect(center=(WIDTH / 2, HEIGHT / 3)))
-
- self.controls_txt.draw(None, self.controls_surface.get_rect(bottomleft=(10, HEIGHT - 10)))
- self.credit_txt.draw(None, self.credit_surface.get_rect(bottomright=(WIDTH - 10, HEIGHT - 10)))
-
-
- for effect in self.effects:
- effect.draw()
- self.player.draw()
diff --git a/player.py b/player.py
deleted file mode 100644
index ba3f230..0000000
--- a/player.py
+++ /dev/null
@@ -1,77 +0,0 @@
-import pygame.mouse
-
-from setup import *
-
-
-class Player:
- LIFE_TIME = 100
-
- image = pygame.image.load("assets/knife.png").convert_alpha()
- txt = Texture.from_surface(renderer, image)
-
- SIZE = pygame.Vector2(50* SCALE, 50* SCALE)
-
- def __init__(self):
- self.sliced_points = []
- self.lines = []
-
- self.previous_mouse_pos = pygame.Vector2(pygame.mouse.get_pos())
- self.mouse_direction = pygame.Vector2(0, 0)
- self.slicing = False
-
- self.angle = 0
-
- def update(self, delta):
- pressed = pygame.mouse.get_pressed()
- if pressed[0]:
- pos = pygame.mouse.get_pos()
- self.sliced_points.append((pygame.Vector2(pos), pygame.time.get_ticks()))
- self.mouse_direction = pygame.Vector2(pos) - self.previous_mouse_pos
- self.previous_mouse_pos = pygame.Vector2(pos)
- self.slicing = True
- else:
- self.mouse_direction = pygame.Vector2(0, 0)
- self.previous_mouse_pos = pygame.Vector2(pygame.mouse.get_pos())
- self.slicing = False
-
-
- self.lines.clear()
- if len(self.sliced_points) > 1:
- for i in range(len(self.sliced_points) - 1):
- self.lines.append(
- (pygame.Vector2(self.sliced_points[i][0]), pygame.Vector2(self.sliced_points[i + 1][0])))
-
- for i, val in enumerate(self.sliced_points):
- pos, time = val
- if pygame.time.get_ticks() - time > self.LIFE_TIME:
- self.sliced_points.pop(i)
- break
-
- def hits(self, fruit):
- for line in self.lines:
- v1 = pygame.Vector2(line[0]) - fruit.position
- v2 = pygame.Vector2(line[1]) - fruit.position
- v = v2 - v1
- r = fruit.radius
-
- if v.magnitude_squared() == 0:
- continue
-
- discriminant = 4 * (v1.dot(v)) ** 2 - 4 * v.magnitude_squared() * (v1.magnitude_squared() - r ** 2)
- if discriminant >= 0:
- t1 = (-2 * v1.dot(v) + math.sqrt(discriminant)) / (2 * v.magnitude_squared())
- t2 = (-2 * v1.dot(v) - math.sqrt(discriminant)) / (2 * v.magnitude_squared())
- if 0 <= t1 <= 1 or 0 <= t2 <= 1:
- return True
- if (t1 < 0 and t2 > 1) or (t2 < 0 and t1 > 1):
- return True
- return False
-
- def draw(self):
- renderer.draw_color = LIGHT_GRAY
- if len(self.sliced_points) > 1:
- for i in range(len(self.sliced_points) - 1):
- renderer.draw_line(self.sliced_points[i][0], self.sliced_points[i + 1][0])
- renderer.draw_line(self.previous_mouse_pos, self.previous_mouse_pos - self.mouse_direction)
- self.txt.draw(None, pygame.Rect(pygame.mouse.get_pos(), self.SIZE))
-
diff --git a/rect.py b/rect.py
deleted file mode 100644
index 7c0fbf6..0000000
--- a/rect.py
+++ /dev/null
@@ -1,18 +0,0 @@
-from setup import *
-
-
-def get_rect_txt(rect, color, border_radius, thickness=0):
- r = pygame.Surface((rect.width, rect.height), pygame.SRCALPHA)
- pygame.draw.rect(r, color, (0, 0, rect.width, rect.height), border_radius=border_radius,
- width=thickness)
- return Texture.from_surface(renderer, r)
-
-
-class Rect:
-
- def __init__(self, rect, color, border_radius=0, thickness=0):
- self.position = pygame.Vector2(rect.x, rect.y)
- self.texture = get_rect_txt(rect, color, border_radius, thickness)
-
- def draw(self):
- self.texture.draw(None, self.position)
diff --git a/setup.py b/setup.py
deleted file mode 100644
index 0c2aced..0000000
--- a/setup.py
+++ /dev/null
@@ -1,103 +0,0 @@
-import pygame
-from pygame._sdl2 import Window, Renderer, Texture, Image
-import random
-import os
-import math
-from functools import cache
-
-pygame.init()
-WIDTH, HEIGHT = pygame.display.Info().current_w, pygame.display.Info().current_h
-display = pygame.display.set_mode((WIDTH, HEIGHT), pygame.FULLSCREEN)
-window = Window.from_display_module()
-renderer = Renderer(window)
-pygame.mouse.set_visible(False)
-
-SCALE = pygame.Vector2(WIDTH / 1536, HEIGHT / 864)
-
-pygame.display.set_caption("Fruit Shinobi")
-icon = pygame.image.load("assets/logo.ico").convert()
-pygame.display.set_icon(icon)
-
-# fonts
-font_small = pygame.font.Font("assets/font/go3v2.ttf", int(30 * SCALE.x))
-font = pygame.font.Font("assets/font/go3v2.ttf", int(60 * SCALE.x))
-font_large = pygame.font.Font("assets/font/go3v2.ttf", int(100 * SCALE.x))
-
-# colors
-WHITE = (255, 255, 255, 255)
-LIGHT_GRAY = (211, 211, 211, 255)
-GRAY = (128, 128, 128, 255)
-DARK_GRAY = (25, 25, 25, 255)
-BLACK = (0, 0, 0, 255)
-
-RED = (255, 0, 0, 255)
-GREEN = (0, 255, 0, 255)
-BLUE = (0, 0, 255, 255)
-ORANGE = (255, 165, 0, 255)
-YELLOW = (255, 255, 0, 255)
-PURPLE = (128, 0, 128, 255)
-
-BROWN = (139, 69, 19, 255)
-DARK_BROWN = (119, 49, 0, 255)
-
-DARK_RED = (139, 0, 0, 255)
-DARK_GREEN = (0, 100, 0, 255)
-DARK_BLUE = (0, 0, 139, 255)
-DARK_ORANGE = (255, 140, 0, 255)
-DARK_YELLOW = (255, 215, 0, 255)
-DARK_PURPLE = (75, 0, 130, 255)
-
-EFFECT_COLORS = [
- (252, 166, 168, 255),
- (247, 203, 168, 255),
- (203, 172, 239, 255),
- (160, 247, 208, 255),
- (222, 244, 141, 255),
- (205, 255, 135, 255),
- (174, 252, 201, 255),
- (247, 167, 111, 255),
- (225, 162, 239, 255),
- (209, 239, 119, 255),
- (211, 255, 178, 255),
- (119, 249, 215, 255),
- (252, 113, 146, 255),
- (204, 247, 160, 255),
- (247, 161, 148, 255),
- (218, 186, 255, 255),
- (112, 239, 116, 255),
- (237, 186, 125, 255),
- (198, 202, 255, 255),
- (197, 252, 174, 255),
-]
-
-
-def darken(color, factor=0.5):
- r, g, b, a = color
- return r * factor, g * factor, b * factor, a
-
-
-def lighten(color, factor=0.5):
- r, g, b, a = color
- return min(255, r * (1 + factor)), min(255, g * (1 + factor)), min(255, b * (1 + factor)), a
-
-
-# commands
-COMMAND_EXIT = 0
-COMMAND_START = 1
-COMMAND_MENU = 2
-
-
-def lerp(start, end, weight):
- return weight * (end - start) + start
-
-
-def clamp(value, minimum, maximum):
- return min(maximum, max(minimum, value))
-
-def determine_angle(pos1, pos2):
- pos1 = pygame.Vector2(pos1)
- pos2 = pygame.Vector2(pos2)
- if pos1.x == pos2.x:
- pos2.x += 0.0001
- a = math.degrees(math.atan((pos2.y - pos1.y) / (pos2.x - pos1.x)))
- return a