With the pong minigame that ships with Ren'Py demo, I noticed this in the ball and paddles uses the following code every time the court is rendered:
Code: Select all
renpy.render(displayable, width, height, st, at)
Code: Select all
python:
class dungeon(renpy.Displayable):
def __init__(self):
renpy.Displayable.__init__(self)
self.x = 0
self.y = 0
self.img = Image( "ramza_sprite.png" ) #our hero
self.ramza = renpy.render(self.img, 800, 600, 0, 0) #our hero's image
self.left = 0
self.right = 0
self.up = 0
self.down = 0
def visit(self):
return []
# Updates the Mr. Ramza's position
def render(self, width, height, st, at):
# The Render object we'll be drawing into.
r = renpy.Render(width, height)
#movement
if self.left == 1:
self.x-=1
if self.right == 1:
self.x+=1
if self.up == 1:
self.y-=1
if self.down == 1:
self.y+=1
#draw Ramza
r.blit( self.ramza, (self.x, self.y) )
renpy.redraw(self, 0)
# Return the Render object.
return r
# Handles events.
def event(self, ev, x, y, st):
import pygame
if ev.type == pygame.MOUSEBUTTONDOWN and ev.button == 1:
return 1
else:
if ev.type == pygame.KEYDOWN or ev.type == pygame.KEYUP:
val = 0
if ev.type == pygame.KEYDOWN:
val = 1
if ev.key == pygame.K_LEFT:
self.left = val
elif ev.key == pygame.K_RIGHT:
self.right = val
elif ev.key == pygame.K_UP:
self.up = val
elif ev.key == pygame.K_DOWN:
self.down = val
elif ev.key == pygame.K_SPACE:
renpy.call_in_new_context( "rawr" )
else:
raise renpy.IgnoreEvent()
Any thoughts?