Compare commits
121 Commits
tmaksimovs
...
master
23
Game_1.sln
|
@ -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
|
BIN
Game_1/Floor.png
Before Width: | Height: | Size: 1.6 KiB |
|
@ -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>
|
|
@ -1,125 +0,0 @@
|
|||
import pygame
|
||||
|
||||
pygame.init()
|
||||
|
||||
|
||||
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)
|
||||
|
||||
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)))
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
screen = pygame.display.set_mode((1920, 1015))
|
||||
pygame.display.set_caption("Game_name")
|
||||
|
||||
clock = pygame.time.Clock()
|
||||
dt = 0
|
||||
|
||||
player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
|
||||
|
||||
floor_image = pygame.transform.scale(pygame.image.load("Floor.png").convert_alpha(), (30, 30))
|
||||
|
||||
#class Player(pygame.sprite.Sprite):
|
||||
#def __init__(self, size, pos, walls)
|
||||
|
||||
player = pygame.transform.scale(pygame.image.load("Player.png").convert_alpha(), (25, 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)
|
||||
|
||||
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))
|
||||
screen.blit(player, (player_pos.x, player_pos.y))
|
||||
|
||||
keys = pygame.key.get_pressed()
|
||||
if keys[pygame.K_w]:
|
||||
player_pos.y -= 200 * dt
|
||||
if keys[pygame.K_s]:
|
||||
player_pos.y += 200 * dt
|
||||
if keys[pygame.K_a]:
|
||||
player_pos.x -= 200 * dt
|
||||
if keys[pygame.K_d]:
|
||||
player_pos.x += 200 * dt
|
||||
|
||||
walls.draw(screen)
|
||||
pygame.display.flip()
|
||||
|
||||
dt = clock.tick(60)/1000
|
||||
|
||||
floor.draw(screen)
|
||||
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pygame.quit()
|
|
@ -1,15 +0,0 @@
|
|||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
- - - - - -
|
||||
# # # # # # # # # # # # # # # # # # # #|# # # # # # # # # # # # # # # #
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # #|# # # # # # # # # # # # # # # #
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # #|# # # # # # # # # # # # # # # #
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # #|# # # # # # # # # # # # # # #
|
||||
|
||||
# # # # # # # # # # # # # # # # # # # # #|# # # # # # # # # # # # # # #
|
126
Game_1/main.py
|
@ -1,126 +0,0 @@
|
|||
import pygame
|
||||
|
||||
pygame.init()
|
||||
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
screen = pygame.display.set_mode((1920, 1015))
|
||||
pygame.display.set_caption("Game_name")
|
||||
|
||||
clock = pygame.time.Clock()
|
||||
dt = 0
|
||||
|
||||
player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
|
||||
|
||||
floor_image = pygame.transform.scale(pygame.image.load("Floor.png").convert_alpha(), (30, 30))
|
||||
|
||||
#class Player(pygame.sprite.Sprite):
|
||||
#def __init__(self, size, pos, walls)
|
||||
|
||||
player = pygame.transform.scale(pygame.image.load("Player.png").convert_alpha(), (25, 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)
|
||||
|
||||
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))
|
||||
screen.blit(player, (player_pos.x, player_pos.y))
|
||||
|
||||
keys = pygame.key.get_pressed()
|
||||
if keys[pygame.K_w]:
|
||||
player_pos.y -= 200 * dt
|
||||
if keys[pygame.K_s]:
|
||||
player_pos.y += 200 * dt
|
||||
if keys[pygame.K_a]:
|
||||
player_pos.x -= 200 * dt
|
||||
if keys[pygame.K_d]:
|
||||
player_pos.x += 200 * dt
|
||||
|
||||
walls.draw(screen)
|
||||
pygame.display.flip()
|
||||
|
||||
dt = clock.tick(60)/1000
|
||||
|
||||
floor.draw(screen)
|
||||
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pygame.quit()
|
|
@ -0,0 +1,428 @@
|
|||
import pygame
|
||||
from random import randint
|
||||
import math
|
||||
import sys
|
||||
|
||||
SCREEN_X = 1280
|
||||
SCREEN_Y = 720
|
||||
|
||||
|
||||
# pygame setup
|
||||
pygame.init()
|
||||
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)
|
||||
self.idle_image = self.image = pygame.image.load("Sprites/Idle/Player_right.png").convert_alpha()
|
||||
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
|
||||
self.maximum_health = 1000
|
||||
self.health_bar_lenght = 500
|
||||
self.health_ratio = self.maximum_health / self.health_bar_lenght
|
||||
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):
|
||||
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
|
||||
if self.target_health <= 0:
|
||||
self.target_health = 0
|
||||
|
||||
|
||||
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):
|
||||
|
||||
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
|
||||
|
||||
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,health_bar_width,25)
|
||||
transition_bar_rect = pygame.Rect(10,45,transition_bar_width,25)
|
||||
|
||||
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):
|
||||
keys = pygame.key.get_pressed()
|
||||
speed_multiplier_x = 0
|
||||
speed_multiplier_y = 0
|
||||
|
||||
if self.direction.x > 0:
|
||||
self.image_direction = 1
|
||||
elif self.direction.x < 0:
|
||||
self.image_direction = -1
|
||||
|
||||
if keys[pygame.K_w]:
|
||||
speed_multiplier_y = -1
|
||||
elif keys[pygame.K_s]:
|
||||
speed_multiplier_y = 1
|
||||
|
||||
# Check if A and D keys are pressed
|
||||
if keys[pygame.K_a]:
|
||||
speed_multiplier_x = -1
|
||||
elif keys[pygame.K_d]:
|
||||
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_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() - 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()
|
||||
self.shoot = True
|
||||
|
||||
|
||||
def update(self):
|
||||
self.input()
|
||||
self.ahealth_bar()
|
||||
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
|
||||
|
||||
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]
|
||||
|
||||
class Arm(pygame.sprite.Sprite):
|
||||
def __init__(self, pos, group):
|
||||
super().__init__(group)
|
||||
self.base_image = pygame.image.load("Sprites/minigun.png").convert_alpha()
|
||||
self.base_image = pygame.transform.scale(self.base_image, (40, 15))
|
||||
|
||||
self.image_direction = 1
|
||||
|
||||
self.direction = pygame.Vector2(0, 0)
|
||||
self.speed = 10
|
||||
angle = math.degrees(math.atan2(-self.direction.y, self.direction.x))
|
||||
self.image = pygame.transform.rotate(self.base_image, angle)
|
||||
self.rect = self.image.get_rect(center = pos)
|
||||
|
||||
def update(self):
|
||||
self.rect.center = player.rect.center
|
||||
self.direction = -(pygame.math.Vector2(self.rect.topleft) - pygame.mouse.get_pos() - camera_group.offset)
|
||||
self.direction = pygame.math.Vector2.normalize(self.direction)
|
||||
angle = math.degrees(math.atan2(-self.direction.y, self.direction.x))
|
||||
if(abs(angle)<90):
|
||||
self.image_direction = 1
|
||||
else:
|
||||
self.image_direction = -1
|
||||
self.rect.center -= pygame.Vector2(math.sin(math.radians(angle-90))*20, math.cos(math.radians(angle-90))*20)
|
||||
if(abs(angle)>90):
|
||||
angle = math.degrees(math.atan2(self.direction.y, self.direction.x))+180
|
||||
self.image = pygame.transform.rotate(self.base_image, angle)
|
||||
|
||||
|
||||
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.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):
|
||||
for enemy in enemies:
|
||||
distance = pygame.math.Vector2.length(pygame.math.Vector2(enemy.rect.center) - self.rect.center)
|
||||
if distance < 20:
|
||||
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
|
||||
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, scale):
|
||||
super().__init__(group)
|
||||
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 = 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 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))
|
||||
|
||||
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
|
||||
if sprite.image_direction == -1:
|
||||
self.display_surface.blit(pygame.transform.flip(sprite.image, True, False), offset_pos)
|
||||
else:
|
||||
self.display_surface.blit(sprite.image, offset_pos)
|
||||
|
||||
def spawn_enemy():
|
||||
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, 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 = []
|
||||
|
||||
|
||||
|
||||
|
||||
player = Player((500, 500), camera_group)
|
||||
Arm((0, 0), camera_group)
|
||||
pygame.time.set_timer(spawn_enemy_event, 100)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
# 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:
|
||||
running = False
|
||||
pygame.quit()
|
||||
|
||||
if e.type == spawn_enemy_event:
|
||||
spawn_enemy()
|
||||
|
||||
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
|
|
@ -1 +1,4 @@
|
|||
# Game_1
|
||||
IMPORTANT: dont forget to download pytmx
|
||||
|
||||
pip install pytmx (in cmd)
|
||||
|
|
After Width: | Height: | Size: 6.1 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 751 B |
After Width: | Height: | Size: 751 B |
After Width: | Height: | Size: 154 B |
After Width: | Height: | Size: 6.5 KiB |
After Width: | Height: | Size: 4.6 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 4.1 KiB |
After Width: | Height: | Size: 954 B |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 6.1 KiB |
After Width: | Height: | Size: 41 KiB |
After Width: | Height: | Size: 123 KiB |
After Width: | Height: | Size: 354 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 308 KiB |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 493 B |
After Width: | Height: | Size: 476 B |
|
@ -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)
|
|
@ -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)
|
|
@ -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()
|
|
@ -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>
|
After Width: | Height: | Size: 60 KiB |
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
After Width: | Height: | Size: 18 KiB |