@p_loo/

(Full) Swamp_Game Ask

Pygame

Functional first 2 levels of game --No end battle--

fork
loading
Files
  • main.py
  • pics
  • boss.py
  • character.py
  • nohup.out
  • second_level.py
  • straw.py
  • water.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.49374003149634715","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IHB5Z2FtZQppbXBvcnQgcmFuZG9tCmZyb20gd2F0ZXIgaW1wb3J0IFdhdGVyCmZyb20gY2hhcmFjdGVyIGltcG9ydCBDaGFyCmZyb20gc2Vjb25kX2xldmVsIGltcG9ydCBsZXZlbF8yCnB5Z2FtZS5pbml0KCkKCldISVRFID0gKDI1NSwyNTUsMjU1KQpCTEFDSyA9ICgwLDAsMCkKCiNzZXQgc2NyZWVuIHNjYWxlCnNjcmVlbl93ID0gODAwCnNjcmVlbl9oID0gNjAwCnNpemUgPSAoc2NyZWVuX3csIHNjcmVlbl9oKQpzY3JlZW4gPSBweWdhbWUuZGlzcGxheS5zZXRfbW9kZShzaXplKQoKeCA9IDMwCnkgPSA0MDAKCmZvbnRfbmFtZSA9IHB5Z2FtZS5mb250Lm1hdGNoX2ZvbnQoJ2FyaWFsJykKCmRlZiBzY29yZV90ZXh0KHN1cmYsIHRleHQsIHNpemUsIHgsIHksIGNvbG9yKToKICAgIGZvbnQgPSBweWdhbWUuZm9udC5TeXNGb250KGZvbnRfbmFtZSwgc2l6ZSkKICAgIHRleHRfc3VyZmFjZSA9IGZvbnQucmVuZGVyKHRleHQsIFRydWUsIGNvbG9yKQogICAgdGV4dF9yZWN0ID0gdGV4dF9zdXJmYWNlLmdldF9yZWN0KCkKICAgIHRleHRfcmVjdC50b3BsZWZ0ID0gKHgsIHkpCiAgICBzdXJmLmJsaXQodGV4dF9zdXJmYWNlLCB0ZXh0X3JlY3QpCgojbG9hZCAmIHNjYWxlIGltYWdlcwpmaWVsZCA9IHB5Z2FtZS5pbWFnZS5sb2FkKCJwaWNzL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N0KQogICAgICBhbGxfc3ByaXRlc19saXN0LmRyYXcoc2NyZWVuKQogICAgICBzY29yZV90ZXh0KHNjcmVlbiwgIlNjb3JlOiAiICsgc3RyKHNjb3JlKSwgNTAsIDIwLCAxMCwgQkxBQ0spCiAgICAgIGNsb2NrLnRpY2soMjApCiAgICAgIHB5Z2FtZS5kaXNwbGF5LmZsaXAoKQoKICAgIGVsc2U6CiAgICAgIHNjcmVlbi5ibGl0KGZpZWxkLCBmaWVsZF9yZWN0KQogICAgICBzY29yZV90ZXh0KHNjcmVlbiwgIkxldmVsIENvbXBsZXRlISIsIDEwMCwgMTUwLCAyMDAsIEJMQUNLKQogICAgICBweWdhbWUudGltZS5kZWxheSgyMDAwKQogICAgICBsZXZlbF8yKCkKICAgICAgY2xvY2sudGljaygyMCkKIAogICAgCnB5Z2FtZS5xdWl0KCk="},"asBuffer":null},"loaded":true}}
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import pygame
import random
from water import Water
from character import Char
from second_level import level_2
pygame.init()

WHITE = (255,255,255)
BLACK = (0,0,0)

#set screen scale
screen_w = 800
screen_h = 600
size = (screen_w, screen_h)
screen = pygame.display.set_mode(size)

x = 30
y = 400

font_name = pygame.font.match_font('arial')

def score_text(surf, text, size, x, y, color):
    font = pygame.font.SysFont(font_name, size)
    text_surface = font.render(text, True, color)
    text_rect = text_surface.get_rect()
    text_rect.topleft = (x, y)
    surf.blit(text_surface, text_rect)

#load & scale images
field = pygame.image.load("pics/field.png")
field = pygame.transform.scale(field, (800,600))
field_rect = field.get_rect()

swamp = pygame.image.load("pics/swamp.png")
swamp = pygame.transform.scale(swamp, (800,600))
swamp_rect = swamp.get_rect()

fruit_list = pygame.sprite.Group()
all_sprites_list = pygame.sprite.Group()

score = 0

for i in range(10):
    # This represents a block
    fruit = Water(BLACK, 75, 85)
 
    # Set a random location for the block
    fruit.rect.x = random.randrange(screen_w)
    fruit.rect.y = random.randrange(screen_h)
 
    # Add the block to the list of objects
    fruit_list.add(fruit)
    all_sprites_list.add(fruit)

player = Char(BLACK, 30, 30)
all_sprites_list.add(player)

#set loop
carryOn = True
clock = pygame.time.Clock()

score = 0

# - - - - MAIN LOOP - - - - - - - - - -
while carryOn:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            carryOn = False

    if score < 20:
      screen.blit(field,(0,0))
      # Calls update() method on every sprite in the list
      all_sprites_list.update()
  
      keys = pygame.key.get_pressed()
      if keys[pygame.K_LEFT]:
          player.moveLeft(20)
      if keys[pygame.K_RIGHT]:
          player.moveRight(20)
          
      # See if the player block has collided with anything.
      fruit_hit_list = pygame.sprite.spritecollide(player, fruit_list, False)
      
      # Check the list of collisions.
      for fruit in fruit_hit_list:
          score += 1
  
          fruit.reset_pos()
  
      # Draw all the spites
      all_sprites_list.draw(screen)

      screen.fill(BLACK)
      screen.blit(field, field_rect)
      all_sprites_list.draw(screen)
      score_text(screen, "Score: " + str(score), 50, 20, 10, BLACK)
      clock.tick(20)
      pygame.display.flip()

    else:
      screen.blit(field, field_rect)
      score_text(screen, "Level Complete!", 100, 150, 200, BLACK)
      pygame.time.delay(2000)
      level_2()
      clock.tick(20)
 
    
pygame.quit()