Exemplo n.º 1
0
    def __init__(self, draw_order, update_order):
        """
        Creates a sun with rotating sun rays that follows the mouse around the screen.
        """
        # Super calls the init method of the base class, allowing the
        # component to be seen as a sprite object by Ragnarok.
        super(Sun, self).__init__(draw_order, update_order)

        # Keep in mind that the object we are creating is custom, so we can
        # do anything we want to with it. Since this object is the sun, we will
        # give it a few behaviours. First of all, it should have Sun Rays that rotate around
        # the sun. The sun, should also follow the mouse around the screen.
        # Let's start by initing up our sun sprite. (See tutorial 2 for info on this process.)

        # We use os.path.join here to ensure the path to our texture will work on
        # multiple operating systems.
        sun_path = os.path.join("Textures", "Sun.png")
        self.sun = R.Sprite()
        self.sun.load_texture(sun_path)

        # Get backbuffer size gets the size of the screen. We divide by 2 to get the center, and then set
        # the sun's coords to the result, placing the sun at the center of the window as its default position.
        self.sun.coords = R.Ragnarok.get_world().get_backbuffer_size() / 2.0
        self.sun.scale = (.35, .35)

        # Let's now create another sprite inside our custom component that represents
        # the Sun Rays around the sun.
        sun_rays_path = os.path.join("Textures", "SunRays.png")
        self.sun_rays = R.Sprite()
        self.sun_rays.load_texture(sun_rays_path)
        self.sun_rays.coords = self.coords
        self.sun_rays.scale = (.95, .95)

        # rotation_val is the amount our sun rays have currently rotated.
        self.rotation_val = 0.0
Exemplo n.º 2
0
def main():
    num = 0
    engine = R.Ragnarok(R.Vector2(800, 600), "Ass-Steroids")

    world = engine.get_world()
    world.clear_color = (0, 0, 0)

    space = R.Sprite()
    space.load_texture("stars.jpg")
    space.scale_to(world.get_backbuffer_size())

    ship = Ship(1, 1)
    asteroids = []

    # while num < 10:
    #     asteroids.append(Asteroid(2, 2))
    #     num += 1
    #     if num == 10:
    #         num = 0

    exitManager = ExitManager()

    world.add_obj(space)
    world.add_obj(ship)
    world.add_obj(exitManager)

    engine.run()
Exemplo n.º 3
0
    def __generate_location(self):
        """
        Reset the location of the cloud once it has left the viewable area of the screen.
        """
        screen_width = world.get_backbuffer_size().X
        self.movement_speed = random.randrange(10, 25)

        # This line of code places the cloud to the right of the viewable screen, so it appears to
        # gradually move in from the right instead of randomally appearing on some portion of the viewable
        # window.
        self.coords = R.Vector2(screen_width + self.image.get_width(),
                                random.randrange(0, 100))
Exemplo n.º 4
0
    def __init__(self, draw_order, update_order, speed=5):
        """Creates a ship that's able to rotate, propel, and shoot"""

        super(Ship, self).__init__(draw_order, update_order)
        self.ship = R.Sprite()
        # Sprite is anything that moves around the screen therefore asteroids are sprites

        self.ship.load_texture("ship1.png")

        self.ship.coords = R.Ragnarok.get_world().get_backbuffer_size() / 2.0

        self.ship.angle = math.pi / 2
        self.ship.speed = speed
Exemplo n.º 5
0
    def update(self, milliseconds):
        # Update the movement of the cloud by moving it horizontally across the screen.
        # Dividing milliseconds by 1000 effictively converts milliseconds into seconds.
        # This allows us to easily move the clouds in pixels per second.
        move_amt = self.movement_speed * (milliseconds / 1000.0)
        self.coords = R.Vector2(self.coords.X - move_amt, self.coords.Y)

        # Check to see if the cloud has moved off the visible area of the screen.
        if self.coords.X < (-self.image.get_width() * 3):
            # Reset the location of the cloud
            self.__generate_location()

        # Call the update method of the base class (Sprite).
        super(Cloud, self).update(milliseconds)
Exemplo n.º 6
0
    def __init__(self, draw_order, update_order):
        super(Cloud, self).__init__(draw_order, update_order)
        cloud_path = os.path.join("Textures", "Cloud.png")
        self.load_texture(cloud_path)

        # Pick a random location on the screen where the cloud will appear.
        x_rand = random.randrange(0, 800)
        y_rand = random.randrange(0, 100)
        self.coords = R.Vector2(x_rand, y_rand)

        # Pick a random size that the cloud should be.
        scale_val = random.randrange(1, 3)
        self.scale = (scale_val, scale_val)

        # Pick a random movement speed for the cloud. This determines how fast our
        # cloud will move across the screen. The speed is in pixels per second.
        self.movement_speed = random.randrange(10, 35)
Exemplo n.º 7
0
    def update(self, milliseconds):
        self.rotation_val = math.pi / 50
        self.ship.trajectory = R.Vector2(math.cos(self.ship.angle),
                                         math.sin(self.ship.angle))

        if R.Ragnarok.get_world().Keyboard.is_down(pg.K_LEFT):
            self.ship.angle -= self.rotation_val
            self.ship.rotation += math.degrees(self.rotation_val)

        if R.Ragnarok.get_world().Keyboard.is_down(pg.K_RIGHT):
            self.ship.angle += self.rotation_val
            self.ship.rotation -= math.degrees(self.rotation_val)

        if R.Ragnarok.get_world().Keyboard.is_down(pg.K_UP):
            self.ship.coords = self.ship.coords - (self.ship.speed *
                                                   self.ship.trajectory)

        if R.Ragnarok.get_world().Keyboard.is_down(pg.K_DOWN):
            self.ship.coords = self.ship.coords + (self.ship.speed *
                                                   self.ship.trajectory)

        # if R.Ragnarok.get_world().Keyboard.is_down(pg.K_SPACE):
        self.ship.update(milliseconds)
Exemplo n.º 8
0
from RagnarokEngine3 import RE3
from os.path import join

engine = RE3.Ragnarok(RE3.Vector2(640, 480), "RAGNAROK TUTORIAL 1")

world = engine.get_world()

world.clear_color = (255, 255, 255)

#end of tutorial 1

sprite = RE3.Sprite()

sprite.update_order = 0
sprite.draw_order = 0

sprite.load_texture("Ragnarok.jpg")

world.add_obj(sprite)

engine.run()

#end of tutorial 2
Exemplo n.º 9
0
from RagnarokEngine3 import RE3 as R
import pygame
import random
import os

# Init our engine.
engine = R.Ragnarok(R.Vector2(800, 600), "RAGNAROK TUTORIAL 3")
world = engine.get_world()
world.clear_color = (0, 0, 0)


# In this tutorial we will demostrate how to create custom components and add them to the world.
# There are many options we have here. The most common course of action is to inherit
# from Ragnarok's Sprite, Animation, UpdatableObject, or DrawableObj types.
# Inherit from UpdatableObj only if the object should update and not draw. If the object is to display
# on the screen, than update from a type that can draw onscreen.
# It is good design practice to inherit from DrawableObject if the class is to display more than one sprite.
# The sun, for example, is made up of the sun texture and a rotating sun ray texture, thus it makes
# more sense to inherit from DrawableObj than it is to inherit from anything else.
class Sun(R.DrawableObj):
    def __init__(self, draw_order, update_order):
        """
        Creates a sun with rotating sun rays that follows the mouse around the screen.
        """
        # Super calls the init method of the base class, allowing the
        # component to be seen as a sprite object by Ragnarok.
        super(Sun, self).__init__(draw_order, update_order)

        # Keep in mind that the object we are creating is custom, so we can
        # do anything we want to with it. Since this object is the sun, we will
        # give it a few behaviours. First of all, it should have Sun Rays that rotate around