diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-31 14:26:23 +0300 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-31 14:26:23 +0300 |
commit | ed325b4713f78bedf31b859fca03e77d3b755fed (patch) | |
tree | 7fef09776a905faa4b6561915fc5c722c64f6b3e | |
parent | 551289aa0d40b80e8c2f8e6e732dbfc8b03e5e96 (diff) |
mouse controls on main menu
-rw-r--r-- | src/sliceitoff/mainmenu/mainmenu.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/sliceitoff/mainmenu/mainmenu.py b/src/sliceitoff/mainmenu/mainmenu.py index e0466a5..551e7b5 100644 --- a/src/sliceitoff/mainmenu/mainmenu.py +++ b/src/sliceitoff/mainmenu/mainmenu.py @@ -3,9 +3,12 @@ from enum import IntEnum import pygame from screens import mainmenu_screen +from display import Scaling from game.anykey import anykey +MOUSE_TRESHOLD = 100 + class MenuItems(IntEnum): """ Items in the menu. Should match mainmenu_screen """ NEWGAME = 0 @@ -22,6 +25,7 @@ class Mainmenu(pygame.sprite.Group): self.active = True self.fadeout = 1_000 self.selection = 0 + self.mousey = 0 def update(self, dt = 0): """ Does it all. Reads keyboard and updates screen """ @@ -45,6 +49,9 @@ class Mainmenu(pygame.sprite.Group): self.selection = MenuItems.QUIT self.explode = True break + if event.type == pygame.MOUSEBUTTONDOWN and event.button <= 3: + self.explode = True + break if event.type == pygame.KEYDOWN: match event.key: case pygame.K_KP_ENTER | pygame.K_RETURN | pygame.K_RIGHT: @@ -60,5 +67,12 @@ class Mainmenu(pygame.sprite.Group): case pygame.K_DOWN: self.selection += 1 self.selection %= len(MenuItems) + elif event.type == pygame.MOUSEMOTION: + self.mousey += pygame.mouse.get_rel()[1] + pygame.mouse.set_pos(Scaling.center) + if abs(self.mousey) > MOUSE_TRESHOLD: + self.selection += 1 if self.mousey > 0 else -1 + self.selection %= len(MenuItems) + self.mousey = 0 self.empty() self.add(mainmenu_screen(self.selection)) |