Python Game Programming Tutorial: SpaceWar 1

Поділитися
Вставка
  • Опубліковано 16 жов 2024
  • This is a relatively beginner-friendly tutorial on how to create a classic space shoot'em up using Python, the turtle module, and basic classes. Enjoy!
    NEED HELP?
    🆘 Watch this first and then let me know in the comments below: • Help Me Help You
    ❤️❤️ SHOW SOME LOVE AND SUPPORT THE CHANNEL ❤️❤️
    Click Join and Become a Channel Member Today!
    Channel members can get preferential comment replies, early access to new content, members only live streams, and access to my private Discord.
    ❤️ / @tokyoedtech
    Amazon Affiliate Links
    💻 My Laptop (Asus Zenbook 13): amzn.to/2H3DLbF
    🎙My New Microphone (Blue Yeti Pro): amzn.to/2HmjOgN
    🎙My Old Microphone (Blue Snowball): amzn.to/3j8magh
    🎶My USB Interface (Focusrite Scarlett Solo): amzn.to/3kqyo5m
    Other Affiliate Links
    ⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. www.kite.com/g...
    LINKS
    🗄️ GITHUB: github.com/wyn...
    💬 Follow me on Twitter: / tokyoedtech
    📜 Subscribe to my Newsletter: eepurl.com/dKgM8k
    📝 Check out my Blog: christianthomp...
    ⬇️ Download Geany Editor: www.geany.org
    LEARN MORE PYTHON
    ➡️Space Invaders: • Python Game Programmin...
    ➡️Snake Game: • Python Game Programmin...
    ➡️Pong: • Python Game Programmin...
    ➡️Space War: • Python Game Programmin...
    ➡️Intro to Python (for Java Coders): • Intro to Python for Ja...
    ➡️Space Arena - The Ultimate Python Turtle Graphics Game Tutorial: • Ultimate Python Turtle...
    LEARN MORE JAVA
    ➡️Basic Java for Beginners: • Basic Java 1&2: Commen...
    ➡️Intro to AP Computer Science A: • AP Computer Science Un...
    #Python #Tutorial #Beginner

КОМЕНТАРІ • 278

  • @Friendsshare
    @Friendsshare 6 років тому +14

    "There's actually a little turtle that starts up but because it's black we don't see it." lol

  • @johnp7158
    @johnp7158 6 років тому +5

    just came across this and your channel, very interested! will review again on final space invaders tutorial once i get that far!

  • @nreis11
    @nreis11 8 років тому +2

    Great tutorial to getting acquainted with turtle! Thanks for explaining each step of the process in creating the game. Easy to follow. It helped me in creating a Tron light cycle game with similar mechanics.

  • @vectork3
    @vectork3 5 років тому +1

    I have watched your coding falling skies playlist and space invaders playlist and went from absolute beginner to "non-beginner" in python! But I have no knowledge about classes and objects in Python. So should I start this series(coding space war) if don't know anything about classes and objects? Looking for your reply :)

    • @TokyoEdTech
      @TokyoEdTech  11 місяців тому

      Sorry I missed this. It's worth giving it a shot. I also have a tutorial on OOP on Python - it's probably a good starting point.

  • @abdurrahman.maricar
    @abdurrahman.maricar 4 роки тому +7

    Me: Makes SpaceWar and is very happy
    My friends: Why don't you make a game like PUBG

    • @jackrinderer6790
      @jackrinderer6790 4 роки тому +1

      Christian Thompson this is also way different. That’s using a game engine and we are coding just using python

    • @abdurrahman.maricar
      @abdurrahman.maricar 4 роки тому +1

      @@jackrinderer6790 But those guys don't understand that

  • @JYFilm-gf8yb
    @JYFilm-gf8yb 7 років тому +1

    Honestly, you make the best tutorials on python.

    • @JYFilm-gf8yb
      @JYFilm-gf8yb 7 років тому

      Do you also make tutorial on pygame?

    • @JYFilm-gf8yb
      @JYFilm-gf8yb 7 років тому

      Christian Thompson thanks,

  • @teacherinthailan6441
    @teacherinthailan6441 3 роки тому +3

    For anyone having issues with Python 3 (or the "4 but 5 listed" __init__ "..error), please try the following code. By the way, the "__int__ " NEEDS DOUBLE underscores!! Before AND After!! As it took lots of searching in the comments to find out. Thank you so much to TokyoEd for his amazing tutorials by the way. The best programming teacher out there. P.S...Don't forget to paste or copy the" turtle.done() " at the end. I left too big a gap I know.
    # SpaceWar by @TokyoEd
    # Part 1: Don't forget double "__" before AND after __init__
    import os
    import random
    import turtle

    wn = turtle.Screen
    turtle.forward(0)
    turtle.speed(0)
    turtle.bgcolor("black")
    turtle.ht()
    turtle.setundobuffer(1)
    turtle.tracer(1)\
    class Sprite(turtle.Turtle):
    def __init__(self, spriteshape, color, startx, starty):
    turtle.Turtle.__init__(self, shape = spriteshape)
    self.speed(0)
    self.penup()
    self.color(color)
    self.fd(0)
    self.goto(startx, starty)
    self.speed = 1
    # Create my Sprites
    player = Sprite("triangle", "white", 0, 0)
    turtle.done()

    • @TokyoEdTech
      @TokyoEdTech  3 роки тому

      Yes - double underscores have a different meaning to single underscores!

  • @mcldsn
    @mcldsn 4 роки тому +1

    Hello! I am at 2:47 and when I run my program, the black window with the title "Python Turtle Graphics" and then the rainbow loading thing starts and I have to force stop Python. I am using PyCharm on my mac. In the past I have followed your Pong tutorial and it works perfectly fine but I wonder what is wrong here. Thanks in advance and thanks for these videos.

  • @dealbreaker_13gamez99
    @dealbreaker_13gamez99 4 роки тому +1

    Please make this on Pygame I’m using python 3.7 and turtle doesn’t work in it

  • @vectork3
    @vectork3 5 років тому

    This is very complicated. Specially from line 17 I dont know about anything you are doing. Can you like post a video about OOP in python from begineer to advanced? Also what is the use of the word self?

  • @nair38
    @nair38 4 роки тому

    Hello. This is from 2016, but is this code still up to date? In other tutorials, it says tracer(0) but in this one it says tracer(1) and it doesn't use Screen().

  • @UsTube.
    @UsTube. 9 місяців тому

    Hi, so I am having troubles with my code and it says that "The name Sprite isn't defined" so I was wondering if you could help me.
    import random
    #Import the Turtle module
    import turtle
    turtle.fd(0)
    turtle.speed(0)
    turtle.bgcolor("black")
    turtle.ht()
    turtle.setundobuffer(1)
    turtle.tracer(1)
    class Sprite(turtle.Turtle):
    def __init__(self, spriteshape, color, startx, starty):
    turtle.turtle.__init__(self, shape = spriteshape)
    self.speed(0)
    self.penup()
    slef.color(color)
    sef.fd(0)
    slef.goto(startx, starty)
    self.speed = 1
    #Create my sprites
    player = Sprite("triangle", "white" , 0, 0)


    delay = raw_input("Press enter to finish. > ")

    • @TokyoEdTech
      @TokyoEdTech  9 місяців тому

      The player = Sprite... Part should NOT be indented.

    • @UsTube.
      @UsTube. 9 місяців тому

      Thank you, I figured out that there was a lot of wrong things, like for example the way I spelled “self”. Thank you you are the best programming teacher!

    • @TokyoEdTech
      @TokyoEdTech  9 місяців тому

      @@UsTube. Glad to hear it - keep on codin'!

  • @christianwembonyamalokongo7767
    @christianwembonyamalokongo7767 6 років тому

    hey i need your help the triangle is showing in the turtle
    #import the turtle module
    import turtle
    turtle.fd(0)
    turtle.speed(0)
    turtle.bgcolor("black")
    turtle.ht()
    turtle.setundobuffer(1)
    turtle.tracer(1)
    class sprite(turtle. turtle):
    def _init_(self, spriteshape, color, startx, starty):
    turtle.turtle._init_(self, shape = spriteshape)
    self.speed(0)
    self.penup()
    self.color(color)
    self.fd(0)
    self.goto(startx, starty)
    self.speed = 1
    #create my sprites
    player = sprite("triangle", "white", 0, 0)
    delay = raw_input("press enter to finish. > ")

  • @rodrigonedel339
    @rodrigonedel339 7 років тому

    on the other tutorials you created the screen with this:
    window = turtle.Screen()
    window.bgcolor("black")
    window.title("Maze")
    window.setup(700, 700)
    here you do
    turtle.speed(0)
    turtle.bgcolor("black")
    turtle.ht() #hide turtle
    turtle.setundobuffer(1)
    turtle.tracer(1)
    what's the difference?

  • @giuliocali2598
    @giuliocali2598 4 роки тому

    Hi I know that I'm late but I'd like to understand why the program can't read the sprite. Does anyone of you know if in the 3.8 version there is something different? Anyway I'm sorry for my bad English

  • @shubhamtrivedi6063
    @shubhamtrivedi6063 6 років тому

    TypeError: __init__() takes from 1 to 4 positional arguments but 5 were given .
    I am getting this error how can I resolve it?

  • @thruzero
    @thruzero 4 роки тому

    I'm having issues within the first 2 minutes on python 3. The first time you attempt running the code, I do as well. I have also changed raw_input() into just input(). But when I run it, the Turtle Crashes and freezes. All of my code is written exactly the same, minus changes needed for python 3. So what gives?

    • @thruzero
      @thruzero 4 роки тому

      Believe I may have found a solution. I changed delay = input() to turtle.exitonclick() and it no longer crashes, though obviously clicking anywhere now closes the program

  • @transitionking01
    @transitionking01 4 місяці тому +2

    Invalid decimal literal is showing , Brother how to solve this problem.

    • @TokyoEdTech
      @TokyoEdTech  4 місяці тому +3

      Can you share the code and error message?

  • @sadlife7262
    @sadlife7262 6 років тому

    Hi, everytime that the game open it keeps loading until it says that the game stop working, it seems to happen everytime i put the delay = input("Press enter to finish. >"), what can i do?
    heres the hole code:
    import os
    import random
    import turtle
    turtle.speed(0)
    turtle.bgcolor("black")
    turtle.hideturtle()
    turtle.setundobuffer(1)
    turtle.tracer(0)
    class Sprite(turtle.Turtle):
    def __init__(self, spriteshape, color,startx,starty):
    turtle.Turtle.__init__(self,shape = spriteshape)
    self.speed(0)
    self.penup()
    self.fd(0)
    self.color(color)
    self.goto(startx,starty)
    self.speed = 0
    #Create the sprites
    player = Sprite("triangle","white",0,0)
    #delay
    delay = input("Press enter to quit. >")

  • @mightycain4725
    @mightycain4725 3 роки тому +1

    Great video but i struggle to get it working. Could you do it on the newest version of Python please?

    • @TokyoEdTech
      @TokyoEdTech  3 роки тому

      I doubt I'll revisit this - check out Space Arena - it uses many of the same concepts. That said, this should work in Python 3 - what problem are you having?

  • @stevejohara774
    @stevejohara774 6 років тому

    Super tutorial again (did space invaders first). But turtle.fd -> needed for Mac OSX or else it would show -> You didn't do that for the space invaders and it also worked. What's the difference?

  • @sebastianmackay5657
    @sebastianmackay5657 5 днів тому

    2 minutes in and it already doesn't work, python doesn't like that raw_input, not defined. Does turtle come preinstalled or do we have to install it first?

    • @TokyoEdTech
      @TokyoEdTech  5 днів тому +2

      @@sebastianmackay5657 Change raw_input to input

    • @sebastianmackay5657
      @sebastianmackay5657 5 днів тому

      @@TokyoEdTech thanks

    • @TokyoEdTech
      @TokyoEdTech  5 днів тому

      @@sebastianmackay5657 Sure thing. Keep on codin' and please subscribe!

  • @victorhe9600
    @victorhe9600 4 роки тому +1

    Doesn't the turtle.bgcolor mean wn.color?

  • @manimekalai4118
    @manimekalai4118 4 роки тому

    Sir what additional apps should we install

  • @CR7SIU2012
    @CR7SIU2012 Рік тому +1

    can u help me
    it keeps saying raw_input is not defined and i dont know what to do. here is my code:
    import os
    import random
    import turtle
    turtle.fd(0)
    turtle.speed(0)
    turtle.bgcolor("black")
    delay = raw_input("Press enter to finish. > ")

    • @TokyoEdTech
      @TokyoEdTech  Рік тому +1

      Sure. Change it to input. That was a change between Python 2 and Python 3.

    • @YarekTech
      @YarekTech Місяць тому

      ????

    • @TokyoEdTech
      @TokyoEdTech  Місяць тому

      Change raw_input to input

    • @YarekTech
      @YarekTech Місяць тому +1

      @@TokyoEdTech thank you so much! your videos are awesome!!1

    • @TokyoEdTech
      @TokyoEdTech  Місяць тому

      @@YarekTech Thanks! Keep on codin'...and please subscribe!

  • @nirmitbaria2654
    @nirmitbaria2654 4 роки тому

    Hello Sir, It is coming that "Type error : __init__() takes from 1 to 4 positional arguments but 5 were given
    Can you please help me??
    🙏

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      Hi. Everytime you have a problem, remember this: I’m happy to help, but I need to see the actual code. Please share your code via pastebin.com link so I can download and test it. To learn how, please watch this video and then get back to me: ua-cam.com/video/L6AwVuu6O3Y/v-deo.html Keep on codin’!

  • @anish8373
    @anish8373 4 роки тому +1

    Hi Christian sir ,is this code suitable for Python 3.8and also need to to now how to get pycharm to our laptop . my laptop is very old version will it work with my system .need your help

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      I think it will mostly work in Python 3 - might need a few changes. I wouldn't use Pycharm if you have an old laptop - try Geany instead.

    • @anish8373
      @anish8373 4 роки тому

      @@TokyoEdTech ok sir tq so much

    • @anish8373
      @anish8373 4 роки тому

      @@TokyoEdTech sir can you give me a code for chess please

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому +1

      @@anish8373 I haven't really done chess - I started a version of it, but haven't had a chance to finish it yet. You should be learning how to do things on your own, not just copying from others.

  • @abhishekchaturvedi6348
    @abhishekchaturvedi6348 4 роки тому +2

    i m getting "raw_input is undefined"..please help..

  • @vinceswu8177
    @vinceswu8177 4 роки тому

    Traceback (most recent call last):
    File "C:\Users\Vince Swu\Desktop\Projects\Space War.pyw", line 26, in
    player = Sprite("triangle", "white", 0,0)
    TypeError: __init__() takes at most 4 positional arguments (5 given)
    >>>

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      There is a link in the description labeled “NEED HELP?” Check that out and get back to me. Keep on codin’!

  • @Prostylin
    @Prostylin 2 роки тому

    I'm writing this in 2022 and in python 3.10 IDLE. Is there possibly a different way that would still work to write this code and is more efficient? Thank you.

    • @TokyoEdTech
      @TokyoEdTech  2 роки тому +1

      Hiya. I'm not sure about making it more efficient; however, I would probably not make the Sprite class a child of the Turtle class. If you check out my Space arena tutorial, I only created one turtle and used that to render all the game objects. This simplifies things a bit, and would you allow you to more easily port the game, for example, to Pygame.

  • @malteolausson355
    @malteolausson355 6 років тому

    Hi!
    When i run the script it says:
    TypeError: __init__() takes from 1 to 4 positional arguments but 5 were given
    Here is the script i've written:
    import os
    import random
    # the turtle
    import turtle
    turtle.speed(0)
    turtle.bgcolor("black")
    turtle.ht()
    turtle.setundobuffer(1)
    turtle.tracer(1)
    class Sprite(turtle.Turtle):
    def _init_(self, spriteshape, color, startx, starty):
    turtle.Turtle._init_(self, shape = spriteshape)
    self.speed(0)
    self.penup()
    self.color(color)
    self.fd(0)
    self.goto(startx, starty)
    self.speed = 1
    #Create the sprites
    player = Sprite("triangle" , "white" , 0, 0)
    delay = input ("Press enter to finish. > ")
    please help me with this, otherwise a great tutorial.

  • @nayyarashakira9874
    @nayyarashakira9874 3 місяці тому

    'py' is not recognized as an internal or external command,
    operable program or batch file.
    hey, how do i solve this problem?

    • @TokyoEdTech
      @TokyoEdTech  3 місяці тому

      Can you share your code and the full error message? Copy and paste them here.

  • @davidmakanju2238
    @davidmakanju2238 4 роки тому

    Do you think you can make a video that makes the level and the lives of the player

  • @shaken5690
    @shaken5690 4 роки тому

    Hello i want to tell you that I am a great fan but I have got something to tell you :
    All your tutorials worked on my computer but this one, not at all! I am on windows and on python 3.9. I wrote exactly like you but I don't know why it didn't work :(. Please move on python 3 and make more tutorials! Glad to speak with you! Have a nice day!

  • @TheEliteSharingan
    @TheEliteSharingan 4 роки тому

    Hi Christian! Thank you so much for this tutorial. I'm currently using Python 3.8.5 with Psycharm and I'm having a bit of problem. Every time I try to run my code, the window keeps freezing and saying "Not responding". Do you know if there's anything I can do to fix this?

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      I’m happy to help, but I need to see the actual code. Please share your code via pastebin.com link so I can download and test it. To learn how, please watch this video and then get back to me: ua-cam.com/video/L6AwVuu6O3Y/v-deo.html Keep on codin’!

    • @ryze3024
      @ryze3024 3 роки тому

      The Reason This Happens, Is If You Are Running Python 3, and Trying To Convert The Code, turtle.setundobuffer(1), combined with turtle.tracer(1), don't really like to work well together. If I were you, I would just switch to python 2.7, and then go back to 3.

  • @DanielLi-p5t
    @DanielLi-p5t 11 місяців тому

    Is there a way to make the spaceship not use 8 directional movement but rather have it rotate around smoothly?

    • @TokyoEdTech
      @TokyoEdTech  11 місяців тому

      Yep. Just like you do with dx and dy, you can do the same thing with da (change in angle).

  • @jasonmorillo836
    @jasonmorillo836 6 місяців тому

    how to do the code for winning the game and losing the game like the first vid?

  • @nurajrimal9259
    @nurajrimal9259 4 роки тому

    sir there is the not responding problem how can i fix that ??

    • @nurajrimal9259
      @nurajrimal9259 4 роки тому

      @@TokyoEdTech thankyou sir
      here is the link
      pastebin.com/UXgiYyUd

  • @sahidansari3784
    @sahidansari3784 6 років тому

    I'm having a problem in it, i am doing everything as shown but my turtle wont appear. The error says that _int_ only accepts 1 to 4 positional arguments and i am giving it 5. But it worked just fine for you. Can you help me out? Here is the code -
    #Importing everything
    import os
    import random
    import turtle
    #Starting
    turtle.fd(0)
    turtle.speed(0)
    turtle.bgcolor("sky blue")
    turtle.ht()
    turtle.setundobuffer(1)
    turtle.tracer(1)
    class Sprite(turtle.Turtle):
    def _init_(self, spriteshape, color, startx, starty):
    turtle.Turtle._init_(self, shape = spriteshape)
    self.speed(0)
    self.penup()
    self.color(color)
    self.fd(0)
    self.goto(startx, starty)
    self.speed = 1
    #Creating the sprites
    player = Sprite("triangle", "green", 0, 0)
    And here is the error -
    Traceback (most recent call last):
    File "C:/Users/admin/Desktop/Python/Project/Sky Strike.py", line 26, in
    player = Sprite("triangle", "white", 0, 0)
    TypeError: __init__() takes from 1 to 4 positional arguments but 5 were given
    I am currently working on Python 3.7.0

    • @sahidansari3784
      @sahidansari3784 6 років тому

      Christian Thompson Hey got it again, another silly mistake, I didn't type two underscores before and after init, so that was causing the error. I really do make a lot of mistakes in coding, gotta watch out for it from now on.

    • @thebakerganimations1114
      @thebakerganimations1114 4 роки тому

      @@TokyoEdTech hi Christian can you help ill send you the link

    • @thebakerganimations1114
      @thebakerganimations1114 4 роки тому

      @@TokyoEdTech pastebin.com/fbnstHE2

    • @thebakerganimations1114
      @thebakerganimations1114 4 роки тому

      Thanks so much I can now finally make the game best UA-camr out there

    • @thebakerganimations1114
      @thebakerganimations1114 4 роки тому

      @@TokyoEdTech it's still happening

  • @JP22_007
    @JP22_007 4 роки тому

    Hey!
    I just want to ask, whether this is possible on Python 3.8.5 because I'm currently stuck at 2:17. I tried using the same steps and it doesn't seem to work...
    Here is my code, if you want:
    import os
    import random
    import turtle
    turtle.fd(0)
    turtle.speed(0)
    turtle.bgcolor("black")
    delay=input("Press enter to finish.")
    Please let me know the problem in the code (if there is any).
    Thanks!

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      Hi Jonathan! For the most part it should work fine. What isn't working?

    • @JP22_007
      @JP22_007 4 роки тому

      TokyoEdTech It shows that the turtle part is undefined, because it doesn’t recognise the variable...

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      @@JP22_007 Are you using Pycharm? If so, you can ignore those warnings.

    • @JP22_007
      @JP22_007 4 роки тому

      @@TokyoEdTech I am not using Pycharm. I am using Visual Studio Code. Anyways, it works but it still shows these errors.
      Thanks for helping!

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому +1

      Those are not errors - they are warnings. There were changes in the turtle module from Python 2 to 3 so that is why that happens.

  • @ridgechang8131
    @ridgechang8131 5 років тому

    You are the best teacher!

  • @hemantdhakers3014
    @hemantdhakers3014 5 місяців тому +1

    hii i have created levels in the game but i want to increase the speed of enemys in every level plz help i tried creating a speed increasing function but it didn't helped plz help

    • @TokyoEdTech
      @TokyoEdTech  5 місяців тому

      Hiya - can you share your code (copy and paste here is fine) and I'll take a look?

    • @hemantdhakers3014
      @hemantdhakers3014 5 місяців тому +1

      @@TokyoEdTech
      class Enemy(Sprite):
      def __init__(self, spriteshape, color, startx, starty, initial_speed):
      Sprite.__init__(self, spriteshape,color, startx, starty)
      self.speed = initial_speed
      self.setheading(random.randint(0, 360))
      def move(self):
      self.fd(self.speed)
      # Border checking and changing direction if necessary
      if self.xcor() > 290 or self.xcor() < -290 or \
      self.ycor() > 290 or self.ycor() < -290:
      self.rt(180) # Turn around if hitting the border
      def update_speed(self, new_speed):
      self.speed = new_speed
      def show_status(self):
      self.pen.clear()
      self.pen.undo()
      self.pen.penup()
      self.pen.goto(-300, 310)
      self.pen.write("Level: {} Score: {}".format(self.level, self.score), font=("Arial", 16, "normal"))
      if self.score >= 300 * self.level:
      self.level += 1
      #self.score -= 100 * (self.level - 1) # Adjust score for next level
      #self.enemies.append(Enemy("circle", "red", -100, 0))
      self.pen.goto(0, 0)
      self.pen.write("Level Up! You've reached Level {}".format(self.level), align="center",
      font=("Arial", 24, "normal"))
      time.sleep(1)
      self.update_colors()
      self.update_enemy_speed()
      def update_enemy_speed(self):
      new_speed = self.initial_enemy_speed + (self.level - 1) * self.enemy_speed_increment
      for enemy in self.enemies:
      enemy.update_speed(new_speed)
      print("Enemy speed updated to:", new_speed)

    • @hemantdhakers3014
      @hemantdhakers3014 5 місяців тому +1

      plz take a look and give some solution

    • @TokyoEdTech
      @TokyoEdTech  5 місяців тому +1

      @@hemantdhakers3014 Did you copy and paste your code?

    • @hemantdhakers3014
      @hemantdhakers3014 5 місяців тому

      @@TokyoEdTech
      class Enemy(Sprite):
      def __init__(self, spriteshape, color, startx, starty, initial_speed):
      Sprite.__init__(self, spriteshape,color, startx, starty)
      self.speed = initial_speed
      self.setheading(random.randint(0, 360))
      def move(self):
      self.fd(self.speed)
      # Border checking and changing direction if necessary
      if self.xcor() > 290 or self.xcor() < -290 or \
      self.ycor() > 290 or self.ycor() < -290:
      self.rt(180) # Turn around if hitting the border
      def update_speed(self, new_speed):
      self.speed = new_speed
      def show_status(self):
      self.pen.clear()
      self.pen.undo()
      self.pen.penup()
      self.pen.goto(-300, 310)
      self.pen.write("Level: {} Score: {}".format(self.level, self.score), font=("Arial", 16, "normal"))
      if self.score >= 300 * self.level:
      self.level += 1
      #self.score -= 100 * (self.level - 1) # Adjust score for next level
      #self.enemies.append(Enemy("circle", "red", -100, 0))
      self.pen.goto(0, 0)
      self.pen.write("Level Up! You've reached Level {}".format(self.level), align="center",
      font=("Arial", 24, "normal"))
      time.sleep(1)
      self.update_colors()
      self.update_enemy_speed()
      print("Level increased to:", self.level)
      def update_enemy_speed(self):
      new_speed = self.initial_enemy_speed + (self.level - 1) * self.enemy_speed_increment
      for enemy in self.enemies:
      enemy.update_speed(new_speed)
      print("Enemy speed updated to:", new_speed)

  • @Sp4nkyWanky
    @Sp4nkyWanky 4 роки тому

    hi, it says
    ModuleNotFoundError: No module named 'tkMessageBox'

    • @Sp4nkyWanky
      @Sp4nkyWanky 4 роки тому

      Oh hi again its working now 😊.
      I have a question why does it lag everytime i shoot? Is it because of my laptop?

  • @sedwars3616
    @sedwars3616 4 роки тому

    The code player = Sprite("triangle", "white", 0, 0) is not working pls tell me why.
    and here is the error message : Traceback (most recent call last):
    File "C:/Users/admin/Desktop/Space war.py", line 23, in
    player = Sprite("triangle", "white", 0, 0)
    TypeError: __init__() takes at most 4 arguments (5 given)

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      Where's the code?

    • @sedwars3616
      @sedwars3616 4 роки тому

      @@TokyoEdTech import os
      import random
      import turtle
      turtle.fd(0)
      turtle.speed(0)
      turtle.bgcolor("black")
      turtle.ht()
      turtle.setundobuffer(1)
      turtle.tracer(1)
      class Sprite(turtle.Turtle):
      def _init_(self, spriteshape, color, starx, starty):
      turtle.Turtle._init_(self, shape = spriteshape)
      self.speed(0)
      self.penup()
      self.color(color)
      self.fd(0)
      self.goto(starx, starty)
      self.speed = 1

      player = Sprite("triangle", "white", 0, 0)
      delay = raw_input("Press enter to finish. > ")

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      Do you have TWO underscores before and after init?

    • @sedwars3616
      @sedwars3616 4 роки тому

      @@TokyoEdTech Yeah one before init and one after init

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      You need 2 before and 2 after (4 total).

  • @hemantdhakers3014
    @hemantdhakers3014 8 місяців тому

    i am not able to run sound in windows 11 can you plz help it's urgent.plz share code of sound in windows

    • @TokyoEdTech
      @TokyoEdTech  8 місяців тому

      Howdy. Check out this video: ua-cam.com/video/1FyqFqAN9UM/v-deo.htmlsi=DjHbgi7kbbcHgP98

  • @jiyometrik
    @jiyometrik 6 років тому +1

    Can you convert to Python 3. New here

  • @krishnasudan3410
    @krishnasudan3410 4 роки тому

    Sir, when will you add the full part including lives and game over screen.

    • @krishnasudan3410
      @krishnasudan3410 4 роки тому

      @@TokyoEdTech sir please update with more parts also.

    • @krishnasudan3410
      @krishnasudan3410 4 роки тому

      @@TokyoEdTech yes sir

    • @krishnasudan3410
      @krishnasudan3410 4 роки тому

      @@TokyoEdTech yes sir I have completed them all.

    • @krishnasudan3410
      @krishnasudan3410 4 роки тому

      @@TokyoEdTech a game over and play again screen when the score become zero

    • @krishnasudan3410
      @krishnasudan3410 4 роки тому

      @@TokyoEdTech the score is going to negative and nothing happens

  • @PrabirsGallery
    @PrabirsGallery 3 роки тому +1

    Which software have you used

    • @TokyoEdTech
      @TokyoEdTech  3 роки тому +1

      You’re in luck - I’ve made a video about this exact topic. Enjoy! ua-cam.com/video/4bL-lCP2tec/v-deo.html

    • @PrabirsGallery
      @PrabirsGallery 3 роки тому +1

      @@TokyoEdTech thank you sir

  • @annajames6226
    @annajames6226 6 років тому +1

    which IDE are you using?

  • @squirky8006
    @squirky8006 4 роки тому

    can you make one for python 3?

  • @sheenajoycediaz1215
    @sheenajoycediaz1215 7 років тому

    TypeError: __init__() takes from 1 to 4 positional arguments but 5 were given
    please help me

    • @sheenajoycediaz1215
      @sheenajoycediaz1215 7 років тому +1

      import os
      import random
      #Import the Turtle module
      import turtle
      turtle.fd(0)
      turtle.speed(0)
      turtle.bgcolor("black")
      turtle.ht()
      turtle.setundobuffer(1)
      turtle.tracer(1)
      class Sprite(turtle.Turtle):
      def _init_ (self, spriteshape, color, startx, starty):
      turtle.Turtle._init_(self, shape = spriteshape)
      self.speed(0)
      self/penup()
      self.color(color)
      self.fd(0)
      self.goto(startx, starty)
      self.speed = 1
      #Create my sprites
      player = Sprite("triangle","white",0, 0)

      delay = input("Press enter to finish. > ")

    • @montacti6353
      @montacti6353 6 років тому

      same thing what do u do to fix it!?

  • @sontapaa11jokulainen94
    @sontapaa11jokulainen94 6 років тому

    AttributeError: 'Sprite' object has no attribute '_shown'
    pls help

  • @randtube401
    @randtube401 4 роки тому

    I really wanted to create the game, but I can't the code doesn't really all work well in python 3 : (

    • @randtube401
      @randtube401 4 роки тому

      @@TokyoEdTechThe first error message I got is the raw_input one. Isn't that working in python3?

    • @randtube401
      @randtube401 4 роки тому

      @@TokyoEdTech But, I guess I'll make it in python2 I'll try to make it first again :). By the way, thanks for your attention and help!

    • @randtube401
      @randtube401 4 роки тому

      @@TokyoEdTech ooh, thanks

  • @geoffyang1766
    @geoffyang1766 6 років тому +1

    I'm getting an error and all turtle._____ turtle has no fd or speed member.
    Here is the error message: Python37-32\lib\turtle.py", line 2488, in __init__
    self._setshape(shapeIndex)
    File "C:\Users\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 2502, in _setshape
    self._type = screen._shapes[shapeIndex]._type
    KeyError: 'tringle
    '
    here is the program: pastebin.com/fvkcrJp0

    • @thatguy7578
      @thatguy7578 6 років тому

      Vrenium I have the same problem I think

  • @madhuneupane7318
    @madhuneupane7318 4 роки тому

    Thank you so much 😊

  • @hemantdhakers3014
    @hemantdhakers3014 5 місяців тому +1

    hii plz help me sir
    how to end this game using enter

    • @TokyoEdTech
      @TokyoEdTech  5 місяців тому +1

      Hiya,
      If you follow the tutorial, you should be able to get most of the way there.
      We already have:
      turtle.onkey(bullet.fire, "space")
      So, you can try this:
      turtle.onkey(exit, "return")
      If you get a keysym error, try:
      turtle.onkey(exit, "Return")

    • @hemantdhakers3014
      @hemantdhakers3014 5 місяців тому +1

      @@TokyoEdTech on pressing enter program is stopped but
      It is showing not responding when I want to cross the program

  • @Joshua-dl3ns
    @Joshua-dl3ns 7 років тому

    Can you give me the link for downloading the python turtle module?

    • @Joshua-dl3ns
      @Joshua-dl3ns 7 років тому

      Christian Thompson ok thx

    • @jiyometrik
      @jiyometrik 6 років тому

      It's already built-in to python

  • @sriharikrishnan2110
    @sriharikrishnan2110 4 роки тому

    which code editor r u using bro!!

    • @penny4839
      @penny4839 4 роки тому

      I think he using visual studio code.

  • @sheenajoycediaz1215
    @sheenajoycediaz1215 7 років тому

    Traceback (most recent call last):
    File "C:/Users/Shara jane diaz/AppData/Local/Programs/Python/Python36-32/SpaceWar.py", line 26, in
    player = Sprite("triangle", "white", 0,0)
    TypeError: __init__() takes at most 4 arguments (5 given)
    >>>

  • @faloudealekk
    @faloudealekk 2 місяці тому

    sorry but can what python is that

  • @factsnhien
    @factsnhien 3 роки тому

    Where you got the image from?

  • @大哥大-z6x
    @大哥大-z6x 4 роки тому

    when I type in “input random” it is gray

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      It should be "import random".
      Also, save your file first.

  • @r4ndom-here
    @r4ndom-here 8 місяців тому

    it says "'raw_input' is not defined"

  • @ScorpionCA
    @ScorpionCA 7 років тому

    What program are you using?

    • @UsTube.
      @UsTube. 9 місяців тому

      Python

    • @ScorpionCA
      @ScorpionCA 9 місяців тому

      ah, thank you for replying so quickly lol, in the time since I posted that comment, I learned Python, C++, Java, Javascript, PHP, HTML, CSS, C# and am in a college course for software engineering@@UsTube.

    • @UsTube.
      @UsTube. 9 місяців тому

      @@ScorpionCA 6 years ago😂

    • @TokyoEdTech
      @TokyoEdTech  9 місяців тому

      Time flies!

  • @gammadeptrai3610
    @gammadeptrai3610 3 роки тому +2

    can get the link

    • @TokyoEdTech
      @TokyoEdTech  3 роки тому

      Check here: christianthompson.com/node/47

  • @johnniegilkerson4724
    @johnniegilkerson4724 8 місяців тому +1

    NameError: name 'raw_input' is not defined

    • @TokyoEdTech
      @TokyoEdTech  8 місяців тому

      Hi. Change raw_input to input

  • @nehavipul
    @nehavipul 4 роки тому

    if the raw_input doesnt work for normal python try using pycharm it works for me

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому +1

      raw_input is for Python 2.x. Change it to input for Python 3.x.

    • @nehavipul
      @nehavipul 4 роки тому

      @@TokyoEdTech ok but now i have another problem when i type raw input it works but now since weve written while true it doesnt show up

    • @nehavipul
      @nehavipul 4 роки тому

      @@TokyoEdTech also remember coding and gaming the guy u subbed to well this is my other account coding and gamings my main account

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      @@nehavipul Hard to keep up! I need to see the actual code. Please share your code via pastebin.com link so I can download and test it. To learn how, please watch this video and then get back to me: ua-cam.com/video/L6AwVuu6O3Y/v-deo.html Keep on codin’!

    • @nehavipul
      @nehavipul 4 роки тому

      @@TokyoEdTech ok

  • @factsnhien
    @factsnhien 3 роки тому

    We you got the image from

    • @TokyoEdTech
      @TokyoEdTech  3 роки тому +1

      Usually I use openclipart.org

  • @x_fracture2936
    @x_fracture2936 3 роки тому

    cant seem to use it... i have mac osx though

    • @TokyoEdTech
      @TokyoEdTech  3 роки тому

      Weird - I'd have to see the code and the error message to be able to help.

  • @amishh7887
    @amishh7887 4 роки тому

    sprite color is not working

  • @BekBrace
    @BekBrace 4 роки тому

    Isn’t this asteroids ? I’m preparing the same project with JavaScript - cheers from Poland

  • @noir66146
    @noir66146 8 місяців тому +1

    wonderful

  • @dronepilotsa3562
    @dronepilotsa3562 7 місяців тому

    Name error '__init__' is not defined please help.

    • @TokyoEdTech
      @TokyoEdTech  7 місяців тому +1

      Hmmm...can you share all the code here?

    • @kilianendres7976
      @kilianendres7976 7 місяців тому +1

      Have you written "def" infront of __init__? You define the constructor, dont call it.

  • @Ez2code
    @Ez2code 7 місяців тому +1

    can you please please write the whole code of the game

    • @TokyoEdTech
      @TokyoEdTech  7 місяців тому +2

      You're in luck - here it is! github.com/wynand1004/Projects/tree/master/SpaceWar

    • @inzaneaztec
      @inzaneaztec 6 місяців тому +1

      @@TokyoEdTech GOAT

    • @TokyoEdTech
      @TokyoEdTech  6 місяців тому

      @@inzaneaztec LOL - thanks!

  • @GabCostaSilva
    @GabCostaSilva 6 років тому +1

    What text editor is that? Nice video, btw.

  • @Odon386
    @Odon386 9 місяців тому

    where an i download this phyton coding program??

    • @TokyoEdTech
      @TokyoEdTech  9 місяців тому +1

      These days I'm using Geany: www.geany.org/

  • @sfreud15
    @sfreud15 3 роки тому

    Can you run this on python idle

  • @Emmett-Scratch
    @Emmett-Scratch Рік тому

    does this only work on Mac? because I use windows to do python code

    • @TokyoEdTech
      @TokyoEdTech  Рік тому +1

      Mostly everything except the sound code is cross platform.

  • @sakman27cap45
    @sakman27cap45 4 роки тому

    They say raw_input is not defined 😟

    • @sakman27cap45
      @sakman27cap45 5 місяців тому

      @Susamogus557 yeah bro I did that, that was like more than 3 years ago, and it is with the new python

  • @amishh7887
    @amishh7887 4 роки тому

    I sent you and I'm working on python 3.8.2

  • @sakman27cap45
    @sakman27cap45 4 роки тому

    i guess i have to do input instead of raw input

  • @gummies579
    @gummies579 3 роки тому

    I am doing this on phone
    It says this error
    File "/data/user/0/ru.iiec.pydroid3/files/temp_iiec_codefile.py", line 8
    turtle.bgcolor(''black'')
    ^
    SyntaxError: invalid syntax

  • @sujalpandey4982
    @sujalpandey4982 3 роки тому +2

    Can u do a GODOT game in future ❤️

    • @TokyoEdTech
      @TokyoEdTech  3 роки тому +3

      Maybe someday - definitely want to play around with it!

    • @sujalpandey4982
      @sujalpandey4982 3 роки тому

      @@TokyoEdTech yeah it would be great❤️

  • @charliebrown1947
    @charliebrown1947 2 місяці тому

    id love to watch this but the white background is burning my retinas. if you ever decide to make a video in dark mode, let me know!

    • @TokyoEdTech
      @TokyoEdTech  2 місяці тому +2

      @@charliebrown1947 #firstworldproblems

    • @charliebrown1947
      @charliebrown1947 2 місяці тому

      @TokyoEdTech 50 inch oled HDR 4k screens are a hell of a drug

  • @simonechannel4148
    @simonechannel4148 3 місяці тому

    Python turtle graphics is not responding. Help

    • @TokyoEdTech
      @TokyoEdTech  3 місяці тому

      I'll respond to your other post on the same subject.

    • @subtheman2136
      @subtheman2136 Місяць тому

      @@TokyoEdTech He said you need a Mac OS to run the program lol

    • @TokyoEdTech
      @TokyoEdTech  Місяць тому

      @@subtheman2136 It will work on Mac, Windows, and Linux.

  • @noobtimespronoobtimespro1379
    @noobtimespronoobtimespro1379 3 роки тому

    python2 or python3 just started to watch

  • @vj4007
    @vj4007 4 роки тому

    Can you please make this game in python 3

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      For the most part, it will work in Python 3. Give it a shot and see what happens.

    • @vj4007
      @vj4007 4 роки тому

      @@TokyoEdTech Okay, but I don't know the syntax for python 2 😕

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      @@vj4007 Just watch the video and try it.

    • @vj4007
      @vj4007 4 роки тому

      @@TokyoEdTech Alright, let's see what happens.😁

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      @@vj4007 Good luck!

  • @krishnasudan3410
    @krishnasudan3410 4 роки тому +1

    Please make this game with python 3.8, please it's my request

    • @krishnasudan3410
      @krishnasudan3410 4 роки тому

      @@TokyoEdTech I'm confused that is there any syntax change in python 2.7 and 3.8

    • @krishnasudan3410
      @krishnasudan3410 4 роки тому

      @@TokyoEdTech like in other games we have used
      wn = turtle.Screen()
      And other functions

    • @krishnasudan3410
      @krishnasudan3410 4 роки тому

      @@TokyoEdTech Actually I'm trying this from a week, and also I have to submit a python game for my project based on python 3.8 and I am getting error while trying the new one, that is why I think that you are the only one who can help me.

    • @krishnasudan3410
      @krishnasudan3410 4 роки тому

      @@TokyoEdTech Can you please make a new one video just changing the syntax or please provide me the code, I have tried very much but not able to get the write one

  • @shlomibenbaron569
    @shlomibenbaron569 5 років тому

    your great !

  • @havenanimates1979
    @havenanimates1979 4 роки тому

    I'm getting the following error, which 2 others have posted. Per your instructions, here is my code -
    pastebin.com/37ct3nf5
    Using 3.8.6 if that helps.
    Traceback (most recent call last):
    File "C:/Users/Eli/Documents/coding/python/space fight.py", line 26, in
    player = Sprite("triangle", "white", 0, 0)
    TypeError: __init__() takes from 1 to 4 positional arguments but 5 were given

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      For def __init__ you need TWO underscores before AND after the init

    • @havenanimates1979
      @havenanimates1979 4 роки тому

      @@TokyoEdTech thank you

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      @@havenanimates1979 You're welcome.

  • @Indianblader
    @Indianblader 2 роки тому +1

    nothing name raw_input

  • @sobrinhodopave
    @sobrinhodopave 5 років тому

    THe Brazilian Laught you man - plz send me code!

  • @pythonicperson7216
    @pythonicperson7216 4 роки тому

    me seeing christian doesnt use wn = turtle.Screen() for the window setup
    *cursed*

  • @paradox9879
    @paradox9879 4 роки тому

    I hate python Because python have so much errors

    • @TokyoEdTech
      @TokyoEdTech  4 роки тому

      A) It's not the language, it's the programmer.
      B) This tutorial is not beginner friendly - I'd try something easier and then come back to this.

    • @richboy3332
      @richboy3332 3 роки тому

      me too

  • @anthonyzhu7464
    @anthonyzhu7464 9 місяців тому

    My code keeps saying:TypeError: Turtle.__init__() takes from 1 to 4 positional arguments but 5 were given here is my code
    import os
    import random
    import turtle
    turtle.fd(0)
    turtle.speed(0)
    turtle.bgcolor("black")
    turtle.ht()
    turtle.setundobuffer(1)
    turtle.tracer(1)
    class Sprite(turtle.Turtle):
    def _init_(self, spriteshape, color, startx, starty):
    turtle.Turtle._init_(self, shape = spriteshape)
    self.speed(0)
    self.penup()
    self.color(color)
    self.fd(0)
    self.goto(startx, starty)
    self.speed= 1
    player=Sprite("triangle", "white", 0, 0)

    • @TokyoEdTech
      @TokyoEdTech  9 місяців тому

      Hi there.
      Do you have two underscores before and after init?

    • @anthonyzhu7464
      @anthonyzhu7464 9 місяців тому

      No @@TokyoEdTech

    • @anthonyzhu7464
      @anthonyzhu7464 9 місяців тому +1

      Never mind, thank you

    • @TokyoEdTech
      @TokyoEdTech  9 місяців тому

      @@anthonyzhu7464 You're welcome.

  • @Nawn_ni_onda
    @Nawn_ni_onda 5 місяців тому

    Help me resolve the issue
    Traceback (most recent call last):
    File"C:\Users\M.Waleed Mustafa\PycharmProjects\pythonProject\main.py", line 18,in
    Player = Sprite("triangle", "white", 0,0)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: Turtle.__init__() takes from 1 to 4 positional arguments but 5 were given
    Process finished with exit code 1

    • @TokyoEdTech
      @TokyoEdTech  5 місяців тому +1

      Can you share all of the code so I can take a look?

    • @NutcasePodcast77
      @NutcasePodcast77 27 днів тому

      ​@@TokyoEdTechI'm having this issue to is there a way to send you screenshots of it please

    • @NutcasePodcast77
      @NutcasePodcast77 27 днів тому

      I'm stuck on it and can't move further

    • @TokyoEdTech
      @TokyoEdTech  27 днів тому

      @@NutcasePodcast77 You can copy and paste the code and error message here.

    • @NutcasePodcast77
      @NutcasePodcast77 27 днів тому

      @@TokyoEdTech will do thanks sir