Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A 4x4 Field in Pygame
#6
(Aug-13-2019, 10:38 AM)Windspar Wrote: Also could just do this.
def can_move(x, y):
    if 0 <= x < 4 and 0 <= y < 4:
        return True
    return False

# in event loop
    if event.key == pygame.K_LEFT:
        if can_move(x - 1, y):
            x -= 1

or
# in event loop
    if event.key == pygame.K_LEFT:
        if 0 <= x - 1 < 4:
            x -= 1

Thank you. I'll try it, but I still have got this problem, I've mentioned above.:

every time I run the code, Python crashes. Eh...yeah. Python crashes. When I'm running other Pygame-Projects, it's not crashing. I ran your code a few times, and the first few times, Python just crashed. I tried it again and then it was not crashing anymore, but just nothing happened (I didn't got an error message).
Thanks for the help, but still not working.

Edit: I just imported pygame. So above the code, I just have the lines:

import pygame

and

pygame.init()(But I'm not sure, if I really need the pygame.init()).

If somebody helps me with this, I'll be able, trying your code.
Reply


Messages In This Thread
A 4x4 Field in Pygame - by Piethon - Aug-11-2019, 04:29 PM
RE: A 4x4 Field in Pygame - by metulburr - Aug-11-2019, 10:06 PM
RE: A 4x4 Field in Pygame - by SheeppOSU - Aug-12-2019, 08:15 PM
RE: A 4x4 Field in Pygame - by Piethon - Aug-13-2019, 09:28 AM
RE: A 4x4 Field in Pygame - by Windspar - Aug-13-2019, 10:38 AM
RE: A 4x4 Field in Pygame - by Piethon - Aug-14-2019, 07:44 AM
RE: A 4x4 Field in Pygame - by Windspar - Aug-14-2019, 12:24 PM
RE: A 4x4 Field in Pygame - by Piethon - Aug-18-2019, 09:50 AM
RE: A 4x4 Field in Pygame - by Piethon - Aug-19-2019, 10:08 AM
RE: A 4x4 Field in Pygame - by Windspar - Aug-18-2019, 11:26 AM
RE: A 4x4 Field in Pygame - by metulburr - Aug-18-2019, 12:23 PM
RE: A 4x4 Field in Pygame - by metulburr - Aug-19-2019, 11:33 AM
RE: A 4x4 Field in Pygame - by Windspar - Aug-19-2019, 11:38 AM
RE: A 4x4 Field in Pygame - by Piethon - Aug-19-2019, 12:09 PM
RE: A 4x4 Field in Pygame - by metulburr - Aug-19-2019, 01:07 PM
RE: A 4x4 Field in Pygame - by Windspar - Aug-19-2019, 04:37 PM
RE: A 4x4 Field in Pygame - by Piethon - Aug-19-2019, 06:49 PM
RE: A 4x4 Field in Pygame - by Windspar - Aug-19-2019, 09:21 PM
RE: A 4x4 Field in Pygame - by metulburr - Aug-19-2019, 10:49 PM
RE: A 4x4 Field in Pygame - by Piethon - Aug-20-2019, 08:51 AM
RE: A 4x4 Field in Pygame - by Windspar - Aug-20-2019, 10:38 AM
RE: A 4x4 Field in Pygame - by metulburr - Aug-20-2019, 12:03 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020