Vpython rocket game

Joined
Jan 4, 2015
Messages
1
Reaction score
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:
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:

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top