Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added animations/base-sword/sprite_0001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animations/base-sword/sprite_0002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animations/base-sword/sprite_0003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animations/base-sword/sprite_0004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animations/mini_main-char/sprite_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animations/mini_main-char/sprite_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animations/mini_main-char/sprite_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animations/mini_main-char/sprite_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animations/mini_main-char/sprite_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animations/mini_main-char/sprite_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animations/mini_main-char/sprite_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animations/mini_main-char/sprite_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungeon/rooms/romm_r-t.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungeon/rooms/room-l.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungeon/rooms/room-t.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungeon/rooms/room_AllExcB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungeon/rooms/room_AllExcL.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungeon/rooms/room_AllExcR.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungeon/rooms/room_AllExcT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungeon/rooms/room_all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungeon/rooms/room_b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungeon/rooms/room_l-b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungeon/rooms/room_l-t.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungeon/rooms/room_r-b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungeon/rooms/room_r-l.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dungeon/rooms/room_t-b.png
Binary file added img/main-char.pdf
Binary file not shown.
Binary file added img/main-char.png
Binary file added img/mini_main-char.pdf
Binary file not shown.
Binary file added img/mini_main-char.png
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
next_room = randint(0, 6)
# перенести на переход персонажа

player_equipment = ['base-armor', 'base-sword']

def dungeon():
global player_equipment
room = Dungeon_room(win_width, win_height)
room.blit_new_room(out_from, win, next_room)
hero.blit(win)
Expand Down
84 changes: 48 additions & 36 deletions player.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ def __init__(self):
self.run_b = False
self.run_t = False
self.run_r = False
self.velX = 0
self.velY = 0
self.inDungeon_img = pygame.transform.scale(pygame.image.load('img/mini_main-char.png'), (self.width, self.height))
self.inDungeon_run = []
for i in range(7):
for i in range(8):
self.inDungeon_run.append(pygame.transform.scale(pygame.image.load('animations/mini_main-char/sprite_'+str(i)+'.png'), (self.width, self.height)))
self.rect = self.inDungeon_img.get_rect()

Expand All @@ -29,46 +31,56 @@ def blit(self, win):
if pygame.mouse.get_pressed()[0]:
self.attack = True

if not self.attack:
self.speed = 4
keys = pygame.key.get_pressed()
if keys[pygame.K_a]:
self.run_l = True
if keys[pygame.K_w]:
self.run_t = True
if keys[pygame.K_s]:
self.run_b = True
if keys[pygame.K_d]:
self.run_r = True
if self.run_l and not self.run_r:
if self.animCount > 6:
self.animCount = 0
self.velX = -self.speed
self.speed = 20
keys = pygame.key.get_pressed()
if keys[pygame.K_a]:
self.run_l = True
else:
self.run_l = False
if keys[pygame.K_w]:
self.run_t = True
else:
self.run_t = False
if keys[pygame.K_s]:
self.run_b = True
else:
self.run_b = False
if keys[pygame.K_d]:
self.run_r = True
else:
self.run_r = False
if self.run_l or self.run_r:
if self.animCount > 6:
self.animCount = 0
if self.run_l:
if self.x >= -50:
self.x -= self.speed
win.blit(self.inDungeon_run[self.animCount], (self.x, self.y))
pygame.time.wait(50)
self.animCount += 1
if self.run_t and not self.run_b:
if self.animCount > 6:
self.animCount = 0
self.velY = -self.speed
elif self.run_r:
if self.x <= 1450:
self.x += self.speed
win.blit(self.inDungeon_run[self.animCount], (self.x, self.y))
pygame.time.wait(50)
self.animCount += 1
if self.run_b and not self.run_t:
if self.animCount > 6:
self.animCount = 0
self.velY = self.speed
elif self.run_t or self.run_b:
if self.animCount > 6:
self.animCount = 0
if self.run_t:
if self.y >= -50:
self.y -= self.speed
win.blit(self.inDungeon_run[self.animCount], (self.x, self.y))
pygame.time.wait(50)
self.animCount += 1
if self.run_r and not self.run_l:
if self.animCount > 6:
self.animCount = 0
self.velX = self.speed
elif self.run_b:
if self.y <= 500:
self.y += self.speed
win.blit(self.inDungeon_run[self.animCount], (self.x, self.y))
pygame.time.wait(50)
self.animCount += 1
else:
win.blit(self.inDungeon_img, (self.x, self.y))
self.run_l = False
self.run_b = False
self.run_t = False
self.run_r = False
self.x += self.velX
self.y += self.velY

else:
win.blit(self.inDungeon_img, (self.x, self.y))
self.x += self.velX
self.y += self.velY
90 changes: 90 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""Smooth Movement in pygame"""

# Imports
import pygame, sys

# Constants
WIDTH, HEIGHT = 400, 400
TITLE = "Smooth Movement"

# pygame initialization
pygame.init()
win = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption(TITLE)
clock = pygame.time.Clock()


# Player Class
class Player:
def __init__(self, x, y):
self.x = int(x)
self.y = int(y)
self.rect = pygame.Rect(self.x, self.y, 32, 32)
self.color = (250, 120, 60)
self.velX = 0
self.velY = 0
self.left_pressed = False
self.right_pressed = False
self.up_pressed = False
self.down_pressed = False
self.speed = 4

def draw(self, win):
pygame.draw.rect(win, self.color, self.rect)

def update(self):
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(int(self.x), int(self.y), 32, 32)


# Player Initialization
player = Player(WIDTH / 2, HEIGHT / 2)

# Main Loop
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
if event.key == pygame.K_d:
player.right_pressed = True
if event.key == pygame.K_w:
player.up_pressed = True
if event.key == pygame.K_s:
player.down_pressed = True
if event.type == pygame.KEYUP:
if event.key == pygame.K_a:
player.left_pressed = False
if event.key == pygame.K_d:
player.right_pressed = False
if event.key == pygame.K_w:
player.up_pressed = False
if event.key == pygame.K_s:
player.down_pressed = False

# Draw
win.fill((12, 24, 36))
player.draw(win)

# update
player.update()
pygame.display.flip()

clock.tick(120)