Initial Commit

This commit is contained in:
2022-08-25 00:27:03 +02:00
commit 2e13c87a9d
15 changed files with 151 additions and 0 deletions
Generated Vendored
+3
View File
@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml
+6
View File
@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (pyGame)" project-jdk-type="Python SDK" />
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/pyGame.iml" filepath="$PROJECT_DIR$/.idea/pyGame.iml" />
</modules>
</component>
</project>
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
View File
Binary file not shown.
+7
View File
@@ -0,0 +1,7 @@
import pygame
_image = pygame.image.load('Background.png')
def draw(surface: pygame.surface):
surface.blit(_image.convert(), (0, 0))
+2
View File
@@ -0,0 +1,2 @@
White = (255, 255, 255)
Black = (0, 0, 0)
+35
View File
@@ -0,0 +1,35 @@
import pygame
import sys
from pygame.locals import *
import osd
from player import Player
import background
surface = pygame.display.set_mode((800, 600))
clock = pygame.time.Clock()
player = Player(surface, x=20)
player2 = Player(surface, x=760)
player2.use_alternate_sprite()
player2.reverse_player()
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
background.draw(surface)
player.control()
player.draw()
player2.y = player.y
player2.draw()
osd.draw_fps(surface, clock)
osd.draw_player_pos(surface, player.y)
# Update scene
clock.tick(120)
pygame.display.update()
+16
View File
@@ -0,0 +1,16 @@
import pygame
import colors as Colors
pygame.init()
pygame.font.init()
_font = pygame.font.SysFont('Calibre', 24)
def draw_fps(surface: pygame.surface, clock: pygame.time.Clock):
_text_fps = _font.render(f"FPS: {round(clock.get_fps(), 0)}", True, Colors.White)
surface.blit(_text_fps, (5, 5))
def draw_player_pos(surface: pygame.surface, pos_y):
_text_fps = _font.render(f"Y: {pos_y}", True, Colors.White)
surface.blit(_text_fps, (5, 25))
+54
View File
@@ -0,0 +1,54 @@
import pygame
class Player:
"""
Creates new instance of player or NPC.
:param surface: Surface to draw player onto
:param x: Horizontal position of player
:return: Returns nothing
"""
def __init__(self, surface: pygame.surface, x):
self._surface = surface
self._image = pygame.image.load('PaddleA.png').convert_alpha()
self._rect = self._image.get_rect()
self.x = x
self.y = round(((self._surface.get_height() / 2) - self._rect.height / 2) / 10, 0) * 10
self.vec = 5
self.player = None
self.dist_bot = 0
self.dist_top = 0
def use_alternate_sprite(self):
""" Changes out default sprite for alternate colorized version. """
self._image = pygame.image.load('PaddleB.png').convert_alpha()
def reverse_player(self):
""" Rotates player sprite 180°. """
self._image = pygame.transform.rotate(self._image, 180)
def draw(self):
""" Draw player to screen and update positions relative to screen area. """
# self.player = pygame.draw.circle(self._surface,
# Colors.White,
# (self.x, self.y),
# 25)
self.player = self._surface.blit(self._image, (self.x, self.y))
# Calculate player position relative to screen area
self.dist_bot = (self._surface.get_height() - self._rect.y - self.y) - self._rect.height
self.dist_top = 0 + self._rect.y + self.y
def control(self):
""" Handover physical controls to player. """
keys = pygame.key.get_pressed()
# print(f"{self.dist_top} {self.dist_bot}")
if keys[pygame.K_w] and self.dist_top > 0:
self.y -= self.vec
if keys[pygame.K_s] and self.dist_bot > 0:
self.y += self.vec