0
\$\begingroup\$

I am a fairly new user of pygame and i decided to start out with a simple but 'funny' game. I have successfully implemented jumping mechanics, movement mechanics and a one directional shooting mechanic, however when trying to put this shooting mechanic to work both ways i couldnt figure out why it didnt work, i have tried a few things to fix it but i do not know what is wrong with it. It will only shoot towards the left side. Also, I did create all the code myself without tutorials and external input so perhaps there is a better system for my shooting mechanic. Here is the code:

#Importation & initialisation
import pygame as py
import sys
import random
py.init()

CLOCK = py.time.Clock()
#loop variable
running = True
#Colours
White = (255, 255, 255)
Black = (0, 0, 0)
Blue = (0, 70, 200)
#variables
#Fruit merchant
FRUITmerchant_HEALTH = 10
XfruitM = 500
YfruitM = 500
SpeedFruitM = 5
RIGHTDASH = False
LEFTDASH = False
JumpingF = False
#weapns for fruit
WeaponFruit_right = False
WeaponFruit_left = False
APPLE = False
YfruitApple = 530
XfruitApple = 495
Apple_reach = 20
Apple_VELOCITYX = Apple_reach
#Veg merchant
XvegM = 100
YvegM = 500
SpeedVegM = 5
JumpingV = False
#Forces
YGRAVITY = 0.7
JUMPHEIGHT = 21
Y_VELOCITY = JUMPHEIGHT
Y_VELOCITYV = JUMPHEIGHT # FOR VEG
Air_Resistance = 1
#Setup
Screen = py.display.set_mode((600, 600))

#Fruit Merchant functions for movement
def move_leftFruitM():
     # a function is like a mini program in your main program so therefore you mjst declare a variable global
    global SpeedFruitM, WeaponFruit_right, WeaponFruit_left
    global XfruitM  
    if py.key.get_pressed()[py.K_LEFT]: #
\$\endgroup\$
4
  • \$\begingroup\$ Where is your current shooting function? \$\endgroup\$ Commented Jul 19 at 20:27
  • \$\begingroup\$ Sorry, i have figured i out after multiple attempts \$\endgroup\$ Commented Jul 20 at 14:58
  • 1
    \$\begingroup\$ The purpose of sharing an answer on this site is so that future readers can learn from what you've shared. Showing your solution, or walking through your problem-solving thought process could be very useful to future readers. "I figured it out" without any elaboration, isn't useful. I'd recommend editing this post to explain in more detail, or deleting your question if you no longer want help with it and don't want to take the time to share tips for future readers \$\endgroup\$ Commented Jul 20 at 16:10
  • \$\begingroup\$ Moved the above from an answer to a comment ^ It would be much appreciated if you could answer your own question with your solution! \$\endgroup\$ Commented Jul 23 at 15:58

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.