forked from OpenBMB/ChatDev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
43 lines (43 loc) · 1.53 KB
/
game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'''
Game class for managing the roguelike game.
'''
import pygame
from player import Player
from level import Level
class Game:
def __init__(self):
self.screen_width = 800
self.screen_height = 800
self.screen = pygame.display.set_mode((self.screen_width, self.screen_height))
pygame.display.set_caption("Roguelike Game")
self.clock = pygame.time.Clock()
self.running = False
self.player = Player(40, 40) # Starting position of the player
self.level = Level()
def run(self):
self.running = True
while self.running:
self.clock.tick(60)
self.handle_events()
self.update()
self.render()
def handle_events(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_w:
self.player.move(0, -1) # Move up
elif event.key == pygame.K_s:
self.player.move(0, 1) # Move down
elif event.key == pygame.K_a:
self.player.move(-1, 0) # Move left
elif event.key == pygame.K_d:
self.player.move(1, 0) # Move right
def update(self):
self.player.update(self.level)
def render(self):
self.screen.fill((0, 0, 0)) # Clear the screen
self.level.draw(self.screen)
self.player.draw(self.screen)
pygame.display.flip()