debut de definition des models et deux personnages
This commit is contained in:
parent
1f98475dd3
commit
f9025ba480
3 changed files with 57 additions and 24 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
*__.py
|
||||
__pycache__/*
|
||||
*.swp
|
||||
*.pyc
|
36
main.py
36
main.py
|
@ -4,10 +4,12 @@
|
|||
### Author: Arthur 'Grizzly' Grisel-Davy
|
||||
|
||||
import pygame
|
||||
|
||||
from models import perso
|
||||
pygame.init()
|
||||
|
||||
|
||||
screen_width = 800
|
||||
screen_width = 1200
|
||||
screen_height = 800
|
||||
screen = pygame.display.set_mode((screen_width, screen_height))
|
||||
done = False
|
||||
|
@ -16,13 +18,10 @@ done = False
|
|||
BACKGROUND=(0,0,0)
|
||||
WHITE=(255,255,255)
|
||||
BLUE=(0,0,255)
|
||||
RED=(255,0,0)
|
||||
|
||||
posx = 400
|
||||
posy = 400
|
||||
width=50
|
||||
height=50
|
||||
|
||||
pygame.draw.rect(screen,BLUE,(posx,posy,width,height))
|
||||
perso1 = perso('Alice',200,200,50,50,RED,pygame.K_o,pygame.K_l,pygame.K_k,pygame.K_m)
|
||||
perso2 = perso('Bjorn',600,600,50,50,BLUE,pygame.K_z,pygame.K_s,pygame.K_q,pygame.K_d)
|
||||
|
||||
speed = 1
|
||||
|
||||
|
@ -32,23 +31,12 @@ while not done:
|
|||
done = True
|
||||
|
||||
keystate = pygame.key.get_pressed()
|
||||
if keystate[pygame.K_LEFT]:
|
||||
posx -= speed
|
||||
if posx <0:
|
||||
posx=0
|
||||
if keystate[pygame.K_RIGHT]:
|
||||
posx += speed
|
||||
if posx+width > screen_width:
|
||||
posx = screen_height-width
|
||||
if keystate[pygame.K_UP]:
|
||||
posy -= speed
|
||||
if posy < 0:
|
||||
posy = 0
|
||||
if keystate[pygame.K_DOWN]:
|
||||
posy += speed
|
||||
if posy+height > screen_height:
|
||||
posy = screen_height-height
|
||||
|
||||
perso1.check_move(keystate,screen_width,screen_height,speed)
|
||||
perso2.check_move(keystate,screen_width,screen_height,speed)
|
||||
|
||||
|
||||
screen.fill(BACKGROUND)
|
||||
pygame.draw.rect(screen,BLUE,(posx,posy,width,height))
|
||||
perso1.draw(screen)
|
||||
perso2.draw(screen)
|
||||
pygame.display.flip()
|
41
models.py
Normal file
41
models.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
|
||||
### Tangled Mind
|
||||
### Author: Arthur 'Grizzly' Grisel-Davy
|
||||
|
||||
import pygame
|
||||
|
||||
class perso():
|
||||
|
||||
def __init__(self,name,posx,posy,width,height,color,key_up,key_down,key_left,key_right):
|
||||
self.name = name
|
||||
self.posx = posx
|
||||
self.posy = posy
|
||||
self.key_up = key_up
|
||||
self.key_down = key_down
|
||||
self.key_left = key_left
|
||||
self.key_right = key_right
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.color = color
|
||||
|
||||
def check_move(self,keystate,screen_width,screen_height,speed):
|
||||
if keystate[self.key_left]:
|
||||
self.posx -= speed
|
||||
if self.posx <0:
|
||||
self.posx=0
|
||||
if keystate[self.key_right]:
|
||||
self.posx += speed
|
||||
if self.posx+self.width > screen_width:
|
||||
self.posx = screen_width-self.width
|
||||
if keystate[self.key_up]:
|
||||
self.posy -= speed
|
||||
if self.posy < 0:
|
||||
self.posy = 0
|
||||
if keystate[self.key_down]:
|
||||
self.posy += speed
|
||||
if self.posy+self.height > screen_height:
|
||||
self.posy = screen_height-self.height
|
||||
|
||||
def draw(self,surface):
|
||||
pygame.draw.rect(surface,self.color,(self.posx,self.posy,self.width,self.height))
|
Loading…
Reference in a new issue