May-02-2019, 01:49 AM
I'm new to programming and I'm barely starting. I'm trying to make a 4 player local Co-op fighting game to play with my friends and family so we could all play on the same keyboard. I got the first player to jump but when i put the code to jump for the 2nd player it doesn't work so I'm stuck. I haven't put the jump code for the 3rd and 4th player yet and my characters are squares right now not 2d sprites yet. I have assigned all different keys to each player. I'm also having a problem of the first player jumping right when i start the game up. Please help
My Code is underneath this!
import pygame
pygame.init()
screen = pygame.display.set_mode((1250, 650))
pygame.display.set_caption("Close to Death")
screenwidth = 1000
x = 50
X = 50
y = 450
Y = 450
width = 50
Wide = 50
Height = 50
Tall = 50
vel = 10
Vel = 10
xx = 50
yy = 450
wider = 50
ht = 50
v = 10
XX = 50
YY = 450
HT = 50
WH = 50
V = 10
IsJump = True
isJump = True
jumpCount = 6
JumpCounts = 6
run = True
while run:
pygame.time.delay(50)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
screen.fill((0, 0, 0))
pygame.draw.rect(screen, (255, 0, 0,), (x, y, width, Height))
pygame.draw.rect(screen, (0, 255, 0,), (X, Y, Wide, Tall))
pygame.draw.rect(screen, (0, 0, 255,), (xx, yy, wider, ht))
pygame.draw.rect(screen, (0, 255, 255,), (XX, YY, WH, HT))
pygame.display.update()
if keys[pygame.K_LEFT] and x > vel:
x -= vel
if keys[pygame.K_RIGHT] and x < 1249 - width - vel:
x += vel
if not isJump:
if keys[pygame.K_UP] and y > vel:
y -= vel
if keys[pygame.K_DOWN] and y < 598 - vel:
y += vel
if keys[pygame.K_PAGEDOWN]:
isJump = True
else:
if jumpCount >= -6:
neg = +1
if jumpCount < 0:
neg = - 1
y -= (jumpCount ** 2) * 1 * neg
jumpCount -= 1
else:
isJump = False
jumpCount = 6
if keys[pygame.K_a] and X > Vel:
X -= Vel
if keys[pygame.K_d] and X < 1249 - Wide - Vel:
X += Vel
if not IsJump:
if keys[pygame.K_w] and Y > Vel:
Y -= Vel
if keys[pygame.K_s] and Y < 598 - Vel:
Y += Vel
if keys[pygame.K_q]:
IsJump = True
else:
if JumpCounts >= -6:
Negative = +1
if JumpCounts < 0:
Negative = - -1
Y -= (JumpCounts ** 2) * 1 * Negative
JumpCounts -= 1
else:
IsJump = False
JumpCounts = 6
if keys[pygame.K_h] and xx > v:
xx -= v
if keys[pygame.K_k] and xx < 1240 - wider - v:
xx += v
if keys[pygame.K_u] and yy > v:
yy -= v
if keys[pygame.K_j] and yy < 455 - v:
yy += v
if keys[pygame.K_KP5] and XX > V:
XX -= V
if keys[pygame.K_KP_PLUS] and XX < 1240 - WH - V:
XX += V
if keys[pygame.K_KP9] and YY > V:
YY -= V
if keys[pygame.K_KP6] and YY < 455 - V:
YY += V
My Code is underneath this!
import pygame
pygame.init()
screen = pygame.display.set_mode((1250, 650))
pygame.display.set_caption("Close to Death")
screenwidth = 1000
x = 50
X = 50
y = 450
Y = 450
width = 50
Wide = 50
Height = 50
Tall = 50
vel = 10
Vel = 10
xx = 50
yy = 450
wider = 50
ht = 50
v = 10
XX = 50
YY = 450
HT = 50
WH = 50
V = 10
IsJump = True
isJump = True
jumpCount = 6
JumpCounts = 6
run = True
while run:
pygame.time.delay(50)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
screen.fill((0, 0, 0))
pygame.draw.rect(screen, (255, 0, 0,), (x, y, width, Height))
pygame.draw.rect(screen, (0, 255, 0,), (X, Y, Wide, Tall))
pygame.draw.rect(screen, (0, 0, 255,), (xx, yy, wider, ht))
pygame.draw.rect(screen, (0, 255, 255,), (XX, YY, WH, HT))
pygame.display.update()
if keys[pygame.K_LEFT] and x > vel:
x -= vel
if keys[pygame.K_RIGHT] and x < 1249 - width - vel:
x += vel
if not isJump:
if keys[pygame.K_UP] and y > vel:
y -= vel
if keys[pygame.K_DOWN] and y < 598 - vel:
y += vel
if keys[pygame.K_PAGEDOWN]:
isJump = True
else:
if jumpCount >= -6:
neg = +1
if jumpCount < 0:
neg = - 1
y -= (jumpCount ** 2) * 1 * neg
jumpCount -= 1
else:
isJump = False
jumpCount = 6
if keys[pygame.K_a] and X > Vel:
X -= Vel
if keys[pygame.K_d] and X < 1249 - Wide - Vel:
X += Vel
if not IsJump:
if keys[pygame.K_w] and Y > Vel:
Y -= Vel
if keys[pygame.K_s] and Y < 598 - Vel:
Y += Vel
if keys[pygame.K_q]:
IsJump = True
else:
if JumpCounts >= -6:
Negative = +1
if JumpCounts < 0:
Negative = - -1
Y -= (JumpCounts ** 2) * 1 * Negative
JumpCounts -= 1
else:
IsJump = False
JumpCounts = 6
if keys[pygame.K_h] and xx > v:
xx -= v
if keys[pygame.K_k] and xx < 1240 - wider - v:
xx += v
if keys[pygame.K_u] and yy > v:
yy -= v
if keys[pygame.K_j] and yy < 455 - v:
yy += v
if keys[pygame.K_KP5] and XX > V:
XX -= V
if keys[pygame.K_KP_PLUS] and XX < 1240 - WH - V:
XX += V
if keys[pygame.K_KP9] and YY > V:
YY -= V
if keys[pygame.K_KP6] and YY < 455 - V:
YY += V