Ultimate Python Turtle Graphics Tutorial: Space Arena 4 (Player Class)

preview_player
Показать описание


NEED HELP?

❤️❤️ 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.

Amazon Affiliate Links

Other Affiliate Links

LINKS

LEARN MORE PYTHON

LEARN MORE JAVA

#Python #Tutorial #Beginner
Рекомендации по теме
Комментарии
Автор

Awesome! Looking forward to the rest of the tutorial. Warp speed commander!

GalaxisStark
Автор

Hey great video! I really love your content creating, because you make it really easy to understand, even if this game is for intermediate programmers. Keep up the good work!

thelittledragon
Автор

Its funny that I'm learning about inheritance just now even though I have had 3 articles on classes and inheritance on my reading list all summer. Great video.

Hyvexx
Автор

This is great. You start out old school and then upgrade bit by bit to OOPS. Really helps guys like me who come from procedural languages like C.

arifkasim
Автор

What computer are you using? I am using a Dell Latitude E5550 running Linux Ubuntu 18.04 Bionic Beaver. For some reason, the rotation speeds for me are insanely fast, so I have to set the speed values to 2.

gardener_leaftail
Автор

Honestly, how do you not have like a million subscribers? I need to know🤔

edwardchen
Автор

So quick question, what times do you usually upload around?

gardener_leaftail
Автор

You are the best teacher and you are awesome and you are like God to me

MABTRG
Автор

Classes...
One of the most useful parts of Python...
💯💯💯💯

SkyFly
Автор

hey can you please do a fast vid about true/false i need it to comp my program yes/no Question in python 3 please i need it...and sorry for bothering thanks for your time love you :) <3

estivaou
Автор

instead of changing the numbers, we can add and timer like this
while True:
time.sleep(0.01)
# and followed by the game stuff

keerthivarmanprakash
Автор

Excellent explanation!
Can you say what is the need of :
Sprite.__init__(self, 0, 0, shape, color)
Why need it?
What will happen without this raw.
Is there another way to do this program without this raw?
Thanks allot:
Moshco

Great_Moshco
Автор

Hi TokyoEdtech in python 3 for the keyboard binding it is onkey press and for python 2 it is onkey and for release onkeyrelease for python 3 what about for python 2 ?? Please help

bereketseyum
Автор

at the start i thought there dubstep music coming out lol

pythonicperson
Автор

Those sprites and the player are going fast! Shall i change the dx and dy by negative or positive? 🐱‍💻🐱‍🏍

sakmancap
Автор

Hey TokoyoEdTech, my enemy and my powerups are to fast, how do I change the speed of that, I tried self.speed in the Sprite class but nothing happend

justsomepikachu
Автор

Is there anyway to exchange the directional key key binding with wasd key binding?

famillelegrand
Автор

and there are millions of errors poping up when i close the window that i had a bluescreen and my 3090 does't even work properly is there a way to fix it?

IIVB
Автор

Is it possible that my computer needs the da 0.5 and -0.5?

oliverlacika
Автор

For some reason, my enemy is the one that's rotating, not the player character.
import turtlimport turtle

screen = turtle.Screen()
ScreenWidth = 800
ScreenHeigth = 600
screen.setup(ScreenWidth, ScreenHeigth)
screen.title("SPACE ARENA")
screen.bgcolor("black")
screen.tracer(0)

pen = turtle.Turtle()
pen.speed()
pen.color("white")
pen.hideturtle()
pen.penup()




class Sprite():
def __init__(self, x, y, shape, color):
self.x = x
self.y = y
self.shape = shape
self.color = color
self.dx = 0
self.dy = 0

def update(self):
self.x += self.dx
self.y += self.dy
def render(self, pen):
pen.goto(self.x, self.y)
pen.shape(self.shape)
pen.color(self.color)
pen.stamp()
pen.setheading(0)
#seperate player class because it's different than the power ups and enemies. You could duplicate the above class. or call part of the class inside of another class

class Player(Sprite):
def __init__(self, x, y, shape, color):
Sprite.__init__(self, 0, 0, shape, color)
self.lives = 3
self.score = 0
self.heading = 90
self.da = 0

def rotate_left(self):
self.da = 1
def rotate_right(self):
self.da = -1
def stop_rotation(self):
self.da = 0
def move_forward(self):
self.heading += 10
def update(self):
self.x += self.dx
self.y += self.dy
self.heading += self.da
def render(self, pen):
pen.goto(self.x, self.y)
pen.shape(self.shape)
pen.color(self.color)
pen.stamp()
pen.setheading(self.heading)




player = Player(0, 0, "triangle", "white")

enemy = Sprite(0, 100, "square", "red")

powerup = Sprite(0, -100, "circle", "blue")

Sprites = []
Sprites.append(player)
Sprites.append(enemy)
Sprites.append(powerup)



#keyboard binding
screen.listen()
screen.onkeypress(player.rotate_left, "Left")
screen.onkeypress(player.rotate_right, "Right")
screen.onkeypress(player.move_forward, "Up")
screen.onkeyrelease(player.stop_rotation, '')

Running = True
while Running:
pen.clear()

for Sprite in Sprites:
Sprite.update()



#render sprites
for Sprite in Sprites:
Sprite.render(pen)



screen.update()e

theadventurousprogrammer