naprawiona nieregularnosc czasowa ruchu
This commit is contained in:
parent
eb535d4ef3
commit
fc2d41e07d
@ -1,4 +1,3 @@
|
||||
from numpy import size
|
||||
import pygame
|
||||
from classes import system
|
||||
|
||||
@ -11,7 +10,7 @@ class Minesweeper:
|
||||
offset_x:int=0
|
||||
offset_y:int=0
|
||||
|
||||
speed=2
|
||||
speed=1
|
||||
|
||||
def __init__(self, position_x=0, position_y=0, size=64):
|
||||
self.position_x=position_x
|
||||
@ -21,20 +20,29 @@ class Minesweeper:
|
||||
self.image = pygame.transform.scale(self.image, (self.size, self.size))
|
||||
self.rotated_image = self.image
|
||||
|
||||
def update_offset(self):
|
||||
def update_offset(self, delta:float):
|
||||
dist=round(self.speed*delta/8)
|
||||
if self.offset_x>0:
|
||||
self.offset_x-=self.speed
|
||||
self.offset_x-=dist
|
||||
if self.offset_x<0:
|
||||
self.offset_x=0
|
||||
elif self.offset_x<0:
|
||||
self.offset_x+=self.speed
|
||||
self.offset_x+=dist
|
||||
if self.offset_x>0:
|
||||
self.offset_x=0
|
||||
if self.offset_y>0:
|
||||
self.offset_y-=self.speed
|
||||
self.offset_y-=dist
|
||||
if self.offset_y<0:
|
||||
self.offset_y=0
|
||||
elif self.offset_y<0:
|
||||
self.offset_y+=self.speed
|
||||
self.offset_y+=dist
|
||||
if self.offset_y>0:
|
||||
self.offset_y=0
|
||||
|
||||
def draw(self, window):
|
||||
def draw(self, window, delta:float):
|
||||
position_on_screen = (self.size*self.position_x + self.offset_x, self.size*self.position_y + self.offset_y)
|
||||
window.blit(self.rotated_image, position_on_screen)
|
||||
self.update_offset()
|
||||
self.update_offset(delta)
|
||||
|
||||
def move(self, dir:int):
|
||||
#południe
|
||||
@ -103,7 +111,7 @@ class Map:
|
||||
for j in range(len(self.terrain_matrix[i])):
|
||||
self.window.window.blit(self.tile_palette[self.terrain_matrix[i][j]], (self.tile_size*j, self.tile_size*i))
|
||||
|
||||
def draw_objects(self):
|
||||
self.minesweeper.draw(self.window.window)
|
||||
def draw_objects(self, delta:float):
|
||||
self.minesweeper.draw(self.window.window, delta)
|
||||
|
||||
|
22
main.py
22
main.py
@ -9,6 +9,9 @@ TILE_SIZE = 64
|
||||
TILES_X = 16
|
||||
TILES_Y = 10
|
||||
|
||||
#ustalenie FPS
|
||||
FPS = 60
|
||||
|
||||
def main():
|
||||
#utworzenie okna do gry
|
||||
window = system.Window(TILE_SIZE*TILES_X, TILE_SIZE*TILES_Y, "Intelligent Minesweeper", "icon.png")
|
||||
@ -22,14 +25,8 @@ def main():
|
||||
game_loop = True
|
||||
clock = pygame.time.Clock()
|
||||
while game_loop:
|
||||
#ustalenie FPS
|
||||
clock.tick(60)
|
||||
|
||||
#sprawdzanie różnych interakcji użytkownika
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
game_loop = False
|
||||
pygame.quit()
|
||||
#ustalenie FPS, delta - czas od ostatniej klatki
|
||||
delta = clock.tick(FPS)
|
||||
|
||||
#sterowanie
|
||||
keys = pygame.key.get_pressed()
|
||||
@ -44,15 +41,18 @@ def main():
|
||||
map.minesweeper.move(3)
|
||||
|
||||
|
||||
|
||||
#narysowanie terenu i obiektów
|
||||
map.draw_tiles()
|
||||
map.draw_objects()
|
||||
map.draw_objects(delta)
|
||||
|
||||
#odświeżenie ekranu
|
||||
pygame.display.update()
|
||||
|
||||
|
||||
#sprawdzanie różnych interakcji użytkownika
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
game_loop = False
|
||||
pygame.quit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
Reference in New Issue
Block a user