Jump to content
  • Advertisement

dMn420

Member
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

1 Neutral

About dMn420

  • Rank
    Newbie

Personal Information

  • Interests
    Programming
  1. dMn420

    How to make main menu in pygame ?

    Sorry I completely forgot to reply, but this is the code for mouse position and event for it if event.type == pygame.MOUSEBUTTONUP: mx, my = pygame.mouse.get_pos() if mx > 10 and mx < 150 and my > 10 and my < 20: done = True break if mx > 10 and mx < 150 and my > 100 and my < 120: pygame.quit() sys.exit()
  2. I'm doing well with my first game that I'm making and I had no problem with understanding, how to do something but now, I don't even have a clue about How to accelerate my character. def move(rect, movement, tiles): collision_types = {'top': False, 'bottom': False, 'right': False, 'left': False} rect.x += movement[0] hit_list = collision_test(rect, tiles) for tile in hit_list: if movement[0] > 0: rect.right = tile.left elif movement[0] < 0: rect.left = tile.right collision_types['left'] = True rect.y += movement[1] hit_list = collision_test(rect, tiles) for tile in hit_list: if movement[1] > 0: rect.bottom = tile.top collision_types['bottom'] = True elif movement[1] < 0: rect.top = tile.bottom collision_types['top'] = True return rect, collision_types player_movement = [0, 0] if moving_right == True: player_movement[0] += 2 if moving_left == True: player_movement[0] -= 2 player_movement[1] += vertical_momentum vertical_momentum += 0.3 if vertical_momentum > 3: vertical_momentum = 3 player_rect, collisions = move(player_rect, player_movement, tile_rects) if collisions['bottom'] == True: air_timer = 0 vertical_momentum = 0 else: air_timer += 1 display.blit(player_img, (player_rect.x - scroll[0], player_rect.y - scroll[1])) for event in pygame.event.get(): # event loop if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_RIGHT: moving_right = True if event.key == K_LEFT: moving_left = True if event.key == K_UP: if air_timer < 6: vertical_momentum = -5 if event.type == KEYUP: if event.key == K_RIGHT: moving_right = False if event.key == K_LEFT: moving_left = False screen.blit(pygame.transform.scale(display, WINDOW_SIZE), (0, 0)) pygame.display.update() clock.tick(60) (initial speed is 2 player_movement[0] += 2). I'm thinking about doing it like - > add 0.1 speed every 0.1 second or every 1 tick so it smooth and make it maximally reach to 5. I was looking at car related games but they are to different.
  3. dMn420

    How to make main menu in pygame ?

    Oh, ty for the edit. I see how it works. Finally I have even more code to play around 😆
  4. dMn420

    How to make main menu in pygame ?

    I fixed the q key 😉 but I don't understand How do I dispay main menu image before the game. This is the code that reads map in my .txt file from my folder. def load_map(path): f = open(path + '.txt', 'r') data = f.read() f.close() data = data.split('\n') game_map = [] for row in data: game_map.append(list(row)) return game_map game_map = load_map('map') so do I need to replace this ↓ with code that reads my .jpg file ? choice = input(""" B: Login Q: Logout Please enter your choice: """)
  5. I was trying to do main menu that shows up on the screen, so when I would press q it gets me into the game ( becuse I'dont know How to make buttons yet ) but it displays in the console. def main(): menu() def menu(): choice = input(""" B: Login Q: Logout Please enter your choice: """) if choice == "B" or choice == "b": login() elif choice == "Q" or choice == "q": sys.exit else: print("You must only select B") print("Please try again") menu() def login(): pass main() Also when I press Q/q It opens the game so sys.exit doesn't work. If you know How can i display this message on the screen or make buttons I will be really gratefull. 👌
  6. I’ve fully used this tutorial : https://www.youtube.com/watch?v=5q7tmIlXROg&t=124s So the code is the same as his ( download in description) and I wanted to go further with it and get to map-making with I really like but first of all, I need some more mechanics. I’ve actually asked Him How to do it and I fully understand that https://imgur.com/a/kw4iAAx same with dash with would simply be the player moving like twice speed in x direction but I don’t know How to write it down. 1 line of code will really help and I will really appreciate if you get me more depth on Why you did it that way so I don’t have to keep asking questions about it. 👌
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!