parent
59943dc54d
commit
6e3aeca232
|
@ -5,15 +5,14 @@ from jacovirt.pad.token import Token, Token_generator, Token_trash
|
|||
|
||||
# Screen title and size
|
||||
SCREEN_TITLE = "Jaco Pad"
|
||||
SCREEN_MULTILPLIER = 1
|
||||
SCREEN_WIDTH = int(1000* SCREEN_MULTILPLIER)
|
||||
SCREEN_HEIGHT = int(1000* SCREEN_MULTILPLIER)
|
||||
SCREEN_WIDTH = int(1000)
|
||||
SCREEN_HEIGHT = int(1000)
|
||||
|
||||
# Window color
|
||||
BACKGROUND_COLOR = (133, 100, 100)
|
||||
|
||||
|
||||
class Pad(arcade.Window):
|
||||
class Window(arcade.Window):
|
||||
"""Main application class"""
|
||||
|
||||
def __init__(self):
|
||||
|
@ -31,24 +30,25 @@ class Pad(arcade.Window):
|
|||
# The held token
|
||||
self.held_token = None
|
||||
|
||||
# List of tokens
|
||||
self.tokens = arcade.SpriteList()
|
||||
|
||||
def setup(self):
|
||||
"""Set up the pad"""
|
||||
logging.info("Set up the pad.")
|
||||
logging.debug("Set up the pad.")
|
||||
|
||||
# Create a token
|
||||
token = Token("up", 1*SCREEN_MULTILPLIER)
|
||||
token = Token("up", 1)
|
||||
token.position = 500, 500
|
||||
self.tokens.append(token)
|
||||
|
||||
# Create a token generator
|
||||
token_generator = Token_generator("up", 1*SCREEN_MULTILPLIER)
|
||||
token_generator = Token_generator("up", 1)
|
||||
token_generator.position = 200, 500
|
||||
self.tokens_generator.append(token_generator)
|
||||
|
||||
# Create a other token generator
|
||||
token_generator = Token_generator("right", 1*SCREEN_MULTILPLIER)
|
||||
token_generator = Token_generator("right", 1)
|
||||
token_generator.position = 800, 500
|
||||
self.tokens_generator.append(token_generator)
|
||||
|
||||
|
@ -57,9 +57,14 @@ class Pad(arcade.Window):
|
|||
trash.position = 500, 800
|
||||
self.tokens_trash.append(trash)
|
||||
|
||||
# Create a camera
|
||||
self.camera = arcade.Camera()
|
||||
|
||||
def on_draw(self):
|
||||
"""Render the screen"""
|
||||
|
||||
self.camera.use()
|
||||
|
||||
# Clear the screen
|
||||
self.clear()
|
||||
|
||||
|
@ -74,17 +79,58 @@ class Pad(arcade.Window):
|
|||
|
||||
def on_key_press(self, symbol, modifiers):
|
||||
"""Called when the user presses key"""
|
||||
logging.debug(f"User press {symbol}, {modifiers}")
|
||||
|
||||
if symbol == arcade.key.R:
|
||||
self.setup()
|
||||
print("Restart !")
|
||||
|
||||
if symbol == arcade.key.Q:
|
||||
arcade.exit()
|
||||
|
||||
|
||||
if symbol == arcade.key.F:
|
||||
# When the user hits f. Flip between full and not full screen.
|
||||
if self.fullscreen:
|
||||
# If in fullscreen, switch to windowed mode
|
||||
self.set_fullscreen(False)
|
||||
|
||||
# Resize the camera to match the window size
|
||||
width, height = self.get_size()
|
||||
self.camera.resize(width, height)
|
||||
|
||||
# Reset camera position
|
||||
self.camera.move((0, 0))
|
||||
|
||||
else:
|
||||
# If not in fullscreen, switch to fullscreen mode
|
||||
|
||||
# Remember the previous window size
|
||||
last_width, last_height = self.get_size()
|
||||
|
||||
# Switch to fullscreen
|
||||
self.set_fullscreen(True)
|
||||
|
||||
# Adjust camera and window size for fullscreen
|
||||
width, height = self.get_size()
|
||||
self.camera.resize(width, height)
|
||||
|
||||
# Calculate the difference in center position between last window size and new fullscreen size
|
||||
self.x_fullscreen_diff = (last_width - width) / 2
|
||||
self.y_fullscreen_diff = (last_height - height) / 2
|
||||
|
||||
# Move camera to keep the same center point in the game
|
||||
self.camera.move((self.x_fullscreen_diff, self.y_fullscreen_diff))
|
||||
|
||||
|
||||
def on_mouse_press(self, x, y, button, key_modifiers):
|
||||
"""Called when the user presses a mouse button"""
|
||||
logging.info(f"Mouse pressed at {x},{y}")
|
||||
|
||||
logging.debug(f"Mouse pressed at {x},{y}")
|
||||
|
||||
# If the game is in fullscreen mode, adjust mouse coordinates
|
||||
if self.fullscreen:
|
||||
x = x + self.x_fullscreen_diff
|
||||
y = y + self.y_fullscreen_diff
|
||||
logging.debug(f"Mouse pressed at {x}, {y} in the game window in full screen")
|
||||
|
||||
# Get list of tokens we've clicked on
|
||||
tokens = arcade.get_sprites_at_point((x, y), self.tokens)
|
||||
|
@ -101,11 +147,11 @@ class Pad(arcade.Window):
|
|||
|
||||
# Get the list of generator we've clicked on
|
||||
generators = arcade.get_sprites_at_point((x, y), self.tokens_generator)
|
||||
|
||||
|
||||
# Have we clicked on a generator ?
|
||||
if len(generators) > 0:
|
||||
generator = generators[-1]
|
||||
logging.info(f"Cliced on the generator of {generator.type}")
|
||||
logging.debug(f"Cliced on the generator of {generator.type}")
|
||||
|
||||
# Create a token and take it
|
||||
self.held_token = generator.create_token(x, y)
|
||||
|
@ -113,7 +159,7 @@ class Pad(arcade.Window):
|
|||
|
||||
def on_mouse_release(self, x, y, button, modifiers):
|
||||
"""Called when the user presses a mouse button"""
|
||||
logging.info(f"Mouse relase at {x},{y}")
|
||||
logging.debug(f"Mouse relase at {x},{y}")
|
||||
|
||||
if self.held_token is not None:
|
||||
# Find the closest trash
|
||||
|
@ -137,6 +183,6 @@ class Pad(arcade.Window):
|
|||
|
||||
def main():
|
||||
"""Main method"""
|
||||
window = Pad()
|
||||
window = Window()
|
||||
window.setup()
|
||||
arcade.run()
|
Loading…
Reference in New Issue
Block a user