diff --git a/gui.py b/gui.py new file mode 100644 index 0000000..32fcc24 --- /dev/null +++ b/gui.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Author: freezed 2018-03-15 +Version: 0.1 + +Licence: `GNU GPL v3` GNU GPL v3: http://www.gnu.org/licenses/ + +This file is part of [_ocp3_ project](https://github.com/freezed/ocp3) +""" + +import pygame +from pygame.locals import ( + K_UP, K_DOWN, K_RIGHT, K_LEFT, KEYDOWN, QUIT, RESIZABLE +) + +MAZE_SIZE_CEL = 15 +CELL_SIZE_PX = 50 +BACK_TILE_IMG = 'img/blue-transp-50.png' +PLAYER_TILE_IMG = 'img/player-50.png' +WINDOW_SIZE_PX = CELL_SIZE_PX * MAZE_SIZE_CEL + +pygame.init() + +WINDOW = pygame.display.set_mode( + (WINDOW_SIZE_PX, WINDOW_SIZE_PX), + RESIZABLE +) + +GRID = range(MAZE_SIZE_CEL ** 2) +back_tiles = [] +for cell in GRID: + back_tiles.append(pygame.image.load(BACK_TILE_IMG).convert()) + x = (cell % MAZE_SIZE_CEL) * CELL_SIZE_PX + y = (cell // MAZE_SIZE_CEL) * CELL_SIZE_PX + WINDOW.blit(back_tiles[cell], (x, y)) + +PLAYER = pygame.image.load(PLAYER_TILE_IMG).convert_alpha() +player_pos = PLAYER.get_rect() + +# Player position +WINDOW.blit(PLAYER, player_pos) + +# Refresh +pygame.display.flip() + +loop = True +while loop: + for event in pygame.event.get(): + if event.type == QUIT: + loop = False + + if event.type == KEYDOWN: + if event.key == K_DOWN: + player_pos = player_pos.move(0, CELL_SIZE_PX) + + if event.type == KEYDOWN: + if event.key == K_LEFT: + player_pos = player_pos.move(-CELL_SIZE_PX, 0) + + if event.type == KEYDOWN: + if event.key == K_UP: + player_pos = player_pos.move(0, -CELL_SIZE_PX) + + if event.type == KEYDOWN: + if event.key == K_RIGHT: + player_pos = player_pos.move(CELL_SIZE_PX, 0) + + # New player position + # WINDOW.blit(back_tiles, (0,0)) + WINDOW.blit(PLAYER, player_pos) + + # Refresh + pygame.display.flip() diff --git a/img/1-blue-transp-50.png b/img/1-blue-transp-50.png new file mode 100644 index 0000000..bda0b9e Binary files /dev/null and b/img/1-blue-transp-50.png differ diff --git a/img/2-blue-transp-50.png b/img/2-blue-transp-50.png new file mode 100644 index 0000000..d2682f5 Binary files /dev/null and b/img/2-blue-transp-50.png differ diff --git a/img/3-blue-transp-50.png b/img/3-blue-transp-50.png new file mode 100644 index 0000000..06f978b Binary files /dev/null and b/img/3-blue-transp-50.png differ diff --git a/img/4-blue-transp-50.png b/img/4-blue-transp-50.png new file mode 100644 index 0000000..3c0b91f Binary files /dev/null and b/img/4-blue-transp-50.png differ diff --git a/img/background.jpg b/img/background.jpg deleted file mode 100644 index 6705943..0000000 Binary files a/img/background.jpg and /dev/null differ diff --git a/img/blue-transp-50.png b/img/blue-transp-50.png new file mode 100644 index 0000000..1ff6f87 Binary files /dev/null and b/img/blue-transp-50.png differ diff --git a/img/blue-white-50.png b/img/blue-white-50.png new file mode 100644 index 0000000..a9504be Binary files /dev/null and b/img/blue-white-50.png differ diff --git a/img/g-orange-transp-50.png b/img/g-orange-transp-50.png new file mode 100644 index 0000000..c2a3b45 Binary files /dev/null and b/img/g-orange-transp-50.png differ diff --git a/img/grey-transp-50.png b/img/grey-transp-50.png new file mode 100644 index 0000000..62eb548 Binary files /dev/null and b/img/grey-transp-50.png differ diff --git a/img/grey-white-50.png b/img/grey-white-50.png new file mode 100644 index 0000000..e578de7 Binary files /dev/null and b/img/grey-white-50.png differ diff --git a/img/grid-800.png b/img/grid-800.png deleted file mode 100644 index c253858..0000000 Binary files a/img/grid-800.png and /dev/null differ diff --git a/img/m-orange-transp-50.png b/img/m-orange-transp-50.png new file mode 100644 index 0000000..46dfc7c Binary files /dev/null and b/img/m-orange-transp-50.png differ diff --git a/img/perso-100.png b/img/perso-100.png deleted file mode 100644 index 5933970..0000000 Binary files a/img/perso-100.png and /dev/null differ diff --git a/img/perso.png b/img/perso.png deleted file mode 100644 index 8dd13f3..0000000 Binary files a/img/perso.png and /dev/null differ diff --git a/img/player-50.png b/img/player-50.png new file mode 100644 index 0000000..8047948 Binary files /dev/null and b/img/player-50.png differ diff --git a/testpygame.py b/testpygame.py deleted file mode 100644 index 798b87b..0000000 --- a/testpygame.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Author: freezed 2018-03-15 -Version: 0.1 - -Licence: `GNU GPL v3` GNU GPL v3: http://www.gnu.org/licenses/ - -The path of the righteous man is beset on all sides by the iniquities -of the selfish and the tyranny of evil men. Blessed is he who, in the -name of charity and good will, shepherds the weak through the valley of -darkness, for he is truly his brother's keeper and the finder of lost -children. And I will strike down upon thee with great vengeance and -furious anger those who would attempt to poison and destroy My brothers. -And you will know My name is the Lord when I lay My vengeance upon thee. -""" - -import pygame -from pygame.locals import * - -pygame.init() - -#Ouverture de la fenêtre Pygame -fenetre = pygame.display.set_mode((800, 800)) - -#Chargement et collage du fond -fond = pygame.image.load("img/grid-800.png").convert() -fenetre.blit(fond, (0,0)) - -#Chargement et collage du personnage -perso = pygame.image.load("img/perso-100.png").convert_alpha() -position_perso = perso.get_rect() -fenetre.blit(perso, position_perso) - -#Rafraîchissement de l'écran -pygame.display.flip() - -#BOUCLE INFINIE -continuer = 1 -while continuer: - for event in pygame.event.get(): #Attente des événements - if event.type == QUIT: - continuer = 0 - # Down - if event.type == KEYDOWN: - if event.key == K_DOWN: - position_perso = position_perso.move(0,100) - # - if event.type == KEYDOWN: - if event.key == K_LEFT: - position_perso = position_perso.move(-100,0) - # - if event.type == KEYDOWN: - if event.key == K_UP: - position_perso = position_perso.move(0,-100) - # - if event.type == KEYDOWN: - if event.key == K_RIGHT: - position_perso = position_perso.move(100,0) - - #Re-collage - fenetre.blit(fond, (0,0)) - fenetre.blit(perso, position_perso) - - #Rafraichissement - pygame.display.flip()