Compare commits

...

69 Commits

Author SHA1 Message Date
Timofejs Maksimovs bda3c715d7 Upload files to "Sprites" 2024-03-04 07:56:07 +00:00
Timofejs Maksimovs ebeef03971 Update menu copy 2.py 2024-03-04 07:55:42 +00:00
Gerhards Kristians Tillers 13e6d6777b Update Game_V2.py 2024-03-04 07:30:53 +00:00
Timofejs Maksimovs 54404cac31 Upload files to "resources/Game/resources" 2024-03-04 07:18:02 +00:00
Romāns Šaduncs bae5f86774 Update Game_V2.py 2024-03-04 07:16:46 +00:00
Gerhards Kristians Tillers cb9ed69a60 Update Game_V2.py 2024-03-04 07:05:03 +00:00
Gerhards Kristians Tillers a493b07760 Upload files to "Sounds" 2024-03-04 07:03:49 +00:00
Timofejs Maksimovs 94ce10056a Delete overlay.png 2024-03-03 21:20:43 +00:00
Timofejs Maksimovs 5d2b7766ff Upload files to "/" 2024-03-03 21:20:30 +00:00
Timofejs Maksimovs 0f227065c4 Upload files to "resources/Free Dungeon - Fantasy Dreamland/48x48" 2024-03-03 21:20:00 +00:00
Timofejs Maksimovs d825aec837 Upload files to "resources/Game" 2024-03-03 21:18:57 +00:00
Timofejs Maksimovs e58c81cd91 Upload files to "resources" 2024-03-03 21:18:31 +00:00
Timofejs Maksimovs d00e901688 Upload files to "/" 2024-03-03 21:17:52 +00:00
Timofejs Maksimovs 98909e7240 Delete map_0.py 2024-03-03 21:17:33 +00:00
Timofejs Maksimovs f91d169fbb Delete level1.tmx 2024-03-03 21:17:24 +00:00
Timofejs Maksimovs 27d898611a Delete FD_Dungeon_Free.tsx 2024-03-03 21:17:15 +00:00
Timofejs Maksimovs daa5e13260 Delete FD_Dungeon_Free.png 2024-03-03 21:17:08 +00:00
Timofejs Maksimovs dbe233dfcc Delete Collisions.csv 2024-03-03 21:17:02 +00:00
Timofejs Maksimovs c000338518 Delete trash/data.json 2024-03-03 21:16:51 +00:00
Timofejs Maksimovs 3363f39d2d Delete resources 2024-03-03 21:15:56 +00:00
Timofejs Maksimovs 501342da02 Delete start.ldtk 2024-03-03 21:15:50 +00:00
Timofejs Maksimovs 758d52c80e Delete try.py 2024-03-03 21:15:42 +00:00
Timofejs Maksimovs dff7e6a903 Delete world0_code.py 2024-03-03 21:15:35 +00:00
Timofejs Maksimovs 14895b9a00 Delete tiles.png 2024-03-03 21:15:08 +00:00
Timofejs Maksimovs ac4952a79d Add resources 2024-03-03 21:11:52 +00:00
Gerhards Kristians Tillers c8515d3312 Delete Movement.py 2024-03-03 20:36:48 +00:00
Gerhards Kristians Tillers d3da2b8c2b Delete Movement+shooting.py 2024-03-03 20:36:38 +00:00
Gerhards Kristians Tillers ed4aba668e Delete explosion.wav 2024-03-03 20:36:24 +00:00
Gerhards Kristians Tillers d1f6d0a52d Delete minigun_shooting.wav 2024-03-03 20:36:16 +00:00
Gerhards Kristians Tillers c0fa26e80a Delete sshooting.py 2024-03-03 20:36:09 +00:00
Gerhards Kristians Tillers 0d1331adf5 Delete minigun_stop.wav 2024-03-03 20:35:56 +00:00
Gerhards Kristians Tillers 17f9409190 Delete Movement_version_3.py 2024-03-03 20:35:37 +00:00
Gerhards Kristians Tillers b694c95d28 Delete Game_1.sln 2024-03-03 20:35:18 +00:00
Gerhards Kristians Tillers efea158dbb Upload files to "Sounds" 2024-03-03 20:34:35 +00:00
Gerhards Kristians Tillers 0a89e951ec Upload files to "assets" 2024-03-03 20:33:56 +00:00
Gerhards Kristians Tillers 831e7ba96b Upload files to "assets" 2024-03-03 20:33:14 +00:00
Gerhards Kristians Tillers 89244e6fa7 Delete Game_1/Game_1.pyproj 2024-03-03 20:31:57 +00:00
Gerhards Kristians Tillers 9da2f79ac5 Delete Game_1/Main.py 2024-03-03 20:31:47 +00:00
Gerhards Kristians Tillers 2268027236 Upload files to "Sprites" 2024-03-03 20:30:58 +00:00
Gerhards Kristians Tillers c39efd2649 Update menu copy 2.py 2024-03-03 20:20:34 +00:00
Gerhards Kristians Tillers 5b4e2f5f2c Update Game_V2.py 2024-03-03 20:20:00 +00:00
Gerhards Kristians Tillers b97bc194b4 Update menu copy 2.py 2024-03-03 20:18:56 +00:00
Timofejs Maksimovs 38f4e36c79 Upload files to "/" 2024-03-03 14:48:42 +00:00
Timofejs Maksimovs f5a7a5656f Upload files to "/" 2024-03-03 14:48:40 +00:00
Timofejs Maksimovs 870658a6b8 Upload files to "/" 2024-03-03 14:38:53 +00:00
Timofejs Maksimovs fa969b92b1 map addition
Browsing map textures, character is yet static
2024-03-03 14:36:47 +00:00
Gerhards Kristians Tillers 3c49c43ba2 Delete Sounds 2024-03-03 14:11:54 +00:00
Gerhards Kristians Tillers 1646899a25 Upload files to "/" 2024-03-03 14:10:22 +00:00
Gerhards Kristians Tillers 811608d8b4 Upload files to "Sprites" 2024-03-03 14:03:58 +00:00
Gerhards Kristians Tillers a16013e8a4 Add Sounds 2024-03-03 14:01:33 +00:00
Gerhards Kristians Tillers 6322cb5b5c Update Game_V2.py 2024-03-03 14:00:13 +00:00
Gerhards Kristians Tillers a43c590d7b Update Game_V2.py 2024-03-03 10:53:31 +00:00
Gerhards Kristians Tillers 7b0dae6f96 Update Game_V2.py 2024-03-03 10:07:51 +00:00
Gerhards Kristians Tillers 0b11590e52 Update menu copy 2.py 2024-03-03 10:07:11 +00:00
Gerhards Kristians Tillers c6537320dc Upload files to "/" 2024-03-03 09:45:29 +00:00
Gerhards Kristians Tillers 5dcfcb05bd Delete Game_V2.py 2024-03-03 09:45:19 +00:00
Romāns Šaduncs eebc489d4f Обновить menu copy 2.py 2024-03-02 21:39:07 +00:00
Romāns Šaduncs 2bafedc81f Загрузить файлы в «assets» 2024-03-02 21:38:03 +00:00
Romāns Šaduncs bccca5ebba Загрузить файлы в «/» 2024-03-02 21:34:09 +00:00
Romāns Šaduncs 610498b140 Удалить Quit Rect.png 2024-03-02 21:32:56 +00:00
Romāns Šaduncs 435364bc89 Удалить Play Rect.png 2024-03-02 21:32:49 +00:00
Romāns Šaduncs 23c1a58dc4 Удалить Options Rect.png 2024-03-02 21:32:41 +00:00
Romāns Šaduncs b4465a0a17 Удалить Background.png 2024-03-02 21:32:33 +00:00
Romāns Šaduncs 6d909da094 Удалить font.ttf 2024-03-02 21:32:25 +00:00
Romāns Šaduncs a5feb09f00 Загрузить файлы в «/» 2024-03-02 21:32:07 +00:00
Romāns Šaduncs 7e45ab8275 Загрузить файлы в «assets» 2024-03-02 21:31:40 +00:00
Romāns Šaduncs 92fa566a2b Добавить assets/file 2024-03-02 21:31:17 +00:00
Romāns Šaduncs fa62e98963 Удалить assets 2024-03-02 21:30:49 +00:00
Romāns Šaduncs df215357ec Добавить assets 2024-03-02 21:30:30 +00:00
39 changed files with 914 additions and 3046 deletions

View File

@ -1,16 +0,0 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,
1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,
1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,1,0,1,1,1,0,1,1,1,
1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,1,1,1,0,1,1,1,
1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,1,1,1,0,1,1,1,
1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,0,1,1,1,0,1,1,1,
1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Can't render this file because it has a wrong number of fields in line 16.

View File

@ -1,23 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34018.315
MinimumVisualStudioVersion = 10.0.40219.1
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "Game_1", "Game_1\Game_1.pyproj", "{5A0A8F0A-4743-4282-A2FA-E1F09FFC6A22}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5A0A8F0A-4743-4282-A2FA-E1F09FFC6A22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5A0A8F0A-4743-4282-A2FA-E1F09FFC6A22}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3BAECF31-65AB-41B5-9E61-740FB272932B}
EndGlobalSection
EndGlobal

View File

@ -1,35 +0,0 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>5a0a8f0a-4743-4282-a2fa-e1f09ffc6a22</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>Game_1.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
<OutputPath>.</OutputPath>
<Name>Game_1</Name>
<RootNamespace>Game_1</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<ItemGroup>
<Compile Include="Game_1.py" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
<!-- Uncomment the CoreCompile target to enable the Build command in
Visual Studio and specify your pre- and post-build commands in
the BeforeBuild and AfterBuild targets below. -->
<!--<Target Name="CoreCompile" />-->
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
</Project>

View File

@ -1,197 +0,0 @@
import pygame
from time import sleep
from pygame.sprite import Sprite
pygame.init()
class Camera:
def __init__(self, player, size=(400, 300)):
self.player = player
self.center = pygame.display.get_surface().get_rect().center
self.size = size
self.player_size = self.player.rect.size
self.speed_x = 0
self.speed_y = 0
def update(self, dt, sprites):
x_move = abs(self.player.rect.centerx - self.center[0]) > self.size[0] // 2
y_move = abs(self.player.rect.centery - self.center[1]) > self.size[1] // 2
if x_move or y_move:
for sprite in sprites:
if x_move:
self.speed_x = (self.player.rect.centerx - self.center[0]) * 2 * dt
sprite.rect.x -= self.speed_x
if y_move:
self.speed_y = (self.player.rect.centery - self.center[1]) * 2 * dt
sprite.rect.y -= self.speed_y
class Wall(pygame.sprite.Sprite):
def __init__(self, size, pos) -> None:
super().__init__()
self.image = pygame.surface.Surface(size)
self.image.fill("red")
self.rect = self.image.get_rect(center=pos)
class Floor(pygame.sprite.Sprite):
def __init__(self, size, pos) -> None:
super().__init__()
def create_floor(file_name):
floor = []
with open (file_name) as f:
lines = f.readlines()
for i, line in enumerate(lines[::2]):
if floor == "#":
floor.append(Floor((30,30), (30 + 30*i)))
return floor
def create_walls(file_name):
walls = []
with open(file_name) as f:
lines = f.readlines()
for i, line in enumerate(lines[::2]):
for j, floor in enumerate(line[1::2]):
if floor == "|":
walls.append(Wall((5, 30), (15 + 30*j, 30*i)))
for i, line in enumerate(lines[1::2]):
for j, floor in enumerate(line[::2]):
if floor == "-":
walls.append(Wall((30, 5), (30*j, 15 + 30*i)))
return walls
class Player(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.right = True
self.move = True
self.player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
self.dt = 0
self.keys = pygame.key.get_pressed()
self.player_right = pygame.transform.scale(pygame.image.load("Sprites/Idle/Player_right.png").convert_alpha(), (35, 40)),
self.player_run_right_1 = pygame.transform.scale(pygame.image.load("Sprites/Running/Player_run_right_1.png").convert_alpha(), (35, 40)),
self.player_run_right_2 = pygame.transform.scale(pygame.image.load("Sprites/Running/Player_run_right_2.png").convert_alpha(), (35, 40)),
self.player_run_right_3 = pygame.transform.scale(pygame.image.load("Sprites/Running/Player_run_right_3.png").convert_alpha(), (35, 40)),
self.player_run_right_4 = pygame.transform.scale(pygame.image.load("Sprites/Running/Player_run_right_4.png").convert_alpha(), (35, 40)),
self.player_run_right_5 = pygame.transform.scale(pygame.image.load("Sprites/Running/Player_run_right_5.png").convert_alpha(), (35, 40)),
self.player_run_right_6 = pygame.transform.scale(pygame.image.load("Sprites/Running/Player_run_right_6.png").convert_alpha(), (35, 40))
self.player_left = pygame.transform.scale(pygame.image.load("Sprites/Idle/Player_left.png").convert_alpha(), (35, 40))
def movement(self):
if self.keys[pygame.K_w]:
self.player_pos.y -= 200 * dt
if self.keys[pygame.K_s]:
self.player_pos.y += 200 * dt
if self.keys[pygame.K_a]:
self.player_pos.x -= 200 * dt
screen.blit(self.player_left, (self.player_pos.x, self.player_pos.y))
right = False
if self.keys[pygame.K_d]:
self.player_pos.x += 200 * dt
screen.blit(self.player_right, (self.player_pos.x, self.player_pos.y))
self.right = True
self.move = True
else:
move = False
def sprites(self):
if self.right == True:
screen.blit(self.player_right, (self.player_pos.x, self.player_pos.y))
else:
screen.blit(self.player_left, (self.player_pos.x, self.player_pos.y))
while self.move == True:
screen.blit(self.player_run_right_1, (self.player_pos.x, self.player_pos.y))
sleep(0.05)
screen.blit(self.player_run_right_2, (self.player_pos.x, self.player_pos.y))
sleep(0.05)
screen.blit(self.player_run_right_3, (self.player_pos.x, self.player_pos.y))
sleep(0.05)
screen.blit(self.player_run_right_4, (self.player_pos.x, self.player_pos.y))
sleep(0.05)
screen.blit(self.player_run_right_5, (self.player_pos.x, self.player_pos.y))
sleep(0.05)
screen.blit(self.player_run_right_6, (self.player_pos.x, self.player_pos.y))
sleep(0.05)
screen = pygame.display.set_mode((1920, 1015))
pygame.display.set_caption("Game_name")
clock = pygame.time.Clock()
floor_image = pygame.transform.scale(pygame.image.load("Floor.png").convert_alpha(), (30, 30))
running = True
wall_list = create_walls("lvl.txt")
for wall in wall_list:
print(f'{wall.rect.size})x = {wall.rect.x}; y = {wall.rect.y}')
walls = pygame.sprite.Group(*wall_list)
floor_list = create_floor("lvl.txt")
for floor in floor_list:
print(f'{floor.rect.size})x = {floor.rect.x}; y = {floor.rect.y}')
floor = pygame.sprite.Group(*floor_list)
player = Player()
all_sprites = pygame.sprite.Group()
all_sprites.add(player)
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill("cyan")
for y in range(10,20):
for x in range(26,38):
screen.blit(floor_image, (30*x, 30*y))
all_sprites.draw(screen)
walls.draw(screen)
pygame.display.flip()
dt = clock.tick(60)/1000
floor.draw(screen)
pygame.quit()

View File

@ -1,17 +1,20 @@
import pygame
from random import randint
import math
import sys
SCREEN_X = 1280
SCREEN_Y = 720
SCREEN_X = 1920
SCREEN_Y = 1015
# pygame setup
pygame.init()
pygame.display.set_caption("Vampire survivors")
pygame.display.set_caption("Rouglite")
screen = pygame.display.set_mode((SCREEN_X, SCREEN_Y))
clock = pygame.time.Clock()
running = True
class Player(pygame.sprite.Sprite):
def __init__(self, pos, group):
super().__init__(group)
@ -19,6 +22,10 @@ class Player(pygame.sprite.Sprite):
self.rect = self.image.get_rect(center = pos)
self.direction = pygame.math.Vector2()
self.speed = 2.25
self.time = 0
self.time_2 = 0
self.SCORE = 0
#health
self.current_health = 1000 #health
@ -44,6 +51,7 @@ class Player(pygame.sprite.Sprite):
self.running_sprites.append(pygame.image.load("Sprites/Running/Player_run_right_"+str(i+1)+".png").convert_alpha())
def get_damage(self, amount):
if self.target_health > 0:
self.target_health -= amount
@ -54,28 +62,29 @@ class Player(pygame.sprite.Sprite):
def get_health(self, amnount):
if self.target_health < self.maximum_health:
self.target_health += amnount
pygame.mixer.Sound("Sounds/health_plus.mp3")
if self.target_health >= self.maximum_health:
self.target_health = self.maximum_health
def ahealth_bar(self):
transition_width = 0
transition_colour = (255,0,0)
if self.current_health < self.target_health:
self.current_health += self.health_change_speed
transition_width = int((self.target_health - self.current_health)/3)
self.current_health += (self.target_health-self.current_health)/10
transition_colour = (0, 255, 0)
health_bar_width = self.current_health/self.health_ratio
transition_bar_width = self.target_health/self.health_ratio
elif self.current_health > self.target_health:
self.current_health -= self.health_change_speed
transition_width = int((self.target_health - self.current_health)/3)
if self.current_health > self.target_health:
health_bar_width = self.target_health/self.health_ratio
transition_bar_width = self.current_health/self.health_ratio
transition_colour = (255, 255, 0)
health_bar_rect = pygame.Rect(10,45,self.current_health/self.health_ratio,25)
transition_bar_rect = pygame.Rect(health_bar_rect.right,45,transition_width,25)
health_bar_rect = pygame.Rect(10,45,health_bar_width,25)
transition_bar_rect = pygame.Rect(10,45,transition_bar_width,25)
pygame.draw.rect(screen,(255,0,0),health_bar_rect)
pygame.draw.rect(screen, transition_colour, transition_bar_rect)
pygame.draw.rect(screen,(255,0,0),health_bar_rect)
pygame.draw.rect(screen,(255,255,255), (10,45,self.health_bar_lenght,25),4)
def input(self):
@ -120,6 +129,8 @@ class Player(pygame.sprite.Sprite):
new_projectile = Projectile(self.rect.center, direction, camera_group)
self.can_shoot = False
self.shoot_cooldown = pygame.time.get_ticks()
self.shoot = True
def update(self):
self.input()
@ -194,6 +205,12 @@ class Projectile(pygame.sprite.Sprite):
enemy.damage(1)
self.kill()
break
for enemy in enemies2:
distance = pygame.math.Vector2.length(pygame.math.Vector2(enemy.rect.center) - self.rect.center)
if distance < 20:
enemy.damage(1)
self.kill()
break
def update(self):
self.rect.center += self.direction * self.speed
@ -204,33 +221,83 @@ class Projectile(pygame.sprite.Sprite):
self.kill()
class Enemy(pygame.sprite.Sprite):
def __init__(self, pos, group):
def __init__(self, pos, group, scale):
super().__init__(group)
self.image = pygame.surface.Surface((20, 20))
self.image.fill("red")
self.rect = self.image.get_rect(center = pos)
self.original_image = pygame.image.load("Sprites/bomb.png").convert_alpha()
self.image = pygame.transform.scale(self.original_image, (int(self.original_image.get_width() * scale), int(self.original_image.get_height() * scale)))
self.phase_2 = pygame.image.load("Sprites/bomb_phase2.png").convert_alpha()
self.phase_2 = pygame.transform.scale(self.phase_2, (int(self.phase_2.get_width() * scale), int(self.phase_2.get_height() * scale)))
self.rect = self.image.get_rect(center=pos)
self.pos = self.rect.center
self.direction = pygame.math.Vector2()
self.speed = 2
self.health = 2
self.health = 3
self.death = pygame.mixer.Sound("Sounds/explosion.wav")
self.image_direction = 1
def damage(self, damage):
self.health -= 1
if self.health == 1:
self.image = self.phase_2
if self.health <= 0:
enemies.remove(self)
self.kill()
self.death.play()
player.SCORE += 1
def update(self):
self.direction = pygame.math.Vector2(player.rect.center) - self.rect.center
if(pygame.math.Vector2.length(self.direction)<20):
if pygame.math.Vector2.length(self.direction) < 20:
if self.image == self.phase_2:
player.get_damage(100)
self.kill()
enemies.remove(self)
player.time = 0
self.death.play()
else:
player.get_damage(200)
self.kill()
enemies.remove(self)
player.time = 0
self.death.play()
self.pos += self.direction.normalize() * self.speed
self.rect.center = (round(self.pos.x), round(self.pos.y))
class Enemy_2(pygame.sprite.Sprite):
def __init__(self, pos, group, scale):
super().__init__(group)
self.original_image = pygame.image.load("Sprites/atom_bomb.png").convert_alpha()
self.image = pygame.transform.scale(self.original_image, (int(self.original_image.get_width() * scale), int(self.original_image.get_height() * scale)))
self.rect = self.image.get_rect(center = pos)
self.pos = self.rect.center
self.direction = pygame.math.Vector2()
self.speed = 1
self.health = 10
self.image_direction = 1
self.death = pygame.mixer.Sound("Sounds/explosion_atomic.wav")
def damage(self, damage):
self.health -= 1
if self.health <= 0:
enemies2.remove(self)
self.kill()
self.death.play()
player.SCORE += 3
def update(self):
self.direction = pygame.math.Vector2(player.rect.center) - self.rect.center
if pygame.math.Vector2.length(self.direction) < 20:
player.get_damage(500)
self.kill()
enemies2.remove(self)
player.time = 0
self.death.play()
self.pos += self.direction.normalize() * self.speed
self.rect.center = (round(self.pos.x), round(self.pos.y))
@ -258,16 +325,33 @@ class CameraGroup(pygame.sprite.Group):
self.display_surface.blit(sprite.image, offset_pos)
def spawn_enemy():
if len(enemies) < 20:
if len(enemies) < 5 + (player.time_2):
random_x = randint(-1000, 1000)
random_y = randint(-1000, 1000)
enemies.append(Enemy((player.rect.centerx + random_x, player.rect.centery + random_y), camera_group))
enemies.append(Enemy((player.rect.centerx + random_x, player.rect.centery + random_y), camera_group, 0.05))
def spawn_enemy2():
if len(enemies2) < 2 + int(player.time_2):
random_x = randint(-1000, 1000)
random_y = randint(-1000, 1000)
enemies2.append(Enemy_2((player.rect.centerx + random_x, player.rect.centery + random_y), camera_group, 0.5))
spawn_enemy_event = pygame.USEREVENT + 1
smallfont = pygame.font.Font("assets/font.ttf", 25)
def score(score):
text = smallfont.render("Score: " + str(score), True, "black")
screen.blit(text, [10,15])
#Setup
camera_group = CameraGroup()
enemies = []
enemies2 = []
@ -282,7 +366,10 @@ pygame.mouse.set_cursor(cursor)
pygame.mouse.set_visible(True | False)
# Add a variable to track player's life status
player_alive = True
# Main game loop
while running:
for e in pygame.event.get():
if e.type == pygame.QUIT:
@ -292,27 +379,50 @@ while running:
if e.type == spawn_enemy_event:
spawn_enemy()
if e.type == pygame.KEYDOWN:
if e.key == pygame.K_UP:
player.get_health(200)
if e.type == pygame.KEYDOWN:
if e.key == pygame.K_DOWN:
player.get_damage(200)
if e.type == spawn_enemy_event:
spawn_enemy2()
if player.time > 3:
if player.current_health < 999 and player.target_health > 0:
player.get_health(100)
player.time -= 1
else:
pass
# Check if the player's health reaches zero
if player.target_health <= 0:
player_alive = False
if not player_alive: # Display death screen
screen.fill((0, 0, 0)) # Fill screen with black color
death_font = pygame.font.Font(None, 50)
death_text = smallfont.render("You Died! Your score was " + str(player.SCORE), True, (255, 255, 255))
screen.blit(death_text, (SCREEN_X // 2 - death_text.get_width() // 2, SCREEN_Y // 2 - death_text.get_height() // 2))
restart_text = smallfont.render("Press SPACE to restart", True, (255, 255, 255))
screen.blit(restart_text, (SCREEN_X // 2 - restart_text.get_width() // 2, SCREEN_Y // 2 + 50))
quit_text = smallfont.render("Press Q to quit", True, (255, 255, 255))
screen.blit(quit_text, (SCREEN_X // 2 - quit_text.get_width() // 2, SCREEN_Y // 2 + 100))
pygame.display.flip()
# Check for restart or quit input
keys = pygame.key.get_pressed()
if keys[pygame.K_SPACE]:
# Reset player's health, score, and other relevant variables
player_alive = True
player.current_health = player.maximum_health
player.target_health = player.maximum_health
player.SCORE = 0
if keys[pygame.K_q]:
pygame.quit()
sys.exit()
else: # If player is alive, continue the game
screen.fill("cyan")
score(player.SCORE)
camera_group.update()
camera_group.custom_draw(player)
pygame.display.flip()
clock.tick(60)
player.time += 0.016
player.time_2 += 0.005

View File

@ -1,205 +0,0 @@
import pygame
import math
import sys
pygame.init()
WIDTH, HEIGHT = 400, 400
DISPLAY_X, DISPLAY_Y = 1920, 1015
bullet_img = pygame.transform.scale(pygame.image.load('bullet.png'), (50, 100))
player_img = pygame.transform.scale(pygame.image.load('player.png'), (50, 30))
enemy_img = pygame.transform.scale(pygame.image.load('enemy.png'), (50, 30))
crosshair_img = pygame.transform.scale(pygame.image.load('crosshair.png'), (30, 30))
player_bullets = []
player_pos = [WIDTH // 2 - player_img.get_width() // 2, HEIGHT - player_img.get_height()]
enemy_pos = [WIDTH // 2 - enemy_img.get_width() // 2, 50]
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Game_name")
clock = pygame.time.Clock()
class Player(pygame.sprite.Sprite):
def __init__(self, pos_x, pos_y, x, y):
super().__init__()
#sprites right
self.sprites_right = []
self.in_animation = False
self.side = True
self.sprites_right.append(pygame.image.load("Sprites/Idle/Player_right.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_1.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_2.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_3.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_4.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_5.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_6.png"))
self.current_sprite_right = 0
self.image = self.sprites_right[self.current_sprite_right]
self.rect = self.image.get_rect()
self.rect.topleft = [pos_x,pos_y]
#sprites left
self.sprites_left = []
self.in_animation_2 = False
self.sprites_left.append(pygame.image.load("Sprites/Idle/Player_left.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_1.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_2.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_3.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_4.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_5.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_6.png"))
self.current_sprite_left = 0
self.image = self.sprites_left[self.current_sprite_left]
self.rect = self.image.get_rect()
self.rect.topleft = [pos_x,pos_y]
self.rect = pygame.Rect(x, y, 32, 32)
self.x = int(x)
self.y = int(y)
self.velX = 0
self.velY = 0
self.speed = 3
self.left_pressed = False
self.right_pressed = False
self.down_pressed = False
self.up_pressed = False
self.shoot_cooldown = 0
self.shoot_cooldown_max = 10 # Задержка между выстрелами
def animate_right(self, start):
self.in_animation = start
def animate_left(self, start):
self.in_animation_2 = start
def sides(self, start):
self.side = start
def update(self):
if self.in_animation:
self.current_sprite_right += 0.2
if self.current_sprite_right >= len(self.sprites_right):
self.current_sprite_right = 0
self.image = self.sprites_right[int(self.current_sprite_right)]
if not any([self.right_pressed, self.left_pressed, self.up_pressed, self.down_pressed]) and self.side:
self.image = self.sprites_right[0]
if not any([self.right_pressed, self.left_pressed, self.up_pressed, self.down_pressed]) and not self.side:
self.image = self.sprites_left[0]
#animation left
if self.in_animation_2:
self.current_sprite_left += 0.2
if self.current_sprite_left >= len(self.sprites_left):
self.current_sprite_left = 0
self.image = self.sprites_left[int(self.current_sprite_left)]
self.velX = 0
self.velY = 0
if self.left_pressed and not self.right_pressed:
self.velX = -self.speed
if self.right_pressed and not self.left_pressed:
self.velX = self.speed
if self.up_pressed and not self.down_pressed:
self.velY = -self.speed
if self.down_pressed and not self.up_pressed:
self.velY = self.speed
self.x += self.velX
self.y += self.velY
self.rect = pygame.Rect(self.x, self.y, 32, 32)
keys = pygame.key.get_pressed()
if self.shoot_cooldown > 0:
self.shoot_cooldown -= 1
if keys[pygame.K_SPACE] and self.shoot_cooldown == 0:
self.shoot()
self.shoot_cooldown = self.shoot_cooldown_max
def shoot(self):
mouse_x, mouse_y = pygame.mouse.get_pos()
angle = math.atan2(mouse_y - self.rect.centery, mouse_x - self.rect.centerx)
player_bullets.append({"position": [self.rect.centerx - bullet_img.get_width() // 2,
self.rect.centery - bullet_img.get_height() // 2],
"angle": angle})
screen = pygame.display.set_mode((DISPLAY_X, DISPLAY_Y))
pygame.display.set_caption("Game_name")
clock = pygame.time.Clock()
moving_sprites = pygame.sprite.Group()
player = Player(100, 100, WIDTH/2, HEIGHT/2)
moving_sprites.add(player)
def draw_elements():
screen.blit(player_img, player_pos)
screen.blit(enemy_img, enemy_pos)
screen.blit(crosshair_img, pygame.mouse.get_pos())
for bullet in player_bullets:
screen.blit(bullet_img, bullet["position"])
moving_sprites = pygame.sprite.Group()
player = Player(100, 100, WIDTH/2, HEIGHT/2)
moving_sprites.add(player)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_a:
player.left_pressed = True
player.animate_left(True)
player.sides(False)
if event.key == pygame.K_d:
player.right_pressed = True
player.animate_right(True) # Start animation when right key pressed
player.sides(True)
if event.key == pygame.K_w:
player.up_pressed = True
if event.key == pygame.K_s:
player.down_pressed = True
# Key release events
if event.type == pygame.KEYUP:
if event.key == pygame.K_a:
player.left_pressed = False
player.animate_left(False)
if event.key == pygame.K_d:
player.right_pressed = False
player.animate_right(False) # Stop animation when right key released
if event.key == pygame.K_w:
player.up_pressed = False
if event.key == pygame.K_s:
player.down_pressed = False
for bullet in player_bullets:
bullet["position"][0] += 5 * math.cos(bullet["angle"])
bullet["position"][1] += 5 * math.sin(bullet["angle"])
if bullet["position"][0] < 0 or bullet["position"][0] > WIDTH or bullet["position"][1] < 0 or bullet["position"][1] > HEIGHT:
player_bullets.remove(bullet)
screen.fill((0, 255, 255))
moving_sprites.draw(screen)
dt = clock.tick(60)/1000
draw_elements()
moving_sprites.update()
pygame.display.flip()

View File

@ -1,205 +0,0 @@
import pygame
import sys
pygame.init()
WIDTH, HEIGHT = 400, 400
DISPLAY_X, DISPLAY_Y = 1920, 1015
class Player(pygame.sprite.Sprite):
def __init__(self, pos_x, pos_y, x, y):
super().__init__()
#sprites right
self.sprites_right = []
self.in_animation = False
self.side = True
self.sprites_right.append(pygame.image.load("Sprites/Idle/Player_right.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_1.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_2.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_3.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_4.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_5.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_6.png"))
self.current_sprite_right = 0
self.image = self.sprites_right[self.current_sprite_right]
self.rect = self.image.get_rect()
self.rect.topleft = [pos_x,pos_y]
#sprites left
self.sprites_left = []
self.in_animation_2 = False
self.sprites_left.append(pygame.image.load("Sprites/Idle/Player_left.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_1.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_2.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_3.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_4.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_5.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_6.png"))
self.current_sprite_left = 0
self.image = self.sprites_left[self.current_sprite_left]
self.rect = self.image.get_rect()
self.rect.topleft = [pos_x,pos_y]
#movement
self.rect = pygame.Rect(x, y, 32, 32)
self.x = int(x)
self.y = int(y)
self.velX = 0
self.velY = 0
self.left_pressed = False
self.right_pressed = False
self.down_pressed = False
self.up_pressed = False
self.speed = 3
def animate_right(self, start):
self.in_animation = start
def animate_left(self, start):
self.in_animation_2 = start
def sides(self, start):
self.side = start
def update(self):
#animation right
if self.in_animation:
self.current_sprite_right += 0.2
if self.current_sprite_right >= len(self.sprites_right):
self.current_sprite_right = 0
self.image = self.sprites_right[int(self.current_sprite_right)]
if not any([self.right_pressed, self.left_pressed, self.up_pressed, self.down_pressed]) and self.side:
self.image = self.sprites_right[0]
if not any([self.right_pressed, self.left_pressed, self.up_pressed, self.down_pressed]) and not self.side:
self.image = self.sprites_left[0]
#animation left
if self.in_animation_2:
self.current_sprite_left += 0.2
if self.current_sprite_left >= len(self.sprites_left):
self.current_sprite_left = 0
self.image = self.sprites_left[int(self.current_sprite_left)]
#movement
self.velX = 0
self.velY = 0
if self.left_pressed and not self.right_pressed:
self.velX = -self.speed
if self.right_pressed and not self.left_pressed:
self.velX = self.speed
if self.up_pressed and not self.down_pressed:
self.velY = -self.speed
if self.down_pressed and not self.up_pressed:
self.velY = self.speed
self.x += self.velX
self.y += self.velY
self.rect = pygame.Rect(self.x, self.y, 32, 32)
screen = pygame.display.set_mode((DISPLAY_X, DISPLAY_Y))
pygame.display.set_caption("Game_name")
clock = pygame.time.Clock()
moving_sprites = pygame.sprite.Group()
player = Player(100, 100, WIDTH/2, HEIGHT/2)
moving_sprites.add(player)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# Key press events
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_a:
player.left_pressed = True
player.animate_left(True)
player.sides(False)
if event.key == pygame.K_d:
player.right_pressed = True
player.animate_right(True)
player.sides(True)
if event.key == pygame.K_w:
player.up_pressed = True
if event.key == pygame.K_s:
player.down_pressed = True
if event.key == pygame.K_a and event.key == pygame.K_w:
player.animate_left(True)
if event.key == pygame.K_w and event.key == pygame.K_d:
player.animate_right(True)
if event.key == pygame.K_d and event.key == pygame.K_s:
player.animate_right(True)
if event.key == pygame.K_s and event.key == pygame.K_a:
player.animate_left(True)
if event.key == pygame.K_w and player.side == False:
player.animate_left(True)
if event.key == pygame.K_w and player.side == True:
player.animate_right(True)
if event.key == pygame.K_s and player.side == False:
player.animate_left(True)
if event.key == pygame.K_s and player.side == True:
player.animate_right(True)
# Key release events
if event.type == pygame.KEYUP:
if event.key == pygame.K_a:
player.left_pressed = False
player.animate_left(False)
if event.key == pygame.K_d:
player.right_pressed = False
player.animate_right(False)
if event.key == pygame.K_w:
player.up_pressed = False
player.animate_left(False)
player.animate_right(False)
if event.key == pygame.K_s:
player.down_pressed = False
player.animate_left(False)
player.animate_right(False)
screen.fill((0, 255, 255))
moving_sprites.draw(screen)
pygame.display.flip()
dt = clock.tick(60)/1000
moving_sprites.update()

View File

@ -1,277 +0,0 @@
import pygame
from random import randint
import math
# pygame setup
pygame.init()
pygame.display.set_caption("Vampire survivors")
screen = pygame.display.set_mode((1920, 1015))
clock = pygame.time.Clock()
running = True
class Player(pygame.sprite.Sprite):
def __init__(self, pos, group, pos_x, pos_y):
super().__init__(group)
self.direction = pygame.math.Vector2()
self.speed = 2.5
# Shooting
self.can_shoot = True
self.shoot_cooldown_time = 200 # Milliseconds
self.shoot_cooldown = 0
#sprites right
self.sprites_right = []
self.in_animation = False
self.side = True
self.sprites_right.append(pygame.image.load("Sprites/Idle/Player_right.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_1.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_2.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_3.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_4.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_5.png"))
self.sprites_right.append(pygame.image.load("Sprites/Running/Player_run_right_6.png"))
self.current_sprite_right = 0
self.image = self.sprites_right[self.current_sprite_right]
self.rect = self.image.get_rect(center = pos)
self.rect = self.image.get_rect()
self.rect.topleft = [pos_x,pos_y]
#sprites left
self.sprites_left = []
self.in_animation_2 = False
self.sprites_left.append(pygame.image.load("Sprites/Idle/Player_left.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_1.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_2.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_3.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_4.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_5.png"))
self.sprites_left.append(pygame.image.load("Sprites/Running/Player_run_left_6.png"))
self.current_sprite_left = 0
self.image = self.sprites_left[self.current_sprite_left]
self.rect = self.image.get_rect()
self.rect.topleft = [pos_x,pos_y]
def animate_right(self, start):
self.in_animation = start
def animate_left(self, start):
self.in_animation_2 = start
def sides(self, start):
self.side = start
def input(self):
keys = pygame.key.get_pressed()
speed_multiplier_x = 0
speed_multiplier_y = 0
if keys[pygame.K_w] or keys[pygame.K_UP]:
speed_multiplier_y = -1
elif keys[pygame.K_s] or keys[pygame.K_DOWN]:
speed_multiplier_y = 1
# Check if A and D keys are pressed
if keys[pygame.K_a] or keys[pygame.K_LEFT]:
speed_multiplier_x = -1
elif keys[pygame.K_d] or keys[pygame.K_RIGHT]:
speed_multiplier_x = 1
# Calculate movement direction based on keys pressed
self.direction.x = speed_multiplier_x
self.direction.y = speed_multiplier_y
self.direction.y = (keys[pygame.K_DOWN] or keys[pygame.K_s]) - (keys[pygame.K_UP] or keys[pygame.K_w])
self.direction.x = (keys[pygame.K_RIGHT] or keys[pygame.K_d]) - (keys[pygame.K_LEFT] or keys[pygame.K_a])
if self.direction.x != 0 and self.direction.y != 0:
self.direction.normalize_ip()
self.direction.x *= self.speed
self.direction.y *= self.speed
if pygame.mouse.get_pressed()[0] and self.can_shoot:
direction = -(pygame.math.Vector2(self.rect.topleft) - pygame.mouse.get_pos() - camera_group.offset)
direction = pygame.math.Vector2.normalize(direction)
new_projectile = Projectile(self.rect.center, direction, camera_group)
self.can_shoot = False
self.shoot_cooldown = pygame.time.get_ticks()
def update(self):
self.input()
self.rect.center += self.direction * self.speed
now = pygame.time.get_ticks()
if now - self.shoot_cooldown > self.shoot_cooldown_time:
self.can_shoot = True
# Animation for moving right
if self.direction.x > 0:
self.animate_right(True)
self.animate_left(False)
self.side = True
self.image = self.sprites_right[int(self.current_sprite_right)]
self.current_sprite_right = (self.current_sprite_right + 0.2) % len(self.sprites_right)
# Animation for moving left
elif self.direction.x < 0:
self.animate_left(True)
self.animate_right(False)
self.side = False
self.image = self.sprites_left[int(self.current_sprite_left)]
self.current_sprite_left = (self.current_sprite_left + 0.2) % len(self.sprites_left)
elif self.direction.y > 0:
if self.side == True:
self.animate_right(True)
self.animate_left(False)
self.image = self.sprites_right[int(self.current_sprite_right)]
self.current_sprite_right = (self.current_sprite_right + 0.2) % len(self.sprites_right)
elif self.side == False:
self.animate_right(False)
self.animate_left(True)
self.image = self.sprites_left[int(self.current_sprite_left)]
self.current_sprite_left = (self.current_sprite_left + 0.2) % len(self.sprites_left)
elif self.direction.y < 0:
if self.side == True:
self.animate_right(True)
self.animate_left(False)
self.image = self.sprites_right[int(self.current_sprite_right)]
self.current_sprite_right = (self.current_sprite_right + 0.2) % len(self.sprites_right)
elif self.side == False:
self.animate_right(False)
self.animate_left(True)
self.image = self.sprites_left[int(self.current_sprite_left)]
self.current_sprite_left = (self.current_sprite_left + 0.2) % len(self.sprites_left)
# Idle animation when not moving
else:
self.animate_right(False)
self.animate_left(False)
# Set the idle sprite based on the last direction
if self.side:
self.image = self.sprites_right[0]
else:
self.image = self.sprites_left[0]
class Projectile(pygame.sprite.Sprite):
def __init__(self, pos, direction, group):
super().__init__(group)
self.image = pygame.image.load("Sprites/bullet.png").convert_alpha()
self.direction = direction
self.speed = 10
angle = math.degrees(math.atan2(-self.direction.y, self.direction.x))
self.image = pygame.transform.rotate(self.image, angle)
self.rect = self.image.get_rect(center = pos)
self.life_timer = 10000 # Milliseconds
self.spawned_time = pygame.time.get_ticks()
def collision(self):
for enemy in enemies:
distance = pygame.math.Vector2.length(pygame.math.Vector2(enemy.rect.center) - self.rect.center)
if distance < 20:
self.kill()
enemy.damage(1)
break
def update(self):
self.rect.center += self.direction * self.speed
self.collision()
now = pygame.time.get_ticks()
if now - self.spawned_time > self.life_timer:
self.kill()
class Enemy(pygame.sprite.Sprite):
def __init__(self, pos, group):
super().__init__(group)
self.image = pygame.surface.Surface((20, 20))
self.image.fill("black")
self.rect = self.image.get_rect(center = pos)
self.direction = pygame.math.Vector2()
self.speed = 1
self.enemy_count = 0
def damage(self, damage):
enemies.remove(self)
self.enemy_count -= 1
self.kill()
def update(self):
self.direction = pygame.math.Vector2(player.rect.center) - self.rect.center
if(pygame.math.Vector2.length(self.direction)<20):
self.kill()
self.direction = pygame.math.Vector2.normalize(self.direction)
self.rect.center += self.direction * self.speed
class CameraGroup(pygame.sprite.Group):
def __init__(self):
super().__init__()
self.display_surface = pygame.display.get_surface()
self.offset = pygame.math.Vector2(300, 100)
self.half_w = self.display_surface.get_size()[0] // 2
self.half_h = self.display_surface.get_size()[1] // 2
def center_target_camera(self, target):
self.offset.x = target.rect.centerx - self.half_w
self.offset.y = target.rect.centery - self.half_h
def custom_draw(self, player):
self.center_target_camera(player)
for sprite in sorted(self.sprites(), key=lambda sprite: sprite.rect.centery):
offset_pos = sprite.rect.topleft - self.offset
self.display_surface.blit(sprite.image, offset_pos)
def spawn_enemy():
random_x = randint(-1000, 1000)
random_y = randint(-1000, 1000)
enemies.append(Enemy((player.rect.centerx + random_x, player.rect.centery + random_y), camera_group))
spawn_enemy_event = pygame.USEREVENT + 1
#Setup
camera_group = CameraGroup()
enemies = []
player = Player((500, 500), camera_group, 10, 10)
pygame.time.set_timer(spawn_enemy_event, 100)
for i in range(10):
spawn_enemy()
crosshair_img = pygame.transform.scale(pygame.image.load('Sprites/crosshair.png'), (30, 30))
cursor = pygame.cursors.Cursor((0, 0), crosshair_img)
pygame.mouse.set_cursor(cursor)
pygame.mouse.set_visible(True | False)
while running:
for e in pygame.event.get():
if e.type == pygame.QUIT:
running = False
if e.type == spawn_enemy_event:
spawn_enemy()
screen.fill("cyan")
camera_group.update()
camera_group.custom_draw(player)
pygame.display.flip()
clock.tick(60)
pygame.quit()

View File

@ -1 +1,4 @@
# Game_1
IMPORTANT: dont forget to download pytmx
pip install pytmx (in cmd)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

BIN
Sprites/bomb.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

BIN
Sprites/loading.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

Before

Width:  |  Height:  |  Size: 308 KiB

After

Width:  |  Height:  |  Size: 308 KiB

View File

Before

Width:  |  Height:  |  Size: 576 B

After

Width:  |  Height:  |  Size: 576 B

BIN
assets/Pixel 7.mp3 100644

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 493 B

After

Width:  |  Height:  |  Size: 493 B

View File

Before

Width:  |  Height:  |  Size: 476 B

After

Width:  |  Height:  |  Size: 476 B

BIN
assets/file 100644

Binary file not shown.

29
button.py 100644
View File

@ -0,0 +1,29 @@
class Button():
def __init__(self, image, pos, text_input, font, base_color, hovering_color):
self.image = image
self.x_pos = pos[0]
self.y_pos = pos[1]
self.font = font
self.base_color, self.hovering_color = base_color, hovering_color
self.text_input = text_input
self.text = self.font.render(self.text_input, True, self.base_color)
if self.image is None:
self.image = self.text
self.rect = self.image.get_rect(center=(self.x_pos, self.y_pos))
self.text_rect = self.text.get_rect(center=(self.x_pos, self.y_pos))
def update(self, screen):
if self.image is not None:
screen.blit(self.image, self.rect)
screen.blit(self.text, self.text_rect)
def checkForInput(self, position):
if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top, self.rect.bottom):
return True
return False
def changeColor(self, position):
if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top, self.rect.bottom):
self.text = self.font.render(self.text_input, True, self.hovering_color)
else:
self.text = self.font.render(self.text_input, True, self.base_color)

279
map+coll+cam.py 100644
View File

@ -0,0 +1,279 @@
import pygame
import pytmx
import math
# Constants
BACKGROUND = (20, 20, 20)
SCREEN_WIDTH = 640
SCREEN_HEIGHT = 480
MAP_COLLISION_LAYER = 1
# Pygame setup
pygame.init()
pygame.display.set_caption("Survive the vawe")
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
clock = pygame.time.Clock()
running = True
class Player(pygame.sprite.Sprite):
def __init__(self, pos):
super().__init__()
# Load the idle image
self.idle_image = pygame.image.load("Sprites/Idle/Player_right.png").convert_alpha()
self.image = self.idle_image
self.rect = self.image.get_rect(topleft=pos) # Adjust rect to match the image size
self.direction = pygame.math.Vector2()
self.speed = 1.6
self.time = 0
# Health
self.current_health = 1000
self.maximum_health = 1000
self.health_bar_length = 500
self.health_ratio = self.maximum_health / self.health_bar_length
self.target_health = 1000
self.health_change_speed = 5
# Shooting
self.can_shoot = True
self.shoot_cooldown_time = 100 # Milliseconds
self.shoot_cooldown = 0
# Animations
self.image_direction = 1
self.animation_timer = 0
self.current_sprite = 0
self.running_sprites = []
for i in range(6):
sprite = pygame.image.load(f"Sprites/Running/Player_run_right_{i + 1}.png").convert_alpha()
self.running_sprites.append(sprite)
def get_damage(self, amount):
if self.target_health > 0:
self.target_health -= amount
if self.target_health <= 0:
self.target_health = 0
def get_health(self, amount):
if self.target_health < self.maximum_health:
self.target_health += amount
if self.target_health >= self.maximum_health:
self.target_health = self.maximum_health
def health_bar(self):
self.current_health += (self.target_health - self.current_health) / 10
# Define smaller health bar dimensions
health_bar_width = self.current_health / self.health_ratio
health_bar_height = 10 # Set the height of the health bar
# Adjust the position of the health bar
health_bar_x = 10
health_bar_y = 10
if self.current_health > self.target_health:
health_bar_width = self.target_health / self.health_ratio
# Draw the health bar with adjusted dimensions and position
health_bar_rect = pygame.Rect(health_bar_x, health_bar_y, health_bar_width, health_bar_height)
pygame.draw.rect(screen, (255, 0, 0), health_bar_rect) # Draw health bar in red
def input(self):
keys = pygame.key.get_pressed()
speed_multiplier_x = 0
speed_multiplier_y = 0
if keys[pygame.K_w]:
speed_multiplier_y = -1
elif keys[pygame.K_s]:
speed_multiplier_y = 1
if keys[pygame.K_a]:
speed_multiplier_x = -1
elif keys[pygame.K_d]:
speed_multiplier_x = 1
self.direction.y = (keys[pygame.K_s]) - (keys[pygame.K_w])
self.direction.x = (keys[pygame.K_d]) - (keys[pygame.K_a])
if self.direction.x != 0 and self.direction.y != 0:
self.direction.normalize_ip()
self.direction.x *= self.speed
self.direction.y *= self.speed
if pygame.mouse.get_pressed()[0] and self.can_shoot:
direction = -(pygame.math.Vector2(self.rect.topleft) - pygame.mouse.get_pos())
direction = pygame.math.Vector2.normalize(direction)
new_projectile = Projectile(self.rect.center, direction)
self.can_shoot = False
self.shoot_cooldown = pygame.time.get_ticks()
def update(self, level):
self.input()
self.health_bar()
self.rect.center += self.direction * self.speed
# Move the screen if the player reaches the screen bounds
if self.rect.right >= SCREEN_WIDTH - 200:
difference = self.rect.right - (SCREEN_WIDTH - 200)
self.rect.right = SCREEN_WIDTH - 200
level.shift_level(-difference, 0)
if self.rect.left <= 200:
difference = 200 - self.rect.left
self.rect.left = 200
level.shift_level(difference, 0)
if self.rect.top <= 200:
difference = 200 - self.rect.top
self.rect.top = 200
level.shift_level(0, difference)
if self.rect.bottom >= SCREEN_HEIGHT - 200:
difference = self.rect.bottom - (SCREEN_HEIGHT - 200)
self.rect.bottom = SCREEN_HEIGHT - 200
level.shift_level(0, -difference)
self.check_collision(level)
now = pygame.time.get_ticks()
if now - self.shoot_cooldown > self.shoot_cooldown_time:
self.can_shoot = True
if now - self.animation_timer > 50:
if pygame.Vector2.length(self.direction) == 0:
self.image = self.idle_image
self.current_sprite = 0
else:
self.animation_timer = pygame.time.get_ticks()
self.current_sprite += 1
if self.current_sprite > len(self.running_sprites) - 1:
self.current_sprite = 0
self.image = self.running_sprites[self.current_sprite]
if self.direction.x < 0: # If moving left, flip the image
self.image = pygame.transform.flip(self.image, True, False)
def check_collision(self, level):
for layer in level.layers:
if layer.index == MAP_COLLISION_LAYER:
for tile in layer.tiles:
if self.rect.colliderect(tile.rect):
self.rect.center -= self.direction * self.speed
return
class Projectile(pygame.sprite.Sprite):
def __init__(self, pos, direction):
super().__init__()
self.image = pygame.image.load("Sprites/bullet.png").convert_alpha()
self.image_direction = 1
self.direction = direction
self.speed = 15
angle = math.degrees(math.atan2(-self.direction.y, self.direction.x))
self.image = pygame.transform.rotate(self.image, angle)
self.rect = self.image.get_rect(center=pos)
self.rect.center += self.direction * 50
self.life_timer = 10000 # Milliseconds
self.spawned_time = pygame.time.get_ticks()
def collision(self):
pass # Removed the collision logic for simplicity
def update(self):
self.rect.center += self.direction * self.speed
self.collision()
now = pygame.time.get_ticks()
if now - self.spawned_time > self.life_timer:
self.kill()
class Game:
def __init__(self):
self.currentLevelNumber = 0
self.levels = []
self.levels.append(Level(fileName="resources/level1.tmx"))
self.currentLevel = self.levels[self.currentLevelNumber]
def draw(self):
screen.fill(BACKGROUND)
self.currentLevel.draw()
player_group.draw(screen) # Draw player sprite
pygame.display.flip()
class Level:
def __init__(self, fileName):
self.mapObject = pytmx.load_pygame(fileName)
self.layers = []
for layer in range(len(self.mapObject.layers)):
self.layers.append(Layer(index=layer, mapObject=self.mapObject))
def draw(self):
for layer in self.layers:
layer.draw()
def shift_level(self, x_amount, y_amount):
for layer in self.layers:
for tile in layer.tiles:
tile.rect.x += x_amount
tile.rect.y += y_amount
class Layer:
def __init__(self, index, mapObject):
self.index = index
self.tiles = pygame.sprite.Group()
self.mapObject = mapObject
for x in range(self.mapObject.width):
for y in range(self.mapObject.height):
img = self.mapObject.get_tile_image(x, y, self.index)
if img:
self.tiles.add(Tile(image=img, x=(x * self.mapObject.tilewidth), y=(y * self.mapObject.tileheight)))
def draw(self):
for tile in self.tiles:
screen.blit(tile.image, tile.rect)
class Tile(pygame.sprite.Sprite):
def __init__(self, image, x, y):
pygame.sprite.Sprite.__init__(self)
self.image = image
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
# Main game setup
game = Game()
player = Player((100, 200)) # Update player spawn coordinates
player_group = pygame.sprite.Group() # Create a sprite group for the player
player_group.add(player) # Add the player sprite to the group
# Main game loop
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
player.get_health(200)
elif event.key == pygame.K_DOWN:
player.get_damage(200)
game.draw()
player.update(game.currentLevel)
pygame.display.flip()
clock.tick(60)

143
map_0.py
View File

@ -1,143 +0,0 @@
import os
import pygame
import json
import csv
pygame.init()
screen_width = 1920
screen_height = 960
screen = pygame.display.set_mode((screen_width, screen_height))
class Wall(pygame.sprite.Sprite):
def __init__(self, color, size, pos):
super().__init__()
self.image = pygame.Surface(size)
self.image.fill(color)
self.rect = self.image.get_rect(topleft=pos)
# Load image for player
player_image = pygame.image.load("Player_right.png").convert_alpha()
player_image = pygame.transform.scale(player_image, (16, 16)) # Adjust player size to fit the new scale
class Player(pygame.sprite.Sprite):
def __init__(self, color, walls):
super().__init__()
self.image = player_image
self.rect = self.image.get_rect()
self.foot_size = 15
self.dt = 0
self.speed_x = 1
self.max_speed_x = 700
self.speed_y = 1
self.max_speed_y = 1500
self.walls = walls
def player_input(self, dt):
keys = pygame.key.get_pressed()
move_direction_x = 0
move_direction_y = 0
if keys[pygame.K_w]:
move_direction_y -= 1
if keys[pygame.K_s]:
move_direction_y += 1
if keys[pygame.K_a]:
move_direction_x -= 1
if keys[pygame.K_d]:
move_direction_x += 1
# Apply movement
self.speed_x = move_direction_x * self.max_speed_x
self.speed_y = move_direction_y * self.max_speed_y
self.rect.x += self.speed_x * dt
self.rect.y += self.speed_y * dt
# Get the directory of the current script
script_dir = os.path.dirname(__file__)
# Initialize Pygame
# Set up the display
pygame.display.set_caption('Medival Guns')
# Load JSON data
with open(os.path.join(script_dir, 'data.json')) as json_file:
level_data = json.load(json_file)
# Load Collisions
collisions = []
with open(os.path.join(script_dir, 'Collisions.csv'), 'r') as csv_file:
csv_reader = csv.reader(csv_file)
for row in csv_reader:
# Convert non-empty strings to integers, skip empty strings
row_data = [int(cell) if cell else 0 for cell in row]
collisions.append(row_data)
#WALLS
walls_group = pygame.sprite.Group()
for i, row in enumerate(collisions):
for j, el in enumerate(row):
if el:
walls_group.add(Wall("purple", (60, 60), (60*j, 60*i)))
#collision functioning
def collision(self):
collisions = pygame.sprite.spritecollide(self, self.walls, False)
if collisions:
for wall in collisions:
if abs(self.rect.bottom - wall.rect.top) < self.foot_size:
self.rect.bottom = wall.rect.top
self.speed_y = 0
self.jumping_time = 0
self.is_jumping = False
elif abs(self.rect.top - wall.rect.bottom) < self.foot_size:
self.rect.top = wall.rect.bottom
self.speed_y = 0
elif abs(self.rect.right - wall.rect.left) < self.foot_size:
self.rect.right = wall.rect.left
self.speed_x = 0
elif abs(self.rect.left - wall.rect.right) < self.foot_size:
self.rect.left = wall.rect.right
self.speed_x = 0
# Load images for LAYERS
layers = {}
for layer in level_data["layers"]:
layers[layer] = pygame.image.load(layer).convert_alpha()
layers[layer] = pygame.transform.scale(layers[layer], (screen_width, screen_height))
# Main game loop
running = True
clock = pygame.time.Clock()
dt = 0
# Main game loop
while running:
# Event handling
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Draw layers
for layer_name, layer_image in layers.items():
screen.blit(layer_image, (0, 0))
#Draw walls
walls_group.draw(screen)
# Update the display
pygame.display.flip()
dt = clock.tick(60) / 1000 # Get time passed since last tick in seconds
# Quit Pygame
pygame.quit()

148
menu copy 2.py 100644
View File

@ -0,0 +1,148 @@
import pygame
import sys
from button import Button # Assuming you have a Button class defined in a separate file
from random import randint
import math
pygame.init()
SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720
SCREEN = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Rouglite")
# Loading images and music
BG = pygame.image.load("assets/Background.png")
LD = pygame.transform.scale(pygame.image.load("Sprites/loading.png").convert(), (SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.mixer.music.load('assets/Pixel 7.mp3')
# Define fonts
def get_font(size): # Returns Press-Start-2P in the desired size
return pygame.font.Font("assets/font.ttf", size)
def show_loading_screen():
start_time = pygame.time.get_ticks()
loading_image_rect = LD.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2))
pygame.mouse.set_visible(False) # Hide the cursor
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
SCREEN.fill((0, 0, 0))
SCREEN.blit(LD, loading_image_rect) # Display the loading image
pygame.display.update()
if pygame.time.get_ticks() - start_time >= 5000:
pygame.mouse.set_visible(True) # Show the cursor
return
# Display loading screen for 5 seconds before showing main menu
show_loading_screen()
def play():
while True:
pygame.time.delay(500)
import Game_V2
# Game_V2 vietāpievienojiet failu ar pabeigto spēli
def options():
volume = 1 # Initial volume
slider_height = 20 # Slider height
while True:
SCREEN.blit(BG, (0, 0))
OPTIONS_MOUSE_POS = pygame.mouse.get_pos()
OPTIONS_TEXT = get_font(45).render("Change Volume", True, "white")
OPTIONS_RECT = OPTIONS_TEXT.get_rect(center=(640, 260))
SCREEN.blit(OPTIONS_TEXT, OPTIONS_RECT)
# Volume slider
pygame.draw.rect(SCREEN, "gray", (500, 330, 200, slider_height)) # Slider background
# Calculate slider width based on volume level
slider_width = int(volume * 200)
slider_color = (62, 74, 49) # Green color
if volume < 1:
slider_color = (0, 255 * (1 - volume), 0) # Decrease green component based on volume level
pygame.draw.rect(SCREEN, slider_color, (500, 330, slider_width, slider_height)) # Actual slider
# Draw "+" and "-" symbols
plus_text = get_font(30).render("+", True, "#5c3938")
minus_text = get_font(30).render("-", True, "#5c3938")
plus_rect = plus_text.get_rect(center=(715, 330 + slider_height // 2))
minus_rect = minus_text.get_rect(center=(485, 330 + slider_height // 2))
SCREEN.blit(plus_text, plus_rect)
SCREEN.blit(minus_text, minus_rect)
# BACK button
OPTIONS_BACK = Button(image=None, pos=(640, 460),
text_input="BACK", font=get_font(75), base_color="#5c3938", hovering_color="White")
OPTIONS_BACK.changeColor(OPTIONS_MOUSE_POS)
OPTIONS_BACK.update(SCREEN)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if OPTIONS_BACK.checkForInput(OPTIONS_MOUSE_POS):
main_menu()
# Check if mouse click is on minus symbol
if minus_rect.collidepoint(event.pos):
volume -= 0.1
if volume < 0:
volume = 0
pygame.mixer.music.set_volume(volume) # Set the volume of the music
# Check if mouse click is on plus symbol
if plus_rect.collidepoint(event.pos):
volume += 0.1
if volume > 1:
volume = 1
pygame.mixer.music.set_volume(volume) # Set the volume of the music
pygame.display.update()
def main_menu():
while True:
SCREEN.blit(BG, (0, 0))
MENU_MOUSE_POS = pygame.mouse.get_pos()
MENU_TEXT = get_font(100).render("Roguelite", True, "white")
MENU_RECT = MENU_TEXT.get_rect(center=(640, 100))
PLAY_BUTTON = Button(image=pygame.image.load("assets/Play Rect.png"), pos=(640, 250),
text_input="PLAY", font=get_font(75), base_color="#5c3938", hovering_color="White")
OPTIONS_BUTTON = Button(image=pygame.image.load("assets/Options Rect.png"), pos=(640, 400),
text_input="OPTIONS", font=get_font(75), base_color="#5c3938", hovering_color="White")
QUIT_BUTTON = Button(image=pygame.image.load("assets/Quit Rect.png"), pos=(640, 550),
text_input="QUIT", font=get_font(75), base_color="#5c3938", hovering_color="White")
SCREEN.blit(MENU_TEXT, MENU_RECT)
for button in [PLAY_BUTTON, OPTIONS_BUTTON, QUIT_BUTTON]:
button.changeColor(MENU_MOUSE_POS)
button.update(SCREEN)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if PLAY_BUTTON.checkForInput(MENU_MOUSE_POS):
play()
if OPTIONS_BUTTON.checkForInput(MENU_MOUSE_POS):
options()
if QUIT_BUTTON.checkForInput(MENU_MOUSE_POS):
pygame.quit()
sys.exit()
pygame.display.update()
main_menu()

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.10" tiledversion="1.10.2" name="48x48" tilewidth="48" tileheight="48" tilecount="768" columns="32">
<image source="../../resources/Free Dungeon - Fantasy Dreamland/48x48/FD_Dungeon_Free.png" width="1536" height="1152"/>
</tileset>

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.10" tiledversion="1.10.2" name="48x48" tilewidth="48" tileheight="48" tilecount="768" columns="32">
<image source="../../Free Dungeon - Fantasy Dreamland/48x48/FD_Dungeon_Free.png" width="1536" height="1152"/>
</tileset>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.10" tiledversion="1.10.2" name="48x48" tilewidth="48" tileheight="48" tilecount="768" columns="32">
<image source="../../Free Dungeon - Fantasy Dreamland/48x48/FD_Dungeon_Free.png" width="1536" height="1152"/>
</tileset>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="40" height="22" tilewidth="48" tileheight="48" infinite="0" nextlayerid="3" nextobjectid="1">
<tileset firstgid="1" source="Game/resources/48x48.tsx"/>
<layer id="1" name="background" width="40" height="22">
<data encoding="base64" compression="zlib">
eJzNlFtuwjAURCMoaUJSwhp4JOXVsAZegYXz2T3VkWakqWtHLkVqKh1d20T4MPem9yiK7j0l6oFDqN/M8ALmhpPj+VdDYogNKfbtegQSVNddpWFleAelnOm5z+9oGIJ2vXDcQRd6JUA9E4/fEve3tYJTiXUp+y6/ObwG2B+xZlZ2TjHOU1nz8xhU4rAUKvEtA/IboLcnOB7gx75rT0fR9/6qVwr4W2LLp5RK15Xg81ugtzM4Hhw94v3a51TypKdv3unE/nKtc+jzO4Ah/I6O79eeMkN7Drv8dBa15yvJ1+f3H9h5Vj3zY5b2e9snvza3S4Df1DAxZCDHvgATYWx4w3mOfY6zCWoW6NfO3DXAjz5j8ZiCsTgUuJ+OdMrl8+kv/M6B+WWSlzrZeRXRz1wzy5/Ph/i1brcAP8KePTpPGX4fM+7K8gxu8DwH+LVumz/4af451oXHizDDJsBvDx71c/XPvreBzw1+VxDi9wGe5cd8XOd0bCL3O6x+NVgbtoad1DVqDfct1iF+nC2f96XjGfXb4e4NqHGmfnyGM1CjduWt9+ta34urJ2f120tGWpnjBpX5buFVW9X2a+Ruzhn7ytlktf/PqN/nkwidy5DvaP++AFtaqow=
</data>
</layer>
<layer id="2" name="collision" width="40" height="22">
<data encoding="base64" compression="zlib">
eJzNVjtOQzEQtN0BIQW0OQKhgDYH4RSIDiQq6KFDIFFBxycpQdSk4SMuQAkNv1yAhl3xTDb7Zu2YFDDSKImza4/H649zzp0QZ/0oT6ntzA2BYhB13qS5jBti29f5Tu0fFQdGjJUnUZJ7B/S9EFdDnQ0xtyaxH0bzduj3LvFStPVVXsxdJ15VMXseiHDf/78Z/iEsiHktgj67pKUX0nkxd9/QFBE1W/79F5T49xdA/rG+61Cvr3Nit2IP5M1R/DxYX5kn8626i1jx2D9e3yca57kai+t9LYzGPoC8JYpZVvr6wRiDxn71aZ0bxv6dovZpwBmfj8nlpXRqHBj+jXt+lhKdtVKn1BhrAs3NOp8nJVorCVkzyLefuRC3qG62iReZPscF96PvEY2B+J7Sx/4dkbZjsBcnQbxHrHu1KdYyd/+mfNP/jesxWmtZ621fj03tX1SvJUR7MuK++pS1rtEy9m+ErNdc7eTyNaI+rvVH4/zp+GGcBHvOay/rQb9BEDX0GSn9jPNl/z4Nfbxm1vly63A9pJjSypB+6rcaQsM4M9nzTrB9R2gFrFX2L/XpuSGk3qcMy3cNNA+0/1L1iLBp7I/S91VqHrk3RQqHhr6Su7/kbfCbfvX++AI6lJGU
</data>
</layer>
</map>

BIN
resources/tiles.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -1,78 +0,0 @@
import pygame
import math
import sys
# Инициализация Pygame
pygame.init()
# Настройки экрана
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Shooting Game")
# Загрузка изображения пули и персонажей
bullet_img = pygame.transform.scale(pygame.image.load('bullet.png'), (50, 100))
player_img = pygame.transform.scale(pygame.image.load('player.png'), (50, 30))
enemy_img = pygame.transform.scale(pygame.image.load('enemy.png'), (50, 30))
crosshair_img = pygame.transform.scale(pygame.image.load('crosshair.png'), (30, 30))
# Позиции игрока и врага
player_pos = [WIDTH // 2 - player_img.get_width() // 2, HEIGHT - player_img.get_height()]
enemy_pos = [WIDTH // 2 - enemy_img.get_width() // 2, 50]
# Скорость перемещения игрока
player_speed = 5
# Списки для хранения пуль игрока и врага
player_bullets = []
# Функция для отрисовки объектов
def draw_elements():
screen.fill((255, 255, 255)) # Фон белого цвета
screen.blit(player_img, player_pos)
screen.blit(enemy_img, enemy_pos)
screen.blit(crosshair_img, pygame.mouse.get_pos()) # Отображение мушки
for bullet in player_bullets:
screen.blit(bullet_img, bullet["position"])
# Основной игровой цикл
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: # Стрельба по нажатию ЛКМ
mouse_x, mouse_y = pygame.mouse.get_pos() # Получаем координаты курсора мыши
angle = math.atan2(mouse_y - player_pos[1], mouse_x - player_pos[0]) # Вычисляем угол между игроком и курсором
player_bullets.append({"position": [player_pos[0] + player_img.get_width() // 2 - bullet_img.get_width() // 2,
player_pos[1] + player_img.get_height() // 2 - bullet_img.get_height() // 2],
"angle": angle})
keys = pygame.key.get_pressed()
if keys[pygame.K_w] and player_pos[1] > 0: # Перемещение вверх
player_pos[1] -= player_speed
if keys[pygame.K_s] and player_pos[1] < HEIGHT - player_img.get_height(): # Перемещение вниз
player_pos[1] += player_speed
if keys[pygame.K_a] and player_pos[0] > 0: # Перемещение влево
player_pos[0] -= player_speed
if keys[pygame.K_d] and player_pos[0] < WIDTH - player_img.get_width(): # Перемещение вправо
player_pos[0] += player_speed
# Обновление позиции пуль игрока
for bullet in player_bullets:
bullet["position"][0] += 5 * math.cos(bullet["angle"]) # Учитываем направление пули
bullet["position"][1] += 5 * math.sin(bullet["angle"]) # Учитываем направление пули
# Удаляем пули, которые выходят за пределы экрана
if bullet["position"][0] < 0 or bullet["position"][0] > WIDTH or bullet["position"][1] < 0 or bullet["position"][1] > HEIGHT:
player_bullets.remove(bullet)
# Отрисовка элементов
draw_elements()
clock = pygame.time.Clock()
dt = 0
dt = clock.tick(60) / 1000
# Обновление экрана
pygame.display.flip()

File diff suppressed because one or more lines are too long

View File

@ -1,148 +0,0 @@
{
"identifier": "World_Level_0",
"uniqueIdentifer": "d53f9950-c640-11ed-8430-4942c04951ff",
"x": 256,
"y": 0,
"width": 512,
"height": 256,
"bgColor": "#404255",
"neighbourLevels": [
{
"levelIid": "5b1771e0-c640-11ed-8430-9b64f8cc95ad",
"dir": "w"
},
{
"levelIid": "e06b8660-c640-11ed-8430-7b6fcb3e9e6b",
"dir": "e"
}
],
"customFields" : {},
"layers": [
"Default_floor.png",
"Custom_floor.png",
"Collisions.png",
"Wall_tops.png"
],
"entities": {
"Door": [
{
"id": "Door",
"iid": "8ac5dda0-c640-11ed-8430-8169bab5952b",
"layer": "Entities",
"x": 160,
"y": 112,
"width": 32,
"height": 16,
"color": 12087120,
"customFields": {
"lockedWith": null
}
},
{
"id": "Door",
"iid": "8d4360c0-c640-11ed-8430-abb21cbec6c0",
"layer": "Entities",
"x": 288,
"y": 112,
"width": 32,
"height": 16,
"color": 12087120,
"customFields": {
"lockedWith": null
}
},
{
"id": "Door",
"iid": "a1e0c860-c640-11ed-8430-e927d6a72261",
"layer": "Entities",
"x": 112,
"y": 144,
"width": 16,
"height": 48,
"color": 12087120,
"customFields": {
"lockedWith": "KeyA"
}
},
{
"id": "Door",
"iid": "c8d51610-3b70-11ee-b655-5116b3326bb0",
"layer": "Entities",
"x": 128,
"y": 64,
"width": 16,
"height": 32,
"color": 12087120,
"customFields": {
"lockedWith": null
}
}
],
"Item": [
{
"id": "Item",
"iid": "c3c403c0-c640-11ed-8430-cd4fd5179384",
"layer": "Entities",
"x": 296,
"y": 56,
"width": 20,
"height": 20,
"color": 16711748,
"customFields": {
"type": "KeyA"
}
},
{
"id": "Item",
"iid": "c75e4180-c640-11ed-8430-ebd1fb662306",
"layer": "Entities",
"x": 56,
"y": 72,
"width": 20,
"height": 20,
"color": 16711748,
"customFields": {
"type": "Health"
}
}
],
"Button": [
{
"id": "Button",
"iid": "cb7d3fa0-c640-11ed-8430-97bfc67769ff",
"layer": "Entities",
"x": 184,
"y": 40,
"width": 10,
"height": 10,
"color": 16711680,
"customFields": {
"targets": [
{
"entityIid": "8d4360c0-c640-11ed-8430-abb21cbec6c0",
"layerIid": "d53f9951-c640-11ed-8430-3f3f71a3daf1",
"levelIid": "d53f9950-c640-11ed-8430-4942c04951ff",
"worldIid": "c9ef2d10-c640-11ed-ad34-f553e1d803f9"
}
]
}
}
],
"Player": [
{
"id": "Player",
"iid": "6edc8020-b0a0-11ee-b6c1-d71cc2f0432a",
"layer": "Entities",
"x": 168,
"y": 152,
"width": 16,
"height": 16,
"color": 248700,
"customFields": {
"ammo": 50,
"life": 100
}
}
]
}
}

View File

@ -1,479 +0,0 @@
from typing import Any, List, Optional, TypeVar, Callable, Type, cast
from uuid import UUID
T = TypeVar("T")
def from_list(f: Callable[[Any], T], x: Any) -> List[T]:
assert isinstance(x, list)
return [f(y) for y in x]
def to_class(c: Type[T], x: Any) -> dict:
assert isinstance(x, c)
return cast(Any, x).to_dict()
def from_str(x: Any) -> str:
assert isinstance(x, str)
return x
def from_int(x: Any) -> int:
assert isinstance(x, int) and not isinstance(x, bool)
return x
def from_none(x: Any) -> Any:
assert x is None
return x
def from_union(fs, x):
for f in fs:
try:
return f(x)
except:
pass
assert False
class WelcomeCustomFields:
pass
def __init__(self, ) -> None:
pass
@staticmethod
def from_dict(obj: Any) -> 'WelcomeCustomFields':
assert isinstance(obj, dict)
return WelcomeCustomFields()
def to_dict(self) -> dict:
result: dict = {}
return result
class Target:
entity_iid: UUID
layer_iid: UUID
level_iid: UUID
world_iid: UUID
def __init__(self, entity_iid: UUID, layer_iid: UUID, level_iid: UUID, world_iid: UUID) -> None:
self.entity_iid = entity_iid
self.layer_iid = layer_iid
self.level_iid = level_iid
self.world_iid = world_iid
@staticmethod
def from_dict(obj: Any) -> 'Target':
assert isinstance(obj, dict)
entity_iid = UUID(obj.get("entityIid"))
layer_iid = UUID(obj.get("layerIid"))
level_iid = UUID(obj.get("levelIid"))
world_iid = UUID(obj.get("worldIid"))
return Target(entity_iid, layer_iid, level_iid, world_iid)
def to_dict(self) -> dict:
result: dict = {}
result["entityIid"] = str(self.entity_iid)
result["layerIid"] = str(self.layer_iid)
result["levelIid"] = str(self.level_iid)
result["worldIid"] = str(self.world_iid)
return result
class ButtonCustomFields:
targets: List[Target]
def __init__(self, targets: List[Target]) -> None:
self.targets = targets
@staticmethod
def from_dict(obj: Any) -> 'ButtonCustomFields':
assert isinstance(obj, dict)
targets = from_list(Target.from_dict, obj.get("targets"))
return ButtonCustomFields(targets)
def to_dict(self) -> dict:
result: dict = {}
result["targets"] = from_list(lambda x: to_class(Target, x), self.targets)
return result
class Button:
id: str
iid: UUID
layer: str
x: int
y: int
width: int
height: int
color: int
custom_fields: ButtonCustomFields
def __init__(self, id: str, iid: UUID, layer: str, x: int, y: int, width: int, height: int, color: int, custom_fields: ButtonCustomFields) -> None:
self.id = id
self.iid = iid
self.layer = layer
self.x = x
self.y = y
self.width = width
self.height = height
self.color = color
self.custom_fields = custom_fields
@staticmethod
def from_dict(obj: Any) -> 'Button':
assert isinstance(obj, dict)
id = from_str(obj.get("id"))
iid = UUID(obj.get("iid"))
layer = from_str(obj.get("layer"))
x = from_int(obj.get("x"))
y = from_int(obj.get("y"))
width = from_int(obj.get("width"))
height = from_int(obj.get("height"))
color = from_int(obj.get("color"))
custom_fields = ButtonCustomFields.from_dict(obj.get("customFields"))
return Button(id, iid, layer, x, y, width, height, color, custom_fields)
def to_dict(self) -> dict:
result: dict = {}
result["id"] = from_str(self.id)
result["iid"] = str(self.iid)
result["layer"] = from_str(self.layer)
result["x"] = from_int(self.x)
result["y"] = from_int(self.y)
result["width"] = from_int(self.width)
result["height"] = from_int(self.height)
result["color"] = from_int(self.color)
result["customFields"] = to_class(ButtonCustomFields, self.custom_fields)
return result
class DoorCustomFields:
locked_with: Optional[str]
def __init__(self, locked_with: Optional[str]) -> None:
self.locked_with = locked_with
@staticmethod
def from_dict(obj: Any) -> 'DoorCustomFields':
assert isinstance(obj, dict)
locked_with = from_union([from_none, from_str], obj.get("lockedWith"))
return DoorCustomFields(locked_with)
def to_dict(self) -> dict:
result: dict = {}
result["lockedWith"] = from_union([from_none, from_str], self.locked_with)
return result
class Door:
id: str
iid: UUID
layer: str
x: int
y: int
width: int
height: int
color: int
custom_fields: DoorCustomFields
def __init__(self, id: str, iid: UUID, layer: str, x: int, y: int, width: int, height: int, color: int, custom_fields: DoorCustomFields) -> None:
self.id = id
self.iid = iid
self.layer = layer
self.x = x
self.y = y
self.width = width
self.height = height
self.color = color
self.custom_fields = custom_fields
@staticmethod
def from_dict(obj: Any) -> 'Door':
assert isinstance(obj, dict)
id = from_str(obj.get("id"))
iid = UUID(obj.get("iid"))
layer = from_str(obj.get("layer"))
x = from_int(obj.get("x"))
y = from_int(obj.get("y"))
width = from_int(obj.get("width"))
height = from_int(obj.get("height"))
color = from_int(obj.get("color"))
custom_fields = DoorCustomFields.from_dict(obj.get("customFields"))
return Door(id, iid, layer, x, y, width, height, color, custom_fields)
def to_dict(self) -> dict:
result: dict = {}
result["id"] = from_str(self.id)
result["iid"] = str(self.iid)
result["layer"] = from_str(self.layer)
result["x"] = from_int(self.x)
result["y"] = from_int(self.y)
result["width"] = from_int(self.width)
result["height"] = from_int(self.height)
result["color"] = from_int(self.color)
result["customFields"] = to_class(DoorCustomFields, self.custom_fields)
return result
class ItemCustomFields:
type: str
def __init__(self, type: str) -> None:
self.type = type
@staticmethod
def from_dict(obj: Any) -> 'ItemCustomFields':
assert isinstance(obj, dict)
type = from_str(obj.get("type"))
return ItemCustomFields(type)
def to_dict(self) -> dict:
result: dict = {}
result["type"] = from_str(self.type)
return result
class Item:
id: str
iid: UUID
layer: str
x: int
y: int
width: int
height: int
color: int
custom_fields: ItemCustomFields
def __init__(self, id: str, iid: UUID, layer: str, x: int, y: int, width: int, height: int, color: int, custom_fields: ItemCustomFields) -> None:
self.id = id
self.iid = iid
self.layer = layer
self.x = x
self.y = y
self.width = width
self.height = height
self.color = color
self.custom_fields = custom_fields
@staticmethod
def from_dict(obj: Any) -> 'Item':
assert isinstance(obj, dict)
id = from_str(obj.get("id"))
iid = UUID(obj.get("iid"))
layer = from_str(obj.get("layer"))
x = from_int(obj.get("x"))
y = from_int(obj.get("y"))
width = from_int(obj.get("width"))
height = from_int(obj.get("height"))
color = from_int(obj.get("color"))
custom_fields = ItemCustomFields.from_dict(obj.get("customFields"))
return Item(id, iid, layer, x, y, width, height, color, custom_fields)
def to_dict(self) -> dict:
result: dict = {}
result["id"] = from_str(self.id)
result["iid"] = str(self.iid)
result["layer"] = from_str(self.layer)
result["x"] = from_int(self.x)
result["y"] = from_int(self.y)
result["width"] = from_int(self.width)
result["height"] = from_int(self.height)
result["color"] = from_int(self.color)
result["customFields"] = to_class(ItemCustomFields, self.custom_fields)
return result
class PlayerCustomFields:
ammo: int
life: int
def __init__(self, ammo: int, life: int) -> None:
self.ammo = ammo
self.life = life
@staticmethod
def from_dict(obj: Any) -> 'PlayerCustomFields':
assert isinstance(obj, dict)
ammo = from_int(obj.get("ammo"))
life = from_int(obj.get("life"))
return PlayerCustomFields(ammo, life)
def to_dict(self) -> dict:
result: dict = {}
result["ammo"] = from_int(self.ammo)
result["life"] = from_int(self.life)
return result
class Player:
id: str
iid: UUID
layer: str
x: int
y: int
width: int
height: int
color: int
custom_fields: PlayerCustomFields
def __init__(self, id: str, iid: UUID, layer: str, x: int, y: int, width: int, height: int, color: int, custom_fields: PlayerCustomFields) -> None:
self.id = id
self.iid = iid
self.layer = layer
self.x = x
self.y = y
self.width = width
self.height = height
self.color = color
self.custom_fields = custom_fields
@staticmethod
def from_dict(obj: Any) -> 'Player':
assert isinstance(obj, dict)
id = from_str(obj.get("id"))
iid = UUID(obj.get("iid"))
layer = from_str(obj.get("layer"))
x = from_int(obj.get("x"))
y = from_int(obj.get("y"))
width = from_int(obj.get("width"))
height = from_int(obj.get("height"))
color = from_int(obj.get("color"))
custom_fields = PlayerCustomFields.from_dict(obj.get("customFields"))
return Player(id, iid, layer, x, y, width, height, color, custom_fields)
def to_dict(self) -> dict:
result: dict = {}
result["id"] = from_str(self.id)
result["iid"] = str(self.iid)
result["layer"] = from_str(self.layer)
result["x"] = from_int(self.x)
result["y"] = from_int(self.y)
result["width"] = from_int(self.width)
result["height"] = from_int(self.height)
result["color"] = from_int(self.color)
result["customFields"] = to_class(PlayerCustomFields, self.custom_fields)
return result
class Entities:
door: List[Door]
item: List[Item]
button: List[Button]
player: List[Player]
def __init__(self, door: List[Door], item: List[Item], button: List[Button], player: List[Player]) -> None:
self.door = door
self.item = item
self.button = button
self.player = player
@staticmethod
def from_dict(obj: Any) -> 'Entities':
assert isinstance(obj, dict)
door = from_list(Door.from_dict, obj.get("Door"))
item = from_list(Item.from_dict, obj.get("Item"))
button = from_list(Button.from_dict, obj.get("Button"))
player = from_list(Player.from_dict, obj.get("Player"))
return Entities(door, item, button, player)
def to_dict(self) -> dict:
result: dict = {}
result["Door"] = from_list(lambda x: to_class(Door, x), self.door)
result["Item"] = from_list(lambda x: to_class(Item, x), self.item)
result["Button"] = from_list(lambda x: to_class(Button, x), self.button)
result["Player"] = from_list(lambda x: to_class(Player, x), self.player)
return result
class NeighbourLevel:
level_iid: UUID
dir: str
def __init__(self, level_iid: UUID, dir: str) -> None:
self.level_iid = level_iid
self.dir = dir
@staticmethod
def from_dict(obj: Any) -> 'NeighbourLevel':
assert isinstance(obj, dict)
level_iid = UUID(obj.get("levelIid"))
dir = from_str(obj.get("dir"))
return NeighbourLevel(level_iid, dir)
def to_dict(self) -> dict:
result: dict = {}
result["levelIid"] = str(self.level_iid)
result["dir"] = from_str(self.dir)
return result
class Welcome:
identifier: str
unique_identifer: UUID
x: int
y: int
width: int
height: int
bg_color: str
neighbour_levels: List[NeighbourLevel]
custom_fields: WelcomeCustomFields
layers: List[str]
entities: Entities
def __init__(self, identifier: str, unique_identifer: UUID, x: int, y: int, width: int, height: int, bg_color: str, neighbour_levels: List[NeighbourLevel], custom_fields: WelcomeCustomFields, layers: List[str], entities: Entities) -> None:
self.identifier = identifier
self.unique_identifer = unique_identifer
self.x = x
self.y = y
self.width = width
self.height = height
self.bg_color = bg_color
self.neighbour_levels = neighbour_levels
self.custom_fields = custom_fields
self.layers = layers
self.entities = entities
@staticmethod
def from_dict(obj: Any) -> 'Welcome':
assert isinstance(obj, dict)
identifier = from_str(obj.get("identifier"))
unique_identifer = UUID(obj.get("uniqueIdentifer"))
x = from_int(obj.get("x"))
y = from_int(obj.get("y"))
width = from_int(obj.get("width"))
height = from_int(obj.get("height"))
bg_color = from_str(obj.get("bgColor"))
neighbour_levels = from_list(NeighbourLevel.from_dict, obj.get("neighbourLevels"))
custom_fields = WelcomeCustomFields.from_dict(obj.get("customFields"))
layers = from_list(from_str, obj.get("layers"))
entities = Entities.from_dict(obj.get("entities"))
return Welcome(identifier, unique_identifer, x, y, width, height, bg_color, neighbour_levels, custom_fields, layers, entities)
def to_dict(self) -> dict:
result: dict = {}
result["identifier"] = from_str(self.identifier)
result["uniqueIdentifer"] = str(self.unique_identifer)
result["x"] = from_int(self.x)
result["y"] = from_int(self.y)
result["width"] = from_int(self.width)
result["height"] = from_int(self.height)
result["bgColor"] = from_str(self.bg_color)
result["neighbourLevels"] = from_list(lambda x: to_class(NeighbourLevel, x), self.neighbour_levels)
result["customFields"] = to_class(WelcomeCustomFields, self.custom_fields)
result["layers"] = from_list(from_str, self.layers)
result["entities"] = to_class(Entities, self.entities)
return result
def welcome_from_dict(s: Any) -> Welcome:
return Welcome.from_dict(s)
def welcome_to_dict(x: Welcome) -> Any:
return to_class(Welcome, x)