2
0

3 کامیت‌ها 41b42eaa66 ... b3ad7d945a

نویسنده SHA1 پیام تاریخ
  josef b3ad7d945a V3 1 هفته پیش
  josef 2073297810 zmeny 2 1 هفته پیش
  josef 68da111c05 starsi zmeny 1 هفته پیش
1فایلهای تغییر یافته به همراه81 افزوده شده و 0 حذف شده
  1. 81 0
      raketa.py

+ 81 - 0
raketa.py

@@ -0,0 +1,81 @@
+# Example file showing a circle moving on screen
+# Example file showing a circle moving on screen
+import pygame
+
+# pygame setup
+pygame.init()
+screen = pygame.display.set_mode((720, 720))
+clock = pygame.time.Clock()
+running = True
+dt = 0
+raketa = pygame.sprite.Sprite()
+raketa.original_image = pygame.image.load("raketa.png").convert_alpha()
+raketa.original_image = pygame.transform.scale(raketa.original_image, (60, 60))
+raketa.image = raketa.original_image
+raketa.rect = raketa.image.get_rect(center=(360, 360))
+angle = 0
+
+wall2 = pygame.sprite.Sprite()
+wall2.image = pygame.Surface((20, 200))
+wall2.image.fill("blue")
+wall2.rect = wall2.image.get_rect(topleft=(100,300))
+
+wall3 = pygame.sprite.Sprite()
+wall3.image = pygame.Surface((20, 300))
+wall3.image.fill("green")
+wall3.rect = wall3.image.get_rect(topleft=(200,500))
+
+wall = pygame.sprite.Sprite()
+wall.image = pygame.Surface((500, 20))
+wall.image.fill("red")
+wall.rect = wall.image.get_rect(topleft=(360, 300))
+
+everything = pygame.sprite.Group([raketa, wall, wall2, wall3])
+player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
+velocity = pygame.Vector2(0,0)
+acceleration = 500
+while running:
+    # poll for events
+    # pygame.QUIT event means the user clicked X to close your window
+    for event in pygame.event.get():
+        if event.type == pygame.QUIT:
+            running = False
+    raketa.rect.center = player_pos
+   
+    # fill the screen with a color to wipe away anything from last frame
+    screen.fill("purple")
+    raketa.image = pygame.transform.rotate(raketa.original_image, angle)
+    raketa.rect = raketa.image.get_rect(center=raketa.rect.center)
+    everything.draw(screen)
+
+
+    keys = pygame.key.get_pressed()
+    if keys[pygame.K_w]:
+        velocity.y -= acceleration * dt
+        angle = 0
+    if keys[pygame.K_s]:
+        velocity.y += acceleration * dt
+        angle = 180
+    if keys[pygame.K_a]:
+        velocity.x -= acceleration * dt
+        angle = 90
+    if keys[pygame.K_d]:
+        velocity.x += acceleration * dt
+        angle = 270
+    player_pos += velocity * dt
+
+    if pygame.sprite.collide_rect(raketa, wall):
+        print("bonk")
+    if pygame.sprite.collide_rect(raketa, wall2):
+        print("bonk")    
+    if pygame.sprite.collide_rect(raketa, wall3):
+        print("bonk")
+    # flip() the display to put your work on screen
+    pygame.display.flip()
+
+    # limits FPS to 60
+    # dt is delta time in seconds since last frame, used for framerate-
+    # independent physics.
+    dt = clock.tick(60) / 1000
+
+pygame.quit()