I'm trying to make a simple mastermind style game; however, the viewport scrollbar doesn't work. It reacts to hovering, but neither the mousewheel nor dragging it changes the viewport.
Either I missed something, or the event handler from the Hackermind() object interferes with it. What bugs me is that the scrollbar handle is very small even when the viewport is almost empty, is that normal? I would like the handle to reflect how much there actually is to scroll.
Another issue: The scrollbar is located at y=0 even though the viewport starts at y=50.
EDIT:
It's not the event handler's fault, the same happens when I use that screen with static images.
Code: Select all
init python:
hack_pref = 'hacking/arrow_'
hack_suff = '.png'
renpy.image('arrow_0', hack_pref+'0'+hack_suff)
renpy.image('arrow_1', hack_pref+'1'+hack_suff)
renpy.image('arrow_2', hack_pref+'2'+hack_suff)
renpy.image('arrow_3', hack_pref+'3'+hack_suff)
renpy.image('arrow_blank', hack_pref+'5'+hack_suff)
renpy.image('arrow_correct', hack_pref+'correct'+hack_suff)
renpy.image('arrow_wrongpos', hack_pref+'wrongpos'+hack_suff)
renpy.image('arrow_wrong', hack_pref+'wrong'+hack_suff)
hack_arrowwidth = 60
class Hackermind(object):
def __init__(self, digits, time, turns, commentslabel, returnlabel):
import pygame
self.digits = digits
self.time = time
self.turns = turns
self.currentturn = 0
self.currentdigit = 0
self.commentslabel = commentslabel
self.returnlabel = returnlabel
self.code = []
for i in range(digits):
self.code.append(renpy.random.randint(0,3))
self.guesses = []
temp = []
self.guesses.append(self.emptyguess())
self.results = []
self.cycle = SpriteManager(event=self.hackevent)
#renpy.show(self.cycle, tag='cycle')
renpy.call_screen('hackinggrid', self)
return
def analyse(self, input):
result = [0, 0, 0]
target = self.code*1
for i in range(self.digits):
if target[i] == input[i]:
result[0] += 1
target[i] = -1
input[i] = -1
for i in range(self.digits):
for j in range(self.digits):
if target[i] == input[j] and target[i] >= 0:
result[1] += 1
target[i] = -1
input[j] = -1
result[2] = self.digits - result[0] - result[1]
return result
def emptyguess(self):
temp = []
for i in range(self.digits):
temp.append(5)
return temp
def hackevent(self, ev, x, y, st):
# We only care about keydown events.
if ev.type != pygame.KEYDOWN:
return
# If it's not the key we want, go back
if ev.key not in [pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT, pygame.K_RIGHT]:
return
# Otherwise, add key to sequence
if ev.key == pygame.K_UP:
temp = 0
elif ev.key == pygame.K_RIGHT:
temp = 1
elif ev.key == pygame.K_DOWN:
temp = 2
elif ev.key == pygame.K_LEFT:
temp = 3
self.guesses[self.currentturn][self.currentdigit] = temp
self.currentdigit += 1
if self.currentdigit == self.digits:
self.results.append(self.analyse(self.guesses[self.currentturn]))
self.currentturn += 1
self.currentdigit = 0
self.guesses.append(self.emptyguess())
renpy.restart_interaction()
return
screen hackinggrid(hackgame):
modal True
viewport id "guesslist":
mousewheel True
scrollbars "vertical"
area (50, 50, 1000, 700)
add hackgame.cycle
for i in range(len(hackgame.guesses)):
for j in range(hackgame.digits):
if hackgame.guesses[i][j] == 0:
add 'arrow_0' xpos 20+j*62 ypos 20+i*70
elif hackgame.guesses[i][j] == 1:
add 'arrow_1' xpos 20+j*62 ypos 20+i*70
elif hackgame.guesses[i][j] == 2:
add 'arrow_2' xpos 20+j*62 ypos 20+i*70
elif hackgame.guesses[i][j] == 3:
add 'arrow_3' xpos 20+j*62 ypos 20+i*70
elif hackgame.guesses[i][j] == 5:
add 'arrow_blank' xpos 20+j*62 ypos 20+i*70
if hackgame.currentturn > i:
for j in range(hackgame.digits):
if j < hackgame.results[i][0]:
add 'arrow_correct' xpos 700+(j/2)*30 ypos 20+(((j+1)%2==0)*30)+i*70
elif j >= hackgame.results[i][0] and j < hackgame.results[i][0]+hackgame.results[i][1]:
add 'arrow_wrongpos' xpos 700+(j/2)*30 ypos 20+(((j+1)%2==0)*30)+i*70
else:
add 'arrow_wrong' xpos 700+(j/2)*30 ypos 20+(((j+1)%2==0)*30)+i*70
Code: Select all
$ game = Hackermind(4, 0, 0, "", "")
