Пример #1
0
 def __init__(self):
     super(WinScreen, self).__init__(self)
     self.winText = r.Text(0, 0, font_path, 84, (255, 255, 255))
     self.winText.text = "You Won!"
     self.winText.coords = r.Vector2(800 / 2.0, 600 / 2.0)
     self.is_enabled = False
     self.is_visible = False
Пример #2
0
    def __step(self, old_pos, desired_pos):
        super().step(old_pos, desired_pos, True)
        collisions = r.TileMapManager.active_map.grab_collisions(
            r.Vector2(old_pos.X, self.coords.Y))
        check_horizontal = True
        for collision in collisions:
            if "Hazard" in collision.binding_type:
                self.hazard_touched_method(self)
                check_horizontal = False
                collisions = []
                break

        if check_horizontal:
            collisions = r.TileMapManager.active_map.grab_collisions(
                r.Vector2(self.coords.X, old_pos.Y))
            for collision in collisions:
                if "Hazard" in collision.binding_type:
                    '''
                    =================================
                    Do something with this collision!
                    If this is difficult: ask!
                    =================================
                    '''
                    pass

        self.desired_position = self.coords
Пример #3
0
    def __init__(self, tileMap, GameScreen, *args):
        """
        Create a basic character that can move around the tile world.
        tileMap is a reference to the tile map that this object is associated with.
        """
        super(TileHeroCharacter, self).__init__(tileMap)
        self.game_screen = GameScreen
        self.desired_position = r.Vector2(100, 20)
        self.JUMPING_STATE = "JUMPING"
        self.NORMAL_STATE = "NORMAL"
        self.is_paused = False
        self.CURRENT_STATE = self.NORMAL_STATE
        self.draw_order = 5000

        #The number of blocks our character can jump.
        #Everything is in pixels per second.
        block_jump_height = 6
        tile_height = 16
        fall_acceleration= 8 * tile_height

        #Based off equation: -vi = sqrt( 2 * acceleration * delta y )
        self.jump_velocity = math.sqrt(2 * (fall_acceleration) * (block_jump_height * tile_height))
        self.run_speed = 145

        #The method that runs when a hazard tile is touched.
        self.hazard_touched_method = None

        self.bounding_box = r.AABoundingBox()
        self.bounding_box = pygame.Rect(0, 0, 100, 100)
        self.velocity = r.Vector2()
        self.acceleration = r.Vector2(0, fall_acceleration)
        r.Ragnarok.get_world().CollisionMgr.add_object(self.bounding_box)
Пример #4
0
    def step(self, old_pos, desired_pos,super=False):
        self.coords = desired_pos
        collisions = r.TileMapManager.active_map.grab_collisions(r.Vector2(old_pos.X, self.coords.Y))
        check_horizontal = True
        for collision in collisions:
            if "Solid" in collision.binding_type:
                self.coords.Y = old_pos.Y
                self.velocity.Y = 0

                #Reset the player state if the player isn't hitting a solid tile from down under.
                if collision.coords.Y > self.coords.Y:
                    self.CURRENT_STATE = self.NORMAL_STATE
            elif "Warp" in collision.binding_type:
                #Move the player to the new start location and start the next level.
                self.game_screen.level_manager.load_next_level()
                self.set_default_pos(r.TileMapManager.active_map.start_location)
                check_horizontal = False
                break
            elif "Reload" in collision.binding_type:
                self.set_default_pos(r.TileMapManager.active_map.start_location)
                check_horizontal = False

        if check_horizontal:
            collisions = r.TileMapManager.active_map.grab_collisions(r.Vector2(self.coords.X, old_pos.Y))
            for collision in collisions:
                if "Solid" in collision.binding_type:
                    self.coords.X = old_pos.X
                    self.velocity.X = 0
                elif "Reload" in collision.binding_type:
                    self.set_default_pos(r.TileMapManager.active_map.start_location)
                    break
        if not super:
            self.desired_position = self.coords
Пример #5
0
 def __handle_input(self, milliseconds):
     if r.Ragnarok.get_world().Keyboard.is_down(pygame.K_RIGHT):
         self.desired_position += r.Vector2(self.run_speed * (milliseconds / 1000.0), 0)
     if r.Ragnarok.get_world().Keyboard.is_down(pygame.K_LEFT):
         self.desired_position -= r.Vector2(self.run_speed * (milliseconds / 1000.0), 0)
     if r.Ragnarok.get_world().Keyboard.is_down(pygame.K_UP):
         if self.CURRENT_STATE != self.JUMPING_STATE:
             self.velocity = r.Vector2(0, -self.jump_velocity)
             self.CURRENT_STATE = self.JUMPING_STATE
Пример #6
0
    def __init__(self, tileMap, GameScreen):
        super(Hero, self).__init__(tileMap, GameScreen)

        # Some of the variables used for physics and stuff
        block_jump_height = 6
        tile_height = 16
        fall_acceleration = 8 * tile_height
        self.jump_velocity = math.sqrt(2 * (fall_acceleration) *
                                       (block_jump_height * tile_height))
        self.run_speed = 145
        self.velocity = r.Vector2()
        self.acceleration = r.Vector2(0, fall_acceleration)
Пример #7
0
 def __init__(self, char):
     global lose_creation_count
     super(LoseScreen, self).__init__(self)
     self.winText = r.Text(0, 0, font_path, 84, (255, 255, 255))
     self.winText.text = "You Lost!"
     self.winText.coords = r.Vector2(800 / 2.0, 600 / 2.0)
     self.spaceText = r.Text(0, 0, font_path, 32, (255, 255, 255))
     self.spaceText.text = "Hit Space"
     self.spaceText.coords = self.winText.coords + r.Vector2(0, 128)
     self.is_enabled = False
     self.is_visible = False
     self.char = char
     self.delay_timer = r.Timer(500)
Пример #8
0
def create_text():
    text_360 = r.Text(110, 110, Screens.font_path, 24, (0, 0, 0))
    text_360.text = "Platforming Block is coming to the XBox 360!"
    text_360.coords = r.Vector2(425, 140)
    text_360.tag = "Final Screen Text"

    twitter = r.Text(110, 110, Screens.font_path, 24, (0, 0, 0))
    twitter.text = "Follow us on Twitter: @LotusGames"
    twitter.coords = r.Vector2(425, 480)
    twitter.tag = "Final Screen Text"

    fb = r.Text(110, 110, Screens.font_path, 24, (0, 0, 0))
    fb.text = "Join the Platforming Block FaceBook page:"
    fb.coords = r.Vector2(425, 520)
    fb.tag = "Final Screen Text"

    fb2 = r.Text(110, 110, Screens.font_path, 16, (0, 0, 0))
    fb2.text = "www.facebook.com/pages/Platforming-Block/123334587706222"
    fb2.coords = r.Vector2(425, 540)
    fb2.tag = "Final Screen Text"

    r.Ragnarok.get_world().add_obj(text_360)
    r.Ragnarok.get_world().add_obj(twitter)
    r.Ragnarok.get_world().add_obj(fb)
    r.Ragnarok.get_world().add_obj(fb2)
Пример #9
0
 def set_default_pos(self, defaultPos):
     """Set the default starting location of our character."""
     self.coords = defaultPos
     self.velocity = r.Vector2()
     self.desired_position = defaultPos
     r.Ragnarok.get_world().Camera.pan = self.coords
     r.Ragnarok.get_world().Camera.desired_pan = self.coords
Пример #10
0
    def __init__(self):
        self.level_manager = LevelData.LevelProgressionManager()
        """
        tile_bindings is used to give our tiles a meaning.
        Each TileMap must be presented with a BindingType dictionary in order to understand what a number in a tilemap file means.

        For example, we could create a dictionary that includes {"0", ["Solid"]}, {"1", ["Solid", "Damage"] }
        When our tilemap parses in a file that contains a 0, that tile will have a binding_type of "Solid"
        When our tilemap parses in a 1, that tile will have a binding_type of "Solid" and "Damage"

        It is up to you to give these tiles meaning in your game.
        """
        tile_bindings = {}
        tile_bindings["0"] = ["Passthrough"]
        tile_bindings["1"] = ["Solid"]
        tile_bindings["2"] = ["Hazard"]
        tile_bindings["3"] = ["Warp"]
        tile_bindings["r"] = ["Reload"]

        #Load all of our levels. MapCount is the number of levels we need to load. (Levels start at index 0.)
        mapCount = 8
        for i in range(mapCount):
            data_path = "..//Maps//Level" + str(i) + "//Data.txt"
            dta = DataParser.parse(data_path)
            prefix = "..//Maps//Level" + str(i) + "//Lv" + str(i)
            tile_path = prefix + "_TileMap.txt"
            collision_path = prefix + "_CollisionMap.txt"
            object_path = prefix + "_ObjectMap.txt"
            level = "Level " + str(i)
            self.level_manager.levels.append(level)
            tile_map = r.SpriteSheet()
            tile_map.load_texture("..//Textures//" + dta[0],
                                  cell_size=r.Vector2(16, 16))
            _map = r.TileMap(tile_map, tile_bindings, tile_path,
                             collision_path, object_path, LevelData.ObjAry,
                             level)
            r.TileMapManager.add_map(_map)

        #Change this variable to the level you want to test.
        level_test = 0
        self.level_manager.current_level = (level_test - 1)
        self.level_manager.load_next_level()

        #Prepare our hero tile for use.
        self.hero = LevelData.load_character(r.TileMapManager.active_map, self)
        self.hero.set_default_pos(r.TileMapManager.active_map.start_location)
        r.Ragnarok.get_world().add_obj(self.hero)
Пример #11
0
def load_character(tile_map, gamescreen):
    """Create an instance of the main character and return it."""
    tile_obj = thc.TileHeroCharacter(tile_map, gamescreen)
    tile_obj.load_texture("..//Textures//character.png")
    tile_obj.origin = r.Vector2(0, 0)
    tile_obj.hazard_touched_method = hazard_touched_method
    tile_obj.special_touched_method = special_touched_method
    return tile_obj
Пример #12
0
    def __update_movement(self):
        old_pos = self.coords.copy()
        previous_position = self.coords.copy()
        direction = self.desired_position - old_pos
        y_step_count = int(abs(direction.Y) / 16) + 1
        x_step_count = int(abs(direction.X) / 16) + 1

        #This code prevents the block from ever moving more than one block per update cycle.
        if y_step_count > 1:
            old_pos = self.tile_map.pixels_to_tiles(old_pos)
            old_pos = self.tile_map.tiles_to_pixels(old_pos)
            self.desired_position.Y = old_pos.Y + (16 * r.sign(direction.Y))

        if x_step_count > 1:
            old_pos = self.tile_map.pixels_to_tiles(old_pos)
            old_pos = self.tile_map.tiles_to_pixels(old_pos)
            self.desired_position.X = old_pos.X + (16 * r.sign(direction.X))

        self.__step(old_pos, self.desired_position)
Пример #13
0
#Platforming Block copyright Lotus Games
#Code by Clinton Myers
#Maps and graphics by Greg Frasier and Clinton Myers

import Ragnarok as r
import pygame
import Game as g

#Create an instance of the Ragnarok engine.
engine = r.Ragnarok(r.Vector2(800, 600), "Platformin' Block")

#The world is the entity where every object is stored.
#It automatically sorts our objects by update and draw order, and then updates and draws them for us.
world = engine.get_world()

#Create an instance of our game, which will add components necessary to gameplay to the Ragnarok engine.
game = g.Game()

#Set a few start up properties
pygame.mouse.set_visible(False)
engine.preferred_fps = 60
engine.print_frames = False

#Start the game loop.
engine.run()