So I'm making a game, wow how exotic, and I'm in very early stages of the process at the moment. It is meant to be an RPG, so I would assume it would be a big thing to have smooth character movement! :o) So, my problem is- the character seems to hit the wall which is OUTSIDE of the window on lower and right sides, which is not a problem for the other side for some reason. I attached all the assets and the video to show my problem in case i didnt elaborate well enough π₯Ή k thx yall!!
I use pygames 2.6.1, python ver 3.11.9 and Kenny Yip Coding for tutorials at the moment if that helps.
(also, 51 is a symbolic number, must be kept)
import pygame
import os
X=850
Y=500
Player_x_loco = X/2
Player_y_loco = Y/2
#51/141 (size of the original pictture)
Dingus_width = 17
Dingus_height = 47
walk_speed = 5.1
#images vvv
sburb=pygame.image.load(os.path.join("asssets", "sburb.png"))
kawaii=pygame.image.load(os.path.join("asssets", "kawaiiSpace.png"))
ding_forward=pygame.image.load(os.path.join("asssets", "dingus_sprite.png"))
screen = pygame.display.set_mode((X, Y))
feel="placeholder"
pygame.display.set_caption(feel)
pygame.display.set_icon(sburb)
clock = pygame.time.Clock() #<--------FRAMERATE GCFGXCHVJK>
running = True
class Player(pygame.Rect):
def __init__(self):
pygame.Rect.__init__(self, Player_x_loco, Player_y_loco, Dingus_width, Dingus_height)
self.image = ding_forward
player=Player()
#better have the visuals in its own lil thing (apparently- ig i see why)
def graph(): #short for GRAPHics
#the up left corner -> (0,0); (down is +, up is -); (the x is normal)
screen.fill((0,80,80))
screen.blit(kawaii, (0,0))
screen.blit(player.image, player)
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT: #x
running = False
graph()
keys = pygame.key.get_pressed()
if (keys[pygame.K_w] or keys[pygame.K_UP]):
player.y=max(player.y-walk_speed, 0)
if (keys[pygame.K_s] or keys[pygame.K_DOWN]):
player.y=min(player.y+walk_speed, Y-player.height)
if (keys[pygame.K_a] or keys[pygame.K_LEFT]):
player.x=max(player.x-walk_speed,0)
if (keys[pygame.K_d] or keys[pygame.K_RIGHT]):
player.x=min(player.x+walk_speed, X-player.width)
pygame.display.update() #<--------- necesaary 2see anything
clock.tick(60)```