May-31-2019, 06:38 PM
I am making a simple CTF game and the bullets aren't travelling, could someone help me?
Blue_direction = 0 Red_direction = 0 game = True import turtle wn = turtle.Screen() wn.title("CTF 1v1") wn.bgcolor("black") wn.setup(width=800, height=600) wn.tracer(0) #Blue (right) Flag Blue_flag = turtle.Turtle() Blue_flag.speed(0) Blue_flag.shape("square") Blue_flag.color("blue") Blue_flag.penup() Blue_flag.goto(350, 0) #Blue fighter Blue_fighter = turtle.Turtle() Blue_fighter.speed(0) Blue_fighter.shape("circle") Blue_fighter.color("blue") Blue_fighter.penup() Blue_fighter.goto(350, 0) #Blue Bullet Blue_bullet = turtle.Turtle() Blue_bullet.speed(0) Blue_bullet.penup() Blue_bullet.shape("square") Blue_bullet.color("Yellow") Blue_bullet.penup() #Red (Left) Flag Red_flag = turtle.Turtle() Red_flag.speed(0) Red_flag.shape("square") Red_flag.color("red") Red_flag.penup() Red_flag.goto(-350, 0) #Red fighter Red_fighter = turtle.Turtle() Red_fighter.speed(0) Red_fighter.shape("circle") Red_fighter.color("red") Red_fighter.penup() Red_fighter.goto(-350, 0) #Red bullet Red_bullet = turtle.Turtle() Red_bullet.speed(0) Red_bullet.penup() Red_bullet.shape("square") Red_bullet.color("Yellow") Red_bullet.penup() #walls #midwall midwall = turtle.Turtle() midwall.speed(0) midwall.shape("square") midwall.color("white") midwall.shapesize(stretch_wid=2, stretch_len=1) midwall.penup() midwall.goto(0, 0) #blue spawn walls midwall = turtle.Turtle() midwall.speed(0) midwall.shape("square") midwall.color("white") midwall.shapesize(stretch_wid=5, stretch_len=1) midwall.penup() midwall.goto(250, 150) midwall = turtle.Turtle() midwall.speed(0) midwall.shape("square") midwall.color("white") midwall.shapesize(stretch_wid=5, stretch_len=1) midwall.penup() midwall.goto(250, -150) #red spawn walls midwall = turtle.Turtle() midwall.speed(0) midwall.shape("square") midwall.color("white") midwall.shapesize(stretch_wid=5, stretch_len=1) midwall.penup() midwall.goto(-250, -150) midwall = turtle.Turtle() midwall.speed(0) midwall.shape("square") midwall.color("white") midwall.shapesize(stretch_wid=5, stretch_len=1) midwall.penup() midwall.goto(-250, 150) #keybindings def Blue_move_up(): y = Blue_fighter.ycor() y += 30 Blue_fighter.sety(y) Blue_direction = "up" def Blue_move_left(): x = Blue_fighter.xcor() x -= 30 Blue_fighter.setx(x) Blue_direction = "left" def Blue_move_down(): y = Blue_fighter.ycor() y -= 30 Blue_fighter.sety(y) Blue_direction = "down" def Blue_move_right(): x = Blue_fighter.xcor() x += 30 Blue_fighter.setx(x) Blue_direction = "right" def Blue_shoot(): Blue_bullet.goto(Blue_pos) if Blue_direction == "up": ybb = Blue_bullet.ycor() ybb += 30 Blue_bullet.sety(y) if Blue_direction == "left": xbb = Blue_bullet.xcor() xbb -= 30 Blue_bullet.setx(x) if Blue_direction == "down": ybb = Blue_bullet.ycor() ybb -= 30 Blue_bullet.sety(y) if Blue_direction == "right": xbb = Blue_bullet.xcor() xbb += 30 Blue_bullet.setx(x) def Red_move_up(): y = Red_fighter.ycor() y += 30 Red_fighter.sety(y) Red_direction = "up" def Red_move_left(): x = Red_fighter.xcor() x -= 30 Red_fighter.setx(x) Red_direction = "left" def Red_move_down(): y = Red_fighter.ycor() y -= 30 Red_fighter.sety(y) Red_direction = "down" def Red_move_right(): x = Red_fighter.xcor() x += 30 Red_fighter.setx(x) Red_direction = "right" def Red_shoot(): Red_bullet.goto(Red_pos) if Red_direction == "up": yrb = Red_bullet.ycor() yrb += 30 Red_bullet.sety(y) if Red_direction == "left": xrb = Red_bullet.xcor() xrb -= 30 Red_bullet.setx(x) if Red_direction == "down": yrb = Red_bullet.ycor() yrb -= 30 Red_bullet.sety(y) if Red_direction == "right": xrb = Red_bullet.xcor() xrb += 30 Red_bullet.setx(x) wn.onkeypress(Blue_move_up, "w") wn.onkeypress(Blue_move_left, "a") wn.onkeypress(Blue_move_down, "s") wn.onkeypress(Blue_move_right, "d") wn.onkeypress(Blue_shoot, "e") wn.onkeypress(Red_move_up, "i") wn.onkeypress(Red_move_left, "j") wn.onkeypress(Red_move_down, "k") wn.onkeypress(Red_move_right, "l") wn.onkeypress(Red_shoot, "o") wn.listen() while True: wn.update() Blue_pos = Blue_fighter.pos() Red_pos = Red_fighter.pos() #collitionsNote: I am not really looking to optimise my code, only to solve the issue with bullet travel