Skip to content

Instantly share code, notes, and snippets.

@Mr-Coxall
Created September 10, 2016 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mr-Coxall/b9bc5316114468f113eb0b86a63fa2c0 to your computer and use it in GitHub Desktop.
Save Mr-Coxall/b9bc5316114468f113eb0b86a63fa2c0 to your computer and use it in GitHub Desktop.
card_scene.py
# for use with https://github.com/omz/PythonistaAppTemplate
from scene import *
import ui
from menu_scene import *
class CardBackScene(Scene):
def __init__(self, card_back_color='blue'):
Scene.__init__(self)
self.img_name = 'card:Back{}1'.format(card_back_color.title())
def setup(self):
# add background color
SpriteNode(anchor_point=(0, 0), color='white', parent=self,
size=self.size)
self.card = SpriteNode(self.img_name, parent=self,
position=self.size/2)
def touch_ended(self, touch):
# moving back to previous scene, so remove modal makes sense
if self.card.frame.contains_point(touch.location):
self.dismiss_modal_scene()
# for use with https://github.com/omz/PythonistaAppTemplate
from scene import *
import ui
import time
from menu_scene import *
class CompanyScene(Scene):
def setup(self):
self.start_time = time.time()
# add background color
SpriteNode(anchor_point=(0, 0), color='green', parent=self,
size=self.size)
self.ship = SpriteNode('spc:EnemyRed3', parent=self,
position=self.size/2)
def update(self):
if not self.presented_scene and time.time() - self.start_time > 2:
self.present_modal_scene(MenuScene())
pass
def touch_began(self, touch):
pass
def touch_ended(self, touch):
if self.ship.frame.contains_point(touch.location):
self.present_modal_scene(MenuScene())
pass
# for use with https://github.com/omz/PythonistaAppTemplate
from scene import *
import ui
from card_scene import *
class MenuScene (Scene):
def setup(self):
# add background color
SpriteNode(anchor_point=(0, 0), color='blue', parent=self,
size=self.size)
self.ace = SpriteNode('card:ClubsA', parent=self, position=(683, 512))
self.king = SpriteNode('card:ClubsK', parent=self, position=(683, 750))
self.queen = SpriteNode('card:ClubsQ', parent=self, position=(683, 238))
def touch_ended(self, touch):
# move to new scenes
if self.ace.frame.contains_point(touch.location):
self.present_modal_scene(CardBackScene('blue'))
elif self.king.frame.contains_point(touch.location):
self.present_modal_scene(CardBackScene('green'))
elif self.queen.frame.contains_point(touch.location):
self.present_modal_scene(CardBackScene('red'))
# for use with https://github.com/omz/PythonistaAppTemplate
from scene import *
import ui
import time
from company_scene import CompanyScene
class SplashScene(Scene):
def setup(self):
# get starting time
self.start_time = time.time()
# add background color
SpriteNode(anchor_point=(0, 0), color='white', parent=self,
size=self.size)
self.ship = SpriteNode('test:Pythonista', anchor_point=(0, 0),
parent=self, size=self.size)
def update(self):
# move to new scene after 2 seconds
if not self.presented_scene and time.time() - self.start_time > 2:
self.present_modal_scene(CompanyScene())
def touch_began(self, touch):
# self.present_modal_scene(SecondScene())
pass
def touch_ended(self, touch):
if self.ship.frame.contains_point(touch.location):
self.present_modal_scene(SecondScene())
#. .. use while developing
main_view = SceneView()
main_view.scene = SplashScene()
main_view.present(hide_title_bar=True, animated=False)
# ..use when deploying app to Xcode
#main_view = ui.View()
#scene_view = SceneView(frame=main_view.bounds, flex='WH')
#main_view.add_subview(scene_view)
#scene_view.scene = FirstScene()
#main_view.present(hide_title_bar=True, animated=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment