Skip to content

Commit

Permalink
improve the proof-of-concept demo(pyv + ECS), name "survival_c"
Browse files Browse the repository at this point in the history
  • Loading branch information
wkta committed Jul 13, 2023
1 parent ce64dfb commit 31b5f9e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
13 changes: 7 additions & 6 deletions examples/survival_c/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@

def init_game():
# here only to ensure that pyv is able to dynamically load Add-ons
print('Test the hub:')
for _ in range(3):
obj = pyv.tabletop.StandardCard.at_random()
print(' ', obj)
# print('Test the hub:')
# for _ in range(3):
# obj = pyv.tabletop.StandardCard.at_random()
# print(' ', obj)
# --- done testing!

gl_vars.screen = pyv.create_screen(SCR_SIZE)
pyv.vars.screen = pyv.create_screen(SCR_SIZE)
pyv.vars.clock = pyv.create_clock()

# Define archetype
pyv.define_archetype("Zombie", ["Position2d", "Health", "Color"])
Expand Down Expand Up @@ -69,7 +70,7 @@ def run_zombie_demo():

# Render game graphics
pyv.flip()
gl_vars.clock.tick(MAX_FPS)
pyv.vars.clock.tick(MAX_FPS)


if __name__ == '__main__':
Expand Down
8 changes: 4 additions & 4 deletions examples/survival_c/gl_vars.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pyved_engine.api import *


clock = create_clock()
screen = surface_create((0, 0))
running = True
NB_STYLES = 4 # styles for the avatar

space_pressed = False # used by the input system
running = True # used in game.py | game loop
20 changes: 7 additions & 13 deletions examples/survival_c/systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import random

import gl_vars
from pyved_engine.api import *
import pyved_engine as pyv
from pyved_engine import * # need to import all constants for keys etc.


__all__ = [ # Careful: the order specified below... It really matters!
Expand All @@ -17,11 +18,6 @@
]


# -------- internal stuff -----------
_pressed_space = False
NB_STYLES = 4


def _blitRotateCenter(surf, image, topleft, angle):
rotated_image = surface_rotate(image, angle)
new_rect = rotated_image.get_rect(center=image.get_rect(topleft=topleft).center)
Expand Down Expand Up @@ -51,13 +47,13 @@ def update_positions(entities, components):


def render_graphics(entities, components):
gl_vars.screen.fill((0, 0, 0)) # Clear screen before rendering
pyv.vars.screen.fill((0, 0, 0)) # Clear screen before rendering

for entity in entities:
if archetype_of(entity) == "Zombie":
x, y = entity["Position2d"]
color = entity["Color"]
draw_polygon(gl_vars.screen, color, [(x, y), (x + 20, y), (x + 10, y + 20)])
draw_polygon(pyv.vars.screen, color, [(x, y), (x + 20, y), (x + 10, y + 20)])

if "Gun" in entity:
# - old way to draw the player
Expand All @@ -70,21 +66,19 @@ def render_graphics(entities, components):
# (x + 10 + 20 * math.cos(angle), y + 10 + 20 * math.sin(angle)), 2)

# - new way to draw the player
_draw_player(gl_vars.screen)
_draw_player(pyv.vars.screen)


def handle_player_input(entities, components):
global _pressed_space

keys = get_pressed_keys()
player = find_by_archetype("Player")
if keys[K_SPACE]:
_pressed_space = True
else:
if _pressed_space:
if gl_vars.space_pressed:
_pressed_space = False
x = player["Gfx"]["Style"]
player["Gfx"]["Style"] = (x + 1) % NB_STYLES
player["Gfx"]["Style"] = (x + 1) % gl_vars.NB_STYLES
if keys[K_UP]:
player["Position2d"][1] -= 2
elif keys[K_DOWN]:
Expand Down

0 comments on commit 31b5f9e

Please sign in to comment.