Strange speed increment in racegame [SOLVED]

Hello all,

I’m currently working on a racegame for a school project.

Basicly the problem is i’ve got a selection menu for single- and multiplayer.

If I click single player a track and car are placed.

When the car reaches 100% damage, the car object is being destroyed.

And you will return to the menu.

When clicking single player again, the speed of the car is almost doubled.
after repeating this proces several times the car is being accelerated faster then a space rocket.

Kinda strange does any of you people have an idea?

If neccesary I’ll post some code snippets.

Thnx in advance.

Wizard

That really depends on your code. Probably you are increasing the speed somewhere when you click Single player.

…I’d need some code to actually see the problem.

Problem is i’d kept calling the taskMgr gameloop so after two times it ran twice etc etc

Main class

from pandac.PandaModules import *
from direct.gui.OnscreenText import OnscreenText
from direct.showbase.DirectObject import DirectObject
from direct.task.Task import Task
from math import sin, cos, pi
from random import randint, choice, random
from direct.interval.MetaInterval import Sequence
from direct.interval.FunctionInterval import Wait,Func
from direct.gui.DirectGui import *
import cPickle, sys, time
import codecs

##ConfigVariableBool("fullscreen",0).setValue(1)

import direct.directbase.DirectStart

##base.disableMouse()
##base.oobe()

## private modules
from intro import Intro
from car import Car
from track import Track
from textToScreen import Text
import textToScreen
from gaugesToScreen import Gauges
from menu import Menu

class GridRacer():


    def __init__(self):

        ##instantiate track in variable self.track1
        self.track1 = Track()

        ##call method readTrackFile
        self.track1.readTrackFile()
        self.hitArray = self.track1.getHitArray()        


        wp = WindowProperties() 
        wp.setTitle("GridRacer - Time To Hit The Streets")
        wp.setCursorHidden(True) 

        base.win.requestProperties(wp) 
        
        ##load intro class
        intro = Intro("intro/Grid Racer Teaser.wmv")

        ##place the intro.movieRunTask in a threaded taskMgr upon death call the self.menu
        taskMgr.add(intro.movieRunTask, "introRunner", uponDeath=self.menu)


    def menu(self, task):

        self.menu = Menu()
        taskMgr.add(self.menu.mouseEvent, "mouseEventCatcher", uponDeath=self.continueLoadProcess)

        

    def continueLoadProcess(self,task):
        
        Text()
        self.Text = textToScreen

        self.choice = self.menu.getChoice()

        del self.menu

        wp = WindowProperties() 
        wp.setCursorHidden(False) 

        if ( self.choice == "singlePlayer"):            

            base.win.requestProperties(wp)
             
            ##disable default cam
            base.camNode.setActive(True)

            
            self.car1 = Car("player1", self.hitArray)
            self.gauge1 = Gauges( "player1" )


        elif (self.choice == "multiPlayer"):
                
            ##disable default cam
            base.camNode.setActive(False)
                
            ##instantiate car with parameter in variable self.car1 and self.car2
            self.car1 = Car("player1", self.hitArray)
            self.car2 = Car("player2", self.hitArray)


            ##places the gauges on the screen
            self.gauge1 = Gauges( "player1" )
            self.gauge2 = Gauges( "player2" )
            

            ##create a 2 camera view one is being positioned over self.car1.Car (the Car object)
            self.camera1=self.createCamera((0.0,0.5,0,1), self.car1.Car)
            ##this one is being positioned over self.car2.Car
            self.camera2=self.createCamera((0.502,1.0,0,1), self.car2.Car)        
                   

        ##create a taskMgr that keeps looping
        self.gameTask = taskMgr.add(self.gameLoop, "gameLoop" )
        self.gameTask.last = 0



    def createCamera(self,dispRegion, player):
        
        camera = base.makeCamera(base.win, displayRegion=dispRegion)
        camera.node().getLens().setAspectRatio(10.0/16.0)
        
        camera.setPos( player.getX(), player.getY() - 40, player.getZ() ) #set its position.        
        return camera

    

    ###########################################################################
    #CREATE THE GAME LOOP
    def gameLoop(self, task):
      
      dt = task.time - task.last
      task.last = task.time

      if (self.choice == "singlePlayer") :

          self.car1.updateCar(dt)
          self.car1.collisionDetection(dt)
          base.camera.setPos(self.car1.Car.getX(), -40, self.car1.Car.getZ() )

          self.Text.getFpsText(dt)
          self.gauge1.setSpeed(self.car1.getAcceleration() )
          self.gauge1.updateGauges( "p1" )

          if (self.car1.getDamage() == 100):              

              self.car1.destroy()
              del self.car1
             
              self.gauge1.destroy()                
              del self.gauge1              
              
              self.choice = ""              
              self.menu(task)
              
          
      elif (self.choice == "multiPlayer"):

          self.car1.updateCar(dt)
          self.car1.collisionDetection(dt)
          self.car2.updateCar(dt)
          self.car2.collisionDetection(dt)

          self.camera1.setPos( self.car1.Car.getX(), -40, self.car1.Car.getZ() )
          self.camera2.setPos( self.car2.Car.getX(), -40, self.car2.Car.getZ() )

          self.gauge1.setSpeed( self.car1.getAcceleration() )
          self.gauge2.setSpeed( self.car2.getAcceleration() )

          self.gauge1.updateGauges( "p1" )
          self.gauge2.updateGauges( "p2" )

          self.Text.getFpsText( dt )


          if (self.car1.getDamage() == 100) or (self.car2.getDamage() == 100 ):

              self.car1.destroy()
              self.gauge1.destroy()
              del self.car1
              del self.gauge1

              self.car2.destroy()
              self.gauge2.destroy()
              del self.car2
              del self.gauge2
              
              self.camera1.removeNode()
              self.camera2.removeNode()
              
              self.choice = ""
              self.menu(task)
              

      return Task.cont



gr = GridRacer()

run()

I don’t really have time to read the whole code, but it seems that a global variable in MP has an affect on another/the same variable in SP.

Danny seems you didn’t read the topic subject :slight_smile:
I already solved it, it wasn’t a variable that was being overwritten or such,

it was the gameloop (TASK), that was being called several times. Thus increasing the acceleration.

when I posted it there was no SOLVED!!!

date of the “SOLVED” edit → Last edited by FormatWizard on Fri Oct 10, 2008 10:29 pm; edited 1 time in total
date of your post → Posted: Sun Oct 12, 2008 4:51 pm
the solved tag was there for 2 whole days by the time you answered…
a “oh sorry didnt see the solved thing” or even nothing at all would’ve been more polite.
just try to keep an eye on it next time.

greetings and have a nice day,
thomas

Lol danke Thomas :slight_smile: