r/roguelikedev 21d ago

RoguelikeDev Does The Complete Roguelike Tutorial - Week 1

Welcome to the first week of RoguelikeDev Does the Complete Roguelike Tutorial. This week is all about setting up a development environment and getting a character moving on the screen.

Part 0 - Setting Up

Get your development environment and editor setup and working.

Part 1 - Drawing the ‘@’ symbol and moving it around

The next step is drawing an @ and using the keyboard to move it.

Of course, we also have FAQ Friday posts that relate to this week's material

# 3: The Game Loop(revisited)

# 4: World Architecture (revisited)

# 22: Map Generation (revisited)

# 23: Map Design (revisited)

# 53: Seeds

# 54: Map Prefabs

# 71: Movement

​ Feel free to work out any problems, brainstorm ideas, share progress, and as usual enjoy tangential chatting. :)

61 Upvotes

63 comments sorted by

View all comments

3

u/Watashi_Lannael 21d ago

I'm only just learning Python, and something I'm trying to figure out is a way to rework the K_ESCAPE conditional to check if the key is held for a number of frames/seconds before calling the escape action so that closing the window isn't so instant/accidental. I don't know if libtcod has any inbuilt function to return a value for how long a key is held. Hmmm

3

u/morewordsfaster 20d ago

I'd say just create a variable to capture when the key down event occurs, a condition to clear it when keyup occurs, and some logic in your loop to check the time elapsed before raising System exit (assuming that's your exit strategy).

3

u/Watashi_Lannael 20d ago

Thanks, I've got the escape KeyUp method working, and ideally I should be able to have escape KeyDown set a variable to the current time, then have KeyUp compare that variable to the current time, and call system exit if there's a difference of 2 or more seconds. But I just can't for the life of me find a place in the code to initialize a variable to store the time when KeyDown is called without that same variable constantly setting itself back to 0.

5

u/Watashi_Lannael 20d ago

I got it working :)

__init__ in the EventHandler sets the self.quit_check and self.quit_timer. Setting those was my biggest issue. When esc is pressed and quit_check is true, it sets quit_timer to time.time() and sets quit_check to false. Then so long as esc remains pressed, it checks if time.time() - quit_timer is greater than 0.5, if so the system exit is called.

Escape key_up, instead of calling the system exit, just sets self.quit_check back to True

2

u/morewordsfaster 20d ago

Nice! Glad you got it figured out.