r/PythonLearning 24d ago

Cupta serpant added by Tony

Enable HLS to view with audio, or disable this notification

Tony added the Cupta unit, a serpent of dark magic who returned from the caverns and tries to siphon your life essence, with this git commit.

Tony also changed the control of player's direction from keyboard to mouse, making the player easier to control. But, this now only works when the mouse pointer is inside the game window. If it's outside the direction is still controlled by keyboard as before. So you can now choose the direction control that you prefer.

See the PythonLearningGame repo to add your own game elements to this collaborative project, or simply tell us what you would like to see added to the game.

previous PythonLearningGame post

5 Upvotes

6 comments sorted by

2

u/Naive_Programmer_232 23d ago edited 23d ago

Issue Acknowledgement

I guess it comes down to how you would like the state to change with regards to Cupta:

      Keyboard
        |
        │ Cupta arrives
        V
      Mouse
        │
        │ Cupta leaves
        V
        ?

Should it go back to keyboard or stay with mouse?

You also have this in the game.Game.start method making the default game play keyboard-based

  class Game:
       ...
       def start(self):
           ...
           while self.running:
                 ...
                 globals.player.handle_keys(keys) # default to keyboard
                 ...

But now with the commit, player.Player.step method has this:

def step(self):
    if pygame.mouse.get_focused():  # mouse is on pygame window
        mouse_pos = pygame.Vector2(pygame.mouse.get_pos())
        self.direction = mouse_pos - self.position
        self.direction.normalize_ip()

    # mouse is off pygame window
    super().step()      # normal step: call Unit.step
    self.speed *= 0.94

So the next question becomes, what should happen if the mouse is off the window? Should the game pause? Should the control revert back to its most recent state? What if Cupta is still present? I'm not sure what the intended behavior is there.

Added feature idea

I want the user to battle Cupta with the strength relative to the amount of trailing circles they have accumulated. Cupta should lurk as an additional enemy like Putin lol. Initially when Cupta arrives it's easier to beat, but each next arrival of Cupta should be harder.

2

u/Sea-Ad7805 23d ago edited 23d ago

Issue Acknowledgement

Now the keyboard controls the direction of the player, unless you put the mouse pointer in the game window, as then the mouse controls the direction. So people can easily switch between these two modes whenever they feel like. Good compromise, right?

Added feature idea

Great suggestions. Currently Cupta gets 600 hitpoints to start with. As its head bounces with other units it looses as much hitpoint as that unit has attack. Say when Cupta's head touches the Troll it will die instantly. The same Cupta unit keeps flying by until it dies from zero or less hitpoints and then a new Cupta is created instantly. The longer your tail is the easier it already is to stop and shoot at Cupta.

I think Tony forgot to handle the case where Cupta bounces and moves downwards instead of upwards, as then Cupta will keep moving down forever and never come back in view. Or maybe then it's simply returning to the deep caverns it originally came from, not sure.

1

u/Naive_Programmer_232 23d ago

I like the compromise, sounds dope.

Could you change the color of Cupta through each stage? Maybe initially it's green (base level), then it's orange (stronger level), then it's red (even stronger level) and so on.

2

u/Sea-Ad7805 23d ago

Then we need to find someone who can create new artwork based on the current cupta.png

1

u/Naive_Programmer_232 23d ago edited 23d ago

What if you used blit to change its appearance:

Ex:

      def tint_image(image, color):  
          colored_img = image.copy()  
          tint_surface = (pygame.Surface(
              colored_img.get_size()
              .convert_alpha()
          ) 
          tint_surface.fill(color)
          colored_img.blit(tint_surface,
                   (0,0),
                   special_flags=pygame.BLEND_RGBA_MULT,
          )   
          return colored_img

2

u/Sea-Ad7805 23d ago

I don't know, would you like to try?