Exemplo n.º 1
0
    def start(self):
        self.image = pygame.image.load("assets/images/space.jpg")
        test_go = GameObject()
        test_go.name = "Ship"
        test_go.get_behaviour("Transform").position.x = 512
        test_go.get_behaviour("Transform").position.y = 388
        test_go.add_behaviour(BoxCollider())
        test_go.get_behaviour("BoxCollider").is_debug = False
        test_go.get_behaviour("BoxCollider").extent = pygame.math.Vector2(150)
        test_go.add_behaviour(ShipRenderer())
        test_go.add_behaviour(ShieldRenderer())
        test_go.add_behaviour(Movement())
        test_go.add_behaviour(ShipCommands())
        self.add_game_object(test_go)

        another_go = GameObject()
        another_go.name = "Obstacle"
        another_go.get_behaviour("Transform").position.x = 200
        another_go.get_behaviour("Transform").position.y = 200
        another_go.add_behaviour(BoxCollider())
        another_go.get_behaviour("BoxCollider").is_debug = True
        another_go.get_behaviour("BoxCollider").extent = Vector2(350)
        self.add_game_object(another_go)

        overlap_go = GameObject()
        overlap_go.name = "Overlap"
        overlap_go.add_behaviour(RectRenderer())
        overlap_go.get_behaviour("RectRenderer").colour = (255, 0, 0)
        overlap_go.get_behaviour("RectRenderer").rect = Rect(0, 0, 0, 0)
        self.add_game_object(overlap_go)
        super().start()
Exemplo n.º 2
0
 def shoot_player(self, x):
     from engine.game_object import GameObject
     bullet = GameObject()
     bullet.name = "EnemyBullet" + str(self.bullet_counter)
     bullet.get_behaviour("Transform").position.x = x
     bullet.get_behaviour("Transform").position.y = 200
     bullet.add_behaviour(EnemyBulletMovement())
     bullet.add_behaviour(BulletRenderer())
     bullet.get_behaviour("BulletRenderer").do_rotate(180)
     GameObject.add_to_screen(bullet)
     self.bullet_counter += 1
Exemplo n.º 3
0
    def start(self):
        #Background setting functionality
        self.image = pygame.image.load("assets/Images/Space.jpg")

        #player character setting:
        #-> Sets the Transform so that the ship begins the game
        #   in the middle of the screen
        #-> Adds a box collider and sets its size
        #-> Also adds Movement, ShipCommands and ShipRenderer
        #   functionality
        #-> Adds the Game Object to the game_objects list
        test_go = GameObject()
        test_go.name = "Ship"
        test_go.get_behaviour("Transform").position = Vector2(512, 388)
        test_go.add_behaviour(BoxCollider())
        test_go.get_behaviour("BoxCollider").extent = Vector2(150)
        test_go.add_behaviour(ShipRenderer())
        test_go.add_behaviour(ShieldRenderer())
        test_go.add_behaviour(Movement())
        test_go.add_behaviour(ShipCommands())
        self.add_game_object(test_go)

        #insert obstacle below:
        #-> Name it "Obstacle"
        #-> Position its Transform at 200, 200
        #-> Add a BoxCollider behaviour
        #-> Set the BoxCollider's is_debug flag to True
        #-> Set the BoxCollider's extent to 350, 350
        #->Add it to the screen's game_objects list
        another_go = GameObject()
        another_go.name = "Obstacle"
        another_go.get_behaviour("Transform").position = Vector2(200, 200)
        another_go.add_behaviour(BoxCollider())
        another_go.get_behaviour("BoxCollider").is_debug = True
        another_go.get_behaviour("BoxCollider").extent = pygame.math.Vector2(
            350)
        self.add_game_object(another_go)

        #insert the overlap game object here:
        #-> Name it "Overlap"
        #-> Add a RectRenderer behaviour
        #-> Set the RectRenderer's colour
        #-> Add the Game Object to the screen's game_objects list
        overlap_go = GameObject()
        overlap_go.name = "Overlap"
        overlap_go.add_behaviour(RectRenderer())
        overlap_go.get_behaviour("RectRenderer").colour = (255, 0, 0)
        self.add_game_object(overlap_go)

        #base class start() call
        super().start()
Exemplo n.º 4
0
    def start(self):
        print("(?) src.game_screen: start() called")
        self.image = pygame.image.load("assets/images/background.jpg")

        def player_death():
            from engine.game_env import Game
            from src.intro_screen import IntroScreen
            print("You died")
            Game.instance.set_screen(IntroScreen())

        lvl_go = GameObject()
        lvl_go.name = "LevelText"
        h = pygame.display.get_surface().get_height()
        lvl_go.get_behaviour("Transform").position = Vector2(10, h - 70)
        lvl_go.add_behaviour(TextRenderer())
        lvl_go.get_behaviour("TextRenderer").text = "Level " + str(self.level)
        lvl_go.get_behaviour("TextRenderer").set_size(90)
        self.add_game_object(lvl_go)

        play_go = GameObject()
        play_go.name = "Player"
        play_go.get_behaviour("Transform").position = Vector2(512, 700)
        play_go.add_behaviour(BoxCollider())
        play_go.get_behaviour("BoxCollider").is_debug = False
        play_go.get_behaviour("BoxCollider").extent = Vector2(150)
        play_go.add_behaviour(ImageRenderer())
        play_go.add_behaviour(PlayerCommands())
        play_go.add_behaviour(LinearMovement())
        play_go.add_behaviour(PlayerData())
        play_go.get_behaviour("PlayerData").death_func = player_death
        play_go.add_behaviour(Boundaries())
        play_go.get_behaviour("Boundaries").set_offset(Vector2(60, 0))
        play_go.add_behaviour(ScreenshotTaker())
        self.add_game_object(play_go)

        for i in range(3):
            sr_go = GameObject()
            sr_go.name = "Shield" + str(i)
            sr_go.get_behaviour("Transform").position.x = 200 + i * 250
            sr_go.get_behaviour("Transform").position.y = 500
            sr_go.add_behaviour(ShieldRenderer())
            self.add_game_object(sr_go)

        el_go = GameObject()
        el_go.name = "EnemyLine"
        el_go.add_behaviour(EnemyLine())
        self.add_game_object(el_go)

        print("(?) src.game_screen: start() done")

        super().start()
Exemplo n.º 5
0
    def shoot(self):
        self.has_shot = True

        from engine.game_object import GameObject
        bullet = GameObject()
        bullet.name = "Bullet" + str(self.bullet_counter)
        tr = self.game_object.get_behaviour("Transform")
        bullet.get_behaviour("Transform").position.x = tr.position.x - 12
        bullet.get_behaviour("Transform").position.y = tr.position.y - 54
        bullet.get_behaviour("Transform").rotation = tr.rotation
        bullet.add_behaviour(BulletMovement())
        bullet.add_behaviour(BulletRenderer())
        GameObject.add_to_screen(bullet)
        self.bullet_counter += 1
Exemplo n.º 6
0
 def start(self):
     #Set image
     self.image = pygame.image.load("assets/images/nebula.jpg")
     #Create Button Game Object, name it "Button", set position
     #Add BoxCollider behaviour and set size
     #Add ButtonBehaviour
     #Add RectRenderer
     #Add game object to screen
     button_go = GameObject()
     button_go.name = "Button"
     button_go.get_behaviour("Transform").position = Vector2(512, 384)
     button_go.add_behaviour(BoxCollider())
     button_go.get_behaviour("BoxCollider").extent = Vector2(200, 100)
     button_go.add_behaviour(ButtonBehaviour())
     button_go.add_behaviour(RectRenderer())
     self.add_game_object(button_go)
     super().start()
Exemplo n.º 7
0
    def start(self):
        self.image = pygame.image.load("assets/images/space.jpg")
        test_go = GameObject()
        test_go.name = "Ship"
        test_go.get_behaviour("Transform").position.x = 512
        test_go.get_behaviour("Transform").position.y = 388
        test_go.add_behaviour(BoxCollider())
        test_go.get_behaviour("BoxCollider").is_debug = False
        test_go.get_behaviour("BoxCollider").extent = pygame.math.Vector2(150)
        test_go.add_behaviour(ShipRenderer())
        test_go.add_behaviour(ShieldRenderer())
        test_go.add_behaviour(Movement())
        test_go.add_behaviour(ShipCommands())
        self.add_game_object(test_go)

        another_go = GameObject()
        another_go.name = "Obstacle"
        another_go.get_behaviour("Transform").position.x = 200
        another_go.get_behaviour("Transform").position.y = 200
        another_go.add_behaviour(BoxCollider())
        another_go.get_behaviour("BoxCollider").is_debug = True
        another_go.get_behaviour("BoxCollider").extent = Vector2(350)
        self.add_game_object(another_go)

        overlap_go = GameObject()
        overlap_go.name = "Overlap"
        overlap_go.add_behaviour(RectRenderer())
        overlap_go.get_behaviour("RectRenderer").colour = (255, 0, 0)
        overlap_go.get_behaviour("RectRenderer").rect = Rect(0, 0, 0, 0)
        self.add_game_object(overlap_go)

        #Create Text Game Object, name it "Text",
        #Set Game Object position
        #Add TextRenderer behaviour
        #Set Message
        #Set Size
        #Add Game Object to screen
        text_go = GameObject()
        text_go.name = "Text"
        text_go.get_behaviour("Transform").position = Vector2(500, 350)
        text_go.add_behaviour(TextRenderer())
        text_go.get_behaviour("TextRenderer").text = "Welcome, Earthlings"
        text_go.get_behaviour("TextRenderer").set_size(30)
        self.add_game_object(text_go)

        super().start()
Exemplo n.º 8
0
 def start(self):
     self.image = pygame.image.load("assets/Images/Space.jpg")
     test_go = GameObject()
     test_go.name = "Ship"
     test_go.get_behaviour("Transform").position.x = 512
     test_go.get_behaviour("Transform").position.y = 388
     test_go.add_behaviour(ShipRenderer())
     test_go.add_behaviour(ShieldRenderer())
     test_go.add_behaviour(Movement())
     test_go.add_behaviour(ShipCommands())
     self.add_game_object(test_go)
     super().start()
Exemplo n.º 9
0
    def start(self):

        player = GameObject()
        player.name = "Player"  # this is the player gameobject

        transform = player.get_behaviour("Transform")
        transform.position.x = 100
        transform.position.y = 500

        # add a renderer to the player object so that we can see it
        renderer = SpriteRenderer()
        renderer.resize((50, 100))  # resize the renderer behaviour
        renderer.center = True  # make the renderer center the sprite
        player.add_behaviour(renderer)

        rigidbody = Rigidbody()
        rigidbody.experience_gravity = True
        player.add_behaviour(rigidbody)

        jetpack = Jetpack()
        player.add_behaviour(jetpack)

        jetpack_particles = ParticleSystem()
        player.add_behaviour(jetpack_particles)

        self.add_game_object(player)

        scientist = GameObject()

        scientist.add_behaviour(SpriteRenderer())
        scientist.add_behaviour(
            Nerd())  # chose to call this behaviour nerd for fun
        scientist.get_behaviour("Nerd").target = transform

        self.add_game_object(scientist)

        super().start()
Exemplo n.º 10
0
    def shoot(self):
        self.has_shot = True

        from engine.game_object import GameObject

        bullet = GameObject()
        bullet.name = "Bullet" + str(self.bullet_counter)
        bullet.get_behaviour(
            "Transform").position.x = self.game_object.get_behaviour(
                "Transform").position.x
        bullet.get_behaviour(
            "Transform").position.y = self.game_object.get_behaviour(
                "Transform").position.y
        bullet.get_behaviour(
            "Transform").rotation = self.game_object.get_behaviour(
                "Transform").rotation
        bullet.add_behaviour(BulletMovement())
        bullet.add_behaviour(BoxCollider())
        bullet.get_behaviour("BoxCollider").is_debug = True
        bullet.get_behaviour("BoxCollider").extent = pygame.math.Vector2(10)
        bullet.add_behaviour(BulletRenderer())

        GameObject.add_to_screen(bullet)
        self.bullet_counter += 1
Exemplo n.º 11
0
    def start(self):

        #Text GO
        text_go = GameObject()
        text_go.name = "Title"
        text_go.get_behaviour("Transform").position = Vector2(512, 250)
        text_go.add_behaviour(TextRenderer())
        text_go.get_behaviour("TextRenderer").text = "Random Game"
        text_go.get_behaviour("TextRenderer").set_size(63)
        self.add_game_object(text_go)
        #button GO

        button_go = GameObject()
        button_go.name = "StartButton"
        button_go.get_behaviour("Transform").position = Vector2(512, 475)
        button_go.add_behaviour(BoxCollider())
        button_go.add_behaviour(ButtonBehaviour())
        button_go.add_behaviour(ButtonRenderer())
        button_go.add_behaviour(TextRenderer())
        button_go.get_behaviour("TextRenderer").text = "START"
        button_go.get_behaviour("TextRenderer").set_size(50)
        self.add_game_object(button_go)
        super().start()
Exemplo n.º 12
0
    def start(self):
        self.image = pygame.image.load("assets/images/background.jpg")

        def btnclick():
            from engine.game_env import Game
            from src.game_screen import GameScreen
            Game.instance.set_screen(GameScreen())

        btn_go = GameObject()
        btn_go.name = "Button"
        btn_go.get_behaviour("Transform").position = Vector2(512, 384)
        btn_go.add_behaviour(BoxCollider())
        btn_go.get_behaviour("BoxCollider").extent = Vector2(200, 100)
        btn_go.add_behaviour(TextRenderer())
        btn_go.get_behaviour("TextRenderer").text = "Start"
        btn_go.get_behaviour("TextRenderer").set_size(90)
        btn_go.add_behaviour(ButtonBehaviour())
        btn_go.get_behaviour("ButtonBehaviour").compute_text_offset()
        btn_go.get_behaviour("ButtonBehaviour").f_onclick = btnclick
        btn_go.add_behaviour(RectRenderer())
        self.add_game_object(btn_go)

        text_go = GameObject()
        text_go.name = "GameText"
        text_go.get_behaviour("Transform").position = Vector2(280, 200)
        text_go.add_behaviour(TextRenderer())
        text_go.get_behaviour("TextRenderer").text = "Space Reinvaders"
        text_go.get_behaviour("TextRenderer").set_size(100)
        self.add_game_object(text_go)

        i1_go = GameObject()
        i1_go.name = "Instr1"
        i1_go.get_behaviour("Transform").position = Vector2(280, 500)
        i1_go.add_behaviour(TextRenderer())
        i1_go.get_behaviour("TextRenderer").text = "Press space to shoot"
        i1_go.get_behaviour("TextRenderer").set_size(50)
        self.add_game_object(i1_go)
        i2_go = GameObject()
        i2_go.name = "Instr2"
        i2_go.get_behaviour("Transform").position = Vector2(280, 550)
        i2_go.add_behaviour(TextRenderer())
        i2_go.get_behaviour("TextRenderer").text = "Press A and D to move"
        i2_go.get_behaviour("TextRenderer").set_size(50)
        self.add_game_object(i2_go)

        super().start()