I'm figuring out programming slowly (yay codecademy for its python course!) and of course I still have a ton to learn.
I figured this would be better done with a custom displayable class, but I still don't have the hang of them yet, so I'm using ATL instead...
Anyway, onto the question!
I have this: Clicking on the buttons moves the rectangle on the corresponding direction, 100 pixels at a time using linear and xpos/ypos.
Then it checks the position of the square to see if it's on a position for something to happen (I need to adjust this to not be so precise, but for now it works), then stuff happens and it returns to the moving loop.
My messy code is this (apologies for making eyes bleed with my messy code :'D ) :
Code: Select all
image mini_penny = Solid("#F00", maximum=(100, 100))
screen move_gui:
textbutton "Left" align (0.0,0.5) action Return("left")
textbutton "Right" align (1.0,0.5) action Return("right")
textbutton "Down" align (0.5, 1.0) action Return("down")
textbutton "Up" align (0.5, 0.0) action Return("up")
transform at_center:
xpos 300
ypos 250
#I want things to move at 200 px/sec
default velocity = 0.005
default penny_xpos = 300
default penny_ypos = 250
default places = {
"up":[300,50],
"down":[400,450],
"left":[0, 250],
"right":[700, 250]
}
default done = ""
transform move_right(x):
linear x*velocity xpos penny_xpos+x
transform move_down(y):
linear y*velocity ypos penny_ypos+y
transform move_left(x):
linear x*velocity xpos penny_xpos-x
transform move_up(y):
linear y*velocity ypos penny_ypos-y
label move_test:
$renpy.show("mini_penny", at_list=[at_center])
label check:
show mini_penny
python:
for key in places:
if places[key][0] == penny_xpos:
if places[key][1] == penny_ypos:
renpy.call(key)
else:
renpy.call("move_loop")
label move_loop:
call screen move_gui
if _return == "left":
$renpy.show("mini_penny", at_list=[move_left(100)])
$penny_xpos -=100
jump check
elif _return == "right":
$renpy.show("mini_penny", at_list=[move_right(100)])
$penny_xpos +=100
jump check
elif _return == "up":
$renpy.show("mini_penny", at_list=[move_up(100)])
$penny_ypos -=100
jump check
elif _return == "down":
$renpy.show("mini_penny", at_list=[move_down(100)])
$penny_ypos +=100
jump check
jump move_loop
label right:
"Arrived at right!"
"Wooo! :D"
"I should check the rest now."
$done = "right"
return
label left:
"Arrived at Left"
"Wooo! :D"
"I should check the rest now."
$done = "left"
return
label up:
"Arrived at at up"
"Wooo! :D"
"I should check the rest now."
$done = "up"
return
label down:
"Arrived at at down"
"Wooo! :D"
"I should check the rest now."
$done = "down"
return
I actually had a function doing the checking of the position vs the places but it never worked, so I just put the whole thing on the check label instead =_=;
Now my questions:
1. I want the check to happen after the square is done moving, not after like it's happening now. How do I do this?
2. I want to know how to change the square to a different square WHILE the square is moving and back to the original square after it's done moving. How do I do this? (instinct says it should be something like an event? or checking the velocity of the object and if it's 0 or >0 do the things?)
Thanks in advance for any and all guidance you can give me *bows*