[SPACE ESCAPE]-Game example to help with Game dev
-
Here is a little game to help new develpoers to game design get started. there is a tutorial in exmples but its very minimal and doesnt give examples of diferent styles of writing. this currently is not a tutorial. and it is not flooded with comments so that its easier to follow the code. any questions are more than welcomeand i will add annotations as needed.
the game itssrlf is not perfect and does have bugs that pop up here and there. this is mainly due to using multiple styles at once creating small conflicts but the game does play and should be easy to expand nd add aditional components. i tried to leave it in a way that made it to whoever was using it could add functionality to help learn and understand game development. all images are builtin and script should run without any dependancies as long as its ran within Pythonista.
Enjoy
Stephen, Frey
-
Very well done!
-
I have noticed a slight error in the game. Occasionally, I will be playing the game, and face a solid wall of gray asteroids. How do I avoid the wall? I can’t. Please, fix this?
-
@Bumbo-Cactoni said:
I have noticed a slight error in the game. Occasionally, I will be playing the game, and face a solid wall of gray asteroids. How do I avoid the wall? I can’t. Please, fix this?
There should always be a gap. What I think is happening here is the gap is being placed above the View Frame and we just cannot see it. I ran some test after changing the following inside
Brush
classdef __init__(self, game): self.game=game self.crateMin=200 self.crateMax=780 self.gaps=list() self.gapSize=4 self.gapMin=4 self.gapMax=6 self.gameObjects=self.game.gameObjects self.startPos=Point(Screen.Width()+128, self.gameObjects.Floor) self.ShieldBoost()
i did not see this happen again but there could still be a chance somehow. all you need to do is limit the hieght for spawning the objects. you could also do a last check to insure there is a gap pressent before returning.
-
@stephen
When I tried to run the code with your updated script, it gave me this error:TypeError
__init__() got an unexpected keyword argument ‘isObsticle’
-
@stephen here’s I did something relying on your code, it’s very similar to the music buttons
from scene import * import sound def sw(): return get_screen_size()[0] def sh(): return get_screen_size()[1] def bw(): return 100 def bh(): return 100 icons = { 'iob:arrow_down_b_256' : (sw()/2, 60), 'iob:arrow_up_b_256' : (sw()/2, bh() + 60), 'iob:arrow_left_b_256' : (sw()/2 - bw(), bh()), 'iob:arrow_right_b_256' : (sw()/2 + bw(), bh()) } class Arrow(ShapeNode): def __init__(self, picture, path=None, size=Size(120, 120), corner_radius=8, border_size=20, borderColor='#3f0917', position=(0,0), parent=None, *args, **kwargs): #for border self.picture = picture self.corner_radius = corner_radius self.border_size = border_size self.borderColor = borderColor self.position = position self.size = size #for super() self.x, self.y = position self.w, self.h = size super().__init__(fill_color='white', path=ui.Path.rounded_rect(self.x, self.y, self.w/1.5, self.h/1.5, self.corner_radius), stroke_color=borderColor, parent=parent, *args, **kwargs) self._setup(self.picture) def _setup(self, pict): if self.picture: arrow = SpriteNode(self.picture, position=Point(0, 0), size=(100, 100), parent=self) class Main(Scene): def setup(self): fill_color = self.background_color self.background_color = 'white' self.arrows = [] for i in icons: arw = Arrow(picture=i, position=icons[i], parent=self) self.arrows.append(arw) def touch_began(self, touch): tapped = True for arw in self.arrows: if touch.location in arw.frame: sound.play_effect('rpg:Chop') arw.fill_color = '#b2b2b2' def touch_ended(self, touch): for arw in self.arrows: if arw.fill_color == '#b2b2b2': arw.fill_color = 'white' run(Main(), PORTRAIT)
I think it will be a base for Tetris
-
https://docs.python.org/3/library/functions.html#enumerate is your friend.
self.arrows = [] for i in icons: arw = Arrow(picture=i, position=icons[i], parent=self) self.arrows.append(arw) # --> self.arrows = [Arrow(picture=i, position=icon, parent=self) for i, icon in enumerate(icons)]
-
@cvp with enumerate doesn’t work cause with this
for i, icon in enumerate(icons)
you get keys of icons and nums 0, 1, 2. So i is the number and icon picture
I did the same but without enumerateself.arrows = [Arrow(i, position=icons[i], parent=self) for i in icons]
Looks better than it was before👍
-
last edited by
-
@cvp yes you’re right 😅