Python Forum
randomly title of game development
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
randomly title of game development
#1
import cmu.graphic
# // % abs() distance() angleTo() getPointInDir() random-value
app.setMaxShapeCount(10000)
app.background=fill=(gradient('darkgreen','royalblue'))
# Fill me in!
app.count=0

app.aa=0
app.ab=0
app.Alph=0
app.stepsPerSecond = 0.5
invader=Group()
invader.add(Circle(50,0,5,fill='red'))
invader.centerX=300
invader.centerY=randrange(100,300)
biginvader=Group()
biginvader.add(
        Arc(200, 175, 60, 60, 270, 180, fill='ghostWhite'),
        Rect(170, 174, 60, 65, fill='ghostWhite'),
        Oval(190, 170, 10, 20, rotateAngle=10),
        Oval(210, 170, 10, 20, rotateAngle=-10),
        Oval(200, 190, 10, 20),
        Arc(165, 200, 35, 30, 265, 90, fill='ghostWhite', rotateAngle=30),
        Arc(235, 200, 35, 30, 5, 90, fill='ghostWhite', rotateAngle=-30),
        Polygon(165, 200, 171, 180, 171, 210, fill='ghostWhite'),
        Polygon(235, 200, 229, 180, 229, 210, fill='ghostWhite'),
        Arc(190, 238, 40, 45, 90, 180, fill='ghostWhite'),
        Arc(210, 238, 40, 30, 90, 110, fill='ghostWhite')
        )
biginvader.centerX=400
biginvader.hight=40
arrow=Group()
app.angle=0
pean=Group()
def arr(start,end):
    arrow.add(Line(40, 160, 40, 110, arrowStart=start,arrowEnd=end))
    
arr(False,True)
# pip install Pillow
# from PIL import Image
# image1=image.open('background.jpg')
# image2=image.open('logo.png').resize((100,100))
# img1.paste(img2,(10,10),mask=img2)
# img2.save('combine.jpg')

def drawHouse(bottom):
    drawhouse=Group()
    drawhouse.add(Rect(150, bottom - 50, 50, 50, fill='pink'),
    Rect(200, bottom - 50, 50, 50, fill='limeGreen'),
    Polygon(140, bottom - 50, 255, bottom - 50, 255, bottom - 100,
            150, bottom - 100, fill='mediumSlateBlue'),
    Polygon(200, bottom - 40, 200, bottom - 60, 225, bottom - 90,
            250, bottom - 60, 250, bottom - 40, fill='lemonChiffon'),
    Polygon(160, bottom - 60, 160, bottom - 70, 170, bottom - 80,
            180, bottom - 70, 180, bottom - 60, fill='lemonChiffon'),
    Rect(175, bottom   - 20, 10, 20, fill='maroon'),
    Rect(150, bottom - 50, 50, 15, fill='cornflowerBlue'),
    Rect(180, bottom - 130, 10, 40, fill='brown'),
    Rect(225, bottom - 20, 12, 20, fill='lightGrey', border='tan', align='center'),
    Rect(225, bottom - 60, 10, 18, fill='lightGrey', border='tan', align='center'),
    Rect(170, bottom - 67, 5, 9, fill='lightGrey', border='tan', align='center'),
    Rect(162, bottom - 15, 6, 12, fill='lightGrey', border='tan', align='center'))
    drawhouse.centerX=20
sunflowers=Group()    
def flo(x,y):
    sunflowers.add(Oval(x-30, y+85, 25, 55, fill=gradient('yellowGreen', 'green', start='top'),
    rotateAngle=-45),
    Oval(x+32, y+45, 25, 55, fill=gradient('yellowGreen', 'green', start='top'),
         rotateAngle=45),
    Line(200, y+145, 200, 220, fill=gradient('yellowGreen', 'green', start='top'),
         lineWidth=25),
    
    Star(200, y-35, 110, 14, fill=gradient('yellow', 'goldenrod'), roundness=80),
    
    
    Oval(200, y-35, 115, 85, fill=gradient('chocolate', 'saddleBrown')))
#print(len(invader.children))
for i in range(10):
    flo(150,0+i*40)
sunflowers.width = 20
sunflowers.height = 40
for i in sunflowers.children:
    for i2 in range(0,400,40):
        i.centerX = 200
        

    
def bullet(x,y):
    b=Group()
    while b.hitsShape(invader)!=True:
        
        b.centerX+=1
    if b.centerX%5==0:
        b.add(Circle(x,y,5,fill='green'))
    for i in b.children:
        if i.centerX>400:
            b.remove(i)
def onStep():
    biginvader.centerX+=1
    
    biginvader.centerY=randrange(0,400)
    biginvader.add(
        Arc(200, 175, 60, 60, 270, 180, fill='ghostWhite'),
        Rect(170, 174, 60, 65, fill='ghostWhite'),
        Oval(190, 170, 10, 20, rotateAngle=10),
        Oval(210, 170, 10, 20, rotateAngle=-10),
        Oval(200, 190, 10, 20),
        Arc(165, 200, 35, 30, 265, 90, fill='ghostWhite', rotateAngle=30),
        Arc(235, 200, 35, 30, 5, 90, fill='ghostWhite', rotateAngle=-30),
        Polygon(165, 200, 171, 180, 171, 210, fill='ghostWhite'),
        Polygon(235, 200, 229, 180, 229, 210, fill='ghostWhite'),
        Arc(190, 238, 40, 45, 90, 180, fill='ghostWhite'),
        Arc(210, 238, 40, 30, 90, 110, fill='ghostWhite')
        )
    #print(bullet.centerX)
    #angle=angleTo(arrow.centerX,arrow.centerY,mouse.centerX,mouse.centerY)
    Label(app.count,360,40,fill='pink')
    
    #invader.toFront()
    app.stepsPerSecond +=-app.stepsPerSecond/2
    #for i in invader.children:
       # i.centerX-=1
    if arrow.centerX<50:
        arrow.centerX>60
    for i in invader.children:
        
        #print(i.centerX)
        getPointInDir(i.right,i.right,app.angle,5)
        while i.centerX>80:
            i.centerX-=3
        if i.hitsShape(arrow):
            app.count+=1
            ma=1
            ma*=-1
            invader.remove(i)
            if ma==1:
                ma=arrowEnd
            elif ma==-1:
                ma=arrowStart
                
                arr(ma)
        if i.hitsShape(pean):
            invader.remove(i)
        if len(invader.children)==0 or app.count>1000:
            Label('victory',200,200,size=50,fill='green')
            app.stop()
        if i.centerX<80 and i.centerY>100 and i.centerY<200:
            Label('zombies ate your brain',200,200,size=40,fill='green')
            app.stop()
    
    
    for i in arrow.children:
        print(i.centerX)
            #kicker.centerX+=-1
            #ball.centerY-3
        for ir in invader.children:
            if distance(i.centerX,i.centerY,ir.centerX,ir.centerY)<10000:
                i_targetY=ir.centerX
                i_targetX=ir.centerY
        #if ((i.targetY != -1) and (i.centerX >= 5)):
            
            # Move the ball towards the target by 3 pixels.
            ### (HINT: The target y is the top of the canvas.)
            ### Place Your Code Here ###
            i.centerX-3 
            angle=angleTo(i.centerY,i.centerX,i_targetY,i_targetX)
            x,y=getPointInDir(i.centerY,i.centerX,angle,3)
            i.centerX=x
            i.centerY=y
        if app.count>50:
            invader.clear()
            Label('victory',200,200,size=50,fill='green')
            app.stop()
def inv(x,y):    
    
            
            
            #(i.centerY)   
    if app.stepsPerSecond>300:
        app.stepsPerSecond=0.5

    if app.stepsPerSecond %10>0 and len(invader.children)<15:
        invader.add(
                RegularPolygon(invader.centerX, invader.centerY - 2, 8, 3, fill=rgb(randrange(0,100),randrange(0,100),randrange(0,100))),
                Rect(invader.centerX - 3, invader.centerY - 10, 6, 5),
                Line(invader.centerX - 3, invader.centerY - 1, invader.centerX + 3, invader.centerY - 1,
                     dashes=(2, 2)),
                Line(invader.centerX - 7, invader.centerY + 3, invader.centerX + 7, invader.centerY + 3, fill=rgb(randrange(0,100),randrange(0,100),randrange(0,100)),
                     dashes=(2, 1)))




def onMouseMove(x, y):
    #a,b=getPoinInDir(80,160,100,)
    pean.add(Circle(80,y+8,20,fill='green'),
    Line(80,160,x,y,fill='black',lineWidth=10),
    Arc(80,y,160,10,45,75,fill='green'),
    Arc(80,160,10,10,125,155,fill='green'))
    for i in pean.children:
        while len(pean)>10:
        
            pean.remove(i)
        
    app.angle=angleTo(arrow.centerX,arrow.centerY,x,y)
    
    #
    arrow.rotateAngle = angleTo(arrow.centerX, arrow.centerY, x, y)
    
    app.aa+=1
    if app.aa%10==0:
        app.ab+=1
    app.Alph+=1
    if app.Alph>7:
        app.Alph-8
    
    for i0 in range(1):
        
        for i in invader.children:
            #if arrow.hitsShape(i)==True:
            
            print(i)
            i.centerX=randrange(1500,3000)*(i0+1)*randrange(80,100)/10000
            i.centerY=i0*randrange(0,400)/(1*i0+1)
            a0=i.centerX-10-app.Alph-(i.centerX-10-app.Alph-(i.centerX-10-app.Alph//1))
            b0=i.centerX-app.Alph-(i.centerX-app.Alph-(i.centerX-app.Alph//1))
            i.centerX=abs(randrange(a0//1,b0//1))+randrange(0,400)
            a=i.centerY-10-app.Alph-(i.centerY-10-app.Alph-(i.centerY-10-app.Alph//1))
            b=i.centerY-app.Alph-(i.centerY-app.Alph-(i.centerY-app.Alph//1))
            i.centerY=abs(randrange(a//1,b//1))+randrange(0,400)
            inv(i.centerX,i.centerY)    
            if abs(i .centerX-sunflowers.centerX)<120:
                invader.remove(i)
            if abs(i.centerY-sunflowers.centerY)<80:
                invader.remove(i)
# god will help you            
def onKeyPress(key):
    if 'x'==key and len(invader.children)>0:
        invader.remove(invader.children[int(randrange(len(invader.children)))])
    if len(invader.children)>20:
        xxx#if len(invader.children)==0:
        Label('victory',200,200,size=50,fill='green')
        app.stop()

    #press this key to win the game!
    if 'k'==(key):
        invader.clear()
        Label('victory',200,200,size=50,fill='green')
        app.stop()

    if 'space'==(key):
        bullet(80,160)
drawHouse(30)
drawHouse(100)
drawHouse(300)
drawHouse(350)
drawHouse(390)
drawHouse(30)
drawHouse(30)
drawHouse(30)
drawHouse(30)
drawHouse(30)
drawHouse(30)
drawHouse(30)
drawHouse(30)
buran write Mar-30-2025, 01:52 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
do you have question?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using randomly generated lists souprqtpie 3 3,258 Apr-19-2019, 07:46 PM
Last Post: souprqtpie
  Randomly generate an even number Truman 17 10,375 Apr-19-2019, 01:47 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020