Request Please help with a code I don't understand so well

The Insider

Member
Game Developer
May 4, 2017
144
255
I have this code from the "lockpick" and I want to increase decrease the difficulty as an achievement (Like training).
I don't understand hot to(Exaple):
Train:
$ difficulty += 1
Please make me understand this "self." thing.



init -1 python:
img = ["images/lock_plate.png", "images/lock_cylinder.png",
"images/lock_tension.png", "lock_pick.png"]
"""
Important: You should have four images listed in this order--The Lock Plate,
The Lock Cylinder, The Lock Tension Bar, The Lock Pick
"""
renpy.music.register_channel("Lock_Move", mixer= "sfx", loop=True)
renpy.music.register_channel("Lock_Click", mixer= "sfx", loop=False, tight=True)
"""These are here so that the various lock sounds play on their own sound channels."""

"""As a Creater Defined Displayable this needs to extend the Displayable class)"""
class Lock(renpy.Displayable):


def __init__(self, difficulty, loot, resize=1920, **kwargs):
"""
This constructor takes the following arguments:
difficulty=How accurate the player has to be, how quickly lock picks break
difficulty is given as a number between 1 and 29 - the lower the number, the more difficult the lock
loot=What the player gets for successfully picking the lock
resize=Your screen width
"""
super(Lock, self).__init__(**kwargs)


self.width = resize
self.lock_plate_image = im.Scale(img[0], resize, resize)
self.lock_cylinder_image = im.Scale(img[1], resize, resize)
self.lock_tension_image = im.Scale(img[2], resize, resize)
self.lock_pick_image = im.Scale(img[3], resize, resize)
self.offset = (resize*2**0.5-resize)/2


self.cylinder_min = 0
self.cylinder_max = 90
self.cylinder_pos = 0
self.cylinder_try_rotate = False
self.cylinder_can_rotate = False
self.cylinder_released = False
self.pick_min = 0
self.pick_max = 180
self.pick_pos = 90
self.pick_can_rotate = True
self.pick_broke = False
self.sweet_spot = renpy.random.randint(0,180)
self.difficulty = difficulty
self.breakage = (difficulty/9 + 0.75)

self.loot = loot

def event(self, ev, x, y, st):
import pygame
LEFT = 1
RIGHT = 3

remaining = 0 + st

if ev.type == pygame.MOUSEBUTTONDOWN and ev.button == LEFT:
self.cylinder_try_rotate = True
self.cylinder_released = False
elif ev.type == pygame.MOUSEBUTTONUP and ev.button == LEFT:
renpy.sound.stop(channel="Lock_Move")
self.cylinder_try_rotate = False
self.cylinder_released = True
self.pick_can_rotate = True
self.pick_broke = False
#global timers
#timers = 0
elif ev.type == pygame.MOUSEBUTTONDOWN and ev.button == RIGHT:
#exit lockpicking
global current_door
current_door = None
renpy.hide_screen("lockpicking")




def render(self, width, height, st, at):
import pygame


if self.difficulty > 29:
self.difficulty = 29
elif self.difficulty < 1:
self.difficulty = 1

if self.pick_can_rotate == True:
x, y = renpy.get_mouse_pos()
self.pick_pos = x/5.3333333333 -90


if self.pick_pos > 180:
self.pick_pos = 180
elif self.pick_pos < 0:
self.pick_pos = 0



if self.pick_pos > self.sweet_spot:
if (self.pick_pos - self.sweet_spot) < self.difficulty:

self.cylinder_can_rotate = True
self.cylinder_max = 90
else:
self.cylinder_can_rotate = True
self.cylinder_max = 90 - (self.pick_pos - self.sweet_spot)*(30/self.difficulty)

if self.cylinder_max < 0:
self.cylinder_max = 0

elif self.pick_pos < self.sweet_spot:
if (self.sweet_spot - self.pick_pos) < self.difficulty:

self.cylinder_can_rotate = True
self.cylinder_max = 90
else:
self.cylinder_can_rotate = True
self.cylinder_max = 90 - (self.sweet_spot - self.pick_pos)*(30/self.difficulty)

if self.cylinder_max < 0:
self.cylinder_max = 0


else:
self.cylinder_can_rotate = True
self.cylinder_max = 90


if self.pick_broke == True:
pick = Transform(child=None)
else:
pick = Transform(child=self.lock_pick_image, rotate=self.pick_pos, subpixel=True)


global display_pos
display_pos = self.pick_pos

global display_spot
display_spot = self.sweet_spot



if self.cylinder_try_rotate == True:




if self.cylinder_can_rotate:

self.cylinder_pos += (2*st)/(at+1)

cylinder = Transform(child=self.lock_cylinder_image, rotate=self.cylinder_pos, subpixel=True)
tension = Transform(child=self.lock_tension_image, rotate=self.cylinder_pos, subpixel=True)


if self.cylinder_pos > self.cylinder_max:
self.cylinder_pos = self.cylinder_max


if self.cylinder_pos == 90:
renpy.sound.stop(channel="Lock_Move")
renpy.sound.play("audio/lock_unlock.mp3", channel="Lock_Click")

self.cylinder_max = 90
self.cylinder_pos = 90
global set_timers
global timers
timers = 0
set_timers = False
pygame.time.wait(150)
self.cylinder_can_rotate = False
renpy.jump("Door_open")
else:

if renpy.sound.is_playing != True:
renpy.sound.play("audio/lock_moving.mp3", channel="Lock_Move")

angle1 = self.cylinder_pos + renpy.random.randint(-2,2)
angle2 = self.cylinder_pos + renpy.random.randint(-4,4)
cylinder = Transform(child=self.lock_cylinder_image, subpixel=True, rotate=angle1)
tension = Transform(child=self.lock_tension_image, subpixel=True, rotate=angle2)

self.pick_can_rotate = False

global lockpicks

global set_timers
global timers
if set_timers == False:
timers = at
set_timers = True

if set_timers == True:
if at > timers+self.breakage:
renpy.sound.stop(channel="Lock_Move")
renpy.sound.play("audio/lock_pick_break.mp3", channel="Lock_Click")
renpy.notify("Broke a lock pick!")
mispick = renpy.random.randint(-30, 30)
pick = Transform(child=self.lock_pick_image, rotate=self.pick_pos+(2*mispick), subpixel=True)
self.pick_can_rotate = False
pygame.time.wait(200)
self.pick_broke = True
self.cylinder_try_rotate = False
lockpicks -= 1
timers = 10
set_timers = False
pygame.mouse.set_pos([self.width/2, self.width/4])
pygame.time.wait(100)
if lockpicks <1:
renpy.call("hallway1")