update 2019-02-17 Method 1b (1a + perspective(scaling)) further down
update 2019-02-17 Method 1a (mouse, all directions) further down
update 2019-02-10 Method 3 (keys) further down
update 2019-01-31 Disable Rollback Side
update 2019-01-17 Method 2 further down
update 2019-10-03 Method 4 futher down
________________________________________________________________________________________
Index
Disable Rollback Side
Walk method 1 walk left or right to mouse click fixed background
Walk method 1a walk all directions to mouse click fixed background, best with isometric
Walk method 1b as 1a + perspective(scaling)
Walk method 2 walk left or right to mouse click scrolling background
Walk method 3 walk left or right on key click scrolling background
Walk method 4 walk following mousepointer
________________________________________________________________________________________
Disable Rollback Side
The function Rollback Side makes it possible for the player to jump back by mouse clicking on the left or right side of the screen.
Rollback Side can interfere with method 1, 1a and 2 below. If you use one of those methods you might want to disable Rollback side.
_____________________________________________________________________________________________________________
Method 1 mouse click, character move left or right inside the screen
This is a method for having a character walking between two points in response to input from the player.
This is the script.
Code: Select all
image bg room="room.png"
image semi stand = "sem6.png"
image semi walk:
"sem1.png"
0.3
"sem2.png"
0.3
"sem3.png"
0.3
"sem4.png"
0.3
"sem5.png"
0.3
"sem6.png"
0.3
repeat
default sX= 310
default sY=260
default mX=0
default dist=0
default standWalk=0
default test=50
screen checkMouse():
if standWalk==0:
key "mousedown_1" action Jump("checkDist")
# The game starts here.
label start:
scene bg room
show screen checkMouse
label standRight:
$ standWalk=0
show semi stand:
xpos sX
ypos sY
xzoom 1.0
$ renpy.pause(hard=True)
label standLeft:
$ standWalk=0
show semi stand:
xpos sX
ypos sY
xzoom -1.0
$ renpy.pause(hard=True)
label walkRight:
$ standWalk=1
show semi walk:
xpos sX
ypos sY
xzoom 1.0
linear dist/100.0 xpos mX
$ renpy.pause(delay=dist/100.0, hard=True)
$ sX=mX
jump standRight
label walkLeft:
$ standWalk=1
show semi walk:
xpos sX
ypos sY
xzoom -1.0
linear dist/100.0 xpos mX
$ renpy.pause(delay=dist/100.0, hard=True)
$ sX=mX
jump standLeft
label checkDist:
$ mX=renpy.get_mouse_pos()[0]
if mX>sX:
$ dist = mX-sX
jump walkRight
else:
$ dist = sX-mX
jump walkLeft
This example is in side view and the character walking to an x position indicated by a mouse click.
_____________________________________________________________________________________________________________
Method 1 A mouse click, character move all directions inside the screen
This is a method for having a character walking between two points in response to input from the player with a mouse click.
Evolved from method 1 above. Now walking in all directions. This version works best with an isometric background.
This is the script.
Code: Select all
init python:
import math
image semi stand = "sem6b.png"
image semi walk:
"sem1b.png"
0.3
"sem2b.png"
0.3
"sem3b.png"
0.3
"sem4b.png"
0.3
"sem5b.png"
0.3
"sem6b.png"
0.3
repeat
default sX= 310
default sY=470
default mX=0
default mY=0
default dist=0
default standWalk=0
screen checkMouse():
if standWalk==0:
key "mousedown_1" action Jump("checkDist")
label start:
scene forroom
show screen checkMouse
label standRight:
$ standWalk=0
show semi stand:
xpos sX-37
ypos sY-150
xzoom 1.0
$ renpy.pause(hard=True)
label standLeft:
$ standWalk=0
show semi stand:
xpos sX-37
ypos sY-150
xzoom -1.0
$ renpy.pause(hard=True)
label walkRight:
$ standWalk=1
show semi walk:
xpos sX-37
ypos sY-150
xzoom 1.0
linear dist/100.0 xpos mX-37 ypos mY-150
$ renpy.pause(delay=dist/100.0, hard=True)
$ sX=mX
$ sY=mY
jump standRight
label walkLeft:
$ standWalk=1
show semi walk:
xpos sX-37
ypos sY-150
xzoom -1.0
linear dist/100.0 xpos mX-37 ypos mY-150
$ renpy.pause(delay=dist/100.0, hard=True)
$ sX=mX
$ sY=mY
jump standLeft
label checkDist:
python:
mX=renpy.get_mouse_pos()[0]
mY=renpy.get_mouse_pos()[1]
if mY<118:
mY=118
if mX<164:
mX=164
elif mX>525:
mX=525
xD = sX-mX
yD = sY-mY
dist = (xD**2)+(yD**2)
dist= math.sqrt(dist)
if mX>sX:
jump walkRight
else:
jump walkLeft
_____________________________________________________________________________________________________________
Method 1 B mouse click, character move all directions inside the screen, background drawn in perspective
This is a method for having a character walking between two points in response to input from the player with a mouse click.
Evolved from method 1 and 1a above.
This is the script.
Code: Select all
init python:
import math
image semi stand = "sem6b.png"
image semi walk:
"sem1b.png"
0.3
"sem2b.png"
0.3
"sem3b.png"
0.3
"sem4b.png"
0.3
"sem5b.png"
0.3
"sem6b.png"
0.3
repeat
default sX= 310
default sY=470
default mX=0
default mY=0
default sZ=1.0
default mZ=1.0
default dist=0
default standWalk=0
screen checkMouse():
if standWalk==0:
key "mousedown_1" action Jump("checkDist")
label start:
scene forroom
show screen checkMouse
label standRight:
$ standWalk=0
show semi stand:
xpos int(sX-(37*sZ))
ypos int(sY-(150*sZ))
xzoom sZ
yzoom sZ
$ renpy.pause(hard=True)
label standLeft:
$ standWalk=0
show semi stand:
xpos int(sX-(37*sZ))
ypos int(sY-(150*sZ))
xzoom -sZ
yzoom sZ
$ renpy.pause(hard=True)
label walkRight:
$ standWalk=1
show semi walk:
xpos int(sX-(37*sZ))
ypos int(sY-(150*sZ))
xzoom sZ
yzoom sZ
linear dist/100.0 xpos int(mX-(37*mZ)) ypos int(mY-(150*mZ)) xzoom mZ yzoom mZ
$ renpy.pause(delay=dist/100.0, hard=True)
$ sX=mX
$ sY=mY
$ sZ=mZ
jump standRight
label walkLeft:
$ standWalk=1
show semi walk:
xpos int(sX-(37*sZ))
ypos int(sY-(150*sZ))
xzoom -sZ
yzoom sZ
linear dist/100.0 xpos int(mX-(37*mZ)) ypos int(mY-(150*mZ)) xzoom -mZ yzoom mZ
$ renpy.pause(delay=dist/100.0, hard=True)
$ sX=mX
$ sY=mY
$ sZ=mZ
jump standLeft
label checkDist:
python:
mX=renpy.get_mouse_pos()[0]
mY=renpy.get_mouse_pos()[1]
if mY<118:
mY=118
if mX<164:
mX=164
elif mX>525:
mX=525
xD = sX-mX
yD = sY-mY
dist = (xD**2)+(yD**2)
dist= math.sqrt(dist)
mZ= 0.6 + ((mY-315)*0.00276)
if mZ<0.6:
mZ=0.6
elif mZ>1.0:
mz=1.0
if mX>sX:
jump walkRight
else:
jump walkLeft
1 c Additional points to 1 a and 1 b
How to have different walk cycles for different angles of walking, walk-able area and 2-stage walk.
Techniques used in this script.
Code: Select all
screen checkMouse():
if standWalk==0:
key "mousedown_1" action Jump("checkDist")
###############################################################################
label start:
scene bg starpre
show screen checkMouse
label stand1:
$ standWalk=0
if 220<walkDegree<320:
show Semi standB:
xpos int(SemX-(37*sZ))
ypos int(SemY-(150*sZ))
zoom sZ
elif 40<walkDegree<140:
show Semi standF:
xpos int(SemX-(37*sZ))
ypos int(SemY-(150*sZ))
zoom sZ
elif 90<walkDegree<270:
show Semi standL:
xpos int(SemX-(37*sZ))
ypos int(SemY-(150*sZ))
zoom sZ
else:
show Semi stand:
xpos int(SemX-(37*sZ))
ypos int(SemY-(150*sZ))
zoom sZ
if inArea(SemX,SemY,240, 420, 335, 480):
menu:
"Do you want to go down the stairs?"
"Yes":
pass
"No":
pass
elif inArea(SemX,SemY,332, 307, 434, 320):
menu:
"Do you want to take a closer look at the painting at the wall?"
"Yes":
pass
"No":
pass
elif inArea(SemX,SemY,542, 316, 592, 340):
"The door is locked. I don't know how to open it."
$ standWalk=0
$ renpy.pause(hard=True)
label walk:
$ standWalk=1
if 220<walkDegree<320:
show Semi WalkUp:
xpos int(SemX-(37*sZ))
ypos int(SemY-(150*sZ))
zoom sZ
linear dist/100.0 xpos int(mX-(37*mZ)) ypos int(mY-(150*mZ)) zoom mZ
elif 40<walkDegree<140:
show Semi WalkDown:
xpos int(SemX-(37*sZ))
ypos int(SemY-(150*sZ))
zoom sZ
linear dist/100.0 xpos int(mX-(37*mZ)) ypos int(mY-(150*mZ)) zoom mZ
elif 90<walkDegree<270:
show Semi WalkLeft:
xpos int(SemX-(37*sZ))
ypos int(SemY-(150*sZ))
zoom sZ
linear dist/100.0 xpos int(mX-(37*mZ)) ypos int(mY-(150*mZ)) zoom mZ
else:
show Semi WalkRight:
xpos int(SemX-(37*sZ))
ypos int(SemY-(150*sZ))
zoom sZ
linear dist/100.0 xpos int(mX-(37*mZ)) ypos int(mY-(150*mZ)) zoom mZ
$ renpy.pause(delay=dist/100.0, hard=True)
$ SemX=mX
$ SemY=mY
$ sZ=mZ
if sX2>0:
$ mX=sX2
$ mY=sY2
$ sX2=0
$ sY2=0
jump cd2
else:
jump stand1
label checkDist:
python:
mX=renpy.get_mouse_pos()[0]
mY=renpy.get_mouse_pos()[1]
label cd2:
python:
if inArea(mX,mY,0, 0, 254, 406) and inArea(SemX,SemY,0, 406, 640, 480): ### 2 step
sX2=mX
sY2=mY
mX= 307
mY= 389
elif inArea(SemX,SemY,0, 0, 254, 406) and inArea(mX,mY,246, 406, 640, 480): #### 2 step
sX2=mX
sY2=mY
mX= 307
mY= 389
elif inArea(mX,mY,0, 406, 246, 480):
mX= 298
mY= 456
if inArea(SemX,SemY,0, 0, 254, 406):
sX2=mX
sY2=mY
mX= 307
mY= 389
elif inArea(mX,mY,307, 164, 442, 263):
mX= 369
mY= 318
elif inArea(mX,mY,571, 214, 594, 320):
mX= 562
mY= 325
elif inArea(mX,mY,0, 391, 174, 407):
mX= 150
mY= 405
if mY<315:
mY=315
if mX<205 and 313<mY<396:
if mX<205-(0.8642*(mY-313)):
mX = int(205-(0.8642*(mY-313)))
if mX>558 and 378>mY:
if mX>558+(0.31429*(mY-309)):
mX = int(558+(0.31429*(mY-309)))
if mX>580 and 379<mY:
if mX>580+(0.81481*(mY-379)):
mX = int(580+(0.81481*(mY-379)))
xD = SemX-mX
yD = SemY-mY
dist = (xD**2)+(yD**2)
dist= math.sqrt(dist)
mZ= 0.6 + ((mY-315)*0.00276)
if mZ<0.6:
mZ=0.6
elif mZ>1.0:
mz=1.0
walkDegree = math.degrees(math.atan2(yD, xD))+180
jump walk
Method 2 side view, mouse click and moving background
Code: Select all
image bg room="longroom.png"
image semi stand = "sem6b.png"
image semi walk:
"sem1b.png"
0.3
"sem2b.png"
0.3
"sem3b.png"
0.3
"sem4b.png"
0.3
"sem5b.png"
0.3
"sem6b.png"
0.3
repeat
define sX= 310
define sY=335
default mX=0
default dist=0
default standWalk=0
default rX= -1000
screen checkMouse():
if standWalk==0:
key "mousedown_1" action Jump("checkDist")
# The game starts here.
label start:
scene bg room:
xpos rX
show screen checkMouse
label standRight:
$ standWalk=0
show semi stand:
xpos sX
ypos sY
xzoom 1.0
$ renpy.pause(hard=True)
label standLeft:
$ standWalk=0
show semi stand:
xpos sX
ypos sY
xzoom -1.0
$ renpy.pause(hard=True)
label walkRight:
$ standWalk=1
scene bg room:
xpos rX
linear dist/100.0 xpos rX-dist
show semi walk:
xpos sX
ypos sY
xzoom 1.0
$ renpy.pause(delay=dist/100.0, hard=True)
$ rX -= dist
jump standRight
label walkLeft:
$ standWalk=1
scene bg room:
xpos rX
linear dist/100.0 xpos rX+dist
show semi walk:
xpos sX
ypos sY
xzoom -1.0
$ renpy.pause(delay=dist/100.0, hard=True)
$ rX += dist
jump standLeft
label checkDist:
$ mX=renpy.get_mouse_pos()[0]
if mX>320:
$ dist = mX-320
if rX-dist<-4067:
$ dist= 4067 + rX
jump walkRight
else:
$ dist = 320-mX
if rX+dist>-351:
$ dist= -(351 + rX)
jump walkLeft
example of test walking using this method (and some more stuff)
_____________________________________________________________________________________________________________
Method 3 side view, key click and moving background
Code: Select all
image bg room="longroom.png"
image semi stand = "sem6b.png"
image semi walk:
"sem1b.png"
0.3
"sem2b.png"
0.3
"sem3b.png"
0.3
"sem4b.png"
0.3
"sem5b.png"
0.3
"sem6b.png"
0.3
repeat
define sX= 310
define sY=335
default rX= -1000.0
default kdir=2
screen checkKey():
if kdir==1:
add "semi walk" xpos sX ypos sY xzoom 1.0
elif kdir==-1:
add "semi walk" xpos sX ypos sY xzoom -1.0
key "K_RIGHT" action [SetVariable("kdir",kdir+1), Jump("t2")]
key "K_LEFT" action [SetVariable("kdir",kdir-1), Jump("t2")]
# The game starts here.
label start:
scene bg room:
xpos int(rX)
show screen checkKey
label stand:
if kdir==2:
show semi stand:
xpos sX
ypos sY
xzoom 1.0
else:
show semi stand:
xpos sX
ypos sY
xzoom -1.0
$ kdir=0
$ renpy.pause(hard=True)
label wtimer:
if rX>-351:
$ rX=-351
$ kdir=-2
jump stand
if rX<-4067:
$ rX=-4067
$ kdir=2
jump stand
$ renpy.pause(delay=0.02, hard=True)
label t2:
if kdir>1:
$ kdir=2
if kdir<-1:
$ kdir=-2
if kdir==1:
jump walkRight
elif kdir==-1:
jump walkLeft
else:
jump stand
label walkRight:
$ rX -= 2.3
scene bg room:
xpos int(rX)
jump wtimer
label walkLeft:
$ rX += 2.3
scene bg room:
xpos int(rX)
jump wtimer
Method 4 following the mousepointer
Method of movement seen in this video
The code for the movement in that video is shown below. The method for stoping the character is not included.
The use of a colormap is demonstrated in this thread; viewtopic.php?f=51&t=57299
The Owl's movements are not included either.
Code: Select all
screen checkMouse():
if SemY>324: #### when Semi is closer to camera
add "bg/stonepeople.png" pos(88, 215)
if SemY>350:
add "bg/erkilstat.png" pos(371, 4)
if walkOn==0: ############# Change mode between stand and walk
text "Stand" ypos 52 color "f00"
$ setattr(config, "mouse", {"default": [("gui/cursor_arrow.png", 0, 0)]})
key "mousedown_1" action SetVariable("walkOn", 1)
elif walkOn==1:
text "Walk" ypos 52 color "0f0"
$ setattr(config, "mouse", {"default": [("images/gui/cursor_walk.png", 0, 0)]})
key "mousedown_1" action SetVariable("walkOn", 0)
if walkOn==0: ################## drawing standing Semi
if walkDegree>60 and walkDegree<120.5:
add "Semi standF" xpos int(SemX-(37*mZ)) ypos int(SemY-(150*mZ)) zoom mZ
elif walkDegree>120 and walkDegree<240.5:
add "Semi standL" xpos int(SemX-(37*mZ)) ypos int(SemY-(150*mZ)) zoom mZ
elif walkDegree>240 and walkDegree<300.5:
add "Semi standB" xpos int(SemX-(37*mZ)) ypos int(SemY-(150*mZ)) zoom mZ
else:
add "Semi stand" xpos int(SemX-(37*mZ)) ypos int(SemY-(150*mZ)) zoom mZ
if walkOn==1: ############################### showing walking Semi
if walkDegree>60 and walkDegree<120.5:
add "Semi WalkDown" xpos int(SemX-(37*mZ)) ypos int(SemY-(150*mZ)) zoom mZ
elif walkDegree>120 and walkDegree<240.5:
add "Semi WalkLeft" xpos int(SemX-(37*mZ)) ypos int(SemY-(150*mZ)) zoom mZ
elif walkDegree>240 and walkDegree<300.5:
add "Semi WalkUp" xpos int(SemX-(37*mZ)) ypos int(SemY-(150*mZ)) zoom mZ
else:
add "Semi WalkRight" xpos int(SemX-(37*mZ)) ypos int(SemY-(150*mZ)) zoom mZ
if SemY<351: ################# when Semi is further back
add "bg/erkilstat.png" pos(371, 4) alpha 0.7
if SemY<325:
add "bg/stonepeople.png" pos(88, 215)
label stand1:
$ speed = dist/4 ################ Setting speed from distance between mouse and point at Semi's feet
if speed>10:
$ speed = 10
if speed<0.1:
$ walkOn=0
if walkOn==1: ################## Changing Semi's X and Y using speed
if xD!=0 and yD!=0:
$ SemX -= (xD/dist) * speed
$ SemY -= (yD/dist) * speed
$ renpy.pause(0.1, hard=True) ##### Wait to get a timed loop
jump checkDistskull
label checkDistskull:
python:
mX=renpy.get_mouse_pos()[0]
mY=renpy.get_mouse_pos()[1]
xD = SemX-mX #### Calculate distance between mousepointer and point at Semi's feet
yD = SemY-mY
dist = (xD**2)+(yD**2)
dist= math.sqrt(dist)
walkDegree = math.degrees(math.atan2(yD, xD))+180 ### and angel between those point
mZ= 0.6 + ((SemY-315)*0.00276) ### Set variable for zooming for different distances from camera
if mZ<0.3:
mZ=0.3
elif mZ>1.0:
mZ=1.0
jump stand1
_____________________________________________________________________________________________________________