Curling Game

Hi, i’m a student from Brazil, and i’m learning Panda3D. I’m trying to make a Curling game (for those who doesn’t know, it’s that game which you play with granite stones and your goal is to get the closest to a target), but I’m having some problems here.

1 - I have a static model that i want to shoot in the Y axis pressing the space key.
self.accept(“space”, self.setKey, [“shoot”,1])
self.accept(“space-up”, self.setKey, [“shoot”,0])

it’s working fine if i hold space, but if I stop holding, the model stops too (obviously ^^), does anyone know a way to press the key just one time and the model goes up?

2 - I will apply a friction force so that the model can stop going Y for the eternity. Does Panda has a library for this?

I’m starting to get crazy with this @_@ If anyone can help me, I would be grateful.

1. Well, then just remove the second line

2. Panda has a Physics library, yes. But for something as simple as this, I would rather just decrease the speed every frame, or so.

Woah, just that? I was worried that maybe I could not restart the value, but I think I understood now \o/. And about the friction, to decrease the speed I have to use a task for this? Because I’m not pretty sure how to use them yet =/

Well, I’d need to see your code to see how you move the thing at all, before I can say how to implement friction.

this is the code, it is PRETTY basic.

``````class Game(DirectObject):
def __init__(self):
self.text = genLabelText("Curling", -1, 0.95, 1, 1, 1, 1, 0.07)

# Desabilitar camera e posiciona-la
self.setupGame()

# Carregar os Modelos

# Setar os controles
self.setKeyboardControl()

def setupGame(self):
base.disableMouse()
base.camera.setPos(0, 50, 3)
base.setBackgroundColor(0.3, 0.5, 0.5)

self.previousTime = 0

def setKeyboardControl(self):
self.keyMap = {"left":0, "right":0, "shoot":0}

self.accept("escape", sys.exit)
self.accept("a", self.setKey, ["left",1])
self.accept("d", self.setKey, ["right",1])
self.accept("space", self.setKey, ["shoot",1])
self.accept("a-up", self.setKey, ["left",0])
self.accept("d-up", self.setKey, ["right",0])
#self.accept("space-up", self.setKey, ["shoot",0])

def setKey(self, key, value):
self.keyMap[key] = value

def forceBar (self):
self.force = 50

self.staticModel.reparentTo(render)
self.staticModel.setPos(-1, 15, 0)

#base.camera.reparentTo(self.staticModel)
base.camera.setPos(0, -50, 100)
base.camera.setP(base.camera.getP() + 15)
#lookAt faz a camera olhar para o persongaem
base.camera.lookAt(self.staticModel)

self.env.reparentTo(render)
self.env.setScale(0.25,0.25,0.25)
self.env.setPos(0, 20, 0)

self.dontStop = False
if (self.keyMap["left"] != 0):
self.staticModel.setPos(self.staticModel.getX() - elapsedTime * 15, self.staticModel.getY(), 0)
#base.camera.setPos(base.camera.getX() - elapsedTime * 15, base.camera.getY(), 40)
#base.camera.lookAt(self.staticModel)
#base.camera.setPos(base.camera.getX() - elapsedTime * 15, base.camera.getY(), 0)
if (self.keyMap["right"] !=0 ):
self.staticModel.setPos(self.staticModel.getX() + elapsedTime * 15, self.staticModel.getY(), 0)
base.camera.setPos(self.staticModel.getX() + elapsedTime * 15, base.camera.getY(), 40)
#base.camera.lookAt(self.staticModel)
if (self.dontStop == False):
if (self.keyMap["shoot"] !=0):

#self.dontStop = True
self.staticModel.setPos(self.staticModel.getX(), self.staticModel.getY() + elapsedTime * self.force, 0)
#base.camera.setPos(self.staticModel.getX() + elapsedTime * 15, self.staticModel.getY(), 0)
base.camera.lookAt(self.staticModel)

Something like this:

1. Initialize self.force in the init, for example by calling self.forceBar.
2. In the task, call self.force *= 0.9 or so. Making the 0.9 value to something like 0.8 will increase the friction, while 0.99 would increase friction.

Okay, I will try it here. Thanks for the help ^^

Hi, it’s me again, with the same problem, unfortunately…I have this code:

class Game(DirectObject):
def init(self):
self.text = genLabelText(“Curling”, -1, 0.95, 1, 1, 1, 1, 0.07)

``````    self.setupGame()

self.setKeyboardControl()

def setupGame(self):
base.disableMouse()
base.camera.setPos(0, 50, 3)
base.setBackgroundColor(0.3, 0.5, 0.5)

self.previousTime = 0

self.dontStop = False

def setKeyboardControl(self):
self.keyMap = {"left":0, "right":0, "shoot":0}

self.accept("escape", sys.exit)
self.accept("a", self.setKey, ["left",1])
self.accept("d", self.setKey, ["right",1])
self.accept("space", self.setKey, ["shoot",1])
self.accept("a-up", self.setKey, ["left",0])
self.accept("d-up", self.setKey, ["right",0])
self.accept("space-up", self.setKey, ["shoot",0])

def setKey(self, key, value):
self.keyMap[key] = value

self.staticModel.reparentTo(render)
self.staticModel.setPos(-1, 15, 0)

base.camera.setPos(0, -50, 100)
base.camera.setP(base.camera.getP() + 15)
base.camera.lookAt(self.staticModel)

self.env.reparentTo(render)
self.env.setScale(0.25,0.25,0.25)
self.env.setPos(0, 20, 0)

if (self.keyMap["left"] != 0):
self.staticModel.setPos(self.staticModel.getX() - elapsedTime * 15, self.staticModel.getY(), 0)
base.camera.lookAt(self.staticModel)
if (self.keyMap["right"] != 0):
self.staticModel.setPos(self.staticModel.getX() + elapsedTime * 15, self.staticModel.getY(), 0)
base.camera.lookAt(self.staticModel)

if (self.keyMap["shoot"] != 0):
self.dontStop = True

self.friction = 0.9
self.speedInit = 10
#self.speedFinal = self.speedInit - self.friction

if (self.dontStop == True):
self.speedFinal = self.speedInit - self.friction
self.staticModel.setPos(self.staticModel.getX(), self.staticModel.getY() - self.speedFinal, 0)
base.camera.lookAt(self.staticModel)
print self.speedFinal
if (self.speedFinal <= 0):
self.dontStop = False