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
-5,9,0
-4,9,0
-3,9,0
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

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??

well cord was the name of the text file on the document.

if your file name is cord.txt for example:

fp = open("cord.txt", "r")

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 *
scene.range=10

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:
    rate(600)
    
    ball.pos= ball.pos + ball.velocity*delta_t

    if ball.y<10:
        ball.velocity.y=-ball.velocity.y
    if distance(ball.pos, panel.pos) <= 0.5:
        ball.velocity.y= -ball.velocity.y
    if scene.kb.keys:
        s=scene.kb.getkey()
        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

dist(a,b):
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

where is your visual module?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.