- from tkinter import *
-
import time
-
import random
-
-
# Set up Root
-
root=Tk()
-
root.geometry("1200x1000")
-
root.title("Aliens Attack!!")
-
-
# Set up Global variables
-
-
global score
-
score=0
-
-
global lives
-
lives=3
-
-
global myRandom1
-
myRandom1=150
-
-
global myRandom2
-
myRandom2=300
-
-
global alienNumber
-
alienNumber=2
-
-
-
# Set up canvases.
-
-
top=Canvas(root,width=1200,height=50, bg="black")
-
top.grid(column=0,row=0)
-
-
playground=Canvas(root,width=1200,height=800,bg='white')
-
playground.grid(column=0,row=1)
-
-
userInterface=Canvas(root,width=1200,height=150, bg="black")
-
userInterface.grid(column=0,row=2)
-
-
# top Canvas Parameters
-
-
scoreLabel=Label(top,text="Score: " + str(score), bg="green", fg="white",font=(50))
-
scoreLabel.place(x=50,y=15)
-
-
livesLabel=Label(top, text="Lives Left: " + str(lives), bg="red", fg="white",font=(50))
-
livesLabel.place(x=1040, y=15)
-
-
# playground Canvas Parameters
-
-
avoidLine=playground.create_line(0,800,1200,800,fill="red")
-
-
shipImage=PhotoImage(file="Ship.png")
-
myShip=playground.create_image(600,530,image=shipImage)
-
-
alienImage=PhotoImage(file="MyAku2.png")
-
Alien=playground.create_image(600,100,image=alienImage)
-
-
Alien2=playground.create_image(400,100,image=alienImage)
-
-
# Bottom Canvas Parameters
-
-
# Functions programmed here....
-
-
# Death of the Ship
-
-
def shipDies():
-
global lives
-
lives -=1
-
livesLabel.config(text="Lives Left: " + str(lives))
-
playground(myShip.destroy)
-
-
-
-
-
# Detects Collision between the ship and alien
-
-
def collisionDetection():
-
sb=playground.bbox(myShip)
-
ab=playground.bbox(Alien)
-
# coming from Right Hand Side
-
if ab[3]>sb[1] and ab[0]>sb[0]< ab[2]:
-
shipDies()
-
# coming from left hand side
-
if ab[0]<sb[0]<ab[2] and ab[1] <sb[1]<ab[3]:
-
shipDies()
-
# coming from left below
-
if ab[1]<sb[2]<ab[3] and ab[0] <sb[3]<ab[2]:
-
shipDies()
-
# coming from right below
-
if ab[1]<sb[0]<ab[3] and ab[0] <sb[3]<ab[2]:
-
shipDies()
-
-
# Aliens Move:
-
-
-
-
-
def AlienMove2():
-
global myRandom1
-
global myRandom2
-
global score
-
myMove=random.randint(myRandom1,myRandom2)
-
playground.move(Alien2,10,5)
-
playground.move(Alien2,-10,5)
-
myX=random.randint(-20,20)
-
myY=random.randint(5,15)
-
playground.move(Alien2,myX,myY)
-
MyCoords=playground.bbox(Alien2)
-
if MyCoords[1]>800:
-
score +=1
-
scoreLabel.config(text= "Score: " + str(score))
-
playground.coords(Alien2,600,50)
-
root.after(myMove,AlienMove2)
-
-
def AlienMove():
-
global myRandom1
-
global myRandom2
-
global score
-
myMove=random.randint(myRandom1,myRandom2)
-
playground.move(Alien,10,5)
-
playground.move(Alien,-10,5)
-
myX=random.randint(-20,20)
-
myY=random.randint(5,15)
-
playground.move(Alien,myX,myY)
-
MyCoords=playground.bbox(Alien)
-
if MyCoords[1]>800:
-
score +=1
-
scoreLabel.config(text= "Score: " + str(score))
-
playground.coords(Alien,600,50)
-
root.after(myMove,AlienMove)
-
-
-
# Key Ship Movements:
-
-
# Right
-
-
def moveRight(event):
-
-
randRight=random.randint(1,8)
-
playground.move(myShip,10,0)
-
playground.move(Alien,randRight,0)
-
collisionDetection()
-
-
# Left
-
-
def moveLeft(event):
-
playground.move(myShip,-10,0)
-
randLeft=random.randint(1,8)
-
playground.move(Alien,-randLeft,0)
-
collisionDetection()
-
-
# Up
-
-
def moveUp(event):
-
playground.move(myShip,0,-10)
-
collisionDetection()
-
-
# Down
-
-
def moveDown(event):
-
playground.move(myShip,0,10)
-
randToward=random.randint(1,5)
-
playground.move(Alien,0,randToward)
-
collisionDetection()
-
-
-
-
# Key Bindings
-
-
playground.bind_all("<Right>", moveRight)
-
playground.bind_all("<Left>", moveLeft)
-
playground.bind_all("<Up>", moveUp)
-
playground.bind_all("<Down>", moveDown)
-
-
-
AlienMove()
-
timing=random.randint(1000,3000)
-
root.after(timing, AlienMove2)
-
root.mainloop()
1 3867
It's all in the error message. You're trying to access something called destroy on an object. But that object has nothing called destroy.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Roy Smith |
last post by:
For the past 6-8 months, I've spent most of my time writing C++ and a
little bit of Java. Both of these languages support and encourage the
use of private data and explicit accessor functions,...
|
by: python newbie |
last post by:
Is there anything that would get in the way of me being able to reference an object attribute, from within a list.
I have:
# one class here
class BackupSet:
fileGroupList =
# ...
|
by: Mike Chirico |
last post by:
Hopefully this will help someone...
Helpful Things to Know about MySQL
Mike Chirico (mchirico@users.sourceforge.net)
Last Updated: Fri Apr 16 11:47:34 EDT 2004
The latest version of this...
|
by: Looks Like Trent |
last post by:
Find a character in a string, at a specified position. How do you do
this? Any help will be appreciated....
|
by: Arjen |
last post by:
Hi,
I have a class with some attributes. For example class person with name as
attribute.
I have add multiple persons in an arraylist.
Now I need a function to get/find a person by the name...
|
by: mike |
last post by:
I was calling a new instance of the dll. I'm not used to using dlls, but that was still pretty ignorant of me. Thanks. I really appreciate all the help from Ben,Bryan, and Armin.
|
by: callre |
last post by:
when i used javascript onchange() the error is coming "object doesnt support this property" my code is-
<script type='text/javascript' language="javascript">
function change()
{ ...
|
by: BiraRai |
last post by:
def getAttributeForProperty(self,rollnumber,attribute):
# attribute have the value _ward
'''
If year is null then use current year.
Returns the value of the attribute for the given roll number...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |