Skip to content

Commit

Permalink
I can see clouds !!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
Nofel committed Feb 20, 2024
1 parent dae316f commit 2675c63
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
Binary file added Scripts/__pycache__/clouds.cpython-311.pyc
Binary file not shown.
31 changes: 31 additions & 0 deletions Scripts/clouds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import random

class Cloud:
def __init__(self, pos, img, speed, depth):
self.pos = list(pos)
self.img = img
self.speed = speed
self.depth = depth

def update(self):
self.pos[0] += self.speed

def render(self, surf, offset=(0,0)):
render_pos = (self.pos[0] - offset[0] * self.depth, self.pos[1] - offset[1] * self.depth)
surf.blit(self.img, (render_pos[0] % (surf.get_width() + self.img.get_width()) - self.img.get_width(), render_pos[1] % (surf.get_height() + self.img.get_height()) - self.img.get_height()))

class Clouds:
def __init__(self, cloud_imgs, count=16):
self.clouds = []

for i in range(count):
self.clouds.append(Cloud((random.random() * 9999, random.random() * 9999), random.choice(cloud_imgs), random.random() * 0.05 + 0.05, random.random() * 0.6 + 0.2))
self.clouds.sort(key=lambda x: x.depth)

def update(self):
for cloud in self.clouds:
cloud.update()

def render(self, surf, offset=(0,0)):
for cloud in self.clouds:
cloud.render(surf, offset)
8 changes: 6 additions & 2 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from Scripts.tilemap import Tilemap
from Scripts.entities import PhysicsEntity
from Scripts.utils import load_image, load_images
from Scripts.clouds import Clouds
class Game:
def __init__(self):

Expand All @@ -24,11 +25,12 @@ def __init__(self):
'stone': load_images('tiles/stone'),
'large_decor': load_images('tiles/large_decor'),
'player': load_image('entities/player.png'),
'background': load_image('background.png')
'background': load_image('background.png'),
'clouds': load_images('clouds')
}

print(self.assets)

self.clouds = Clouds(self.assets['clouds'], count=16)
self.player = PhysicsEntity(self, 'player', (50,50), (8,15))
self.tilemap = Tilemap(self, tile_size=16)

Expand All @@ -41,6 +43,8 @@ def run(self):
self.scroll[1] += (self.player.rect().centery - self.display.get_height() / 2 - self.scroll[1]) / 30
render_scroll = (int(self.scroll[0]), int(self.scroll[1]))

self.clouds.update()
self.clouds.render(self.display, offset=render_scroll)

self.tilemap.render(self.display, offset=render_scroll)

Expand Down

0 comments on commit 2675c63

Please sign in to comment.