How can I make this Pygame loop work correctly?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
thexerox123
Regular
Posts: 134
Joined: Fri Jan 20, 2023 3:21 pm
itch: thexerox123
Contact:

How can I make this Pygame loop work correctly?

#1 Post by thexerox123 »

I'm trying to make a top-down 2D snowball-rolling minigame. There's a base grass layer to the ground, then I want to layer tiles of snow overtop by way of a spritesheet... as you roll the snowball over the snow tiles, I want them to lose snow (eventually revealing the grass), and for the snowball to gain snow, increasing in size.

I'll eventually need to add collisions and gamification, but right now I'm having trouble just getting it set up.

I had a previous mess of a thread about it where I just rambled to myself:

viewtopic.php?f=8&t=66363&sid=a078c6ea3 ... 5fd5c927f3

I'm going to close that thread to simplify things to this thread with just one question:

how do I get this game loop working? My mess of code was refactored by a kind redditor, but I still needed to get the update and draw methods working, and I haven't had any luck so far. The window just immediately closes, so there's something wrong with my game loop.

So, here's where my code currently stands:

SnowlyRoller.py:

Code: Select all

import pygame
import spritesheet
import itertools
from pygame.locals import (
    K_UP,
    K_DOWN,
    K_LEFT,
    K_RIGHT,
    K_ESCAPE,
    KEYDOWN,
    QUIT,
)


class Game:
    def __init__(self) -> None:
        self.window_surface = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
        pygame.display.set_caption("Snowly Roller")
        self.x = 500.0
        self.y = 500.0
        self.fps = 60
        self.clock = pygame.time.Clock()
        self.init_time = pygame.time.get_ticks()
        self.player = spritesheet.Player()
        self.snowball = spritesheet.Snowball()
        self.terrain = spritesheet.Terrain()
        self.grass = pygame.image.load('images/Grass.png')
        self.g = Game()


    def setup_background(self): 
        self.window_surface.blit(self.terrain.land_list[self.terrain.landframe], (162, 90)) 
        brick_width, brick_height = self.terrain.land_list[self.terrain.landframe].get_width(), self.terrain.land_list[self.terrain.landframe].get_height()
        for self.x,self.y in itertools.product(range(0,1920+1,brick_width), range(0,1080+1,brick_height)):
            self.window_surface.blit(self.terrain.land_list[self.terrain.landframe], (self.x, self.y))  
            return

    def run(self):
        running = True
        while running:
            # # drawing stuff
            # self.window_surface.blit(self.grass, (0, 0))
            # self.setup_background()
            # self.window_surface.blit(self.player.animation_list[self.player.action][self.player.frame], (self.x, y))
            # self.window_surface.blit(self.snowball.snow_list[self.snowball.frame], (self.x + self.snowball.x, y + self.snowball.y))
            # handling events
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
                elif event.type == pygame.KEYUP:
                    if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT or event.key == pygame.K_UP or event.key == pygame.K_DOWN:
                        self.player.is_moving = False
                        self.player.frame = 0
                elif event.type == KEYDOWN:
                    if event.key == K_ESCAPE:
                        running = False
                    if event.key == K_UP:
                        self.player.action = 1
                        self.player.frame = 0
                        self.snowball.x = 17
                        self.snowball.y = -12
                    if event.key == K_LEFT:
                        self.player.action = 2
                        self.player.frame = 0
                        self.snowball.x = -22
                        self.snowball.y = 23
                    if event.key == K_DOWN:
                        self.player.action = 3
                        self.player.frame = 0
                        self.snowball.x = 22
                        self.snowball.y = 62
                    if event.key == K_RIGHT:
                        self.player.action = 0
                        self.player.frame = 0
                        self.snowball.x = 65
                        self.snowball.y = 24  
                elif event.type == QUIT:
                    running = False 

            key_pressed_is = pygame.key.get_pressed()   
            if key_pressed_is[K_LEFT] and self.x > 200:
                self.x -= 10
                self.player.is_moving = True
            if key_pressed_is[K_RIGHT] and self.x < 1640:
                self.x += 10
                self.player.is_moving = True
            if key_pressed_is[K_UP] and y > 100:
                self.y -= 10
                self.player.is_moving = True
            if key_pressed_is[K_DOWN] and y < 880:
                self.y += 10
                self.player.is_moving = True   

            current_time = pygame.time.get_ticks()
            if current_time - self.init_time >= self.player.animation_cooldown:
                if self.player.is_moving:
                    self.player.frame += 1
                    self.snowball.frame += 1
                    self.init_time = current_time
                    if self.player.frame >= len(self.player.animation_list[self.player.action]):
                        self.player.frame = 0
                    if self.snowball.frame >= len(self.snowball.snow_list):
                        self.snowball.frame = 0   

            self.update()  # calling update method
            self.window_surface.blit(self.grass, (0, 0))
            self.setup_background()
            self.draw()  

            self.clock.tick(self.fps)
            pygame.display.update() 
            return

        # pygame.quit()   


    def update(self):
        self.player.update()
        self.snowball.update()
        self.terrain.update()
        # This function should be called for every loop through the main game loop.
        # It should tell every object to update itself.
        # You may end up needing to pass variables to the objects for them to update properly. For instance, player inputs.
        return


    def draw(self):
        self.player.draw(self.window_surface)
        self.snowball.draw(self.window_surface)
        self.terrain.draw(self.window_surface)
        # This function should be called every loop through the main game loop.
        # This should tell every object to draw itself.
        # You may have to pass the surface you want objects to draw themselves on to.
        return



if __name__ == "__main__":
    SCREEN_WIDTH, SCREEN_HEIGHT = 1920, 1080
    pygame.init()
    Game() 
    g.run()

spritesheet.py:

Code: Select all

import pygame   

pygame.init()

players = []

class Player(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.sprite_sheet_surface = pygame.image.load('images/master.png').convert_alpha()
        self.rect = self.sprite_sheet_surface.get_rect()
        self.is_moving = False
        self.step_counter = 0
        self.animation_cooldown = 125
        self.action = 0
        self.animation_list = []
        self.animation_steps = [12, 12, 12, 12]
        self.frame = 0
        self.load_animation_list()
        players.append(self)


    def get_image(self, frame, width, height, scale, colour):
        image = pygame.Surface((width, height)).convert_alpha()
        image.blit(self.sprite_sheet_surface, (0, 0), ((frame * width), 0, width, height))
        self.rect = (self.sprite_sheet_surface, (0, 0), ((frame * width), 0, width, height))
        image = pygame.transform.scale(image, (width * scale, height * scale))
        image.set_colorkey(colour)
        return image

    def load_animation_list(self):
        for animation in self.animation_steps:
            temp_img_list = []
            for _ in range(animation):
                temp_img_list.append(self.get_image(self.step_counter, 32, 32, 3, (0, 0, 0)))
                self.step_counter += 1
            self.animation_list.append(temp_img_list)
            return

    def update(self):
        # self.x += self.velocity[0]
        # self.y += self.velocity[1]
        self.rect = self.sprite_sheet_surface.get_rect()
        self.draw()
        # This is where the code for updating the indices for the player should live.
        return

    def draw(self):
        window_surface.blit(pygame.transform.scale(self.animation_list[self.action][self.frame], (96, 96)), (self.rect.x, self.rect.y))
        # This is where the player should be drawing itself onto the surface. 
        # You may need to have the game pass the main window surface here as a variable.
        return

snowballs = []

class Snowball(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.sprite_sheet_surface = pygame.image.load('images/snowball.png').convert_alpha()
        self.rect = self.sprite_sheet_surface.get_rect()
        self.x = 65
        self.y = 24
        self.spheresize = 0.1
        self.frame = 0
        self.snow_list = []
        self.snow_steps = 5
        self.load_animation_list()
        snowballs.append(self)


    def get_image(self, frame, width, height, scale, colour):
        image = pygame.Surface((width, height)).convert_alpha()
        image.blit(self.sprite_sheet_surface, (0, 0), ((frame * width), 0, width, height))
        self.rect = (self.sprite_sheet_surface, (0, 0), ((frame * width), 0, width, height))
        image = pygame.transform.scale(image, (width * scale, height * scale))
        image.set_colorkey(colour)
        return image
    
    def load_animation_list(self):
        for snow in range(self.snow_steps):
            self.snow_list.append(self.get_image(snow, 416, 450, self.spheresize, (0, 0, 0)))
            return

    def update(self):        
        self.rect = self.sprite_sheet_surface.get_rect()
        self.draw()
        return

    def draw(self):
        window_surface.blit(self.snow_list[self.frame], (self.x, self.y))
        return

terrains = []

class Terrain(pygame.sprite.Sprite):
    def __init__(self):
        self.sprite_sheet_surface = pygame.image.load('images/land.png').convert_alpha() 
        self.rect = self.sprite_sheet_surface.get_rect()
        self.landframe = 0
        self.land_list = []
        self.land_steps = 9
        self.load_animation_list()

        terrains.append(self)

    def get_image(self, frame, width, height, colour):
        image = pygame.Surface((width, height)).convert_alpha()
        image.blit(self.sprite_sheet_surface, (0, 0), ((frame * width), 0, width, height))
        image.set_colorkey(colour)
        return image    

    def load_animation_list(self):
        for land in range(self.land_steps):
            self.land_list.append(self.get_image(land, 150, 180, (0, 0, 0)))
            return

    def update(self):
        self.rect = self.sprite_sheet_surface.get_rect()
        pass

    def draw(self):
        brick_width, brick_height = self.land_list[self.landframe].get_width(), self.land_list[self.landframe].get_height()
        for x, y in itertools.product(range(0, surface.get_width()+1, brick_width), range(0, surface.get_height()+1, brick_height)):
            tile_rect = pygame.Rect(x, y, brick_width, brick_height)
            surface.blit(self.land_list[self.landframe], tile_rect)
            self.tile_rects.append(tile_rect)
            return

Thanks in advance to anybody who has insight or advice into my issue! :)

I've definitely learned a lot through this process, and was able to solve a lot of the issues that have come up on my own, but I feel like I've been spinning my wheels on just getting these rects set up and working. :(

Edit: Added g.run() to the if condition at the end... now it opens! ...but then is frozen on a black screen. So, still something wrong with the loop.

User avatar
PyTom
Ren'Py Creator
Posts: 16097
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How can I make this Pygame loop work correctly?

#2 Post by PyTom »

You'll need to refactor it to be event driven. You can't really just port pygame stuff directly into Ren'Py.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

thexerox123
Regular
Posts: 134
Joined: Fri Jan 20, 2023 3:21 pm
itch: thexerox123
Contact:

Re: How can I make this Pygame loop work correctly?

#3 Post by thexerox123 »

PyTom wrote: Mon Apr 03, 2023 10:50 am You'll need to refactor it to be event driven. You can't really just port pygame stuff directly into Ren'Py.
Oh, dang, okay, thank you! :)

Would I be better off just writing the minigame in Python, or is Pygame still the best way to approach it? I suppose either way, it will probably need to be event-driven? So I'll look into some good examples for that.

I should probably just put this minigame on hold for a bit and switch over to one of the easier ones I have an idea for. :lol:

User avatar
PyTom
Ren'Py Creator
Posts: 16097
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How can I make this Pygame loop work correctly?

#4 Post by PyTom »

You're better off writing it using Ren'Py's creator-defined displayable system - you can't directly port over pygame, at least right now.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

thexerox123
Regular
Posts: 134
Joined: Fri Jan 20, 2023 3:21 pm
itch: thexerox123
Contact:

Re: How can I make this Pygame loop work correctly?

#5 Post by thexerox123 »

PyTom wrote: Mon Apr 03, 2023 11:16 am You're better off writing it using Ren'Py's creator-defined displayable system - you can't directly port over pygame, at least right now.
Okay, thank you so much!

I'll start over and reformat accordingly. :)

thexerox123
Regular
Posts: 134
Joined: Fri Jan 20, 2023 3:21 pm
itch: thexerox123
Contact:

Re: How can I make this Pygame loop work correctly?

#6 Post by thexerox123 »

Well, I'm... kinda making progress.

I managed to get the grass background down with snow tiled on top and indexed so that I can change the tiles later as the snow melts... I have a countdown timer and had managed to add my player character in a screen, but am now trying to translate that to a CDD/class, which is where I keep ending up losing my way.

Currently getting this error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 329, in script call
    call rollstart from _call_rollstart
  File "game/script.rpy", line 313, in script
    call screen snowlyroller
  File "renpy/common/000statements.rpy", line 670, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "game/script.rpy", line 212, in render
    r.blit(renpy.render(self.image, self.width, self.height, st, at), (self.x,self.y))
AttributeError: 'str' object has no attribute 'style'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 329, in script call
    call rollstart from _call_rollstart
  File "game/script.rpy", line 313, in script
    call screen snowlyroller
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\ast.py", line 2259, in execute
    self.call("execute")
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\ast.py", line 2241, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\statements.py", line 307, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 670, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\exports.py", line 3332, in call_screen
    rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\ui.py", line 299, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\display\core.py", line 3471, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, pause_modal=pause_modal, **kwargs) # type: ignore
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\display\core.py", line 4042, in interact_core
    self.draw_screen(root_widget, fullscreen_video, (not fullscreen_video) or video_frame_drawn)
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\display\core.py", line 2677, in draw_screen
    surftree = renpy.display.render.render_screen(
  File "render.pyx", line 492, in renpy.display.render.render_screen
  File "render.pyx", line 266, in renpy.display.render.render
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\display\layout.py", line 886, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 266, in renpy.display.render.render
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\display\layout.py", line 886, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 266, in renpy.display.render.render
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\display\layout.py", line 886, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 266, in renpy.display.render.render
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\display\screen.py", line 731, in render
    child = renpy.display.render.render(self.child, w, h, st, at)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 266, in renpy.display.render.render
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\display\layout.py", line 886, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 266, in renpy.display.render.render
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\display\layout.py", line 1107, in render
    surf = render(d, width - x, rh, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 266, in renpy.display.render.render
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\display\image.py", line 513, in render
    return wrap_render(self.target, width, height, st, at)
  File "C:\Users\thexe\Downloads\renpy-8.0.3-sdk\renpy\display\image.py", line 316, in wrap_render
    rend = render(child, w, h, st, at)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 266, in renpy.display.render.render
  File "game/script.rpy", line 212, in render
    r.blit(renpy.render(self.image, self.width, self.height, st, at), (self.x,self.y))
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 222, in renpy.display.render.render
AttributeError: 'str' object has no attribute 'style'

Windows-10-10.0.22621 AMD64
Ren'Py 8.1.0.23031701+nightly
Snowly Roller 1.0
Mon Apr 10 12:43:23 2023

I'm not quite sure what string it's referring to that has the error. I tried changing some things, but was just flipping between that error and errors saying that my Images aren't defined. Gonna keep plugging away, but I'm feeling pretty muddled at the moment. :?

Here's my current mess of code:

Code: Select all

init:

    image PlayerDown:
        "images/Down1.png"
        0.1
        "images/Down2.png"
        0.1
        "images/Down3.png"
        0.1
        "images/Down4.png"
        0.1
        "images/Down5.png"
        0.1
        "images/Down6.png"
        0.1
        "images/Down7.png"
        0.1
        "images/Down8.png"
        0.1
        "images/Down9.png"
        0.1
        "images/Down10.png"
        0.1
        "images/Down11.png"
        0.1
        "images/Down12.png"
        0.1
        repeat    

    image PlayerUp:
        "images/Up1.png"
        0.1
        "images/Up2.png"
        0.1
        "images/Up3.png"
        0.1
        "images/Up4.png"
        0.1
        "images/Up5.png"
        0.1
        "images/Up6.png"
        0.1
        "images/Up7.png"
        0.1
        "images/Up8.png"
        0.1
        "images/Up9.png"
        0.1
        "images/Up10.png"
        0.1
        "images/Up11.png"
        0.1
        "images/Up12.png"
        0.1
        repeat    
   

    image PlayerLeft:
        "images/Left1.png"
        0.1
        "images/Left2.png"
        0.1
        "images/Left3.png"
        0.1
        "images/Left4.png"
        0.1
        "images/Left5.png"
        0.1
        "images/Left6.png"
        0.1
        "images/Left7.png"
        0.1
        "images/Left8.png"
        0.1
        "images/Left9.png"
        0.1
        "images/Left10.png"
        0.1
        "images/Left11.png"
        0.1
        "images/Left12.png"
        0.1
        repeat    

    image PlayerRight:
        "images/Right1.png"
        0.1
        "images/Right2.png"
        0.1
        "images/Right3.png"
        0.1
        "images/Right4.png"
        0.1
        "images/Right5.png"
        0.1
        "images/Right6.png"
        0.1
        "images/Right7.png"
        0.1
        "images/Right8.png"
        0.1
        "images/Right9.png"
        0.1
        "images/Right10.png"
        0.1
        "images/Right11.png"
        0.1
        "images/Right12.png"
        0.1
        repeat

    default running = True

    default x = 500
    default y = 500


    transform playerloc(x, y):
        zoom 3.0
        xpos (0 + x) ypos (0 + y)



    python:


            # This function will run a countdown of the given length. It will
            # be white until 5 seconds are left, and then red until 0 seconds are
            # left, and then will blink 0.0 when time is up. 
        def countdown(st, at, length=0.0):    

            remaining = length - st    

            if remaining > 2.0:
                return Text("%.1f" % remaining, color="#000", size=72), .1
            elif remaining > 0.0:
                return Text("%.1f" % remaining, color="#f00", size=72), .1
            else:
                return anim.Blink(Text("0.0", color="#f00", size=72)), None 
                running = False

    # Show a countdown for 10 seconds.
    image countdown = DynamicDisplayable(countdown, length=60.0)


init -2 python:
    
    class Tilemap(renpy.Displayable):
        
        """
        
        This creates a displayable by tiling other displayables. It has the following field values.
        
        map -  A 2-dimensional list of integers that represent index of a tileset.
        tileset -  A list of displayables that is used as a tile of tilemap.
        tile_width - width of each tile.
        tile_height - height of each tile.
        area - Rectangle area of the displayable that will be rendered. If it's None, default, it renders all tiles. 
                
        """
        
        def __init__(self, map, tileset, tile_width, tile_height, **properties):
            
            super(Tilemap, self).__init__(**properties)            
            self.map = map
            self.tileset = tileset
            self.tile_width = tile_width
            self.tile_height = tile_height                    
            self.area = None                    
            
            
        def render(self, width, height, st, at):
                
            render = renpy.Render(width, height)
            
            # Blit all tiles into the render.
            for y in xrange(len(self.map)):
                for x in xrange(len(self.map[y])):
                    render.blit(renpy.render(self.tileset[self.map[y][x]], self.tile_width, self.tile_height, st, at), (x*self.tile_width, y*self.tile_height))
                    
            # Crop the render.
            if self.area == None:
                render = render.subsurface((0, 0, len(self.map[y])*self.tile_width, len(self.map)*self.tile_height))
            else:
                render = render.subsurface(self.area)
                
            return render
            
            
        def per_interact(self):
            
            # Redraw per interact.
            renpy.redraw(self, 0)
            
init python:
    import pygame

    class PlayChar(renpy.Displayable):
        def __init__(self,image,width,height,x,y):
            super(renpy.Displayable,self).__init__()
            self.image = image
            self.width = width
            self.height = height
            self.x = x
            self.y = y
            self.last_st = 0.0

        def render(self,width,height,st,at):
            self.last_st = st

            r = renpy.Render(width, height)
            r.blit(renpy.render(self.image, self.width, self.height, st, at), (self.x,self.y))

            renpy.redraw(self, 0)
            return r

        def event(self, ev, x, y, st):

            # How fast we move, in pixels per second.
            RATE = 1

            if ev.type == pygame.KEYDOWN:
                if ev.key == pygame.K_LEFT:
                    self.image = "PlayerLeft"
                    self.x -= RATE
                    self.last_st = st
                    renpy.redraw(self, 0)
                    raise renpy.IgnoreEvent()

                elif ev.key == pygame.K_RIGHT:
                    self.image = "PlayerRight"
                    self.x += RATE
                    self.last_st = st
                    renpy.redraw(self, 0)
                    raise renpy.IgnoreEvent()

                elif ev.key == pygame.K_UP:
                    self.image = "PlayerUp"
                    self.y -= RATE 
                    self.last_st = st 
                    renpy.redraw(self, 0)
                    raise renpy.IgnoreEvent()
                    

                elif ev.key == pygame.K_DOWN:
                    self.image = "PlayerDown"
                    self.y += RATE 
                    self.last_st = st 
                    renpy.redraw(self, 0)
                    raise renpy.IgnoreEvent()

            # elif ev.type == pygame.KEYUP:
            #     if ev.key == pygame.K_LEFT:
            #         if self.rate == RATE:
            #             self.rate = 0
            #             raise renpy.IgnoreEvent()

            #     elif ev.key == pygame.K_RIGHT:
            #         if self.rate == RATE:
            #             self.rate = 0
            #             raise renpy.IgnoreEvent()

            return None


     
            


init python:

    snowtile = Image("SnowTile.png")
    snowtile1 = Image("SnowTile1.png")
    snowtile2 = Image("SnowTile2.png")
    snowtile3 = Image("SnowTile3.png")
    snowtile4 = Image("SnowTile4.png")
    snowtile5 = Image("SnowTile5.png")
    snowtile6 = Image("SnowTile6.png")


    # Define a list of displayables.
    snowtiles = [snowtile, snowtile1, snowtile2, snowtile3, snowtile4, snowtile5, snowtile6]
        
    # Define a 2-demensional list of integers. Integers should be an index number of a tileset.
    # e.g. 0 stands tileset[0]
    snowroll = [
        [0,0,0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0,0,0],
        ]
    
    snowmap = Tilemap(snowroll, snowtiles, 160,180)

    theplayer = PlayChar("PlayerDown", 108, 108, 500, 500)


image overworld = snowmap

image protag = theplayer

screen snowlyroller:
    vbox:
        add "protag"



label rollstart:
    scene bg grass

    $ snowmap.area = None
    show overworld at truecenter 
    show countdown at topleft
    call screen snowlyroller
    $ _rollback = False


label loop:
    if running == True:
        $ renpy.restart_interaction(snowlyroller)
        jump rollstart


    else:
        jump results


    
label start: 
    call rollstart from _call_rollstart


label results:
    "Time is up."
    return

Post Reply

Who is online

Users browsing this forum: No registered users