Python Game Programming Tutorial: SpaceWar 6

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
Рекомендации по теме
Комментарии
Автор

i love seeing this and having the explainative commentary.

it feels like im playing the game in a new way. its phenomenal !

noir
Автор

Just starting at college to become a developer here in Brazil, these videos of yours are the best to get use to programing even do we had only used C. Thanks man!

otavioandreas
Автор

At this point it reminds me more of Asteroids than Space Invaders.

mrsmiley
Автор

First! hey man i see the code has improved quite a bit from the space invaders video! i was able to go back and fix alot of things that bugged me, like the bullet sticking on firing.
I tell everyone about your vids

creamygoodness
Автор

ha, never mind I figure it out, thanks

dajean
Автор

I was following the code and I got lost cause I had to go out of town, do you have the whole file to study it? thanks Bro, great material!!!

dajean
Автор

Could you by chance make a tutorial for a 2 player space war, i was thinking myself if ways that could work but i just kept getting confused, you don't have to if you don't want to bc I'm obviously commenting this like 8 years after this was posted, so you probably won't respond, but it's just an Idea❤

Bluething
Автор

wait how do you get your bullet not to lag cause mine does. did i do anything wrong?:
import os
import random

#import turtle module
import turtle
turtle.fd(0)
turtle.speed(0)
turtle.bgcolor("black")
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

def move(self):
self.fd(self.speed)

#boundarydetection
if self.xcor() > 290:
self.setx(290)
self.rt(60)

if self.xcor() < -290:
self.setx(-290)
self.rt(60)

if self.ycor() > 290:
self.sety(290)
self.rt(60)

if self.ycor() < -290:
self.sety(-290)
self.rt(60)

def is_collision(self, other):
if (self.xcor() >= (other.xcor() -20)) and \
(self.xcor() <= (other.xcor() + 20)) and \
(self.ycor() >= (other.ycor() - 20)) and \
(self.ycor() <= (other.ycor() + 20)):
return True
else:
return False

class Player(Sprite):
def __init__(self, spriteshape, color, startx, starty):
Sprite.__init__(self, spriteshape, color, startx, starty)
self.speed = 3
self.lives = 3

def turn_left(self):
self.lt(25)

def turn_right(self):
self.rt(25)

def accelerate(self):
self.speed += 0.5

def deccelerate(self):
self.speed -= 0.5

class Enemy(Sprite):
def __init__(self, spriteshape, color, startx, starty):
Sprite.__init__(self, spriteshape, color, startx, starty)
self.speed = 6
self.setheading(random.randint(0, 360))

class Missile(Sprite):
def __init__(self, spriteshape, color, startx, starty):
Sprite.__init__(self, spriteshape, color, startx, starty)
self.shapesize(stretch_wid=0.3, stretch_len=0.4, outline=None)
self.speed = 20
self.status = "ready"
self.goto(-1000, 1000)

def fire(self):
if self.status == "ready":
self.goto(player.xcor(), player.ycor())

self.status = "firing"

def move(self):

if self.status == "ready":
self.goto(-1000, 1000)


if self.status == "firing":
self.fd(self.speed)

# border check(see if missile hit border)
if self.xcor() < -290 or self.xcor() > 290 or \
self.ycor() < -290 or self.ycor()> 290:
self.goto(-1000, 1000)
self.status = "ready"


class Game():
def __init__(self):
self.level = 1
self.score = 0
self.state = "playing"
self.pen = turtle.Turtle()
self.lives = 3

def draw_border(self):
#draw border
self.pen.speed(0)
self.pen.color("white")
self.pen.pensize(3)
self.pen.penup()
self.pen.goto(-300, 300)
self.pen.pendown()
for side in range(4):
self.pen.fd(600)
self.pen.rt(90)
self.pen.penup()
self.pen.ht()


#create game object
game = Game()

#draw game border
game.draw_border()






#Create my sprites
player = Player("triangle", "red", 0, 0)
enemy = Enemy("circle", "white", -240, 240)
missile = Missile("triangle", "yellow", 0, 0)



#keyboard bindings
turtle.onkey(player.turn_left, "Left")
turtle.onkey(player.turn_right, "Right")
turtle.onkey(player.accelerate, "Up")
turtle.onkey(player.deccelerate, "Down")
turtle.onkey(missile.fire, "space")
turtle.listen()


#Main game loop
while True:
player.move()
enemy.move()
missile.move()

#Check for collision
if player.is_collision(enemy):
x = random.randint(-250, 250)
y = random.randint(-250, 250)
enemy.goto(x, y)
#check if there is a colision missile enemy
if missile.is_collision(enemy):
x = random.randint(-250, 250)
y = random.randint(-250, 250)
enemy.goto(x, y)
missile.status = "ready"
















delay = input()

richboy
join shbcf.ru