Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > problem with exam task for college

Reply
Thread Tools

problem with exam task for college

 
 
jeltedeproft@hotmail.com
Guest
Posts: n/a
 
      01-04-2013
hy everyone, for my exam this year i had to write a computer game on vpython (visualpython).we had to make a lunar lander game where the ship drops bygravity and is able to manouver to safely land on the moon.<br>right now iam completely stuck on trying to make the visual of the ship rotate.<br>i'm new to this forum, i guess i'll just paste my code here. Everything worksfine on the game, except the rotation of the ship. however the when you press "up" the after rotating the velocity actually changes direction , but the visual doesn't. i'm getting kinda nervous because due date is coming, any help is appreciated, here is the code:

from visual import *
import time
import math
import random
from datetime import datetime
import operator


class lunar_lander(object):
def __init__(self):
scene.title = 'mini star wars'
scene.width = 375
scene.height = 550
scene.center = (0,0)
self.pos = (0,0)
self.axis = 0
self.brandstofmeter = brandstofmeter()
self.ruimteschip = ruimteschip()
self.view = game_view(self)



def play(self):
t=0
dt=0.01
while t<999999999:
time.sleep(0.01)
self.brandstofmeter.update
self.ruimteschip.update(dt)
t = t + dt



class game_view(object):
def __init__(self,owner):
autoscale=True
box(pos=( 0, -375, 0), length=500, height=5, width=0, color= color.white)
box(pos=(0,375, 0), length=500, height=5, width=0, color = color.white)
box(pos=(-250,0, 0), length=5, height=750, width=0, color = color.white)
box(pos=(250,0, 0), length=5, height=750, width=0, color = color.white)

maan = curve(pos=[(-250,-353),(-240,-341),(-210,-354),(-199.5,-374)],color=color.red)
maana = curve(pos=[(-199.5,-374),(-166,-374)],color=color.green)
maanb = curve(pos=[(-166,-374),(-140,-357),(-80,-319),(-40,-361),(0,-321),(40,-329),(80,-347)],color=color.red)
maanc = curve(pos=[(80,-347),(140,-347)],color=color.green)
maand = curve(pos=[(140,-347),(162,-337),(189.5,-365),(210,-355),(240,-372),(250,-33],color=color.red)

for i in random.sample(range (-250,250),20):
for j in random.sample(range (-375,375),20):
sterren = points(pos = [i,j,0],size = 2, color=color.white)


class brandstofmeter(object):
def __init__(self):
self.size = (25,45)
axis = 0
self.pos = (220,345)
self.view = brandstofmeter_view(self)

def update(self):
while True:
if scene.kb.keys:
s = scene.kb.getkey()
if (s == 'up'):
self.view.update(self)




class brandstofmeter_view(object):
def __init__(self,owner):
self.owner = owner
meter = box(pos = owner.pos,size = owner.size,color = color..green)

def update (self,owner):
self.size = self.size - (0,0.45)




class ruimteschip(object):
def __init__(self):
self.pos = vector(0,330)
self.acceleration = vector(0,-88,0)
self.axis = (1,0,0)
self.hoek = (90*math.pi)/180
self.graden = math.degrees(self.hoek)
self.gas = vector(10 * cos(self.hoek),10 * sin (self.hoek))
self.velocity = vector(0,0,0)
self.angle = (1,0,0)
self.view = ruimteschip_view(self)
self.vlam = self.view.vlam
self.frame = self.view.frame





def update(self,dt):
self.velocity = self.velocity + (self.acceleration * dt)
self.pos = self.pos + self.velocity * dt
a = 0
b = 0
if scene.kb.keys:
a = a + 0.001
s = scene.kb.getkey()
if (s == "up"):
self.velocity = self.velocity + self.gas
self.vlam.visible = True
b = b + 2
if (s == "left"):
self.gas = rotate(self.gas,angle = math.pi/10, axis =(0,0,1))
c = list(self.frame.axis)
c[2] -= 0.1
c = tuple(c)
c = self.frame.axis
if (s == "right") :
self.gas = rotate(self.gas,angle = -(math.pi/10), axis = (0,0,1))
c = list(self.frame.axis)
c[2] += 0.1
c = tuple(c)
c = self.frame.axis
if (a == 0):
self.vlam.visible = False


if self.pos.x > 250:
self.pos.x = -250
if self.pos.x < -250:
self.pos.x = 250
self.view.update(self)

class ruimteschip_view(object):
def __init__(self,owner):
self.owner = owner
self.frame = frame(pos = owner.pos,axis = owner.axis)
self.motor = curve(frame = self.frame,pos=[(0,24.0),(22.0,24.0),(22.0,39.0),(-22.0,39.0),(-22,24),(0,24)])
self.capsule = curve(frame = self.frame,color = color.blue ,pos=[(0,39),(-3,39),(-9,44),(-12,46),(-18,4,(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50) ,(18,4,(12,46),(9,44),(3,39),(0,39)])
self.poota = curve(frame = self.frame,pos = [(-18,24),(-20,24),(-20,0),(-18,0),(-18,24)])
self.pootb = curve(frame = self.frame,pos = [(18,24),(20,24),(20,0),(18,0),(18,24)])
self.vlam = curve(frame = self.frame,color = color.orange , visible=false,pos = [(0,24.0),(-9.0,14.0),(0,-5.0),(9,14.0),(0,24.0)])

def update(self,owner):
self.frame.axis = owner.axis
self.frame.pos = owner.pos



 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      01-04-2013
On Sat, Jan 5, 2013 at 5:23 AM, <(E-Mail Removed)> wrote:
> hy everyone, for my exam this year i had to write a computer game on vpython (visualpython).we had to make a lunar lander game where the ship drops by gravity and is able to manouver to safely land on the moon.<br>right nowi am completely stuck on trying to make the visual of the ship rotate.<br>i'm new to this forum, i guess i'll just paste my code here. Everything works fine on the game, except the rotation of the ship. however the when you press "up" the after rotating the velocity actually changes direction , butthe visual doesn't. i'm getting kinda nervous because due date is coming, any help is appreciated, here is the code:


Ha, I remember playing a game along those lines that was drawn in pure
ASCII text... the visuals change, the concept doesn't

> self.brandstofmeter = brandstofmeter()
> self.ruimteschip = ruimteschip()


I'm having trouble understanding these names, and am guessing they're
either aggressively abbreviated or not English, but it's hard to tell
which. It's conventional in Python code to capitalize separate words
in class names, and to either capitalize or use underscores (more
usually the latter) between words in instance variables and method
names. Google tells me that brandstofmeter might mean "Babylon 9" and
ruimteschip is German for "spaceship", but that would be more obvious
if I were not trying to figure out what "brands-t-of-meter" might
mean.

> self.brandstofmeter.update
> self.ruimteschip.update(dt)


But I'm guessing that this right here is your problem. The second
update method is called, but the first one isn't. Python evaluates the
name, then does nothing with it. Unlike in BASIC, Python allows you to
manipulate functions just like you do integers and strings, so
actually _calling_ a function requires the parentheses, empty if you
don't need any args:

self.brandstofmeter.update()

> for i in random.sample(range (-250,250),20):
> for j in random.sample(range (-375,375),20):
> sterren = points(pos = [i,j,0],size = 2, color=color.white)


Without seeing the definition of points() anywhere, I can't say
whether this is effective or not; or is that something from module
visual? This is where "from x import *" can quickly get confusing -
it's not obvious whether the name 'points' has come from your code or
someone else's.

The result is being put into sterren and then ignored. You can happily
omit this if you don't need that return value; Python will quietly do
nothing with it:

points(pos = [i,j,0],size = 2, color=color.white)

> class brandstofmeter_view(object):
> def __init__(self,owner):
> self.owner = owner
> meter = box(pos = owner.pos,size = owner.size,color = color.green)
>
> def update (self,owner):
> self.size = self.size - (0,0.45)


Is self.size set anywhere? You may find that, when you fix the above
problem with this method not being called, it begins bombing. What
data type is self.size supposed to be? If it's a tuple, this won't
work, and you'll need to do something like:

self.size = (self.size[0], self.size[1]-0.45)

Or alternatively, use a mutable type such as a list. (Possibly the
vector that you use elsewhere will do. I'm not familiar with that
class, so it may be that you can subtract a tuple from it.)

> def update(self,dt):
> self.velocity = self.velocity + (self.acceleration * dt)
> self.pos = self.pos + self.velocity * dt


Tip: Use augmented assignment for these sorts of statements. It's
clearer what you're doing:

self.velocity += self.acceleration * dt
self.pos += self.velocity * dt

Your class structure feels overengineered, to me. The
model/view/controller system is overkill in most of the places it's
used. Lots of your code is just passing information around from place
to place; instead of the separate _view class, you could simply have a
class ruimteschip that knows how to draw itself.

Final comment: Your code is fairly well laid out, and your query is
clear. Thanks! It's so much easier to read than something that's vague
about what's actually wrong Just one thing. Your subject line
doesn't actually say what's going on (though again, your honesty about
it being an exam task is appreciated); something describing the
problem would have been helpful. But that's fairly minor. Your post is
a joy to answer. Thanks!

Chris Angelico
 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      01-04-2013
On Sat, Jan 5, 2013 at 5:59 AM, Chris Angelico <(E-Mail Removed)> wrote:
> Google tells me that brandstofmeter might mean "Babylon 9"


And by the way, in case it didn't come across, I'm jesting there. What
I mean is that Google didn't have any useful and obvious results
indicating what this actually means. But I'm guessing it's a fuel or
altitude gauge.

ChrisA
 
Reply With Quote
 
MRAB
Guest
Posts: n/a
 
      01-04-2013
On 2013-01-04 18:59, Chris Angelico wrote:
> On Sat, Jan 5, 2013 at 5:23 AM, <(E-Mail Removed)> wrote:
>> hy everyone, for my exam this year i had to write a computer game on vpython (visualpython).we had to make a lunar lander game where the ship drops by gravity and is able to manouver to safely land on the moon.<br>right now i am completely stuck on trying to make the visual of the ship rotate.<br>i'm new to this forum, i guess i'll just paste my code here. Everything works fine on the game, except the rotation of the ship. however the when you press "up" the after rotating the velocity actually changes direction , but the visual doesn't. i'm getting kinda nervous because due date is coming, any help is appreciated, here is the code:

>
> Ha, I remember playing a game along those lines that was drawn in pure
> ASCII text... the visuals change, the concept doesn't
>
>> self.brandstofmeter = brandstofmeter()
>> self.ruimteschip = ruimteschip()

>
> I'm having trouble understanding these names, and am guessing they're
> either aggressively abbreviated or not English, but it's hard to tell
> which. It's conventional in Python code to capitalize separate words
> in class names, and to either capitalize or use underscores (more
> usually the latter) between words in instance variables and method
> names. Google tells me that brandstofmeter might mean "Babylon 9" and
> ruimteschip is German for "spaceship", but that would be more obvious
> if I were not trying to figure out what "brands-t-of-meter" might
> mean.
>

[snip]
Google Translate says it's Dutch:

ruimteschip -> spaceship
brandstofmeter -> fuel gauge

 
Reply With Quote
 
Joshua Landau
Guest
Posts: n/a
 
      01-04-2013
On 4 January 2013 19:00, Chris Angelico <(E-Mail Removed)> wrote:

> On Sat, Jan 5, 2013 at 5:59 AM, Chris Angelico <(E-Mail Removed)> wrote:
> > Google tells me that brandstofmeter might mean "Babylon 9"

>
> And by the way, in case it didn't come across, I'm jesting there. What
> I mean is that Google didn't have any useful and obvious results
> indicating what this actually means. But I'm guessing it's a fuel or
> altitude gauge.
>


It might measure a brand in femtometers .

But, seriously, it's Dutch for Fuel Gauge. Google told me, in case you
think I know Dutch, but it's in the Python Spirit either way.

ruimteschip -> Spaceship
hoek -> angle
sterren -> stars
poot -> leg
vlam -> flame
graden -> degrees
maan -> moon

I'd say they'd be good names if you're in the Netherlands.

 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      01-04-2013
On Sat, Jan 5, 2013 at 6:18 AM, Joshua Landau
<(E-Mail Removed)> wrote:
> It might measure a brand in femtometers .


LOL!

> But, seriously, it's Dutch for Fuel Gauge. Google told me, in case you think
> I know Dutch, but it's in the Python Spirit either way.
>
> ruimteschip -> Spaceship
> hoek -> angle
> sterren -> stars
> poot -> leg
> vlam -> flame
> graden -> degrees
> maan -> moon
>
> I'd say they'd be good names if you're in the Netherlands.


Yep, I'd agree, those are fine names. I still would expect to see the
class names in uppercase though; a single leading capital letter
strongly suggests that it's a single-word name, where all-lowercase
could just be rammed up together non-delimited. But yeah, that's a
pretty minor point. Those name are well suited to their tasks. (And
quite a few of them can be figured out from context without even
turning to the translator, like hoek == angle.)

ChrisA
 
Reply With Quote
 
jeltedeproft@hotmail.com
Guest
Posts: n/a
 
      01-04-2013
woow jeezes, thanks for the amazingly fast and detailed response, you guys are amazing.



let's clear a few things up :

1) points is a module in vpython to make points, the points do in fact appear although its not really the effect i intended to have, the points are "lined up" in stead of randomly separated, if you know what i mean

2) sorry for the dutch names

3) i put the parenteces there and then i got a bunch of errors which i fixed






2 problems:

a) my program seems to be stuck in the update phase of brandstoftank(=fuel tank), it doesnt get to the update of the spaceship

b) the problem i originally described in my first post was not resolved, by means of elimination i could conclude that the problem situates itself in this lines :

if (s == "left"):
self.gas = rotate(self.gas,angle = math.pi/10, axis = (0,0,1))
c = list(self.frame.axis)
c[2] -= 0.1
c = tuple(c)
c = self.frame.axis
if (s == "right") :
self.gas = rotate(self.gas,angle = -(math.pi/10), axis = (0,0,1))
c = list(self.frame.axis)
c[2] += 0.1
c = tuple(c)
c = self.frame.axis

i will put the full revisited code here :


from visual import *
import time
import math
import random
from datetime import datetime
import operator


class lunar_lander(object):
def __init__(self):
scene.title = 'mini star wars'
scene.width = 375
scene.height = 550
scene.center = (0,0)
self.pos = (0,0)
self.axis = 0
self.brandstofmeter_view = brandstofmeter_view()
self.ruimteschip = ruimteschip()
self.view = game_view(self)



def play(self):
t=0
dt=0.01
while t<999999999:
time.sleep(0.01)
self.brandstofmeter_view.update()
self.ruimteschip.update(dt)
t = t + dt



class game_view(object):
def __init__(self,owner):
autoscale=True
box(pos=( 0, -375, 0), length=500, height=5, width=0, color = color.white)
box(pos=(0,375, 0), length=500, height=5, width=0, color = color.white)
box(pos=(-250,0, 0), length=5, height=750, width=0, color = color.white)
box(pos=(250,0, 0), length=5, height=750, width=0, color = color.white)

maan = curve(pos=[(-250,-353),(-240,-341),(-210,-354),(-199.5,-374)],color=color.red)
maana = curve(pos=[(-199.5,-374),(-166,-374)],color=color.green)
maanb = curve(pos=[(-166,-374),(-140,-357),(-80,-319),(-40,-361),(0,-321),(40,-329),(80,-347)],color=color.red)
maanc = curve(pos=[(80,-347),(140,-347)],color=color.green)
maand = curve(pos=[(140,-347),(162,-337),(189.5,-365),(210,-355),(240,-372),(250,-33],color=color.red)

for i in random.sample(range (-250,250),20):
for j in random.sample(range (-375,375),20):
sterren = points(pos = [i,j,0],size = 2, color=color.white)




class brandstofmeter_view(object):
def __init__(self):
axis = 0
self.pos = (220,345)
self.meter = box(pos = self.pos, lenght = 25, height = 45,color = color.green)

def update (self):
s = scene.kb.getkey()
if (s == "up"):
self.meter.height = self.meter.height - 1





class ruimteschip(object):
def __init__(self):
self.pos = vector(0,330)
self.acceleration = vector(0,-88,0)
self.axis = (1,0,0)
self.hoek = (90*math.pi)/180
self.graden = math.degrees(self.hoek)
self.gas = vector(10 * cos(self.hoek),10 * sin (self.hoek))
self.velocity = vector(0,0,0)
self.angle = (1,0,0)
self.view = ruimteschip_view(self)
self.vlam = self.view.vlam
self.frame = self.view.frame





def update(self,dt):
self.velocity = self.velocity + (self.acceleration * dt)
self.pos = self.pos + self.velocity * dt
a = 0
b = 0
if scene.kb.keys:
a = a + 0.001
s = scene.kb.getkey()
if (s == "up"):
self.velocity = self.velocity + self.gas
self.vlam.visible = True
b = b + 2
if (s == "left"):
self.gas = rotate(self.gas,angle = math.pi/10, axis = (0,0,1))
c = list(self.frame.axis)
c[2] -= 0.1
c = tuple(c)
c = self.frame.axis
if (s == "right") :
self.gas = rotate(self.gas,angle = -(math.pi/10), axis = (0,0,1))
c = list(self.frame.axis)
c[2] += 0.1
c = tuple(c)
c = self.frame.axis
if (a == 0):
self.vlam.visible = False


if self.pos.x > 250:
self.pos.x = -250
if self.pos.x < -250:
self.pos.x = 250
self.view.update(self)

class ruimteschip_view(object):
def __init__(self,owner):
self.owner = owner
self.frame = frame(pos = owner.pos,axis = owner.axis)
self.motor = curve(frame = self.frame,pos=[(0,24.0),(22.0,24.0),(22.0,39.0),(-22.0,39.0),(-22,24),(0,24)])
self.capsule = curve(frame = self.frame,color = color.blue ,pos=[(0,39),(-3,39),(-9,44),(-12,46),(-18,4,(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50) ,(18,4,(12,46),(9,44),(3,39),(0,39)])
self.poota = curve(frame = self.frame,pos = [(-18,24),(-20,24),(-20,0),(-18,0),(-18,24)])
self.pootb = curve(frame = self.frame,pos = [(18,24),(20,24),(20,0),(18,0),(18,24)])
self.vlam = curve(frame = self.frame,color = color.orange , visible=false,pos = [(0,24.0),(-9.0,14.0),(0,-5.0),(9,14.0),(0,24.0)])

def update(self,owner):
self.frame.axis = owner.axis
self.frame.pos = owner.pos



thanks again, are you guys getting paid for this or is this voluntarily? either way i really appreciate it

 
Reply With Quote
 
jeltedeproft@hotmail.com
Guest
Posts: n/a
 
      01-04-2013
woow jeezes, thanks for the amazingly fast and detailed response, you guys are amazing.



let's clear a few things up :

1) points is a module in vpython to make points, the points do in fact appear although its not really the effect i intended to have, the points are "lined up" in stead of randomly separated, if you know what i mean

2) sorry for the dutch names

3) i put the parenteces there and then i got a bunch of errors which i fixed






2 problems:

a) my program seems to be stuck in the update phase of brandstoftank(=fuel tank), it doesnt get to the update of the spaceship

b) the problem i originally described in my first post was not resolved, by means of elimination i could conclude that the problem situates itself in this lines :

if (s == "left"):
self.gas = rotate(self.gas,angle = math.pi/10, axis = (0,0,1))
c = list(self.frame.axis)
c[2] -= 0.1
c = tuple(c)
c = self.frame.axis
if (s == "right") :
self.gas = rotate(self.gas,angle = -(math.pi/10), axis = (0,0,1))
c = list(self.frame.axis)
c[2] += 0.1
c = tuple(c)
c = self.frame.axis

i will put the full revisited code here :


from visual import *
import time
import math
import random
from datetime import datetime
import operator


class lunar_lander(object):
def __init__(self):
scene.title = 'mini star wars'
scene.width = 375
scene.height = 550
scene.center = (0,0)
self.pos = (0,0)
self.axis = 0
self.brandstofmeter_view = brandstofmeter_view()
self.ruimteschip = ruimteschip()
self.view = game_view(self)



def play(self):
t=0
dt=0.01
while t<999999999:
time.sleep(0.01)
self.brandstofmeter_view.update()
self.ruimteschip.update(dt)
t = t + dt



class game_view(object):
def __init__(self,owner):
autoscale=True
box(pos=( 0, -375, 0), length=500, height=5, width=0, color = color.white)
box(pos=(0,375, 0), length=500, height=5, width=0, color = color.white)
box(pos=(-250,0, 0), length=5, height=750, width=0, color = color.white)
box(pos=(250,0, 0), length=5, height=750, width=0, color = color.white)

maan = curve(pos=[(-250,-353),(-240,-341),(-210,-354),(-199.5,-374)],color=color.red)
maana = curve(pos=[(-199.5,-374),(-166,-374)],color=color.green)
maanb = curve(pos=[(-166,-374),(-140,-357),(-80,-319),(-40,-361),(0,-321),(40,-329),(80,-347)],color=color.red)
maanc = curve(pos=[(80,-347),(140,-347)],color=color.green)
maand = curve(pos=[(140,-347),(162,-337),(189.5,-365),(210,-355),(240,-372),(250,-33],color=color.red)

for i in random.sample(range (-250,250),20):
for j in random.sample(range (-375,375),20):
sterren = points(pos = [i,j,0],size = 2, color=color.white)




class brandstofmeter_view(object):
def __init__(self):
axis = 0
self.pos = (220,345)
self.meter = box(pos = self.pos, lenght = 25, height = 45,color = color.green)

def update (self):
s = scene.kb.getkey()
if (s == "up"):
self.meter.height = self.meter.height - 1





class ruimteschip(object):
def __init__(self):
self.pos = vector(0,330)
self.acceleration = vector(0,-88,0)
self.axis = (1,0,0)
self.hoek = (90*math.pi)/180
self.graden = math.degrees(self.hoek)
self.gas = vector(10 * cos(self.hoek),10 * sin (self.hoek))
self.velocity = vector(0,0,0)
self.angle = (1,0,0)
self.view = ruimteschip_view(self)
self.vlam = self.view.vlam
self.frame = self.view.frame





def update(self,dt):
self.velocity = self.velocity + (self.acceleration * dt)
self.pos = self.pos + self.velocity * dt
a = 0
b = 0
if scene.kb.keys:
a = a + 0.001
s = scene.kb.getkey()
if (s == "up"):
self.velocity = self.velocity + self.gas
self.vlam.visible = True
b = b + 2
if (s == "left"):
self.gas = rotate(self.gas,angle = math.pi/10, axis = (0,0,1))
c = list(self.frame.axis)
c[2] -= 0.1
c = tuple(c)
c = self.frame.axis
if (s == "right") :
self.gas = rotate(self.gas,angle = -(math.pi/10), axis = (0,0,1))
c = list(self.frame.axis)
c[2] += 0.1
c = tuple(c)
c = self.frame.axis
if (a == 0):
self.vlam.visible = False


if self.pos.x > 250:
self.pos.x = -250
if self.pos.x < -250:
self.pos.x = 250
self.view.update(self)

class ruimteschip_view(object):
def __init__(self,owner):
self.owner = owner
self.frame = frame(pos = owner.pos,axis = owner.axis)
self.motor = curve(frame = self.frame,pos=[(0,24.0),(22.0,24.0),(22.0,39.0),(-22.0,39.0),(-22,24),(0,24)])
self.capsule = curve(frame = self.frame,color = color.blue ,pos=[(0,39),(-3,39),(-9,44),(-12,46),(-18,4,(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50) ,(18,4,(12,46),(9,44),(3,39),(0,39)])
self.poota = curve(frame = self.frame,pos = [(-18,24),(-20,24),(-20,0),(-18,0),(-18,24)])
self.pootb = curve(frame = self.frame,pos = [(18,24),(20,24),(20,0),(18,0),(18,24)])
self.vlam = curve(frame = self.frame,color = color.orange , visible=false,pos = [(0,24.0),(-9.0,14.0),(0,-5.0),(9,14.0),(0,24.0)])

def update(self,owner):
self.frame.axis = owner.axis
self.frame.pos = owner.pos



thanks again, are you guys getting paid for this or is this voluntarily? either way i really appreciate it

 
Reply With Quote
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      01-04-2013
On Fri, 4 Jan 2013 10:23:24 -0800 (PST), http://www.velocityreviews.com/forums/(E-Mail Removed)
declaimed the following in gmane.comp.python.general:

> hy everyone, for my exam this year i had to write a computer game on vpython (visualpython).we had to make a lunar lander game where the ship drops by gravity and is able to manouver to safely land on the moon.<br>right now i am completely stuck on trying to make the visual of the ship rotate.<br>i'm new to this forum, i guess i'll just paste my code here. Everything works fine on the game, except the rotation of the ship. however the when you press "up" the after rotating the velocity actually changes direction , but the visual doesn't. i'm getting kinda nervous because due date is coming, any help is appreciated, here is the code:
>


Except for the initial de-orbit burn, the lunar landers didn't
really rotate during the descent phase. The main engine was used to
control the fall from gravity (vertical speed), and maneuvering
thrusters on all sides were used to "slide" the LEM horizontally (and
somewhat vertically, until actually "stopping" the descent to land). One
reason is that "riding the main engine" down (rotating) would result in
being unable to see the landing point -- instead of "hovering" on the
main jet while traversing for the best flat spot.

Instead of rotating the LEM to fire X-lbs of fuel at, say, a 45
degree angle, they'd fire X/Y1 vertically, and X/Y2 horizontally, where
the Y1&Y2 values result in a vector sum equivalent to X at 45 degrees.

Most all of the graphical lunar lander games I've seen start with
the LEM in the vertical/upright position and only control descent and
horizontal velocity.

My college version (all text in those days, no graphics at all) had
one minor bug... No check was made on input values; one could enter:

burn -100 lbs of fuel
at 180 degrees (0 degrees was straight down)...

The result: one gained fuel while still slowing the ship. I used to
crash with more fuel than I started out with. The game scored by how
close to the designated target sight one came, and how hard the impact
was... I once managed a near perfect accuracy score, with a low vertical
impact. Problem -- in real life I'd have left the landing gear some 30
miles away... My vertical rate was measured in inches per hour, but the
horizontal rate started in miles per hour... I SLID into the landing
zone!

--
Wulfraed Dennis Lee Bieber AF6VN
(E-Mail Removed) HTTP://wlfraed.home.netcom.com/

 
Reply With Quote
 
jeltedeproft@hotmail.com
Guest
Posts: n/a
 
      01-05-2013
hy again,thanx, i updated my code with your more efficient approach , so that possibly resolves problem number 2, but still leaves me with problem n1, my code is still stuck in the first update of the fuel tank (brandstoftank), for the sake of your easyness i'll paste the code again

from visual import *
import time
import math
import random
from datetime import datetime
import operator


class lunar_lander(object):
def __init__(self):
scene.title = 'mini star wars'
scene.width = 375
scene.height = 550
scene.center = (0,0)
self.pos = (0,0)
self.axis = 0
self.brandstofmeter_view = brandstofmeter_view()
self.ruimteschip = ruimteschip()
self.view = game_view(self)



def play(self):
t=0
dt=0.01
while t<999999999:
time.sleep(0.01)
self.brandstofmeter_view.update()
self.ruimteschip.update(dt)
t = t + dt



class game_view(object):
def __init__(self,owner):
autoscale=True
box(pos=( 0, -375, 0), length=500, height=5, width=0, color= color.white)
box(pos=(0,375, 0), length=500, height=5, width=0, color = color.white)
box(pos=(-250,0, 0), length=5, height=750, width=0, color = color.white)
box(pos=(250,0, 0), length=5, height=750, width=0, color = color.white)

maan = curve(pos=[(-250,-353),(-240,-341),(-210,-354),(-199.5,-374)],color=color.red)
maana = curve(pos=[(-199.5,-374),(-166,-374)],color=color.green)
maanb = curve(pos=[(-166,-374),(-140,-357),(-80,-319),(-40,-361),(0,-321),(40,-329),(80,-347)],color=color.red)
maanc = curve(pos=[(80,-347),(140,-347)],color=color.green)
maand = curve(pos=[(140,-347),(162,-337),(189.5,-365),(210,-355),(240,-372),(250,-33],color=color.red)

for i in random.sample(range (-250,250),20):
for j in random.sample(range (-375,375),20):
sterren = points(pos = [i,j,0],size = 2, color=color.white)




class brandstofmeter_view(object):
def __init__(self):
axis = 0
self.pos = (220,345)
self.meter = box(pos = self.pos, lenght = 25, height = 45,color = color.green)

def update (self):
s = scene.kb.getkey()
if (s == "up"):
self.meter.height = self.meter.height - 1





class ruimteschip(object):
def __init__(self):
self.pos = vector(0,330)
self.acceleration = vector(0,-88,0)
self.axis = (1,0,0)
self.hoek = (90*math.pi)/180
self.graden = math.degrees(self.hoek)
self.gas = vector(10 * cos(self.hoek),10 * sin (self.hoek))
self.velocity = vector(0,0,0)
self.angle = (1,0,0)
self.view = ruimteschip_view(self)
self.vlam = self.view.vlam
self.frame = self.view.frame





def update(self,dt):
self.velocity = self.velocity + (self.acceleration * dt)
self.pos = self.pos + self.velocity * dt
a = 0
b = 0
if scene.kb.keys:
a = a + 0.001
s = scene.kb.getkey()
if (s == "up"):
self.velocity = self.velocity + self.gas
self.vlam.visible = True
b = b + 2
if (s == "left"):
self.gas = rotate(self.gas,angle = math.pi/10, axis =(0,0,1))
(x,y,z) = self.frame.axis
self.frame.axis = (x,y,z-0.1)
if (s == "right") :
self.gas = rotate(self.gas,angle = -(math.pi/10), axis = (0,0,1))
(x,y,z) = self.frame.axis
self.frame.axis = (x,y,z+0.1)
if (a == 0):
self.vlam.visible = False


if self.pos.x > 250:
self.pos.x = -250
if self.pos.x < -250:
self.pos.x = 250
self.view.update(self)

class ruimteschip_view(object):
def __init__(self,owner):
self.owner = owner
self.frame = frame(pos = owner.pos,axis = owner.axis)
self.motor = curve(frame = self.frame,pos=[(0,24.0),(22.0,24.0),(22.0,39.0),(-22.0,39.0),(-22,24),(0,24)])
self.capsule = curve(frame = self.frame,color = color.blue ,pos=[(0,39),(-3,39),(-9,44),(-12,46),(-18,4,(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50) ,(18,4,(12,46),(9,44),(3,39),(0,39)])
self.poota = curve(frame = self.frame,pos = [(-18,24),(-20,24),(-20,0),(-18,0),(-18,24)])
self.pootb = curve(frame = self.frame,pos = [(18,24),(20,24),(20,0),(18,0),(18,24)])
self.vlam = curve(frame = self.frame,color = color.orange , visible=false,pos = [(0,24.0),(-9.0,14.0),(0,-5.0),(9,14.0),(0,24.0)])

def update(self,owner):
self.frame.axis = owner.axis
self.frame.pos = owner.pos



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
UR SCHOOL AND COLLEGE'S, PLEASE REGISTER UR SCHOOL AND COLLEGE NAME'SIN THIS SITE. "" IF U HAVE TIME THEN DO IT. PLEASE I REQUEST. """ jack Python 0 06-07-2008 06:34 AM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSE 4 11-15-2006 02:40 AM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola Microsoft Certification 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd realexxams@yahoo.com Microsoft Certification 0 05-10-2006 02:35 PM



Advertisments