-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import pygame | ||
pygame.init() | ||
win = pygame.display.set_mode((850,480)) | ||
|
||
pygame.display.set_caption("hello there ") | ||
|
||
walkRight = [pygame.image.load('R1.png'), pygame.image.load('R2.png'), pygame.image.load('R3.png'), pygame.image.load('R4.png'), pygame.image.load('R5.png'), pygame.image.load('R6.png'), pygame.image.load('R7.png'), pygame.image.load('R8.png'), pygame.image.load('R9.png')] | ||
walkLeft = [pygame.image.load('L1.png'), pygame.image.load('L2.png'), pygame.image.load('L3.png'), pygame.image.load('L4.png'), pygame.image.load('L5.png'), pygame.image.load('L6.png'), pygame.image.load('L7.png'), pygame.image.load('L8.png'), pygame.image.load('L9.png')] | ||
bg = pygame.image.load('bg.jpg') | ||
char = pygame.image.load('standing.png') | ||
|
||
clock=pygame.time.Clock() | ||
|
||
class player(object): | ||
def __init__(self,x,y,height,width): | ||
self.x= x | ||
self.y=y | ||
self.height=height | ||
self.width=width | ||
self.vel=10 | ||
self.isJump=False | ||
self.jumpCount=10 | ||
self.Left=False | ||
self.Right=False | ||
self.Walk=0 | ||
self.standing = True | ||
|
||
def draw(self,win): | ||
if self.Walk + 1 >= 27: | ||
self.Walk = 0 | ||
|
||
if not(self.standing): | ||
if self.Left: | ||
win.blit(walkLeft[self.Walk // 3], (self.x, self.y)) | ||
self.Walk += 1 | ||
|
||
elif self.Right: | ||
win.blit(walkRight[self.Walk // 3], (self.x, self.y)) | ||
self.Walk += 1 | ||
else: | ||
if self.Right: | ||
win.blit(walkRight[0],(self.x,self.y)) | ||
else: | ||
win.blit(walkLeft[0],(self.x,self.y)) | ||
|
||
class projectile(object): | ||
def __init__(self,x,y,radius,color,facing): | ||
self.x=x | ||
self.y=y | ||
self.radius=radius | ||
self.color=color | ||
self.facing=facing | ||
self.vel=8*facing | ||
|
||
def draw(self,win): | ||
pygame.draw.circle(win,self.color,(self.x,self.y),self.radius ) | ||
|
||
|
||
|
||
|
||
|
||
def redrawGameWindow(): | ||
|
||
win.blit(bg,(0,0)) | ||
man.draw(win) | ||
for bullet in bullets: | ||
bullet.draw(win) | ||
pygame.display.update() | ||
|
||
#main loop | ||
man = player(50,380,64,64) | ||
run = True | ||
bullets = [] | ||
while run: | ||
clock.tick(27) | ||
|
||
for event in pygame.event.get(): | ||
if event.type == pygame.QUIT: | ||
run =False | ||
for bullet in bullets: | ||
if bullet.x < 850 and bullet.x>0: | ||
bullet.x += bullet.vel | ||
else: | ||
bullets.pop(bullets.index(bullet)) | ||
|
||
keys=pygame.key.get_pressed() | ||
|
||
if keys[pygame.K_SPACE]: | ||
if man.Left: | ||
facing= -1 | ||
else: | ||
facing=1 | ||
if len(bullets)<5: | ||
bullets.append(projectile(round(man.x + man.width//2),round(man.y , man.height//2),6,(0,0,0),facing)) | ||
|
||
if keys[pygame.K_LEFT] and man.x > man.vel: | ||
man.x -= man.vel | ||
man.Left= True | ||
man.Right=False | ||
man.standing=False | ||
|
||
elif keys[pygame.K_RIGHT] and man.x < 800: | ||
man.x += man.vel | ||
man.Right=True | ||
man.Left=False | ||
man.standing=False | ||
else: | ||
man.standing=True | ||
man.Walk=0 | ||
if not(man.isJump): | ||
|
||
if keys[pygame.K_UP] : | ||
man.isJump = True | ||
man.Right=False | ||
man.Left=False | ||
man.Walk=0 | ||
|
||
else : | ||
if man.jumpCount >= -10: | ||
neg = 1 | ||
if man.jumpCount<0: | ||
neg= -1 | ||
man.y -= (man.jumpCount ** 2)* 0.5 * neg | ||
man.jumpCount -= 1 | ||
else : | ||
man.isJump =False | ||
man.jumpCount=10 | ||
|
||
redrawGameWindow() | ||
|
||
|
||
|
||
pygame.quit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pygame | ||
|
||
pygame.init() | ||
|
||
win = pygame.display.set_mode((500,500)) | ||
|
||
pygame.display.set_caption("my first pygame project") | ||
|
||
x=50 | ||
y=50 | ||
height=40 | ||
width=60 | ||
vel=5 | ||
|
||
run = True | ||
|
||
while run: | ||
pygame.time.delay(100) | ||
|
||
for event in pygame.event.get(): | ||
if event.type == pygame.QUIT: | ||
run = False | ||
|
||
keys = pygame.key.get_pressed( ) | ||
|
||
if keys[pygame.K_w]: | ||
x += vel | ||
|
||
win.fill((0,0,0)) | ||
pygame.draw.rect(win, (253,52,1), (x,y,height,width)) | ||
pygame.display.update() | ||
pygame.quit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import pygame | ||
pygame.init() | ||
#every time use this upper line to initial pygame | ||
|
||
win = pygame.display.set_mode((500,500)) | ||
#this upper line makes window to play game in , here "win" is variable for that window | ||
|
||
pygame.display.set_caption("my first pygame") | ||
|
||
x=50 | ||
y=400 | ||
height=40 | ||
width= 40 | ||
vel = 5 | ||
|
||
isJump= True | ||
jumpCount = 10 | ||
jumpHeight = 50 | ||
|
||
run = True | ||
|
||
while run: | ||
pygame.time.delay(100) | ||
|
||
for event in pygame.event.get(): | ||
if event.type == pygame.QUIT: | ||
run = False | ||
|
||
keys = pygame.key.get_pressed() | ||
|
||
if keys[pygame.K_d] and x < 450: | ||
x += vel | ||
if keys[pygame.K_a] and x > vel: | ||
x -= vel | ||
if not(isJump): | ||
` y += vel | ||
if keys[pygame.K_w] and y > vel: | ||
y -= vel | ||
if keys[pygame.K_SPACE] : | ||
isJump= True | ||
else: | ||
if jumpCount >= -10: | ||
heg=1 | ||
if jumpCount<0: | ||
heg= -1 | ||
y -= (jumpCount ** 2)* 0.5 * heg | ||
jumpCount -= 1 | ||
else : | ||
isJump = False | ||
jumpCount=10 | ||
|
||
win.fill((0,0,0)) | ||
pygame.draw.rect(win, (253,52,1), (x,y,height,width)) | ||
pygame.display.update() | ||
|
||
pygame.quit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
home = C:\Users\ADMIN\AppData\Local\Programs\Python\Python37-32 | ||
include-system-site-packages = false | ||
version = 3.7.3 |
Oops, something went wrong.