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