Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36128 > unrolled thread

problem with exam task for college

Started byjeltedeproft@hotmail.com
First post2013-01-04 10:23 -0800
Last post2013-01-14 13:54 -0500
Articles 20 on this page of 25 — 9 participants

Back to article view | Back to comp.lang.python


Contents

  problem with exam task for college jeltedeproft@hotmail.com - 2013-01-04 10:23 -0800
    Re: problem with exam task for college Chris Angelico <rosuav@gmail.com> - 2013-01-05 05:59 +1100
    Re: problem with exam task for college Chris Angelico <rosuav@gmail.com> - 2013-01-05 06:00 +1100
    Re: problem with exam task for college MRAB <python@mrabarnett.plus.com> - 2013-01-04 19:17 +0000
    Re: problem with exam task for college Joshua Landau <joshua.landau.ws@gmail.com> - 2013-01-04 19:18 +0000
    Re: problem with exam task for college Chris Angelico <rosuav@gmail.com> - 2013-01-05 06:30 +1100
      Re: problem with exam task for college jeltedeproft@hotmail.com - 2013-01-04 12:01 -0800
        Re: problem with exam task for college Chris Angelico <rosuav@gmail.com> - 2013-01-05 07:36 +1100
        Re: problem with exam task for college Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-01-05 16:09 -0500
      Re: problem with exam task for college jeltedeproft@hotmail.com - 2013-01-04 12:01 -0800
    Re: problem with exam task for college Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-01-04 17:11 -0500
    Re: problem with exam task for college jeltedeproft@hotmail.com - 2013-01-05 04:24 -0800
      Re: problem with exam task for college Chris Angelico <rosuav@gmail.com> - 2013-01-05 23:39 +1100
    Re: problem with exam task for college jeltedeproft@hotmail.com - 2013-01-05 05:14 -0800
      Re: problem with exam task for college Chris Angelico <rosuav@gmail.com> - 2013-01-06 00:32 +1100
    Re: problem with exam task for college jeltedeproft@hotmail.com - 2013-01-07 08:22 -0800
      Re: problem with exam task for college Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2013-01-07 18:40 +0100
      Re: problem with exam task for college Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-01-07 15:36 -0500
    Re: problem with exam task for college jeltedeproft_8@hotmail.com - 2013-01-13 04:29 -0800
    Re: problem with exam task for college jeltedeproft@hotmail.com - 2013-01-13 04:48 -0800
    Re: problem with exam task for college jeltedeproft@hotmail.com - 2013-01-13 05:57 -0800
      Re: problem with exam task for college Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-13 17:28 +0000
    Re: problem with exam task for college stefaang@gmail.com - 2013-01-14 04:57 -0800
    Re: problem with exam task for college jeltedeproft@hotmail.com - 2013-01-14 08:01 -0800
      Re: problem with exam task for college Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-01-14 13:54 -0500

Page 1 of 2  [1] 2  Next page →


#36128 — problem with exam task for college

Fromjeltedeproft@hotmail.com
Date2013-01-04 10:23 -0800
Subjectproblem with exam task for college
Message-ID<6f3c7fdf-7439-43b1-b3a2-da9da019b1ec@googlegroups.com>
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:

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,-338)],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,48),(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50),(18,48),(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
        

                          

[toc] | [next] | [standalone]


#36132

FromChris Angelico <rosuav@gmail.com>
Date2013-01-05 05:59 +1100
Message-ID<mailman.95.1357325949.2939.python-list@python.org>
In reply to#36128
On Sat, Jan 5, 2013 at 5:23 AM,  <jeltedeproft@hotmail.com> 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.

>             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

[toc] | [prev] | [next] | [standalone]


#36133

FromChris Angelico <rosuav@gmail.com>
Date2013-01-05 06:00 +1100
Message-ID<mailman.96.1357326055.2939.python-list@python.org>
In reply to#36128
On Sat, Jan 5, 2013 at 5:59 AM, Chris Angelico <rosuav@gmail.com> 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

[toc] | [prev] | [next] | [standalone]


#36136

FromMRAB <python@mrabarnett.plus.com>
Date2013-01-04 19:17 +0000
Message-ID<mailman.98.1357327055.2939.python-list@python.org>
In reply to#36128
On 2013-01-04 18:59, Chris Angelico wrote:
> On Sat, Jan 5, 2013 at 5:23 AM,  <jeltedeproft@hotmail.com> 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

[toc] | [prev] | [next] | [standalone]


#36137

FromJoshua Landau <joshua.landau.ws@gmail.com>
Date2013-01-04 19:18 +0000
Message-ID<mailman.99.1357327175.2939.python-list@python.org>
In reply to#36128

[Multipart message — attachments visible in raw view] — view raw

On 4 January 2013 19:00, Chris Angelico <rosuav@gmail.com> wrote:

> On Sat, Jan 5, 2013 at 5:59 AM, Chris Angelico <rosuav@gmail.com> 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.

[toc] | [prev] | [next] | [standalone]


#36138

FromChris Angelico <rosuav@gmail.com>
Date2013-01-05 06:30 +1100
Message-ID<mailman.100.1357327851.2939.python-list@python.org>
In reply to#36128
On Sat, Jan 5, 2013 at 6:18 AM, Joshua Landau
<joshua.landau.ws@gmail.com> 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

[toc] | [prev] | [next] | [standalone]


#36139

Fromjeltedeproft@hotmail.com
Date2013-01-04 12:01 -0800
Message-ID<f5c1a4cb-f96a-4e6d-9f32-511f9bcd04ee@googlegroups.com>
In reply to#36138
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,-338)],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,48),(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50),(18,48),(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 

[toc] | [prev] | [next] | [standalone]


#36141

FromChris Angelico <rosuav@gmail.com>
Date2013-01-05 07:36 +1100
Message-ID<mailman.102.1357331777.2939.python-list@python.org>
In reply to#36139
On Sat, Jan 5, 2013 at 7:01 AM,  <jeltedeproft@hotmail.com> wrote:
> woow jeezes, thanks for the amazingly fast and detailed response, you guys are amazing.
>
> thanks again, are you guys getting paid for this or is this voluntarily? either way i really appreciate it

We're all volunteers (and it's now 7:30AM Saturday and I've been up
all night, so this post quite probably doesn't carry the hallmarks of
intelligence). To be more strictly correct, we are members of a
community - people helping people. Far as I know, there's not one
person here who has never asked a question. I tend to join a mailing
list to ask one or more questions, and hang around answering them long
after my personal needs are satisfied, kinda like seeding back a
torrent after you've downloaded it.

We answer questions for a variety of reasons. Partly, because this is
one of the best forms of help that the Python community can offer,
which means that supporting Python in this way strengthens the
language. Partly, because our names are connected to our posts, and we
are seen to be helpful people (and, since the list/newsgroup is
archived on the web, potential employers who search the web for our
names will see us being helpful and knowledgeable). Partly, because
we're repaying the community for the benefits we've gained from it.
Partly, because in answering questions, we ourselves learn. And there
are other reasons too.

> 2) sorry for the dutch names :)

No probs; as was said in several follow-ups, those are well-chosen names.

> 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 :
>
>                 c = list(self.frame.axis)
>                 c[2] -= 0.1
>                 c = tuple(c)
>                 c = self.frame.axis

This code is looking quite messy, here. But the most obvious problem
is that you're setting up 'c' to be the modified axis, and then...
overwriting c with the old axis. Try doing the assignment the other
way in the last line:

self.frame.axis = c

Alternatively, you could do the whole thing more cleanly by unpacking
and then repacking the tuple:

(x, y, z) = self.frame.axis
self.frame.axis = (x, y, z-0.1)

Two lines that do the job of the above four. Note that the parentheses
are optional here; they look nice since axis is holding coordinates,
but Python doesn't care.

Hope that helps!

ChrisA

[toc] | [prev] | [next] | [standalone]


#36210

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2013-01-05 16:09 -0500
Message-ID<mailman.144.1357420181.2939.python-list@python.org>
In reply to#36139
On Fri, 4 Jan 2013 12:01:10 -0800 (PST), jeltedeproft@hotmail.com
declaimed the following in gmane.comp.python.general:


>                 c = list(self.frame.axis)
>                 c[2] -= 0.1
>                 c = tuple(c)
>                 c = self.frame.axis

	I suspect you want

		self.frame.axis = c

>             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
>
	Note that you have a lot of repeated code that could be put outside
the if-block...
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#36140

Fromjeltedeproft@hotmail.com
Date2013-01-04 12:01 -0800
Message-ID<mailman.101.1357330300.2939.python-list@python.org>
In reply to#36138
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,-338)],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,48),(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50),(18,48),(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 

[toc] | [prev] | [next] | [standalone]


#36142

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2013-01-04 17:11 -0500
Message-ID<mailman.103.1357337518.2939.python-list@python.org>
In reply to#36128
On Fri, 4 Jan 2013 10:23:24 -0800 (PST), jeltedeproft@hotmail.com
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
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#36161

Fromjeltedeproft@hotmail.com
Date2013-01-05 04:24 -0800
Message-ID<9ba228d7-0654-412a-9b55-c2a07aedbe24@googlegroups.com>
In reply to#36128
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 n°1, 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,-338)],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,48),(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50),(18,48),(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
        

                          

[toc] | [prev] | [next] | [standalone]


#36163

FromChris Angelico <rosuav@gmail.com>
Date2013-01-05 23:39 +1100
Message-ID<mailman.113.1357389570.2939.python-list@python.org>
In reply to#36161
On Sat, Jan 5, 2013 at 11:24 PM,  <jeltedeproft@hotmail.com> wrote:
> 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 n°1, 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

Not sure what you mean by "stuck", but is it that scene.kb.getkey()
waits for a key?

ChrisA

[toc] | [prev] | [next] | [standalone]


#36167

Fromjeltedeproft@hotmail.com
Date2013-01-05 05:14 -0800
Message-ID<d86158c6-b1c8-4eef-a5fc-d0ad24e56bdb@googlegroups.com>
In reply to#36128
that's probably it, how do i solve it?

[toc] | [prev] | [next] | [standalone]


#36169

FromChris Angelico <rosuav@gmail.com>
Date2013-01-06 00:32 +1100
Message-ID<mailman.116.1357392743.2939.python-list@python.org>
In reply to#36167
On Sun, Jan 6, 2013 at 12:14 AM,  <jeltedeproft@hotmail.com> wrote:
> that's probably it, how do i solve it?

I'm afraid I can't help you there. Check out the docs for the getkey
function and see if it can be put into non-blocking mode; if not, you
may have to completely change your model. For instance, if I were
writing this sort of game today, I'd probably use a GUI system that
fires an event whenever a key is pressed/released, and then have a
timer-tick for the descent, rather than explicit sleep() calls. But it
depends on your UI facilities.

The LANDER.BAS that I played with - yes, it was written in BASIC - was
fully prompt-driven. To move to the next time unit, you had to answer
all its prompts. Advantage: No need to code a Pause feature.
Disadvantage: The game ended up way too scientific, like D&D combat.
(It's amazing how your party of bumbling characters suddenly become
lightning-fast strategists as soon as initiative is rolled!)

ChrisA

[toc] | [prev] | [next] | [standalone]


#36362

Fromjeltedeproft@hotmail.com
Date2013-01-07 08:22 -0800
Message-ID<9d4db036-b840-4c2e-8cfb-edc2afb7bbaa@googlegroups.com>
In reply to#36128
ok after another round of reparations, my update works again and it updates the fuel meter, but i still can't get the view of the spaceship to rotate, for now only the direction the spaceship accelerates when pressing "up" changes after a rotation, but the spaceship itself keeps pointing up. This is the code for the rotating :    p.s : the problem has to be in this code because the update of the view of the position of the spaceship does work.


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"):
                if self.zicht.meter.height != 0:
                    self.velocity = self.velocity + self.gas
                    self.vlam.visible = True
                    b = b + 2
                    self.zicht.meter.height = self.zicht.meter.height - 0.1
                    self.zicht.update
            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

[toc] | [prev] | [next] | [standalone]


#36365

FromVincent Vande Vyvre <vincent.vandevyvre@swing.be>
Date2013-01-07 18:40 +0100
Message-ID<mailman.229.1357580886.2939.python-list@python.org>
In reply to#36362
Le 07/01/13 17:22, jeltedeproft@hotmail.com a écrit :
> ok after another round of reparations, my update works again and it updates the fuel meter, but i still can't get the view of the spaceship to rotate, for now only the direction the spaceship accelerates when pressing "up" changes after a rotation, but the spaceship itself keeps pointing up. This is the code for the rotating :    p.s : the problem has to be in this code because the update of the view of the position of the spaceship does work.
>
>
> 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"):
>                 if self.zicht.meter.height != 0:
>                     self.velocity = self.velocity + self.gas
>                     self.vlam.visible = True
>                     b = b + 2
>                     self.zicht.meter.height = self.zicht.meter.height - 0.1
>                     self.zicht.update
>             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
Are you sure with this code:

(x,y,z) = self.frame.axis ?

frame.axis is a 'cvisual.vector' and this unpacking cause a program
crashes with a segfault.

For left-rigth moves of the LEM, this code seems works:

--------------------------------------

        if scene.kb.keys:
            key = scene.kb.getkey()
            if key == "left":
                # Set left deviation
                self.frame.axis -= (0, 0, 0.05)
                self.gas = vector(-sin(self.angle), cos(self.angle))

            elif key == "right":
                # Set right deviation
                self.frame.axis += (0, 0, 0.05)
                self.gas = vector(sin(self.angle), cos(self.angle))

            elif key == "up":
                self.deviate()

    def deviate(self):
        # Set modified velocity
        self.frame.velocity += self.gas
        self.frame.pos += self.frame.velocity
        # Reset falling velocity
        self.frame.velocity -= self.gas

--------------------------------------

with angle = PI / 2.0

-- 
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>

[toc] | [prev] | [next] | [standalone]


#36374

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2013-01-07 15:36 -0500
Message-ID<mailman.238.1357591018.2939.python-list@python.org>
In reply to#36362
On Mon, 7 Jan 2013 08:22:28 -0800 (PST), jeltedeproft@hotmail.com
declaimed the following in gmane.comp.python.general:

> ok after another round of reparations, my update works again and it updates the fuel meter, but i still can't get the view of the spaceship to rotate, for now only the direction the spaceship accelerates when pressing "up" changes after a rotation, but the spaceship itself keeps pointing up. This is the code for the rotating :    p.s : the problem has to be in this code because the update of the view of the position of the spaceship does work.
>

	So where is the code that draws this "spaceship"
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#36729

Fromjeltedeproft_8@hotmail.com
Date2013-01-13 04:29 -0800
Message-ID<f975a28f-c3d3-4e39-8623-117795470e62@googlegroups.com>
In reply to#36128
sorry for the extremely late reply, i have been very very busy :s

i implemented the solution that was posted in the second to last post. but now it gets a little confusing because i think a couple terms where deleted that i refered to in other code blocks, so once again i''l post the full 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 = brandstofmeter()
        self.ruimteschip = ruimteschip()
        self.view = game_view(self)
        
        

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

            
            
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,-338)],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):
        axis = 0
        self.pos = (210,345)
        self.length = 25
        self.height = 45
        self.meter = box(pos = self.pos, length = self.length, height = self.height,color = color.green)
    def update(self):
        self.height = self.height - 0.2
        print "ok"
        
                    
                    
        
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 = pi / 2
        self.updatemeter = False
        self.view = ruimteschip_view(self)
        self.vlam = self.view.vlam
        self.frame = self.view.frame
        self.zicht = brandstofmeter()
        
        

    def update(self,dt):
        self.velocity = self.velocity + (self.acceleration * dt)
        self.pos = self.pos + self.velocity * dt
        
        if scene.kb.keys:
            key = scene.kb.getkey()
            if key == "left":
                # Set left deviation
                self.frame.axis -= (0, 0, 0.05)
                self.gas = vector(-sin(self.angle), cos(self.angle))

            elif key == "right":
                # Set right deviation
                self.frame.axis += (0, 0, 0.05)
                self.gas = vector(sin(self.angle), cos(self.angle))

            elif key == "up":
                self.deviate()

    def deviate(self):
        # Set modified velocity
        self.frame.velocity += self.gas
        self.frame.pos += self.frame.velocity
        # Reset falling velocity
        self.frame.velocity -= self.gas

            
             
        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,48),(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50),(18,48),(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
        

                          

[toc] | [prev] | [next] | [standalone]


#36731

Fromjeltedeproft@hotmail.com
Date2013-01-13 04:48 -0800
Message-ID<f3f0d66c-e3db-47bf-bb5c-b09dd0fe7097@googlegroups.com>
In reply to#36128
corrected a bit, loop works, gas doesn't work


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
        self.ruimteschip.updatemeter = False
        while t<999999999:
            time.sleep(0.01)
            self.ruimteschip.update(dt)
            t = t + dt
            if self.ruimteschip.updatemeter == True:
                self.brandstofmeter.update
                
                

            
            
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,-338)],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):
        axis = 0
        self.pos = (210,345)
        self.length = 25
        self.height = 45
        self.meter = box(pos = self.pos, length = self.length, height = self.height,color = color.green)
    def update(self):
        self.height = self.height - 0.2
        print "ok"
        
                    
                    
        
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 = pi / 2
        self.updatemeter = False
        self.view = ruimteschip_view(self)
        self.vlam = self.view.vlam
        self.frame = self.view.frame
        self.zicht = brandstofmeter()
        
        

    def update(self,dt):
        self.velocity = self.velocity + (self.acceleration * dt)
        self.pos = self.pos + self.velocity * dt
        
        if scene.kb.keys:
            key = scene.kb.getkey()
            if key == "left":
                # linkerafwijking
                self.frame.axis -= (0, 0, 0.05)
                self.gas = vector(-sin(self.angle), cos(self.angle))
                self.vlam.visible = True
                self.updatemeter = True

            elif key == "right":
                # rechterafwijking
                self.frame.axis += (0, 0, 0.05)
                self.gas = vector(sin(self.angle), cos(self.angle))

            elif key == "up":
                self.deviate()
        self.vlam.visible = False
        self.updatemeter = False

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

    def deviate(self):
        # zet veranderde snelheid
        self.frame.velocity += self.gas
        self.frame.pos += self.frame.velocity
        # Reset valsnelheid
        self.frame.velocity -= self.gas

            
             
        
                    
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,48),(-22,50),(-18,52),(-12,54),(-9,56),(-3,61),(0,61),(3,59),(9,56),(12,54),(18,52),(22,50),(18,48),(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
        self.frame.velocity = owner.velocity
        

                          

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.python


csiph-web