Vpython rocket game

Discussion in 'Python' started by dario, Jan 4, 2015.

  1. dario

    dario

    Joined:
    Jan 4, 2015
    Messages:
    1
    Likes Received:
    0
    Hi,

    I am making a code for a game called "Moon Cave Explorer", it is for a task for my exam, and I am stuck.
    The rocket should move up when you hit the "up"-button and the rocker should move down by the gravity of the moon (-1.6 m/s²), when you're doing nothing. When you hit the "right" button the rocket needs to rotate and move to the right, vice versa for the "left" button.
    The rocket starts in the left corner (downside) on the green "platform", the rocket may not pass the cave (how do you do that?), and the rocket should land on the blue "platform".

    During the game, the fuel needs to get updated also (see while-loop)

    Why doesn't my code work?
    Please help,
    my deadline is 11 january

    Dario



    Code:
    Code (Python):

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


    class Moon_Cave_Explorer(object):
        def __init__(self):
            scene.title = "Land safely captain!"
            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 True:
                rate(20)
                #print 'in while'
                if scene.kb.keys:
                    t=0
                    a=0
                    b=0
                    a = a + 0.001
                    s = scene.kb.getkey()
                    if s == "up":
                        self.ruimteschip.frame.update_snelheid(10)
                        self.brandstofmeter.update_brandstof()
                        b = b + 2
                    elif s == "left":
                        self.ruimteschip.gas = rotate(self.ruimteschip.gas,angle = math.pi/10, axis = (0,0,1))
                        c = list(self.ruimteschip.frame.axis)
                        c[2] -= 0.1
                        c = tuple(c)
                        c = self.ruimteschip.frame.axis
                    elif s == "right":
                        self.ruimteschip.gas = rotate(self.ruimteschip.gas,angle = -(math.pi/10), axis = (0,0,1))
                        c = list(self.ruimteschip.frame.axis)
                        c[2] += 0.1
                        c = tuple(c)
                        c = self.ruimteschip.frame.axis
                    elif s == None:
                        self.ruimteschip.vlam.visible = False# ?
                        self.ruimteschip.pos += self.ruimteschip.acceleration
                     
             
               
    class View(object):
        def __init__(self,owner):
            self.owner=owner
         
    class game_view(View):
        def __init__(self,owner):
            View.__init__(self,owner)
            autoscale=True
            box(pos=( 0, -400, 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=(-350,0, 0), length=5, height=750, width=0, color = color.white)
            box(pos=(350,0, 0), length=5, height=750, width=0, color = color.white)

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


    class brandstofmeter(object):
            def __init__(self):
                self.meter=box(pos=(220,345),length=25,height=45,width=0,color=color.green)
            def update_brandstof(self):
                self.meter.height = self.meter.height - 0.10
         
                 
                     
    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.frame = frame()
            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.white,pos=[(22.,39.),(0.,61.),(-22.,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.yellow , visible=False, pos = [(0,24.0),(-9.0,14.0),(0,-5.0),(9,14.0),(0,24.0)])
        def update_snelheid(self,dt):
            self.velocity += self.acceleration * dt
            self.pos +=  self.velocity * dt
    ##        if self.pos.x > 250:
    ##            self.pos.x = -250
    ##        if self.pos.x < -250:
    ##            self.pos.x = 250
    ##          
         
         
         
        def update(self,owner):
            self.frame.axis = owner.axis
            self.frame.pos = owner.pos


    spel = Moon_Cave_Explorer()
    spel.play()
     
     
    Last edited by a moderator: Jan 13, 2015
    dario, Jan 4, 2015
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bruce
    Replies:
    0
    Views:
    898
    Bruce
    Aug 13, 2004
  2. Stephen Lohning

    Simulation of rocket IO in virtex 2 pro

    Stephen Lohning, May 20, 2005, in forum: VHDL
    Replies:
    3
    Views:
    957
  3. kedarpapte@gmail.com

    Simulation of Xilinx Rocket IO Instance

    kedarpapte@gmail.com, Mar 6, 2006, in forum: VHDL
    Replies:
    3
    Views:
    2,285
    Paul Hartke
    Mar 7, 2006
  4. BlackHawke
    Replies:
    12
    Views:
    1,973
    Andrew Thompson
    Jan 26, 2004
  5. E. Robert Tisdale

    Troll Alert: isn't exactly rocket science

    E. Robert Tisdale, Nov 7, 2003, in forum: C++
    Replies:
    2
    Views:
    506
    jeffc
    Nov 7, 2003
  6. judith
    Replies:
    0
    Views:
    2,562
    judith
    Nov 1, 2006
  7. Max Kubierschky
    Replies:
    10
    Views:
    2,330
    pabloreda
    Mar 31, 2007
  8. Advertiser for `2D Games Development Central`

    {Game Development} 2D Game Development Central

    Advertiser for `2D Games Development Central`, May 7, 2008, in forum: Java
    Replies:
    2
    Views:
    648
    RedGrittyBrick
    May 8, 2008
Loading...