#๐Ÿ”’ Help with pacman movement

85 messages ยท Page 1 of 1 (latest)

dense sandalBOT
#

@ember pecan

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

ember pecan
#

Hello, when I try to move the pacman... everything works fine at first but if the pacman is facing down and I try to move it right or left, it won't work, I can only go in the upward direction; have a look

limpid umbra
#

need ocde

#

code

ember pecan
ember pecan
limpid umbra
#

give me the code as text

#

is it in multiple files?

ember pecan
#

nope

#

wait

limpid umbra
#

then send it as text

ember pecan
#

hmm just copy and paste here you mean? I try to do that but something is wrong

limpid umbra
#

yes

ember pecan
#

my message is getting deleted, wait

limpid umbra
#

the bot is probably telling you to upload it somewhere

#

go and do that

lucid furnace
#

!paste

dense sandalBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

limpid umbra
#

then paste the link

ember pecan
#

ok wait

#

here

limpid umbra
#

i get an error, you have imported board but it doesnt seem to work for me

ember pecan
#

oh this is in another file ops... it's the map

#

wait

limpid umbra
#

in you video theres a file "board.py", you imported that file so i need that too

ember pecan
#

ok 2sec

#

hmm there is also a folder where I place the picture of the pacman

#

I should upload that also I think

limpid umbra
#

is your code on github or something else?

ember pecan
#

hmm no :c

limpid umbra
#

i cnat run the code without those files

#

you have to upload them

ember pecan
#

2sec

#

Hmm I have uploaded the pictures.... you need to create the assets folder next to the python file you will run the code... then just create a sub-folder containing the images... name the sub-folder as player_images

#

oh we can't download the images?

limpid umbra
#

i can download them

ember pecan
#

๐Ÿ˜ญ

limpid umbra
#

give me a minute

ember pecan
#

oh ok

#

I will just give you the name of each picture

#

They are named 1 , 2 , 3 ,4

#

I think that's all what you need... juste create another file called board then write the code in the above link

limpid umbra
#

got the game working

ember pecan
limpid umbra
#

yes

#

if i understand you use numbers for the direction the player is facing

ember pecan
#

yep

limpid umbra
#

3 is down and 0,1 is left right

ember pecan
#

0 right , 1 left, 2 up and 3 down

#

yes

#

0 is right

limpid umbra
#

you could use strings to make it more readable but whatever

fervent fern
#

^^^^^^^^^^^^^

meager marlin
limpid umbra
#

i think i have the problem

#

something is wrong with valid turns

ember pecan
#

Hmm I'm trying to find the error ๐Ÿ˜ญ

limpid umbra
#

at the bottom you can see vailid_turns

#

only 2 (up) is a valid turn

dire zinc
#

that indentation doesn't seem right

#

I would assume KEYUP and KEYDOWN should be on the same level

limpid umbra
dire zinc
#

I'd probably not use the event loop anyway, but rather the pygame.key.get_pressed() function, that gives you (outside of the for-event loop) a dict of the currently pressed keys. (actually a dict of the states of all the keys, and the pressed ones mapping to True)

meager marlin
limpid umbra
#

i think i have it

#

i can move but the player is stuck

#

i dont know how to explain the bahavior that i see so ill use ppython code

#
valid_turn = [false, false, false, false]
direction = 0
if direction = 0:
  valid_turns = [false, true, true, false]
if direction = 1:
  valid_turns = [true, false, true, false]```
#

its allways the oppsite side

meager marlin
#

hey i gotta go to work, if you're still having trouble, you can DM me up around 3pm EST

limpid umbra
#

@ember pecan if im looking to the right then left is a valid_turn but if i look to the left then right is a valid_turn

ember pecan
limpid umbra
#

im looking left but i cant move there because valid_turns has left as False

#

im just stuck in place and can only move up

#

but i can rotate the player

ember pecan
#

hmm

#

wait

limpid umbra
#

something else is wrong with valid_turns

#

if you edit this line you can rotate but i dont know why you cant muve

ember pecan
#

I think the problem if with the constant num3... what it basically does, it allows us to move like a small distance within a tile which contains a block element... when I try to change it from 15 to 10 for example,,, as long that I'm moving I notice that I was able to change direction but if I'm stopped, it's no longer the case (not for all directions) hmm this seems weird... In fact I'm watching a tutorial on youtube... the problem is that he use different screen size and I uses different screen size so maybe this is affecting how the collision system works

ember pecan
#

anyone have an idea? ๐Ÿ˜ญ If I changes the screen height to 950 and the value of 518 to 500, it works fine but the layout is too big for my screen

dense sandalBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.