First game need help

Hi

I’m actually working on an easy game, a spaceship move forward and you can move left, right, up and down. This is a very simple concept yet i do have some issue :
First, when you move to the left for instance, the spaceship rotate on the x axis, same for the other direction. Then if you mess with the keys, the spaceship end rotating on the z axis. How can i lock my spaceship so he don’t rotate on this axis ? (the python way)
Second, my spaceship is an X-wing, so when it shoot, i want it to fire four laser at once (one on each wing). Do i have to write the all “addObject” script four time ?
Finally, i don’t really understand how/where to use “class bpy.types.AlwaysSensor(Sensor)”. I actually use the logicbricks but i really want a full python powered game.

French here, sorry about my english.

Glasth

Are you using python for the moving? Maybe you should post the script?

I applaud you for doing your first game with python. :slight_smile:

I actually use python for everything except the always sensor and the physics. Here’s the whole script :

import bge

def main():

cont = bge.logic.getCurrentController()
player = cont.owner
keyboard = bge.logic.keyboard
scene = bge.logic.getCurrentScene()

movSpeed = 0.1
rushSpeed = 0.5
rotSpeed = 0.25
bulletSpeed = 2500

if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.LEFTSHIFTKEY]:
    #rushavant
    player.applyMovement((rushSpeed, 0, 0), True)
    
    
if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.ZKEY] :
    #deplbas
    player.applyMovement((0, 0, -movSpeed), True)
if bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.ZKEY] :
    #rotbas
    player.applyRotation((0, rotSpeed, 0), True)
if bge.logic.KX_INPUT_JUST_RELEASED == keyboard.events[bge.events.ZKEY] :
    #antirotbas
    player.applyRotation((0, -rotSpeed, 0), True)
    
if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.SKEY] :
    #deplhaut
    player.applyMovement((0, 0, movSpeed), True)
if bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.SKEY] :
    #rothaut
    player.applyRotation((0, -rotSpeed, 0), True)
if bge.logic.KX_INPUT_JUST_RELEASED == keyboard.events[bge.events.SKEY] :
    #antirothaut
    player.applyRotation((0, rotSpeed, 0), True)
    
if bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.QKEY] :
    #rotgauche
    player.applyRotation((-rotSpeed, 0, 0), True)
if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.QKEY] :
    #deplgauche
    player.applyMovement((0, movSpeed, 0), True)
if bge.logic.KX_INPUT_JUST_RELEASED == keyboard.events[bge.events.QKEY] :
    #antirotgauche
    player.applyRotation((rotSpeed, 0, 0), True)
    
if bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.DKEY] :
    #rotdroite
    player.applyRotation((rotSpeed, 0, 0), True)
if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.DKEY] :
    #depldroite
    player.applyMovement((0, -movSpeed, 0), True)
if bge.logic.KX_INPUT_JUST_RELEASED == keyboard.events[bge.events.DKEY] :
    #antirotdroite
    player.applyRotation((-rotSpeed,0 ,0), True)
    
if bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.SPACEKEY] :
    #tir
    bullet = scene.addObject('Bullet', 'Barrel', 150)
    bullet.applyForce((-bulletSpeed, 0, 0), True)
    bullet.color = (1, 0, 0, 1)

main()

By the way is there an other way to write the moving part : i need an event as long input is active, an event that run once when the input is active (JUST_ACTIVATED) and one when the input is released which make three if for each direction.

No need for applause since the game is awkardly short and simplist :wink: