Obstacles In A Maze
Hi, I am developing a random maze for no reason, and I want to add something the user can move his object to get the gold. But I don't know how to make it so, something happens when the user's object touches the gold.
Help would be appreciated
Thanks!
Coder100
Well, I would like to say I don't see any gold?
goldx = 10 goldy = 10 score = 0 playerx = 0 playery = 0 def executeThisFunctionEachTimeThePlayerMoves(): if playerx == goldx and playery == goldy: score += 1
read the function name
RYANTADIPARTHI
@Coder100 yeah, you don't see any gold, because that's the question i asked, but ok. Anyway, could you give me some code, based on my type of code. Meaning like, could you explain how i could implement this into my code? Thanks!
Coder100
@RYANTADIPARTHI ok sure
Coder100
wait is this a snake game? Why is there a prev_char_x
? @RYANTADIPARTHI
RYANTADIPARTHI
@Coder100 no, this is not a snake game. This is a maze game for absolutely no reason.
From what I can see:
@Coder100 ok, so i tried this code, but you had some errors, i fixed it. but, you're just giving the indexes of gold, not the object. Could you also make the object. Like for the player it's a
X
so for gold, so the user can see it, can you show how to put an object? Thanks!@Coder100 ok, nvm, i did that too, so this is my code:
So everything seems to be working. only thing is, i want it to print good when the
X
has collided with theT
or gold object. Could yo ushow how to do that?Thanks!
ok sure @RYANTADIPARTHI
@RYANTADIPARTHI why is the player part of the arena array. The player should have an X and Y coord, and should not be in place of the array for obvious reasons.
Then you can just see if their coords are matching to determine if the player is touching the gold
@RYANTADIPARTHI
@realTronsi uhh, soo, then if possible, could you show it how in MY code?
@Coder100 it's still not working. When i move the player , and it touches the
T
, it does nothing, and just goes on.from what I can see, that's what he's doing, but he's just also putting it inside the array so his drawer can draw it later. @realTronsi
@Coder100 yeah ik but he is editing the actual arena which is bad, and will cause issues later
hm @RYANTADIPARTHI
oh, refactor it to:
@RYANTADIPARTHI
@Coder100 yeah, so... do you have the solution?
yes, for one, if he forgets to update some objects, they completely disappear when the player goes over them. @realTronsi
did my refactored code not work? @RYANTADIPARTHI
@Coder100 nope, still the same. It's still not working.
@Coder100 no.
@Coder100 yes but he will have to keep track of the object under the player and all that and it's just bad. It will cause the game to be slower and less efficient as well as needing more development time and likely more bugs. Just when you render if you hit the player coord render the player instead of the object. It won't slow down as much in the long term and saves you from plenty of bugs in the long term
@realTronsi @coder100 here's something i made for my rpg, and it could work here:
So grid is the array, where the objects are nested.
self.ops
stores the operators: soBecause D +=1, A -=1 in terms of moving the player.
Direction is obviously, the direction of which the player is moving.
Then we pass in the player's position, with
player.position
. I calculated this with grid index.self.position = grid.index("CHARACTER FOR PLAYER")
And
self.directionOP
stores the amount to add/subtract:self.directionOP = {"d":1,"a":1,"w":20,"s":20}
Because operator returns a value from 2 values, i pass through the int player.position, followed by the amount to add/sub.
the value of w and s is 20 because that is the length of my board.
Then, you just can just do:
And objects would be an dict of symbols and values representing obstacles, such as
Remember that this relies on class objects! if you aren't using classes, try replacing the variables.
TLDR
calculate the element's below/above/left/right you's value, and determine if it's a obstacle.
Edit:
remember to
yeah, that's what I would do @pepelaugh
@Coder100
Also works well with movement.
probably not the best but still efficient
@Coder100 also why is OP using x,y lol you can just rely on the array: here's ref: https://repl.it/@pepelaugh/rpg#main.py
@pepelaugh oh yes, right, forgot about that
how about tuple @pepelaugh
@Coder100 works but it's there's not much of a point to that
@Coder100 have you gotten a solution?
@Coder100 @pepelaugh silly gooses tuples are immutable
@RYANTADIPARTHI dude i solved it just take my code lol.
@realTronsi ...
@pepelaugh could you show me your code?
@pepelaugh ... tuples are immutable
@RYANTADIPARTHI I literally gave you it lol read the comment smh. heres a repl but don't steal it all and credit me. https://repl.it/@pepelaugh/rpg#main.py
@pepelaugh listen, i don't need your code. I just need how to implement printing something when the object in MY code collides with something. You didn't explain that.
so what part isn't working anyways @RYANTADIPARTHI
@RYANTADIPARTHI I clearly did in my comment. Are you so incompetent that you cannot add what I laid out? Not to say that you literally asked for my code.
If you want me to add it invite me, ill be on in like 1 hour, im doing something on discord.
@Coder100 when the user's object collides, i want it to print something.
@pepelaugh ok, i'll invite, but not now, I'm in school.
@RYANTADIPARTHI Alright, sorry for the rant but you can't expect everything to be done for you, the struggle is the part you learn.
@pepelaugh np.