Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def draw_ninja(pos,width):
- #draw a ninja as requested such that pos is the righ-down position of the ninja
- #and width is the size of the bounding box of the ninja (and should be used to determine
- #the unit size of the squares in the bounding box
- c=width//6
- w=get_value_of("_w")
- print(pos)
- """
- corps=create_rectangle(pos,c,c,(255,0,0))
- jambe1=create_rectangle(pos,c,c,(255,0,0))
- bandeau=create_rectangle(pos,c,c,(255,0,0))
- """
- jambe2=create_rectangle((pos[0],pos[1]),c,c,(0,0,0))
- """
- casebandeau1=create_rectangle((pos,w["height"]-c*6),c,c,(255,0,0))
- casebandeau2=create_rectangle(pos,c,c,(255,0,0))
- oeil=create_rectangle(pos,c,c,(255,0,0))
- draw_rectangle(corps)
- draw_rectangle(jambe1)
- draw_rectangle(bandeau)
- """
- draw_rectangle(jambe2)
- """
- draw_rectangle(casebandeau1)
- draw_rectangle(casebandeau2)
- draw_rectangle(oeil)
- """
- return
- def draw_stick(pos,lenght,thickness):
- #draw a vertical stick of a given thickness such that the bottom of the stick is at position pos and
- #it goes up until the given lenght
- return
- def draw_platforms(min_gap, min_platform_width, platform_height):
- #draw two platforms of height platform_height
- #the first platform starts from the left border of the window and is exactly of width min_platform_width
- #there is a minimal gap of min_gap between the two platforms
- #moreover the second platform has a random size respecting the min_platform_width and the fact that
- #a minimal gap of min_gap with the right border of the window should exist
- #The second platform has a 10x10 square right in the top middle to indicate the perfect lenght for the stick
- #The function returns the position of the top right corner of the first platform and the perfect distance for the stick
- return ((0,0),0)
- def draw_score():
- #draw a random number in [0,10] at the top-center of the window
- _w=get_value_of("_w")
- s=randrange(0,10)
- score=create_text(str(s), (_w["width"]/2,0), (255,0,0), 20, textanchor="topmiddle")
- draw_text(score)
- return
- def draw():
- #should not been modified
- _state=get_value_of("_state")
- if _state=="init":
- print("init")
- set_value_of("_w",initialize(randrange(200,600),randrange(400,600),'Ninja'))
- set_value_of("_state","draw")
- set_value_of("_cpt",0)
- return
- if _state=="draw":
- set_value_of("_cpt",get_value_of("_cpt")+1)
- if get_value_of("_cpt")>5:
- set_value_of("_state","destroy")
- return
- w=get_value_of("_w")
- fill_window((255,255,255))
- (p,d)=draw_platforms(w["width"]//10,2*w["width"]//10,w["height"]//10)
- draw_ninja(p,w["width"]//10)
- draw_stick(p,d,w["width"]//100)
- draw_score()
- return
- if _state=="destroy":
- uninitialize()
- return
- def main_app():
- set_value_of("_state","init")
- repeat_process(3000,draw)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement