Hi, so I am trying to create a text file, that holds coordinates of bricks for the game brick breaker. I have a the textfile labeled as level1, and the coordinates are
now I am having trouble with getting python to open the file, and read the coordinates. I am not sure what command I would use to get that.
also I am not sure on how to convert them into integers once they are read. Because they are currently in string form

6 Years
Discussion Span
Last Post by pyTony
fp = open(filename, "r") #"r" means open in read mode

for converting your string to integer:

Let's say I have a string "test" with the coordinates:

test = '20, 10, -5'

num1, num2, num3 = test.split(',')

print int(num1.strip(' '))
print int(num2.strip(' '))
print int(num3.strip(' '))

okay, so say if I wanted to make those into bricks, thats the part I am having the issue with, making those coordinates into bricks, then adding them to a brick, called brick list.


So I tried to open the file using what you sent me, and it did not work i have

fp=open(cord,"r")# but it did not run.

What is the name of your file???

I assume that "cord" in your code is a string that holds the name of the file, right??


Could you help me with my brick game? I am having a difficult time checking if the ball has collided with the panel and the bricks. so far I have

from visual import *
from __future__ import math *

bricks = [box(pos=vector(i-5,9,0),lenght=1,height=1, width=0, color=color.white)for i in range(0,11)]

ball=sphere(color=color.cyan, pos=vector(0,0,0), radius=0.2)
ball.velocity = vector(0,-1,0)

delta_t= 0.01

panel=box(pos=(0,-9,0), length=2, height=0.5, width=0, color=color.white)
panel.velocity = vector(1,0,0)


while True:
    ball.pos= ball.pos + ball.velocity*delta_t

    if ball.y<10:
    if distance(ball.pos, panel.pos) <= 0.5:
        ball.velocity.y= -ball.velocity.y
    if scene.kb.keys:
        if s == 'right':
            panel.pos.x = panel.pos.x + 0.2
        if s == 'left':
            panel.pos.x = panel.pos.x - 0.2

Now, I had made a distance function earlier in my class:

x1 = int(raw_input("please enter your first x value  "))
y1 = int(raw_input("please enter your first y value  "))
x2 = int(raw_input("please enter your second x value  "))
y2 = int(raw_input("please enter your second y value  "))

def distance():

    dx = x2 - x1 #Takes the x2 and subtracts the x1

    dy = y2 - y1 #Takes the y2 and subtraces the y1

    return math.sqrt(dx**2 + dy**2

however this is taking two points a user inputs. how would I get it to check the distance of the ball and panel. In theory, I want to make a function like this

returns a #
if dist(ball.pos,panel.pos)<= 0.5:
ball.velocity.y=-ball.velocity.y + ball.velocity.x

however, I am not sure exactly how to get it to check the panel, and the ball, then the ball and the bricks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.