Skip to content

Commit

Permalink
+ added support for pygbag (toolchain to use pygame with WebAssembly …
Browse files Browse the repository at this point in the history
…aka wasm)
  • Loading branch information
HubertReX committed Sep 4, 2022
1 parent 21d56d5 commit 690e346
Show file tree
Hide file tree
Showing 42 changed files with 1,327 additions and 1,288 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "python",
"request": "launch",
"program": "main.py",
"cwd": "${workspaceFolder}//code",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"justMyCode": true
}
Expand Down
11 changes: 11 additions & 0 deletions build_web.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo off
set project_name=Pirate
REM building web version using pygbag (toolchain to use pygame with WebAssembly aka wasm)
REM build can be found in bin\web
REM add --archive to crate web.zip (e.g. for easy deploy to itch.io)
REM see https://pypi.org/project/pygbag/ for more details

set current_dir=%CD%
cd ..
pygbag --build --archive --app_name %project_name% "%current_dir%"
cd "%current_dir%"
2 changes: 2 additions & 0 deletions code/build.bat → build_win.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@echo off
REM building Windows exe file
REM build can be found in bin\win
REM https://stackoverflow.com/questions/54210392/how-can-i-convert-pygame-to-exe

python setup.py build
Binary file removed code/__pycache__/decoration.cpython-310.pyc
Binary file not shown.
Binary file removed code/__pycache__/decoration.cpython-39.pyc
Binary file not shown.
Binary file removed code/__pycache__/enemy.cpython-310.pyc
Binary file not shown.
Binary file removed code/__pycache__/enemy.cpython-39.pyc
Binary file not shown.
Binary file removed code/__pycache__/game_data.cpython-310.pyc
Binary file not shown.
Binary file removed code/__pycache__/game_data.cpython-39.pyc
Binary file not shown.
Binary file removed code/__pycache__/level.cpython-310.pyc
Binary file not shown.
Binary file removed code/__pycache__/level.cpython-39.pyc
Binary file not shown.
Binary file removed code/__pycache__/overworld.cpython-310.pyc
Binary file not shown.
Binary file removed code/__pycache__/overworld.cpython-39.pyc
Binary file not shown.
Binary file removed code/__pycache__/particles.cpython-310.pyc
Binary file not shown.
Binary file removed code/__pycache__/particles.cpython-39.pyc
Binary file not shown.
Binary file removed code/__pycache__/player.cpython-310.pyc
Binary file not shown.
Binary file removed code/__pycache__/player.cpython-39.pyc
Binary file not shown.
Binary file removed code/__pycache__/settings.cpython-310.pyc
Binary file not shown.
Binary file removed code/__pycache__/settings.cpython-39.pyc
Binary file not shown.
Binary file removed code/__pycache__/support.cpython-310.pyc
Binary file not shown.
Binary file removed code/__pycache__/support.cpython-39.pyc
Binary file not shown.
Binary file removed code/__pycache__/tiles.cpython-310.pyc
Binary file not shown.
Binary file removed code/__pycache__/tiles.cpython-39.pyc
Binary file not shown.
Binary file removed code/__pycache__/ui.cpython-310.pyc
Binary file not shown.
Binary file removed code/__pycache__/ui.cpython-39.pyc
Binary file not shown.
86 changes: 0 additions & 86 deletions code/game_data.py

This file was deleted.

180 changes: 90 additions & 90 deletions code/decoration.py → decoration.py
Original file line number Diff line number Diff line change
@@ -1,90 +1,90 @@
from settings import VERTICAL_TILE_NUMBER, TILE_SIZE, SCREEN_WIDTH
import pygame
from tiles import AnimatedTile, StaticTile
from support import import_folder
from random import choice, randint

class Sky:
def __init__(self,horizon,style = 'level'):
self.top = pygame.image.load('../graphics/decoration/sky/sky_top.png').convert()
self.bottom = pygame.image.load('../graphics/decoration/sky/sky_bottom.png').convert()
self.middle = pygame.image.load('../graphics/decoration/sky/sky_middle.png').convert()
self.horizon = horizon

# stretch
self.top = pygame.transform.scale(self.top,(SCREEN_WIDTH,TILE_SIZE))
self.bottom = pygame.transform.scale(self.bottom,(SCREEN_WIDTH,TILE_SIZE))
self.middle = pygame.transform.scale(self.middle,(SCREEN_WIDTH,TILE_SIZE))

self.style = style
if self.style == 'overworld':
palm_surfaces = import_folder('../graphics/overworld/palms')
self.palms = []

for surface in [choice(palm_surfaces) for image in range(10)]:
x = randint(0,SCREEN_WIDTH)
y = (self.horizon * TILE_SIZE) + randint(50,100)
rect = surface.get_rect(midbottom = (x,y))
self.palms.append((surface,rect))

cloud_surfaces = import_folder('../graphics/overworld/clouds')
self.clouds = []

for surface in [choice(cloud_surfaces) for image in range(10)]:
x = randint(0,SCREEN_WIDTH)
y = randint(0,(self.horizon * TILE_SIZE) - 100)
rect = surface.get_rect(midbottom = (x,y))
self.clouds.append((surface,rect))

def draw(self,surface):
for row in range(VERTICAL_TILE_NUMBER):
y = row * TILE_SIZE
if row < self.horizon:
surface.blit(self.top,(0,y))
elif row == self.horizon:
surface.blit(self.middle,(0,y))
else:
surface.blit(self.bottom,(0,y))

if self.style == 'overworld':
for palm in self.palms:
surface.blit(palm[0],palm[1])
for cloud in self.clouds:
surface.blit(cloud[0],cloud[1])

class Water:
def __init__(self,top,level_width):
water_start = -SCREEN_WIDTH
water_tile_width = 192
tile_x_amount = int((level_width + SCREEN_WIDTH * 2) / water_tile_width)
self.water_sprites = pygame.sprite.Group()

for tile in range(tile_x_amount):
x = tile * water_tile_width + water_start
y = top
sprite = AnimatedTile(192,x,y,'../graphics/decoration/water')
self.water_sprites.add(sprite)

def draw(self,surface,shift):
self.water_sprites.update(shift)
self.water_sprites.draw(surface)

class Clouds:
def __init__(self,horizon,level_width,cloud_number):
cloud_surf_list = import_folder('../graphics/decoration/clouds')
min_x = -SCREEN_WIDTH
max_x = level_width + SCREEN_WIDTH
min_y = 0
max_y = horizon
self.cloud_sprites = pygame.sprite.Group()

for cloud in range(cloud_number):
cloud = choice(cloud_surf_list)
x = randint(min_x,max_x)
y = randint(min_y,max_y)
sprite = StaticTile(0,x,y,cloud)
self.cloud_sprites.add(sprite)

def draw(self,surface,shift):
self.cloud_sprites.update(shift)
self.cloud_sprites.draw(surface)
from settings import VERTICAL_TILE_NUMBER, TILE_SIZE, SCREEN_WIDTH
import pygame
from tiles import AnimatedTile, StaticTile
from support import import_folder
from random import choice, randint

class Sky:
def __init__(self,horizon,style = 'level'):
self.top = pygame.image.load('graphics/decoration/sky/sky_top.png').convert()
self.bottom = pygame.image.load('graphics/decoration/sky/sky_bottom.png').convert()
self.middle = pygame.image.load('graphics/decoration/sky/sky_middle.png').convert()
self.horizon = horizon

# stretch
self.top = pygame.transform.scale(self.top,(SCREEN_WIDTH,TILE_SIZE))
self.bottom = pygame.transform.scale(self.bottom,(SCREEN_WIDTH,TILE_SIZE))
self.middle = pygame.transform.scale(self.middle,(SCREEN_WIDTH,TILE_SIZE))

self.style = style
if self.style == 'overworld':
palm_surfaces = import_folder('graphics/overworld/palms')
self.palms = []

for surface in [choice(palm_surfaces) for image in range(10)]:
x = randint(0,SCREEN_WIDTH)
y = (self.horizon * TILE_SIZE) + randint(50,100)
rect = surface.get_rect(midbottom = (x,y))
self.palms.append((surface,rect))

cloud_surfaces = import_folder('graphics/overworld/clouds')
self.clouds = []

for surface in [choice(cloud_surfaces) for image in range(10)]:
x = randint(0,SCREEN_WIDTH)
y = randint(0,(self.horizon * TILE_SIZE) - 100)
rect = surface.get_rect(midbottom = (x,y))
self.clouds.append((surface,rect))

def draw(self,surface):
for row in range(VERTICAL_TILE_NUMBER):
y = row * TILE_SIZE
if row < self.horizon:
surface.blit(self.top,(0,y))
elif row == self.horizon:
surface.blit(self.middle,(0,y))
else:
surface.blit(self.bottom,(0,y))

if self.style == 'overworld':
for palm in self.palms:
surface.blit(palm[0],palm[1])
for cloud in self.clouds:
surface.blit(cloud[0],cloud[1])

class Water:
def __init__(self,top,level_width):
water_start = -SCREEN_WIDTH
water_tile_width = 192
tile_x_amount = int((level_width + SCREEN_WIDTH * 2) / water_tile_width)
self.water_sprites = pygame.sprite.Group()

for tile in range(tile_x_amount):
x = tile * water_tile_width + water_start
y = top
sprite = AnimatedTile(192,x,y,'graphics/decoration/water')
self.water_sprites.add(sprite)

def draw(self,surface,shift):
self.water_sprites.update(shift)
self.water_sprites.draw(surface)

class Clouds:
def __init__(self,horizon,level_width,cloud_number):
cloud_surf_list = import_folder('graphics/decoration/clouds')
min_x = -SCREEN_WIDTH
max_x = level_width + SCREEN_WIDTH
min_y = 0
max_y = horizon
self.cloud_sprites = pygame.sprite.Group()

for cloud in range(cloud_number):
cloud = choice(cloud_surf_list)
x = randint(min_x,max_x)
y = randint(min_y,max_y)
sprite = StaticTile(0,x,y,cloud)
self.cloud_sprites.add(sprite)

def draw(self,surface,shift):
self.cloud_sprites.update(shift)
self.cloud_sprites.draw(surface)
48 changes: 24 additions & 24 deletions code/enemy.py → enemy.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import pygame
from tiles import AnimatedTile
from random import randint

class Enemy(AnimatedTile):
def __init__(self,size,x,y):
super().__init__(size,x,y,'../graphics/enemy/run')
self.rect.y += size - self.image.get_size()[1]
self.speed = randint(3,5)

def move(self):
self.rect.x += self.speed

def reverse_image(self):
if self.speed > 0:
self.image = pygame.transform.flip(self.image,True,False)

def reverse(self):
self.speed *= -1

def update(self,shift):
self.rect.x += shift
self.animate()
self.move()
import pygame
from tiles import AnimatedTile
from random import randint

class Enemy(AnimatedTile):
def __init__(self,size,x,y):
super().__init__(size,x,y,'graphics/enemy/run')
self.rect.y += size - self.image.get_size()[1]
self.speed = randint(3,5)

def move(self):
self.rect.x += self.speed

def reverse_image(self):
if self.speed > 0:
self.image = pygame.transform.flip(self.image,True,False)

def reverse(self):
self.speed *= -1

def update(self,shift):
self.rect.x += shift
self.animate()
self.move()
self.reverse_image()
Loading

0 comments on commit 690e346

Please sign in to comment.