EASY Random Map Generation - Python ASCII Tutorial

Поделиться
HTML-код
  • Опубликовано: 7 июн 2024
  • Here's my simple idea of how anyone can create random maps for their ASCII games without complicated algorithms!
    NOTE: I simplified the logic of tile objects by deprecating the "colored" parameter.
    The "color" parameter can also be used for the same purpose. 👇👇👇
    REPO: github.com/orkslayergamedev/r...
    ×oOo×-----------------------👽SOCIALS👽-----------------------×oOo×
    ☕ SUPPORT ME: ko-fi.com/orkslayergamedev/
    🎮 TRY OUT MY GAMES: orkslayergamedev.itch.io/
    👾 PM FOR COMMISSIONS: www.fiverr.com/astral_freak/
    (out of office at the moment)
    📸 Instagram: / orkslayergamedev
    🐱 GitHub: github.com/orkslayergamedev/
    🔗 Reddit: / orkslayergamedev
    ×oOo×--------------------🙌🏼SUPPORTERS🙌🏼---------------------×oOo×
    ⭐ MisterDenko
    ⭐ Geekbean
    ×oOo×--------------------🕒TIMESTAMPS🕒---------------------×oOo×
    00:00 - Project Overview
    00:36 - Map Basics
    03:35 - Tile Objects
    05:28 - Patch Generation
    07:05 - Randomizing Patches
    08:02 - Final Result
    ×oOo×-------------------------💿MUSIC📀-------------------------×oOo×
    From the RUclips Library.
    ×oOo×--------------------------✨TAGS✨--------------------------×oOo×
    #pygame #python #gamedev
    #indiedev #indiegame #indiegames
    #indiegamedev #pixelart #gamedevelopment
    #orkslayer #orkslayergamedev
    #tutorial #particles #visuals
  • ХоббиХобби

Комментарии • 28

  • @bandedecodeurs
    @bandedecodeurs 5 месяцев назад +7

    Just falling in love with your channel. So inspiring. Thank you very much 🙏🏻

    • @orkslayergamedev
      @orkslayergamedev  5 месяцев назад

      My pleasure! Thank you for the kind words, they mean a lot! 🙌🏻

  • @sirknumbskull3418
    @sirknumbskull3418 5 месяцев назад +2

    Hey, I love that one! Thanks!

    • @orkslayergamedev
      @orkslayergamedev  5 месяцев назад

      I'm happy to hear this, thank you for the feedback! 🙏🏻

  • @GamingGuruImMortaL
    @GamingGuruImMortaL 5 месяцев назад +1

    Great video, nice explanation as usual 🙌🏻, a future video idea: implement the feature to set a minimum number of each type of tile, because during some execution it is visible that some tiles are too small and some are great in number.

    • @orkslayergamedev
      @orkslayergamedev  5 месяцев назад +1

      I always appreciate some great feedback! 🙏🏻
      The issue you mentioned is due to the patch generator overwriting any tile it's covering. So you might create a patch and it's possible that it won't be there at the end if another patch is spawned after it the same place (on top of that). This could be solved by overwriting the tile only if it's the default one. But I like your idea nevertheless!
      This tutorial is kinda basic, it could use some improvements like exception handling instead of numerical limits, this way the sides of the map could be covered as well :) Maybe in the next one!
      Anyways, thanks a lot, bro 🙌🏻

  • @noahvb9835
    @noahvb9835 3 месяца назад

    Hey, I am loving these videos. Quick question! Why do you put " -> None" when defining things within a class?

    • @orkslayergamedev
      @orkslayergamedev  3 месяца назад +2

      Thanks for the feedback! Sorry for the late reply, let me copy my previous answer, as I get this question quite regularly.
      When defining functions and methods, you can leave type hints for the arguments and the return value. Let me show examples:
      def sum_numbers(n1: int, n2: int) -> int:
      return n1 + n2
      Here we say both arguments should be integers, just like the returned number. If you use an IDE (code editor) that has a built-in linter (code checker), it will automatically warn you if you
      A, define the function/method in a way that the actual returned value is not what you define in the first line (where the arrow points):
      def sum_numbers(n1: int, n2: int) -> int:
      return str(n1 + n2)
      B, you call the function/method with arguments not matching their annotated types:
      sum_numbers(n1="string", n2=True)
      So, whenever you create a method that returns nothing, you can also emphasize it by putting -> None at the end of the definition, like...
      def useless_printer() -> None:
      print("I don't return anything")
      ...and when you call it:
      result = useless_printer()
      >>> "I don't return anything"
      print(result)
      >>> None
      Whereas you call the other method that has a returned value...
      result = sum_numbers(3, 4)
      print(result)
      >>> 7
      I hope this helps :)

  • @philtoa334
    @philtoa334 5 месяцев назад

    Nice.

  • @Balance080
    @Balance080 Месяц назад +1

    Hi Ork great vid and very educational and helpful, however i got a issue at the very end:
    Traceback (most recent call last):
    File "d:\Desktop\Python\main.py", line 4, in
    hero = Hero(name="Hero", health=100)
    File "d:\Desktop\Python\character.py", line 24, in __init__
    self.health_bar = HealthBar(self, color="blue")
    TypeError: HealthBar() takes no arguments
    Any ideas how or why this happened, any help would be appreciated, used Python 3.10.9, it worked until the hp bars were added and my code should be the same as the one in the vid, i compared it a couple of times and saw no significant differences.

    • @orkslayergamedev
      @orkslayergamedev  Месяц назад

      Hey, thanks a bunch for the feedback!
      I think I see the issue. Based on the line you showed (File "d:\Desktop\Python\character.py", line 24, in _init_), it seems there might be a typo in how you defined the constructor method. You should use double underscores on both sides (__init__) instead of _init_.
      Because it's written as _init_, Python doesn't recognize it as the constructor, and it defaults to a built-in __init__ method that accepts no arguments. Hence the TypeError.
      Try changing _init_ to __init__ in your HealthBar class, and that should fix the issue. Please let me know if this resolves the problem! Cheers! 🐍

  • @Poulet39
    @Poulet39 5 месяцев назад

    Liked your video i do this on my games and i convert the ascii characters to png image to get also another graphic mod available. Would like to see a map editor.

    • @orkslayergamedev
      @orkslayergamedev  5 месяцев назад

      Thanks a lot for the feedback! I'll actually upload a video with the same technique implemented in Pygame.
      For map editing I can recommend Tiled, a free software for this purpose 👌🏻

  • @superbautumn969
    @superbautumn969 4 месяца назад +1

    This is great video i was able to put a health bar for the ascii game but making something move on the map is throwing me in loop i cant seem to figure out

    • @orkslayergamedev
      @orkslayergamedev  4 месяца назад +1

      Thanks for the feedback! If it's player movement that you struggle with, I recommend my upcoming video where I will feature lots of cool game mechanics like that one.
      While the video is in production, feel free to send me code pieces so I can try to help you! 👋🏻

    • @superbautumn969
      @superbautumn969 4 месяца назад +1

      Thank you very much 🙏

  • @ElGreco15
    @ElGreco15 29 дней назад +1

    I'm trying to make a static map, and between the last video and this one there is a step I am missing. How do I display the map I created in the last video using gamemap = [[Tile(plains), Tile(mountains)...etc]
    I do not want the batches or procedural creation. I just want to see the map from the previous in this playlist.

    • @orkslayergamedev
      @orkslayergamedev  29 дней назад

      Hey! I hope I understand the issue correctly. Here's a simplified version of the modules you want to use:
      ## --------------- tile.py --------------- ##
      ANSI_RESET = "\033[0m"
      ANSI_YELLOW = "\033[33m"
      ANSI_GREEN = "\033[32m"
      ANSI_BLUE = "\033[34m"
      ANSI_RED = "\033[31m"
      ANSI_WHITE = "\033[97m"
      ANSI_MAGENTA = "\033[35m"
      ANSI_CYAN = "\033[36m"
      class Tile:
      def __init__(self, symbol: str, color: str | None = None):
      self.symbol = f"{color}{symbol}{ANSI_RESET}" if color else symbol
      plains = Tile(".", ANSI_YELLOW)
      forest = Tile("8", ANSI_GREEN)
      pines = Tile("Y", ANSI_GREEN)
      mountain = Tile("A", ANSI_WHITE)
      water = Tile("~", ANSI_CYAN)
      ## -------------------- ## -------------------- ##
      ## --------------- map.py --------------- ##
      from random import randint
      from tile import Tile, plains, forest, pines, mountain, water
      class Map:
      def __init__(self, width: int, height: int) -> None:
      self.width = width
      self.height = height
      self.map_data: list[list[Tile]]
      def display_map(self) -> None:
      frame = "x" + self.width * "=" + "x"
      print(frame)
      for row in self.map_data:
      row_tiles = [tile.symbol for tile in row]
      print("|" + "".join(row_tiles) + "|")
      print(frame)
      ## -------------------- ## -------------------- ##
      ## --------------- main.py --------------- ##
      from map import Map
      import os
      os.system("")
      def run() -> None:
      while True:
      game_map.display_map()
      input("> ")
      if __name__ == "__main__":
      # considering you have a complete map that you created manually
      map = Map(5, 5)
      map.map_data = [
      [forest, forest, forest, mountain, mountain],
      [plains, forest, forest, pines, mountain],
      [plains, forest, forest, pines, pines],
      [plains, plains, forest, forest, forest],
      [plains, plains, plains, plains, plains],
      ]
      run()
      ## -------------------- ## -------------------- ##
      With these 3 simplified files, you can display your map if you run "python main.py" from the console in the directory where these modules are located. Let me know if this solved your problem!

    • @ElGreco15
      @ElGreco15 28 дней назад

      @@orkslayergamedev map.py
      in display_map
      row_tiles =[tile.symbol for tile in row]
      ^^^^^^^^^^^^
      AttributeError: 'str ' object has no attribute 'symbol'
      I don't know if maybe there's a difference in the latest version of python and yours, but this is the exact line that's been stopping me

  • @programmingchannel9739
    @programmingchannel9739 5 месяцев назад

    I like the idea, however, my script doesn't generate a new patch when hitting Enter. It always repeats the same patch in the same position until I rerun the script. As the video, It is supposed to generate a new patch in a new position after hitting Enter!

    • @orkslayergamedev
      @orkslayergamedev  5 месяцев назад +1

      Hi! Thanks for reaching out to me. There must be some difference that creates this issue. You can either show me your code so I can have a look, or feel free to use my files as an exact reference: github.com/orkslayergamedev/random-ascii-map-generation

    • @programmingchannel9739
      @programmingchannel9739 5 месяцев назад

      Thank you for your quick response. I compared my copy with yours several times, they look the same. However, I believe there is no problem, according to your script it should act the way I mentioned, unless instantiating the map class inside the loop in the the main function.
      By the way, I cloned your repo and ran it! It did exactly as my copy.@@orkslayergamedev

    • @orkslayergamedev
      @orkslayergamedev  5 месяцев назад +1

      ​@@programmingchannel9739 You're totally right, there is no problem! Seems like I successfully confused myself too, haha. Turns out it's a bit misleading, because in the recording I don't actually press enter in the console, I rerun the interpreter instead. If you look at the green button at the top right corner of Pycharm, you can see it getting pressed multiple times. It's the same as if I ran "python main.py" again and again.
      Apologies for the headache!

    • @programmingchannel9739
      @programmingchannel9739 5 месяцев назад +1

      Hey, thanks a lot for your quick response! Really, no need to apologize - it's all part of the learning process for all of us. I actually wanted to say that it's been a real pleasure for me to discuss Python code with a programmer like you. I've been learning Python for about three years now, and this is the first time I've had the opportunity to have a conversation like this. It's been a great experience and definitely a highlight in my programming journey. Keep up the awesome work with your tutorials - they're a big help!@@orkslayergamedev

    • @orkslayergamedev
      @orkslayergamedev  4 месяца назад +1

      Wow! I really appreciate your support and I'm delighted to hear that you enjoyed our conversation. I always love to connect with fellow Python enthusiasts and share the joy of programming. If you ever need some help, feel free to reach out, I'll be in touch :)
      Good luck with your journey! 🐍
      (ps. I just found your answer, as youtube doesn't send notification of threads 😞)

  • @gustavoduarte3121
    @gustavoduarte3121 5 месяцев назад

    make ASCII games Greats Again!!!