Initial Commit
This commit is contained in:
+3
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
Generated
+4
@@ -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>
|
||||
Generated
+8
@@ -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>
|
||||
Generated
+10
@@ -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
@@ -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>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 67 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
import pygame
|
||||
|
||||
_image = pygame.image.load('Background.png')
|
||||
|
||||
|
||||
def draw(surface: pygame.surface):
|
||||
surface.blit(_image.convert(), (0, 0))
|
||||
@@ -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()
|
||||
@@ -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))
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user