import pygame import sys import math import random import csv import time # Initial Setup pygame.init() clock = pygame.time.Clock() FPS = 120 # Set up the screen WIDTH = 1024 HEIGHT = 1024 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Game") ROWS = 32 COLS = 32 TILE_SIZE = HEIGHT // ROWS # def draw_grid(): # for c in range(COLS + 1): # pygame.draw.line(screen, WHITE, (c * TILE_SIZE, 0), (c * TILE_SIZE, HEIGHT)) # for c in range(ROWS + 1): # pygame.draw.line(screen, WHITE, (0, c * TILE_SIZE), (WIDTH, c * TILE_SIZE)) # Colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) BLUE = (0, 0, 255) DARK_BLUE = (0, 18, 46) # Player attributes player_width = 25 player_height = 25 player_x = WIDTH // 2 - player_width // 2 player_y = HEIGHT // 2 - player_height // 2 player_speed = 2 player_x_direction = 1 player_y_direction = 1 player_dash_count = 15 can_dashX = True can_dashY = True # Variables to track spacebar state space_pressed = False space_released = True # Main game loop running = True while running: screen.fill(DARK_BLUE) #draw_grid() for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYUP: if event.key == pygame.K_LSHIFT: can_dashY = True can_dashX = True # Get the state of the keyboard keys = pygame.key.get_pressed() # Move the player if keys[pygame.K_a]: player_x -= player_speed player_x_direction = -1 player_y_direction = 0 if keys[pygame.K_d]: player_x += player_speed player_x_direction = 1 player_y_direction = 0 if keys[pygame.K_w]: player_y -= player_speed player_y_direction = -1 player_x_direction = 0 if keys[pygame.K_s]: player_y += player_speed player_y_direction = 1 player_x_direction = 0 if keys[pygame.K_LSHIFT]: # need to make it so player direction can't change during dash # also so dash fully completes when pressing space if test == True and player_x_direction == -1 or test == True and player_x_direction == 1: player_x += player_dash_count * player_x_direction player_dash_count -= 1 if player_dash_count == 0: player_dash_count = 15 test = False if test2 == True and player_y_direction == -1 or test2 == True and player_y_direction == 1: player_y += player_dash_count * player_y_direction player_dash_count -= 1 if player_dash_count == 0: player_dash_count = 15 test2 = False # Boundaries player_x = max(0, min(player_x, WIDTH - player_width)) player_y = max(0, min(player_y, HEIGHT - player_height)) # Draw the player pygame.draw.rect(screen, WHITE, (player_x, player_y, player_width, player_height)) # Update the display pygame.display.flip() # Cap the frame rate clock.tick(FPS) # Quit Pygame pygame.quit() sys.exit()