The X and Y of my player will only go past a certain point











up vote
0
down vote

favorite












Note: I am using python/pygame.
I was building a mini-map, and I based the character's icon's location off the character's x and y values. I soon realized that the icon went only to a certain point. I decided to print the player's x any y and soon learned that the the x and y would only update until 955, and 350-ish. If you could read through this and I am missing something obvious, please let me know. This is all the relevant code.
Thank you! Also, if I need to be more specific, just message me rather than take this down.



Here's the code - some of his might not be needed but I added it just in case:



class You(pygame.sprite.Sprite):
def __init__(self, x, y):
super().__init__()
self.image = pygame.Surface([50, 50])
self.image.fill(BLUE)
self.rect = self.image.get_rect()
self.inventory = pygame.sprite.Group()
self.touched_trees = pygame.sprite.Group()
self.OpenInventory = False
self.rect.x = x
self.rect.y = y
self.dx = 0
self.dy = 0
self.speed = 5
self.strength = 5
self.food = 10
self.water = 10
self.outside = True
self.health = 20
self.coords =
self.incar = False
self.insidehp = False
self.insideHouse = False
self.insidegym = False
self.insideFirestation = False
self.intread = False
self.intree = False
self.inbench = False
self.alive = True
self.action = False
self.frozen = False
self.benchfactor = 0
self.benchmeter = 0
self.mask = pygame.mask.from_surface(self.image)

def update(self):
screen.blit(self.image, (self.rect.x, self.rect.y))
if self.dx != 0:
self.move_single_axis(self.dx, 0)
if self.dy != 0:
self.move_single_axis(0, self.dy)
if self.food > 10:
self.food = 10
if self.food < 1:
self.alive = False
if self.water > 10:
self.water = 10
if self.water < 1:
self.alive = False


def move_single_axis(self, dx, dy):
global ct
self.rect.x += dx
self.rect.y += dy
if self.outside:
wall = pygame.sprite.spritecollide(player, map.home, False)
for w in wall:
if self. insideHouse == False:
if dx > 0:
self.rect.right = w.rect.left
elif dx < 0:
self.rect.left = w.rect.right
elif dy > 0:
self.rect.bottom = w.rect.top
elif dy < 0:
self.insideHouse = True
self.rect.y -= 50


elif self.rect.bottom == w.rect.bottom:
self.rect.y += 50
print('exit det is good')
self.insideHouse = False
pwall = pygame.sprite.spritecollide(player, otherpeoples, False)
for p in pwall:
if dx > 0:
p.rect.x += self.speed
elif dx < 0:
p.rect.x -= self.speed
elif dy > 0:
p.rect.y += self.speed
elif dy < 0:
p.rect.y -= self.speed
if self.outside:
#tree collisions
twall = pygame.sprite.spritecollide(player, forest.NormalTreeses, False)
for a in twall:
forest.NormalTreeses.remove(a)
self.touched_trees.add(a)
self.intree = True
twall2 = pygame.sprite.spritecollide(player, self.touched_trees, False)
for t in self.touched_trees:
for o in forest.Trunks:
if o.rect.x == w.rect.x+225 and o.rect.y == w.rect.y+225:
screen.blit(o.image, (o.rect.x, o.rect.y))
if not twall2:
for touch in self.touched_trees:
forest.NormalTreeses.add(touch)
self.touched_trees.remove(touch)
self.intree = False

if self.intree:
twall3 = pygame.sprite.spritecollide(player, forest.Trunks, False)
for t in twall3:
if dx > 0:
self.rect.right = t.rect.left
elif dx < 0:
self.rect.left = t.rect.right
elif dy > 0:
self.rect.bottom = t.rect.top
elif dy < 0:
self.rect.top = t.rect.bottom

if self.outside:
cwall = pygame.sprite.spritecollide(player, map.HP, False)
for c in cwall:
if self.insidehp == False:
if dx > 0:
self.rect.right = c.rect.left
elif dx < 0:
self.rect.left = c.rect.right
elif dy > 0:
self.rect.bottom = c.rect.top
elif dy < 0:
self.insidehp = True
self.rect.y -= 50

elif self.rect.bottom == c.rect.bottom:
self.rect.y += 50
self.insidehp = False

if self.insidehp == True:
hpwalldet = pygame.sprite.spritecollide(self, hpwalls, False)
for h in hpwalldet:
if dx > 0:
self.rect.right = h.rect.left
elif dx < 0:
self.rect.left = h.rect.right
elif dy > 0:
self.rect.bottom = h.rect.top
elif dy < 0:
self.rect.top = h.rect.bottom

if self.insideFirestation == True:
fswalldet = pygame.sprite.spritecollide(self, fswalls, False)
for f in fswalldet:
if dx > 0:
self.rect.right = f.rect.left
elif dx < 0:
self.rect.left = f.rect.right
elif dy > 0:
self.rect.bottom = f.rect.top
elif dy < 0:
self.rect.top = f.rect.bottom


if self.outside:
dwall = pygame.sprite.spritecollide(player, map.gyms, False)
for d in dwall:
if self.insidegym == False:
if dx > 0:
self.rect.right = d.rect.left
elif dx < 0:
self.rect.left = d.rect.right
elif dy > 0:
self.rect.bottom = d.rect.top
elif dy < 0:
self.insidegym = True
d.image.fill(WHITE)
self.rect.y -= 50


elif self.rect.bottom == d.rect.bottom:
self.rect.y -= 50
d.image = pygame.image.load("Images/gym.png")
d.image = pygame.transform.scale(d.image, (2000, 1000))
self.insidegym = False

if self.outside:
ewall = pygame.sprite.spritecollide(player, map.firestations, False)
for e in ewall:
if self.insideFirestation == False:
if dx > 0:
self.rect.right = e.rect.left
elif dx < 0:
self.rect.left = e.rect.right
elif dy > 0:
self.rect.bottom = e.rect.top
elif dy < 0:
self.insideFirestation = True
e.image.fill(WHITE)
self.rect.y -= 50

elif self.rect.bottom == e.rect.bottom:
self.rect.y -= 50
e.image = pygame.image.load("Images/firehouse.png")
e.image = pygame.transform.scale(e.image, (1000, 1000))
self.insideFirestation = False

ct = pygame.sprite.spritecollide(self, carlist, False)
if self.incar == False:
if ct:
for t in ct:
t.lose_attributes()
incarlist.add(t)
player.GainCarAttributes(t)




def GainCarAttributes(self, car):
self.image = pygame.Surface([200, 200])
self.image.fill(YELLOW)
self.speed = car.speed
self.health = car.health
self.incar = True
print('became car')

def ExitCar(self, car):
self.image = pygame.Surface([50, 50])
car.image = pygame.Surface([200, 200])
car.image.fill(YELLOW)
incarlist.x = player.rect.x
incarlist.y = player.rect.y
self.rect.x -= 55
self.image.fill(BLUE)
self.speed -= self.speed
self.speed += 10
self.health = 20
self.incar = False

def left(self, _deltatime):
self.dx = -self.speed

def right(self, _deltatime):
self.dx = self.speed

def up(self, _deltatime):
self.dy = -self.speed

def down(self, _deltatime):
self.dy = self.speed

def stopx(self):
self.dx = 0

def stopy(self):
self.dy = 0


---- i skipped a bit



def event_collector():
global inmenu
inmenu = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
global done
done = True
if event.type == pygame.KEYDOWN:
if player.frozen == False:
if event.key == pygame.K_w:
player.up(deltatime)
if event.key == pygame.K_a:
player.left(deltatime)
if event.key == pygame.K_s:
player.down(deltatime)
if event.key == pygame.K_d:
player.right(deltatime)
if event.key == pygame.K_t:
tx = int(input('enter column: '))
ty = int(input('enter row: '))
player.rect.x = tx * 1000
player.rect.y = ty * 1000
if event.key == pygame.K_p:
player.health -= 10
player.water -= 5
player.food -= 5
if event.key == pygame.K_e and player.incar == True:
player.ExitCar(t)
incarlist.remove([0])
player.incar = False
print("Car exited")

elif player.inbench:
if player.benchmeter < .9:
if event.key == pygame.K_q:
if player.strength < 25:
player.benchfactor += 0.1
print(player.strength)
player.benchmeter += 0.1
else:
time.sleep(1)
player.benchmeter = 0

if event.type == pygame.KEYUP:
if event.key == pygame.K_w or event.key == pygame.K_s:
player.stopy()
if event.key == pygame.K_a or event.key == pygame.K_d:
player.stopx()
if event.key == pygame.K_e:
player.action = False
if event.key == pygame.K_q:
if player.OpenInventory == False:
player.OpenInventory = True
else:
player.OpenInventory = False
if event.key == pygame.K_ESCAPE:
pause_menu = True
if event.key == pygame.K_e:
player.action = True

if event.type == pygame.MOUSEBUTTONUP:
for o in otherpeoples:
if o.rect.collidepoint(pygame.mouse.get_pos()):
selected.add(o)
inmenu = True

if inmenu:
for s in selected:
for i in TalkMenu:
if i.rect.collidepoint(pygame.mouse.get_pos()):
print('doublecheck')
if event.type == pygame.MOUSEBUTTONUP:
jerry.friendmeter += 1
print(s.friendmeter)
for i in TalkMenu:
screen.blit(i.image, (s.rect.x, s.rect.y - 50))


while not done:
screen.fill(GREY)
if pause_menu == False:
event_collector()
if player.alive == True:
print(player.rect.x, player.rect.y)
if player.rect.right > 1000:
diff = player.rect.right - 1000
player.rect.right = 1000
map.shiftworldx(-diff)

if player.rect.left < 500:
diff = 500 - player.rect.left
player.rect.left = 500
map.shiftworldx(diff)

if player.rect.bottom > 400:
diff = player.rect.bottom - 400
player.rect.bottom = 400
map.shiftworldy(-diff)

if player.rect.top < 200:
diff = 200 - player.rect.top
player.rect.top = 200
map.shiftworldy(diff)


map.buildings.draw(screen)
map.home.draw(screen)
map.gyms.draw(screen)
map.roads.draw(screen)
map.HP.draw(screen)
for n in forest.NormalTreeses:
screen.blit(n.image, (n.rect.x, n.rect.y))
forest.FallenTrees.draw(screen)
market.MarketBoothsSpawns.draw(screen)
map.firestations.draw(screen)
for o in otherpeoples:
screen.blit(o.image, (o.rect.x, o.rect.y))
#Minimap
screen.blit(minimap.image, ((WIDTH1/100)-13, (HEIGHT1/100)-7))
#HUD besides inv
minimap.displayBuildings(screen, player)
screen.blit(playICON.image, (100 * (player.rect.x / 10000), (player.rect.y / 10000) * 100))
hbar.update(player, LGREEN)
screen.blit(hback.image, (385, 0))
screen.blit(hbar.image, (395, 10))
screen.blit(FWback.image, (385, 20))
fbar.update(player, RED)
screen.blit(fbar.image, (395, 30))
wbar.update(player, BLUE)
screen.blit(wbar.image, (645, 30))
#Inventory
if player.OpenInventory == True:
HUD.openInentory(WIDTH1, HEIGHT1, screen, player, 0, 1)
else:
screen.blit(pygame.image.load('Images/backpack1.png'), (WIDTH1 / 2 * 1.9, HEIGHT1 / 10 + 1 * 50 - 100))
for i in player.inventory:
i.AMMO.draw(screen)
i.USED_AMMO.draw(screen)

#treadmill
if player.intread == True:
player.rect.y += player.speed - 2
if player.speed < 15.1:
player.speed += .01

if player.insideFirestation == True:
fswalls.draw(screen)
fsbeds.draw(screen)
fscountertops.draw(screen)
fscouches.draw(screen)


if player.insidehp == True:
cwall = pygame.sprite.spritecollide(player, map.HP, False)
locR = 5
for c in cwall:
screen.blit(frontdesk.image, (c.rect.x + 1250, c.rect.y + 2500))
hpwalls.draw(screen)


if player.insideHouse == True:
wall = pygame.sprite.spritecollide(player, map.home, False)
for w in wall:
x = w.rect.x + 375
y = w.rect.y + 400
cx = w.rect.x + 800
cy = w.rect.y + 700
w.image = floor.image
screen.blit(couch.image, (x, y))
screen.blit(counter.image, (cx, cy))
if player.rect.x < w.rect.x:
player.rect.left = w.rect.left
if player.rect.x > w.rect.x + 850:
player.rect.right = w.rect.right
if player.rect.y < w.rect.y:
player.rect.top = w.rect.top


if player.insidegym == True:
gym_treadmills.draw(screen)
gym_bench_press.draw(screen)
tredcollideP1 = pygame.sprite.spritecollide(player, gym_treadmills, False)
for t in tredcollideP1:
if player.intread == False:
if t.InUse == False:
if player.dx > 0:
player.rect.right = t.rect.left
elif player.dx < 0:
player.rect.left = t.rect.right
elif player.dy > 0:
player.rect.bottom = t.rect.top
elif player.dy < 0:
player.rect.x = t.rect.x + 37.5
player.rect.y = t.rect.y + 25
intreadlist.add(t)
player.intread = True
t.InUse = True

if player.intread:
for i in intreadlist:
if player.rect.y > i.rect.y + 175:
print('sec')
i.InUse = False
intreadlist.empty()
player.intread = False

benchcollideP1 = pygame.sprite.spritecollide(player, gym_bench_press, False)
for b in benchcollideP1:
if player.inbench == False:
if b.InUse == False:
if player.dx > 0:
player.rect.right = b.rect.left
elif player.dx < 0:
player.rect.left = b.rect.right
elif player.dy > 0:
player.rect.bottom = b.rect.top
elif player.dy < 0:
if player.action == True:
player.rect.x = b.rect.x + 37.5
player.rect.y = b.rect.y + 25
player.frozen = True
player.inbench = True
player.action = False
b.InUse = True
else:
player.rect.top = b.rect.bottom
if player.inbench:
if player.action == True:
player.rect.x +=30
player.frozen = False
player.inbench = False


incarlist.draw(screen)
carlist.draw(screen)
carlist.update(screen)
player.update()

elif pause_menu == True:
message_display('RESUME', BLACK, HEIGHT1/3)
message_display('FULLSCREEN', BLACK, HEIGHT1/3+45)
message_display('QUIT GAME', BLACK, HEIGHT1/3+90)
resume.rect.x = WIDTH1 / 2 - 100
resume.rect.y = HEIGHT1 / 3 - 30
fullscreenHitBox.rect.x = WIDTH1 / 2 - 132
fullscreenHitBox.rect.y = HEIGHT1 / 3 + 18
quit_game.rect.x = WIDTH1/2-117
quit_game.rect.y = HEIGHT1/3+73
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if resume.rect.collidepoint(pygame.mouse.get_pos()):
if event.type == pygame.MOUSEBUTTONUP:
pause_menu = False
if fullscreenHitBox.rect.collidepoint(pygame.mouse.get_pos()):
if event.type == pygame.MOUSEBUTTONUP:
pygame.display.toggle_fullscreen()
if quit_game.rect.collidepoint(pygame.mouse.get_pos()):
if event.type == pygame.MOUSEBUTTONUP:
done = True
mpx, mpy = pygame.mouse.get_pos()
screen.blit(mousey.image, (mpx, mpy))
pygame.display.update()
pygame.display.flip()
deltatime = clock.tick()/10
# print (deltatime)
# print (fp1.matrix)
pygame.quit()









share|improve this question




















  • 1




    dont link to offsite code... create the minimum example you can ...
    – Joran Beasley
    Nov 20 at 0:53












  • Thank you, I wasn't going to, not trying to make excuses, but I was trying to copy and paste my code, I finally got it here. It's not very minimal, but It was as small as I could get it, so I doubt you will need to read through all of it. Thanks for the advice!
    – PlzHelp
    Nov 20 at 1:04










  • Welcome to Stack Overflow. You've posted way too much code. Most people here (me included) don't have time to read, analyze and debug so much code. If you want help, I suggest creating a new example from scratch and only insert the code that's necessary to reproduce the bug. The example should be minimal, complete (runnable) and verifiable.
    – skrx
    Nov 20 at 13:26















up vote
0
down vote

favorite












Note: I am using python/pygame.
I was building a mini-map, and I based the character's icon's location off the character's x and y values. I soon realized that the icon went only to a certain point. I decided to print the player's x any y and soon learned that the the x and y would only update until 955, and 350-ish. If you could read through this and I am missing something obvious, please let me know. This is all the relevant code.
Thank you! Also, if I need to be more specific, just message me rather than take this down.



Here's the code - some of his might not be needed but I added it just in case:



class You(pygame.sprite.Sprite):
def __init__(self, x, y):
super().__init__()
self.image = pygame.Surface([50, 50])
self.image.fill(BLUE)
self.rect = self.image.get_rect()
self.inventory = pygame.sprite.Group()
self.touched_trees = pygame.sprite.Group()
self.OpenInventory = False
self.rect.x = x
self.rect.y = y
self.dx = 0
self.dy = 0
self.speed = 5
self.strength = 5
self.food = 10
self.water = 10
self.outside = True
self.health = 20
self.coords =
self.incar = False
self.insidehp = False
self.insideHouse = False
self.insidegym = False
self.insideFirestation = False
self.intread = False
self.intree = False
self.inbench = False
self.alive = True
self.action = False
self.frozen = False
self.benchfactor = 0
self.benchmeter = 0
self.mask = pygame.mask.from_surface(self.image)

def update(self):
screen.blit(self.image, (self.rect.x, self.rect.y))
if self.dx != 0:
self.move_single_axis(self.dx, 0)
if self.dy != 0:
self.move_single_axis(0, self.dy)
if self.food > 10:
self.food = 10
if self.food < 1:
self.alive = False
if self.water > 10:
self.water = 10
if self.water < 1:
self.alive = False


def move_single_axis(self, dx, dy):
global ct
self.rect.x += dx
self.rect.y += dy
if self.outside:
wall = pygame.sprite.spritecollide(player, map.home, False)
for w in wall:
if self. insideHouse == False:
if dx > 0:
self.rect.right = w.rect.left
elif dx < 0:
self.rect.left = w.rect.right
elif dy > 0:
self.rect.bottom = w.rect.top
elif dy < 0:
self.insideHouse = True
self.rect.y -= 50


elif self.rect.bottom == w.rect.bottom:
self.rect.y += 50
print('exit det is good')
self.insideHouse = False
pwall = pygame.sprite.spritecollide(player, otherpeoples, False)
for p in pwall:
if dx > 0:
p.rect.x += self.speed
elif dx < 0:
p.rect.x -= self.speed
elif dy > 0:
p.rect.y += self.speed
elif dy < 0:
p.rect.y -= self.speed
if self.outside:
#tree collisions
twall = pygame.sprite.spritecollide(player, forest.NormalTreeses, False)
for a in twall:
forest.NormalTreeses.remove(a)
self.touched_trees.add(a)
self.intree = True
twall2 = pygame.sprite.spritecollide(player, self.touched_trees, False)
for t in self.touched_trees:
for o in forest.Trunks:
if o.rect.x == w.rect.x+225 and o.rect.y == w.rect.y+225:
screen.blit(o.image, (o.rect.x, o.rect.y))
if not twall2:
for touch in self.touched_trees:
forest.NormalTreeses.add(touch)
self.touched_trees.remove(touch)
self.intree = False

if self.intree:
twall3 = pygame.sprite.spritecollide(player, forest.Trunks, False)
for t in twall3:
if dx > 0:
self.rect.right = t.rect.left
elif dx < 0:
self.rect.left = t.rect.right
elif dy > 0:
self.rect.bottom = t.rect.top
elif dy < 0:
self.rect.top = t.rect.bottom

if self.outside:
cwall = pygame.sprite.spritecollide(player, map.HP, False)
for c in cwall:
if self.insidehp == False:
if dx > 0:
self.rect.right = c.rect.left
elif dx < 0:
self.rect.left = c.rect.right
elif dy > 0:
self.rect.bottom = c.rect.top
elif dy < 0:
self.insidehp = True
self.rect.y -= 50

elif self.rect.bottom == c.rect.bottom:
self.rect.y += 50
self.insidehp = False

if self.insidehp == True:
hpwalldet = pygame.sprite.spritecollide(self, hpwalls, False)
for h in hpwalldet:
if dx > 0:
self.rect.right = h.rect.left
elif dx < 0:
self.rect.left = h.rect.right
elif dy > 0:
self.rect.bottom = h.rect.top
elif dy < 0:
self.rect.top = h.rect.bottom

if self.insideFirestation == True:
fswalldet = pygame.sprite.spritecollide(self, fswalls, False)
for f in fswalldet:
if dx > 0:
self.rect.right = f.rect.left
elif dx < 0:
self.rect.left = f.rect.right
elif dy > 0:
self.rect.bottom = f.rect.top
elif dy < 0:
self.rect.top = f.rect.bottom


if self.outside:
dwall = pygame.sprite.spritecollide(player, map.gyms, False)
for d in dwall:
if self.insidegym == False:
if dx > 0:
self.rect.right = d.rect.left
elif dx < 0:
self.rect.left = d.rect.right
elif dy > 0:
self.rect.bottom = d.rect.top
elif dy < 0:
self.insidegym = True
d.image.fill(WHITE)
self.rect.y -= 50


elif self.rect.bottom == d.rect.bottom:
self.rect.y -= 50
d.image = pygame.image.load("Images/gym.png")
d.image = pygame.transform.scale(d.image, (2000, 1000))
self.insidegym = False

if self.outside:
ewall = pygame.sprite.spritecollide(player, map.firestations, False)
for e in ewall:
if self.insideFirestation == False:
if dx > 0:
self.rect.right = e.rect.left
elif dx < 0:
self.rect.left = e.rect.right
elif dy > 0:
self.rect.bottom = e.rect.top
elif dy < 0:
self.insideFirestation = True
e.image.fill(WHITE)
self.rect.y -= 50

elif self.rect.bottom == e.rect.bottom:
self.rect.y -= 50
e.image = pygame.image.load("Images/firehouse.png")
e.image = pygame.transform.scale(e.image, (1000, 1000))
self.insideFirestation = False

ct = pygame.sprite.spritecollide(self, carlist, False)
if self.incar == False:
if ct:
for t in ct:
t.lose_attributes()
incarlist.add(t)
player.GainCarAttributes(t)




def GainCarAttributes(self, car):
self.image = pygame.Surface([200, 200])
self.image.fill(YELLOW)
self.speed = car.speed
self.health = car.health
self.incar = True
print('became car')

def ExitCar(self, car):
self.image = pygame.Surface([50, 50])
car.image = pygame.Surface([200, 200])
car.image.fill(YELLOW)
incarlist.x = player.rect.x
incarlist.y = player.rect.y
self.rect.x -= 55
self.image.fill(BLUE)
self.speed -= self.speed
self.speed += 10
self.health = 20
self.incar = False

def left(self, _deltatime):
self.dx = -self.speed

def right(self, _deltatime):
self.dx = self.speed

def up(self, _deltatime):
self.dy = -self.speed

def down(self, _deltatime):
self.dy = self.speed

def stopx(self):
self.dx = 0

def stopy(self):
self.dy = 0


---- i skipped a bit



def event_collector():
global inmenu
inmenu = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
global done
done = True
if event.type == pygame.KEYDOWN:
if player.frozen == False:
if event.key == pygame.K_w:
player.up(deltatime)
if event.key == pygame.K_a:
player.left(deltatime)
if event.key == pygame.K_s:
player.down(deltatime)
if event.key == pygame.K_d:
player.right(deltatime)
if event.key == pygame.K_t:
tx = int(input('enter column: '))
ty = int(input('enter row: '))
player.rect.x = tx * 1000
player.rect.y = ty * 1000
if event.key == pygame.K_p:
player.health -= 10
player.water -= 5
player.food -= 5
if event.key == pygame.K_e and player.incar == True:
player.ExitCar(t)
incarlist.remove([0])
player.incar = False
print("Car exited")

elif player.inbench:
if player.benchmeter < .9:
if event.key == pygame.K_q:
if player.strength < 25:
player.benchfactor += 0.1
print(player.strength)
player.benchmeter += 0.1
else:
time.sleep(1)
player.benchmeter = 0

if event.type == pygame.KEYUP:
if event.key == pygame.K_w or event.key == pygame.K_s:
player.stopy()
if event.key == pygame.K_a or event.key == pygame.K_d:
player.stopx()
if event.key == pygame.K_e:
player.action = False
if event.key == pygame.K_q:
if player.OpenInventory == False:
player.OpenInventory = True
else:
player.OpenInventory = False
if event.key == pygame.K_ESCAPE:
pause_menu = True
if event.key == pygame.K_e:
player.action = True

if event.type == pygame.MOUSEBUTTONUP:
for o in otherpeoples:
if o.rect.collidepoint(pygame.mouse.get_pos()):
selected.add(o)
inmenu = True

if inmenu:
for s in selected:
for i in TalkMenu:
if i.rect.collidepoint(pygame.mouse.get_pos()):
print('doublecheck')
if event.type == pygame.MOUSEBUTTONUP:
jerry.friendmeter += 1
print(s.friendmeter)
for i in TalkMenu:
screen.blit(i.image, (s.rect.x, s.rect.y - 50))


while not done:
screen.fill(GREY)
if pause_menu == False:
event_collector()
if player.alive == True:
print(player.rect.x, player.rect.y)
if player.rect.right > 1000:
diff = player.rect.right - 1000
player.rect.right = 1000
map.shiftworldx(-diff)

if player.rect.left < 500:
diff = 500 - player.rect.left
player.rect.left = 500
map.shiftworldx(diff)

if player.rect.bottom > 400:
diff = player.rect.bottom - 400
player.rect.bottom = 400
map.shiftworldy(-diff)

if player.rect.top < 200:
diff = 200 - player.rect.top
player.rect.top = 200
map.shiftworldy(diff)


map.buildings.draw(screen)
map.home.draw(screen)
map.gyms.draw(screen)
map.roads.draw(screen)
map.HP.draw(screen)
for n in forest.NormalTreeses:
screen.blit(n.image, (n.rect.x, n.rect.y))
forest.FallenTrees.draw(screen)
market.MarketBoothsSpawns.draw(screen)
map.firestations.draw(screen)
for o in otherpeoples:
screen.blit(o.image, (o.rect.x, o.rect.y))
#Minimap
screen.blit(minimap.image, ((WIDTH1/100)-13, (HEIGHT1/100)-7))
#HUD besides inv
minimap.displayBuildings(screen, player)
screen.blit(playICON.image, (100 * (player.rect.x / 10000), (player.rect.y / 10000) * 100))
hbar.update(player, LGREEN)
screen.blit(hback.image, (385, 0))
screen.blit(hbar.image, (395, 10))
screen.blit(FWback.image, (385, 20))
fbar.update(player, RED)
screen.blit(fbar.image, (395, 30))
wbar.update(player, BLUE)
screen.blit(wbar.image, (645, 30))
#Inventory
if player.OpenInventory == True:
HUD.openInentory(WIDTH1, HEIGHT1, screen, player, 0, 1)
else:
screen.blit(pygame.image.load('Images/backpack1.png'), (WIDTH1 / 2 * 1.9, HEIGHT1 / 10 + 1 * 50 - 100))
for i in player.inventory:
i.AMMO.draw(screen)
i.USED_AMMO.draw(screen)

#treadmill
if player.intread == True:
player.rect.y += player.speed - 2
if player.speed < 15.1:
player.speed += .01

if player.insideFirestation == True:
fswalls.draw(screen)
fsbeds.draw(screen)
fscountertops.draw(screen)
fscouches.draw(screen)


if player.insidehp == True:
cwall = pygame.sprite.spritecollide(player, map.HP, False)
locR = 5
for c in cwall:
screen.blit(frontdesk.image, (c.rect.x + 1250, c.rect.y + 2500))
hpwalls.draw(screen)


if player.insideHouse == True:
wall = pygame.sprite.spritecollide(player, map.home, False)
for w in wall:
x = w.rect.x + 375
y = w.rect.y + 400
cx = w.rect.x + 800
cy = w.rect.y + 700
w.image = floor.image
screen.blit(couch.image, (x, y))
screen.blit(counter.image, (cx, cy))
if player.rect.x < w.rect.x:
player.rect.left = w.rect.left
if player.rect.x > w.rect.x + 850:
player.rect.right = w.rect.right
if player.rect.y < w.rect.y:
player.rect.top = w.rect.top


if player.insidegym == True:
gym_treadmills.draw(screen)
gym_bench_press.draw(screen)
tredcollideP1 = pygame.sprite.spritecollide(player, gym_treadmills, False)
for t in tredcollideP1:
if player.intread == False:
if t.InUse == False:
if player.dx > 0:
player.rect.right = t.rect.left
elif player.dx < 0:
player.rect.left = t.rect.right
elif player.dy > 0:
player.rect.bottom = t.rect.top
elif player.dy < 0:
player.rect.x = t.rect.x + 37.5
player.rect.y = t.rect.y + 25
intreadlist.add(t)
player.intread = True
t.InUse = True

if player.intread:
for i in intreadlist:
if player.rect.y > i.rect.y + 175:
print('sec')
i.InUse = False
intreadlist.empty()
player.intread = False

benchcollideP1 = pygame.sprite.spritecollide(player, gym_bench_press, False)
for b in benchcollideP1:
if player.inbench == False:
if b.InUse == False:
if player.dx > 0:
player.rect.right = b.rect.left
elif player.dx < 0:
player.rect.left = b.rect.right
elif player.dy > 0:
player.rect.bottom = b.rect.top
elif player.dy < 0:
if player.action == True:
player.rect.x = b.rect.x + 37.5
player.rect.y = b.rect.y + 25
player.frozen = True
player.inbench = True
player.action = False
b.InUse = True
else:
player.rect.top = b.rect.bottom
if player.inbench:
if player.action == True:
player.rect.x +=30
player.frozen = False
player.inbench = False


incarlist.draw(screen)
carlist.draw(screen)
carlist.update(screen)
player.update()

elif pause_menu == True:
message_display('RESUME', BLACK, HEIGHT1/3)
message_display('FULLSCREEN', BLACK, HEIGHT1/3+45)
message_display('QUIT GAME', BLACK, HEIGHT1/3+90)
resume.rect.x = WIDTH1 / 2 - 100
resume.rect.y = HEIGHT1 / 3 - 30
fullscreenHitBox.rect.x = WIDTH1 / 2 - 132
fullscreenHitBox.rect.y = HEIGHT1 / 3 + 18
quit_game.rect.x = WIDTH1/2-117
quit_game.rect.y = HEIGHT1/3+73
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if resume.rect.collidepoint(pygame.mouse.get_pos()):
if event.type == pygame.MOUSEBUTTONUP:
pause_menu = False
if fullscreenHitBox.rect.collidepoint(pygame.mouse.get_pos()):
if event.type == pygame.MOUSEBUTTONUP:
pygame.display.toggle_fullscreen()
if quit_game.rect.collidepoint(pygame.mouse.get_pos()):
if event.type == pygame.MOUSEBUTTONUP:
done = True
mpx, mpy = pygame.mouse.get_pos()
screen.blit(mousey.image, (mpx, mpy))
pygame.display.update()
pygame.display.flip()
deltatime = clock.tick()/10
# print (deltatime)
# print (fp1.matrix)
pygame.quit()









share|improve this question




















  • 1




    dont link to offsite code... create the minimum example you can ...
    – Joran Beasley
    Nov 20 at 0:53












  • Thank you, I wasn't going to, not trying to make excuses, but I was trying to copy and paste my code, I finally got it here. It's not very minimal, but It was as small as I could get it, so I doubt you will need to read through all of it. Thanks for the advice!
    – PlzHelp
    Nov 20 at 1:04










  • Welcome to Stack Overflow. You've posted way too much code. Most people here (me included) don't have time to read, analyze and debug so much code. If you want help, I suggest creating a new example from scratch and only insert the code that's necessary to reproduce the bug. The example should be minimal, complete (runnable) and verifiable.
    – skrx
    Nov 20 at 13:26













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Note: I am using python/pygame.
I was building a mini-map, and I based the character's icon's location off the character's x and y values. I soon realized that the icon went only to a certain point. I decided to print the player's x any y and soon learned that the the x and y would only update until 955, and 350-ish. If you could read through this and I am missing something obvious, please let me know. This is all the relevant code.
Thank you! Also, if I need to be more specific, just message me rather than take this down.



Here's the code - some of his might not be needed but I added it just in case:



class You(pygame.sprite.Sprite):
def __init__(self, x, y):
super().__init__()
self.image = pygame.Surface([50, 50])
self.image.fill(BLUE)
self.rect = self.image.get_rect()
self.inventory = pygame.sprite.Group()
self.touched_trees = pygame.sprite.Group()
self.OpenInventory = False
self.rect.x = x
self.rect.y = y
self.dx = 0
self.dy = 0
self.speed = 5
self.strength = 5
self.food = 10
self.water = 10
self.outside = True
self.health = 20
self.coords =
self.incar = False
self.insidehp = False
self.insideHouse = False
self.insidegym = False
self.insideFirestation = False
self.intread = False
self.intree = False
self.inbench = False
self.alive = True
self.action = False
self.frozen = False
self.benchfactor = 0
self.benchmeter = 0
self.mask = pygame.mask.from_surface(self.image)

def update(self):
screen.blit(self.image, (self.rect.x, self.rect.y))
if self.dx != 0:
self.move_single_axis(self.dx, 0)
if self.dy != 0:
self.move_single_axis(0, self.dy)
if self.food > 10:
self.food = 10
if self.food < 1:
self.alive = False
if self.water > 10:
self.water = 10
if self.water < 1:
self.alive = False


def move_single_axis(self, dx, dy):
global ct
self.rect.x += dx
self.rect.y += dy
if self.outside:
wall = pygame.sprite.spritecollide(player, map.home, False)
for w in wall:
if self. insideHouse == False:
if dx > 0:
self.rect.right = w.rect.left
elif dx < 0:
self.rect.left = w.rect.right
elif dy > 0:
self.rect.bottom = w.rect.top
elif dy < 0:
self.insideHouse = True
self.rect.y -= 50


elif self.rect.bottom == w.rect.bottom:
self.rect.y += 50
print('exit det is good')
self.insideHouse = False
pwall = pygame.sprite.spritecollide(player, otherpeoples, False)
for p in pwall:
if dx > 0:
p.rect.x += self.speed
elif dx < 0:
p.rect.x -= self.speed
elif dy > 0:
p.rect.y += self.speed
elif dy < 0:
p.rect.y -= self.speed
if self.outside:
#tree collisions
twall = pygame.sprite.spritecollide(player, forest.NormalTreeses, False)
for a in twall:
forest.NormalTreeses.remove(a)
self.touched_trees.add(a)
self.intree = True
twall2 = pygame.sprite.spritecollide(player, self.touched_trees, False)
for t in self.touched_trees:
for o in forest.Trunks:
if o.rect.x == w.rect.x+225 and o.rect.y == w.rect.y+225:
screen.blit(o.image, (o.rect.x, o.rect.y))
if not twall2:
for touch in self.touched_trees:
forest.NormalTreeses.add(touch)
self.touched_trees.remove(touch)
self.intree = False

if self.intree:
twall3 = pygame.sprite.spritecollide(player, forest.Trunks, False)
for t in twall3:
if dx > 0:
self.rect.right = t.rect.left
elif dx < 0:
self.rect.left = t.rect.right
elif dy > 0:
self.rect.bottom = t.rect.top
elif dy < 0:
self.rect.top = t.rect.bottom

if self.outside:
cwall = pygame.sprite.spritecollide(player, map.HP, False)
for c in cwall:
if self.insidehp == False:
if dx > 0:
self.rect.right = c.rect.left
elif dx < 0:
self.rect.left = c.rect.right
elif dy > 0:
self.rect.bottom = c.rect.top
elif dy < 0:
self.insidehp = True
self.rect.y -= 50

elif self.rect.bottom == c.rect.bottom:
self.rect.y += 50
self.insidehp = False

if self.insidehp == True:
hpwalldet = pygame.sprite.spritecollide(self, hpwalls, False)
for h in hpwalldet:
if dx > 0:
self.rect.right = h.rect.left
elif dx < 0:
self.rect.left = h.rect.right
elif dy > 0:
self.rect.bottom = h.rect.top
elif dy < 0:
self.rect.top = h.rect.bottom

if self.insideFirestation == True:
fswalldet = pygame.sprite.spritecollide(self, fswalls, False)
for f in fswalldet:
if dx > 0:
self.rect.right = f.rect.left
elif dx < 0:
self.rect.left = f.rect.right
elif dy > 0:
self.rect.bottom = f.rect.top
elif dy < 0:
self.rect.top = f.rect.bottom


if self.outside:
dwall = pygame.sprite.spritecollide(player, map.gyms, False)
for d in dwall:
if self.insidegym == False:
if dx > 0:
self.rect.right = d.rect.left
elif dx < 0:
self.rect.left = d.rect.right
elif dy > 0:
self.rect.bottom = d.rect.top
elif dy < 0:
self.insidegym = True
d.image.fill(WHITE)
self.rect.y -= 50


elif self.rect.bottom == d.rect.bottom:
self.rect.y -= 50
d.image = pygame.image.load("Images/gym.png")
d.image = pygame.transform.scale(d.image, (2000, 1000))
self.insidegym = False

if self.outside:
ewall = pygame.sprite.spritecollide(player, map.firestations, False)
for e in ewall:
if self.insideFirestation == False:
if dx > 0:
self.rect.right = e.rect.left
elif dx < 0:
self.rect.left = e.rect.right
elif dy > 0:
self.rect.bottom = e.rect.top
elif dy < 0:
self.insideFirestation = True
e.image.fill(WHITE)
self.rect.y -= 50

elif self.rect.bottom == e.rect.bottom:
self.rect.y -= 50
e.image = pygame.image.load("Images/firehouse.png")
e.image = pygame.transform.scale(e.image, (1000, 1000))
self.insideFirestation = False

ct = pygame.sprite.spritecollide(self, carlist, False)
if self.incar == False:
if ct:
for t in ct:
t.lose_attributes()
incarlist.add(t)
player.GainCarAttributes(t)




def GainCarAttributes(self, car):
self.image = pygame.Surface([200, 200])
self.image.fill(YELLOW)
self.speed = car.speed
self.health = car.health
self.incar = True
print('became car')

def ExitCar(self, car):
self.image = pygame.Surface([50, 50])
car.image = pygame.Surface([200, 200])
car.image.fill(YELLOW)
incarlist.x = player.rect.x
incarlist.y = player.rect.y
self.rect.x -= 55
self.image.fill(BLUE)
self.speed -= self.speed
self.speed += 10
self.health = 20
self.incar = False

def left(self, _deltatime):
self.dx = -self.speed

def right(self, _deltatime):
self.dx = self.speed

def up(self, _deltatime):
self.dy = -self.speed

def down(self, _deltatime):
self.dy = self.speed

def stopx(self):
self.dx = 0

def stopy(self):
self.dy = 0


---- i skipped a bit



def event_collector():
global inmenu
inmenu = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
global done
done = True
if event.type == pygame.KEYDOWN:
if player.frozen == False:
if event.key == pygame.K_w:
player.up(deltatime)
if event.key == pygame.K_a:
player.left(deltatime)
if event.key == pygame.K_s:
player.down(deltatime)
if event.key == pygame.K_d:
player.right(deltatime)
if event.key == pygame.K_t:
tx = int(input('enter column: '))
ty = int(input('enter row: '))
player.rect.x = tx * 1000
player.rect.y = ty * 1000
if event.key == pygame.K_p:
player.health -= 10
player.water -= 5
player.food -= 5
if event.key == pygame.K_e and player.incar == True:
player.ExitCar(t)
incarlist.remove([0])
player.incar = False
print("Car exited")

elif player.inbench:
if player.benchmeter < .9:
if event.key == pygame.K_q:
if player.strength < 25:
player.benchfactor += 0.1
print(player.strength)
player.benchmeter += 0.1
else:
time.sleep(1)
player.benchmeter = 0

if event.type == pygame.KEYUP:
if event.key == pygame.K_w or event.key == pygame.K_s:
player.stopy()
if event.key == pygame.K_a or event.key == pygame.K_d:
player.stopx()
if event.key == pygame.K_e:
player.action = False
if event.key == pygame.K_q:
if player.OpenInventory == False:
player.OpenInventory = True
else:
player.OpenInventory = False
if event.key == pygame.K_ESCAPE:
pause_menu = True
if event.key == pygame.K_e:
player.action = True

if event.type == pygame.MOUSEBUTTONUP:
for o in otherpeoples:
if o.rect.collidepoint(pygame.mouse.get_pos()):
selected.add(o)
inmenu = True

if inmenu:
for s in selected:
for i in TalkMenu:
if i.rect.collidepoint(pygame.mouse.get_pos()):
print('doublecheck')
if event.type == pygame.MOUSEBUTTONUP:
jerry.friendmeter += 1
print(s.friendmeter)
for i in TalkMenu:
screen.blit(i.image, (s.rect.x, s.rect.y - 50))


while not done:
screen.fill(GREY)
if pause_menu == False:
event_collector()
if player.alive == True:
print(player.rect.x, player.rect.y)
if player.rect.right > 1000:
diff = player.rect.right - 1000
player.rect.right = 1000
map.shiftworldx(-diff)

if player.rect.left < 500:
diff = 500 - player.rect.left
player.rect.left = 500
map.shiftworldx(diff)

if player.rect.bottom > 400:
diff = player.rect.bottom - 400
player.rect.bottom = 400
map.shiftworldy(-diff)

if player.rect.top < 200:
diff = 200 - player.rect.top
player.rect.top = 200
map.shiftworldy(diff)


map.buildings.draw(screen)
map.home.draw(screen)
map.gyms.draw(screen)
map.roads.draw(screen)
map.HP.draw(screen)
for n in forest.NormalTreeses:
screen.blit(n.image, (n.rect.x, n.rect.y))
forest.FallenTrees.draw(screen)
market.MarketBoothsSpawns.draw(screen)
map.firestations.draw(screen)
for o in otherpeoples:
screen.blit(o.image, (o.rect.x, o.rect.y))
#Minimap
screen.blit(minimap.image, ((WIDTH1/100)-13, (HEIGHT1/100)-7))
#HUD besides inv
minimap.displayBuildings(screen, player)
screen.blit(playICON.image, (100 * (player.rect.x / 10000), (player.rect.y / 10000) * 100))
hbar.update(player, LGREEN)
screen.blit(hback.image, (385, 0))
screen.blit(hbar.image, (395, 10))
screen.blit(FWback.image, (385, 20))
fbar.update(player, RED)
screen.blit(fbar.image, (395, 30))
wbar.update(player, BLUE)
screen.blit(wbar.image, (645, 30))
#Inventory
if player.OpenInventory == True:
HUD.openInentory(WIDTH1, HEIGHT1, screen, player, 0, 1)
else:
screen.blit(pygame.image.load('Images/backpack1.png'), (WIDTH1 / 2 * 1.9, HEIGHT1 / 10 + 1 * 50 - 100))
for i in player.inventory:
i.AMMO.draw(screen)
i.USED_AMMO.draw(screen)

#treadmill
if player.intread == True:
player.rect.y += player.speed - 2
if player.speed < 15.1:
player.speed += .01

if player.insideFirestation == True:
fswalls.draw(screen)
fsbeds.draw(screen)
fscountertops.draw(screen)
fscouches.draw(screen)


if player.insidehp == True:
cwall = pygame.sprite.spritecollide(player, map.HP, False)
locR = 5
for c in cwall:
screen.blit(frontdesk.image, (c.rect.x + 1250, c.rect.y + 2500))
hpwalls.draw(screen)


if player.insideHouse == True:
wall = pygame.sprite.spritecollide(player, map.home, False)
for w in wall:
x = w.rect.x + 375
y = w.rect.y + 400
cx = w.rect.x + 800
cy = w.rect.y + 700
w.image = floor.image
screen.blit(couch.image, (x, y))
screen.blit(counter.image, (cx, cy))
if player.rect.x < w.rect.x:
player.rect.left = w.rect.left
if player.rect.x > w.rect.x + 850:
player.rect.right = w.rect.right
if player.rect.y < w.rect.y:
player.rect.top = w.rect.top


if player.insidegym == True:
gym_treadmills.draw(screen)
gym_bench_press.draw(screen)
tredcollideP1 = pygame.sprite.spritecollide(player, gym_treadmills, False)
for t in tredcollideP1:
if player.intread == False:
if t.InUse == False:
if player.dx > 0:
player.rect.right = t.rect.left
elif player.dx < 0:
player.rect.left = t.rect.right
elif player.dy > 0:
player.rect.bottom = t.rect.top
elif player.dy < 0:
player.rect.x = t.rect.x + 37.5
player.rect.y = t.rect.y + 25
intreadlist.add(t)
player.intread = True
t.InUse = True

if player.intread:
for i in intreadlist:
if player.rect.y > i.rect.y + 175:
print('sec')
i.InUse = False
intreadlist.empty()
player.intread = False

benchcollideP1 = pygame.sprite.spritecollide(player, gym_bench_press, False)
for b in benchcollideP1:
if player.inbench == False:
if b.InUse == False:
if player.dx > 0:
player.rect.right = b.rect.left
elif player.dx < 0:
player.rect.left = b.rect.right
elif player.dy > 0:
player.rect.bottom = b.rect.top
elif player.dy < 0:
if player.action == True:
player.rect.x = b.rect.x + 37.5
player.rect.y = b.rect.y + 25
player.frozen = True
player.inbench = True
player.action = False
b.InUse = True
else:
player.rect.top = b.rect.bottom
if player.inbench:
if player.action == True:
player.rect.x +=30
player.frozen = False
player.inbench = False


incarlist.draw(screen)
carlist.draw(screen)
carlist.update(screen)
player.update()

elif pause_menu == True:
message_display('RESUME', BLACK, HEIGHT1/3)
message_display('FULLSCREEN', BLACK, HEIGHT1/3+45)
message_display('QUIT GAME', BLACK, HEIGHT1/3+90)
resume.rect.x = WIDTH1 / 2 - 100
resume.rect.y = HEIGHT1 / 3 - 30
fullscreenHitBox.rect.x = WIDTH1 / 2 - 132
fullscreenHitBox.rect.y = HEIGHT1 / 3 + 18
quit_game.rect.x = WIDTH1/2-117
quit_game.rect.y = HEIGHT1/3+73
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if resume.rect.collidepoint(pygame.mouse.get_pos()):
if event.type == pygame.MOUSEBUTTONUP:
pause_menu = False
if fullscreenHitBox.rect.collidepoint(pygame.mouse.get_pos()):
if event.type == pygame.MOUSEBUTTONUP:
pygame.display.toggle_fullscreen()
if quit_game.rect.collidepoint(pygame.mouse.get_pos()):
if event.type == pygame.MOUSEBUTTONUP:
done = True
mpx, mpy = pygame.mouse.get_pos()
screen.blit(mousey.image, (mpx, mpy))
pygame.display.update()
pygame.display.flip()
deltatime = clock.tick()/10
# print (deltatime)
# print (fp1.matrix)
pygame.quit()









share|improve this question















Note: I am using python/pygame.
I was building a mini-map, and I based the character's icon's location off the character's x and y values. I soon realized that the icon went only to a certain point. I decided to print the player's x any y and soon learned that the the x and y would only update until 955, and 350-ish. If you could read through this and I am missing something obvious, please let me know. This is all the relevant code.
Thank you! Also, if I need to be more specific, just message me rather than take this down.



Here's the code - some of his might not be needed but I added it just in case:



class You(pygame.sprite.Sprite):
def __init__(self, x, y):
super().__init__()
self.image = pygame.Surface([50, 50])
self.image.fill(BLUE)
self.rect = self.image.get_rect()
self.inventory = pygame.sprite.Group()
self.touched_trees = pygame.sprite.Group()
self.OpenInventory = False
self.rect.x = x
self.rect.y = y
self.dx = 0
self.dy = 0
self.speed = 5
self.strength = 5
self.food = 10
self.water = 10
self.outside = True
self.health = 20
self.coords =
self.incar = False
self.insidehp = False
self.insideHouse = False
self.insidegym = False
self.insideFirestation = False
self.intread = False
self.intree = False
self.inbench = False
self.alive = True
self.action = False
self.frozen = False
self.benchfactor = 0
self.benchmeter = 0
self.mask = pygame.mask.from_surface(self.image)

def update(self):
screen.blit(self.image, (self.rect.x, self.rect.y))
if self.dx != 0:
self.move_single_axis(self.dx, 0)
if self.dy != 0:
self.move_single_axis(0, self.dy)
if self.food > 10:
self.food = 10
if self.food < 1:
self.alive = False
if self.water > 10:
self.water = 10
if self.water < 1:
self.alive = False


def move_single_axis(self, dx, dy):
global ct
self.rect.x += dx
self.rect.y += dy
if self.outside:
wall = pygame.sprite.spritecollide(player, map.home, False)
for w in wall:
if self. insideHouse == False:
if dx > 0:
self.rect.right = w.rect.left
elif dx < 0:
self.rect.left = w.rect.right
elif dy > 0:
self.rect.bottom = w.rect.top
elif dy < 0:
self.insideHouse = True
self.rect.y -= 50


elif self.rect.bottom == w.rect.bottom:
self.rect.y += 50
print('exit det is good')
self.insideHouse = False
pwall = pygame.sprite.spritecollide(player, otherpeoples, False)
for p in pwall:
if dx > 0:
p.rect.x += self.speed
elif dx < 0:
p.rect.x -= self.speed
elif dy > 0:
p.rect.y += self.speed
elif dy < 0:
p.rect.y -= self.speed
if self.outside:
#tree collisions
twall = pygame.sprite.spritecollide(player, forest.NormalTreeses, False)
for a in twall:
forest.NormalTreeses.remove(a)
self.touched_trees.add(a)
self.intree = True
twall2 = pygame.sprite.spritecollide(player, self.touched_trees, False)
for t in self.touched_trees:
for o in forest.Trunks:
if o.rect.x == w.rect.x+225 and o.rect.y == w.rect.y+225:
screen.blit(o.image, (o.rect.x, o.rect.y))
if not twall2:
for touch in self.touched_trees:
forest.NormalTreeses.add(touch)
self.touched_trees.remove(touch)
self.intree = False

if self.intree:
twall3 = pygame.sprite.spritecollide(player, forest.Trunks, False)
for t in twall3:
if dx > 0:
self.rect.right = t.rect.left
elif dx < 0:
self.rect.left = t.rect.right
elif dy > 0:
self.rect.bottom = t.rect.top
elif dy < 0:
self.rect.top = t.rect.bottom

if self.outside:
cwall = pygame.sprite.spritecollide(player, map.HP, False)
for c in cwall:
if self.insidehp == False:
if dx > 0:
self.rect.right = c.rect.left
elif dx < 0:
self.rect.left = c.rect.right
elif dy > 0:
self.rect.bottom = c.rect.top
elif dy < 0:
self.insidehp = True
self.rect.y -= 50

elif self.rect.bottom == c.rect.bottom:
self.rect.y += 50
self.insidehp = False

if self.insidehp == True:
hpwalldet = pygame.sprite.spritecollide(self, hpwalls, False)
for h in hpwalldet:
if dx > 0:
self.rect.right = h.rect.left
elif dx < 0:
self.rect.left = h.rect.right
elif dy > 0:
self.rect.bottom = h.rect.top
elif dy < 0:
self.rect.top = h.rect.bottom

if self.insideFirestation == True:
fswalldet = pygame.sprite.spritecollide(self, fswalls, False)
for f in fswalldet:
if dx > 0:
self.rect.right = f.rect.left
elif dx < 0:
self.rect.left = f.rect.right
elif dy > 0:
self.rect.bottom = f.rect.top
elif dy < 0:
self.rect.top = f.rect.bottom


if self.outside:
dwall = pygame.sprite.spritecollide(player, map.gyms, False)
for d in dwall:
if self.insidegym == False:
if dx > 0:
self.rect.right = d.rect.left
elif dx < 0:
self.rect.left = d.rect.right
elif dy > 0:
self.rect.bottom = d.rect.top
elif dy < 0:
self.insidegym = True
d.image.fill(WHITE)
self.rect.y -= 50


elif self.rect.bottom == d.rect.bottom:
self.rect.y -= 50
d.image = pygame.image.load("Images/gym.png")
d.image = pygame.transform.scale(d.image, (2000, 1000))
self.insidegym = False

if self.outside:
ewall = pygame.sprite.spritecollide(player, map.firestations, False)
for e in ewall:
if self.insideFirestation == False:
if dx > 0:
self.rect.right = e.rect.left
elif dx < 0:
self.rect.left = e.rect.right
elif dy > 0:
self.rect.bottom = e.rect.top
elif dy < 0:
self.insideFirestation = True
e.image.fill(WHITE)
self.rect.y -= 50

elif self.rect.bottom == e.rect.bottom:
self.rect.y -= 50
e.image = pygame.image.load("Images/firehouse.png")
e.image = pygame.transform.scale(e.image, (1000, 1000))
self.insideFirestation = False

ct = pygame.sprite.spritecollide(self, carlist, False)
if self.incar == False:
if ct:
for t in ct:
t.lose_attributes()
incarlist.add(t)
player.GainCarAttributes(t)




def GainCarAttributes(self, car):
self.image = pygame.Surface([200, 200])
self.image.fill(YELLOW)
self.speed = car.speed
self.health = car.health
self.incar = True
print('became car')

def ExitCar(self, car):
self.image = pygame.Surface([50, 50])
car.image = pygame.Surface([200, 200])
car.image.fill(YELLOW)
incarlist.x = player.rect.x
incarlist.y = player.rect.y
self.rect.x -= 55
self.image.fill(BLUE)
self.speed -= self.speed
self.speed += 10
self.health = 20
self.incar = False

def left(self, _deltatime):
self.dx = -self.speed

def right(self, _deltatime):
self.dx = self.speed

def up(self, _deltatime):
self.dy = -self.speed

def down(self, _deltatime):
self.dy = self.speed

def stopx(self):
self.dx = 0

def stopy(self):
self.dy = 0


---- i skipped a bit



def event_collector():
global inmenu
inmenu = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
global done
done = True
if event.type == pygame.KEYDOWN:
if player.frozen == False:
if event.key == pygame.K_w:
player.up(deltatime)
if event.key == pygame.K_a:
player.left(deltatime)
if event.key == pygame.K_s:
player.down(deltatime)
if event.key == pygame.K_d:
player.right(deltatime)
if event.key == pygame.K_t:
tx = int(input('enter column: '))
ty = int(input('enter row: '))
player.rect.x = tx * 1000
player.rect.y = ty * 1000
if event.key == pygame.K_p:
player.health -= 10
player.water -= 5
player.food -= 5
if event.key == pygame.K_e and player.incar == True:
player.ExitCar(t)
incarlist.remove([0])
player.incar = False
print("Car exited")

elif player.inbench:
if player.benchmeter < .9:
if event.key == pygame.K_q:
if player.strength < 25:
player.benchfactor += 0.1
print(player.strength)
player.benchmeter += 0.1
else:
time.sleep(1)
player.benchmeter = 0

if event.type == pygame.KEYUP:
if event.key == pygame.K_w or event.key == pygame.K_s:
player.stopy()
if event.key == pygame.K_a or event.key == pygame.K_d:
player.stopx()
if event.key == pygame.K_e:
player.action = False
if event.key == pygame.K_q:
if player.OpenInventory == False:
player.OpenInventory = True
else:
player.OpenInventory = False
if event.key == pygame.K_ESCAPE:
pause_menu = True
if event.key == pygame.K_e:
player.action = True

if event.type == pygame.MOUSEBUTTONUP:
for o in otherpeoples:
if o.rect.collidepoint(pygame.mouse.get_pos()):
selected.add(o)
inmenu = True

if inmenu:
for s in selected:
for i in TalkMenu:
if i.rect.collidepoint(pygame.mouse.get_pos()):
print('doublecheck')
if event.type == pygame.MOUSEBUTTONUP:
jerry.friendmeter += 1
print(s.friendmeter)
for i in TalkMenu:
screen.blit(i.image, (s.rect.x, s.rect.y - 50))


while not done:
screen.fill(GREY)
if pause_menu == False:
event_collector()
if player.alive == True:
print(player.rect.x, player.rect.y)
if player.rect.right > 1000:
diff = player.rect.right - 1000
player.rect.right = 1000
map.shiftworldx(-diff)

if player.rect.left < 500:
diff = 500 - player.rect.left
player.rect.left = 500
map.shiftworldx(diff)

if player.rect.bottom > 400:
diff = player.rect.bottom - 400
player.rect.bottom = 400
map.shiftworldy(-diff)

if player.rect.top < 200:
diff = 200 - player.rect.top
player.rect.top = 200
map.shiftworldy(diff)


map.buildings.draw(screen)
map.home.draw(screen)
map.gyms.draw(screen)
map.roads.draw(screen)
map.HP.draw(screen)
for n in forest.NormalTreeses:
screen.blit(n.image, (n.rect.x, n.rect.y))
forest.FallenTrees.draw(screen)
market.MarketBoothsSpawns.draw(screen)
map.firestations.draw(screen)
for o in otherpeoples:
screen.blit(o.image, (o.rect.x, o.rect.y))
#Minimap
screen.blit(minimap.image, ((WIDTH1/100)-13, (HEIGHT1/100)-7))
#HUD besides inv
minimap.displayBuildings(screen, player)
screen.blit(playICON.image, (100 * (player.rect.x / 10000), (player.rect.y / 10000) * 100))
hbar.update(player, LGREEN)
screen.blit(hback.image, (385, 0))
screen.blit(hbar.image, (395, 10))
screen.blit(FWback.image, (385, 20))
fbar.update(player, RED)
screen.blit(fbar.image, (395, 30))
wbar.update(player, BLUE)
screen.blit(wbar.image, (645, 30))
#Inventory
if player.OpenInventory == True:
HUD.openInentory(WIDTH1, HEIGHT1, screen, player, 0, 1)
else:
screen.blit(pygame.image.load('Images/backpack1.png'), (WIDTH1 / 2 * 1.9, HEIGHT1 / 10 + 1 * 50 - 100))
for i in player.inventory:
i.AMMO.draw(screen)
i.USED_AMMO.draw(screen)

#treadmill
if player.intread == True:
player.rect.y += player.speed - 2
if player.speed < 15.1:
player.speed += .01

if player.insideFirestation == True:
fswalls.draw(screen)
fsbeds.draw(screen)
fscountertops.draw(screen)
fscouches.draw(screen)


if player.insidehp == True:
cwall = pygame.sprite.spritecollide(player, map.HP, False)
locR = 5
for c in cwall:
screen.blit(frontdesk.image, (c.rect.x + 1250, c.rect.y + 2500))
hpwalls.draw(screen)


if player.insideHouse == True:
wall = pygame.sprite.spritecollide(player, map.home, False)
for w in wall:
x = w.rect.x + 375
y = w.rect.y + 400
cx = w.rect.x + 800
cy = w.rect.y + 700
w.image = floor.image
screen.blit(couch.image, (x, y))
screen.blit(counter.image, (cx, cy))
if player.rect.x < w.rect.x:
player.rect.left = w.rect.left
if player.rect.x > w.rect.x + 850:
player.rect.right = w.rect.right
if player.rect.y < w.rect.y:
player.rect.top = w.rect.top


if player.insidegym == True:
gym_treadmills.draw(screen)
gym_bench_press.draw(screen)
tredcollideP1 = pygame.sprite.spritecollide(player, gym_treadmills, False)
for t in tredcollideP1:
if player.intread == False:
if t.InUse == False:
if player.dx > 0:
player.rect.right = t.rect.left
elif player.dx < 0:
player.rect.left = t.rect.right
elif player.dy > 0:
player.rect.bottom = t.rect.top
elif player.dy < 0:
player.rect.x = t.rect.x + 37.5
player.rect.y = t.rect.y + 25
intreadlist.add(t)
player.intread = True
t.InUse = True

if player.intread:
for i in intreadlist:
if player.rect.y > i.rect.y + 175:
print('sec')
i.InUse = False
intreadlist.empty()
player.intread = False

benchcollideP1 = pygame.sprite.spritecollide(player, gym_bench_press, False)
for b in benchcollideP1:
if player.inbench == False:
if b.InUse == False:
if player.dx > 0:
player.rect.right = b.rect.left
elif player.dx < 0:
player.rect.left = b.rect.right
elif player.dy > 0:
player.rect.bottom = b.rect.top
elif player.dy < 0:
if player.action == True:
player.rect.x = b.rect.x + 37.5
player.rect.y = b.rect.y + 25
player.frozen = True
player.inbench = True
player.action = False
b.InUse = True
else:
player.rect.top = b.rect.bottom
if player.inbench:
if player.action == True:
player.rect.x +=30
player.frozen = False
player.inbench = False


incarlist.draw(screen)
carlist.draw(screen)
carlist.update(screen)
player.update()

elif pause_menu == True:
message_display('RESUME', BLACK, HEIGHT1/3)
message_display('FULLSCREEN', BLACK, HEIGHT1/3+45)
message_display('QUIT GAME', BLACK, HEIGHT1/3+90)
resume.rect.x = WIDTH1 / 2 - 100
resume.rect.y = HEIGHT1 / 3 - 30
fullscreenHitBox.rect.x = WIDTH1 / 2 - 132
fullscreenHitBox.rect.y = HEIGHT1 / 3 + 18
quit_game.rect.x = WIDTH1/2-117
quit_game.rect.y = HEIGHT1/3+73
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if resume.rect.collidepoint(pygame.mouse.get_pos()):
if event.type == pygame.MOUSEBUTTONUP:
pause_menu = False
if fullscreenHitBox.rect.collidepoint(pygame.mouse.get_pos()):
if event.type == pygame.MOUSEBUTTONUP:
pygame.display.toggle_fullscreen()
if quit_game.rect.collidepoint(pygame.mouse.get_pos()):
if event.type == pygame.MOUSEBUTTONUP:
done = True
mpx, mpy = pygame.mouse.get_pos()
screen.blit(mousey.image, (mpx, mpy))
pygame.display.update()
pygame.display.flip()
deltatime = clock.tick()/10
# print (deltatime)
# print (fp1.matrix)
pygame.quit()






python pygame






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 1:02

























asked Nov 20 at 0:47









PlzHelp

11




11








  • 1




    dont link to offsite code... create the minimum example you can ...
    – Joran Beasley
    Nov 20 at 0:53












  • Thank you, I wasn't going to, not trying to make excuses, but I was trying to copy and paste my code, I finally got it here. It's not very minimal, but It was as small as I could get it, so I doubt you will need to read through all of it. Thanks for the advice!
    – PlzHelp
    Nov 20 at 1:04










  • Welcome to Stack Overflow. You've posted way too much code. Most people here (me included) don't have time to read, analyze and debug so much code. If you want help, I suggest creating a new example from scratch and only insert the code that's necessary to reproduce the bug. The example should be minimal, complete (runnable) and verifiable.
    – skrx
    Nov 20 at 13:26














  • 1




    dont link to offsite code... create the minimum example you can ...
    – Joran Beasley
    Nov 20 at 0:53












  • Thank you, I wasn't going to, not trying to make excuses, but I was trying to copy and paste my code, I finally got it here. It's not very minimal, but It was as small as I could get it, so I doubt you will need to read through all of it. Thanks for the advice!
    – PlzHelp
    Nov 20 at 1:04










  • Welcome to Stack Overflow. You've posted way too much code. Most people here (me included) don't have time to read, analyze and debug so much code. If you want help, I suggest creating a new example from scratch and only insert the code that's necessary to reproduce the bug. The example should be minimal, complete (runnable) and verifiable.
    – skrx
    Nov 20 at 13:26








1




1




dont link to offsite code... create the minimum example you can ...
– Joran Beasley
Nov 20 at 0:53






dont link to offsite code... create the minimum example you can ...
– Joran Beasley
Nov 20 at 0:53














Thank you, I wasn't going to, not trying to make excuses, but I was trying to copy and paste my code, I finally got it here. It's not very minimal, but It was as small as I could get it, so I doubt you will need to read through all of it. Thanks for the advice!
– PlzHelp
Nov 20 at 1:04




Thank you, I wasn't going to, not trying to make excuses, but I was trying to copy and paste my code, I finally got it here. It's not very minimal, but It was as small as I could get it, so I doubt you will need to read through all of it. Thanks for the advice!
– PlzHelp
Nov 20 at 1:04












Welcome to Stack Overflow. You've posted way too much code. Most people here (me included) don't have time to read, analyze and debug so much code. If you want help, I suggest creating a new example from scratch and only insert the code that's necessary to reproduce the bug. The example should be minimal, complete (runnable) and verifiable.
– skrx
Nov 20 at 13:26




Welcome to Stack Overflow. You've posted way too much code. Most people here (me included) don't have time to read, analyze and debug so much code. If you want help, I suggest creating a new example from scratch and only insert the code that's necessary to reproduce the bug. The example should be minimal, complete (runnable) and verifiable.
– skrx
Nov 20 at 13:26

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384679%2fthe-x-and-y-of-my-player-will-only-go-past-a-certain-point%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384679%2fthe-x-and-y-of-my-player-will-only-go-past-a-certain-point%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python