This shows you the differences between two versions of the page.
ii:lab:laborator3 [2016/11/24 00:40] iulian_gabriel.radu [Instalare python și pip pe Windows fără drepturi de administrator] |
ii:lab:laborator3 [2020/11/25 10:25] (current) florin.stancu [Input de la utilizator] fix code |
||
---|---|---|---|
Line 50: | Line 50: | ||
<code python> | <code python> | ||
+ | # -*- coding: utf-8 -*- | ||
+ | |||
import pygame | import pygame | ||
Line 62: | Line 64: | ||
# Rect(left, top, width, height) -> Rect | # Rect(left, top, width, height) -> Rect | ||
# | # | ||
- | pygame.draw.rect(screen, (255, 0, 0), Rect(120, 120, 200, 100)) | + | pygame.draw.rect(screen, (255, 0, 0), pygame.Rect(120, 120, 200, 100)) |
# Afișam modificările pe ecran | # Afișam modificările pe ecran | ||
Line 76: | Line 78: | ||
<code python> | <code python> | ||
+ | # -*- coding: utf-8 -*- | ||
+ | |||
import pygame | import pygame | ||
Line 81: | Line 85: | ||
# Încărcăm imaginea în memorie | # Încărcăm imaginea în memorie | ||
- | image = pygame.pygame.load('image.png') | + | image = pygame.image.load('image.png') |
# Transferăm pixelii imaginii în fereastră | # Transferăm pixelii imaginii în fereastră | ||
Line 95: | Line 99: | ||
<code python> | <code python> | ||
+ | # -*- coding: utf-8 -*- | ||
+ | |||
import pygame | import pygame | ||
+ | from pygame import KEYDOWN | ||
screen = pygame.display.set_mode((800, 600)) | screen = pygame.display.set_mode((800, 600)) | ||
Line 107: | Line 114: | ||
if event.type == KEYDOWN: | if event.type == KEYDOWN: | ||
- | if event.key == K_UP: | + | if event.key == pygame.K_UP: |
print 'sageata sus' | print 'sageata sus' | ||
- | elif event.key == K_DOWN: | + | elif event.key == pygame.K_DOWN: |
print 'sageata jos' | print 'sageata jos' | ||
- | elif event.key == K_LEFT: | + | elif event.key == pygame.K_LEFT: |
print 'sageata stanga' | print 'sageata stanga' | ||
- | elif event.key == K_RIGHT: | + | elif event.key == pygame.K_RIGHT: |
print 'sageata dreapta' | print 'sageata dreapta' | ||
- | elif event.key == K_SPACE: | + | elif event.key == pygame.K_SPACE: |
print 'space' | print 'space' | ||
Line 137: | Line 144: | ||
<code>msiexec /a python-2.7.12.msi /qb TARGETDIR=C:\development\</code> | <code>msiexec /a python-2.7.12.msi /qb TARGETDIR=C:\development\</code> | ||
- | - Descărcați scriptul de mai jos și salvați-l în directorul C:\development (folosiți <code>Click dreapta -> Save link as</code>): | + | - Descărcați scriptul de mai jos și salvați-l în directorul C:\development (folosiți Click dreapta -> Save link as): |
https://bootstrap.pypa.io/get-pip.py | https://bootstrap.pypa.io/get-pip.py | ||
- Navigați în directorul C:\development și rulati comanda: | - Navigați în directorul C:\development și rulati comanda: | ||
- | <code>python.exe get-pip.py --user</code> | + | <code>python.exe get-pip.py</code> |
- Rulati comanda de mai jos pentru a instala pygame | - Rulati comanda de mai jos pentru a instala pygame | ||
- | <code>python.exe Lib\site-packages\pip\__main__.py pygame --user</code> | + | <code>python.exe Lib\site-packages\pip\__main__.py install pygame --user</code> |
- Din directorul C:\development puteți rula orice script folosind: | - Din directorul C:\development puteți rula orice script folosind: | ||
<code>python.exe $nume_script</code> | <code>python.exe $nume_script</code> | ||
- | |||
- | ===== Phaser ===== | ||
- | |||
===== Exerciții ===== | ===== Exerciții ===== | ||
- | Creeați un joc la alegere pornind de la unul dintre scheletele de cod de mai jos. | + | === Task-uri: === |
- | + | Creeați [[https://www.andoverpatio.co.uk/21/space-invaders/|Space Invaders]] plcand de la scheletul de cod de mai jos: | |
- | - Python/PyGame | + | - **[20p]** Jucator: poate sa se deplaseze stanga(A) / dreapta(D) si sa lanseze proiectile (Space) |
+ | - **[20p]** Bunkere destructibile | ||
+ | - **[20p]** Inamici mobili organizati in 5 randuri | ||
+ | - **[20p]** Cel mai apropiat inamic de pe fiecare coloana ataca | ||
+ | - **[20p]** Score si High-Score (salvat intre run-uri) | ||
+ | === Resurse aditionale: === | ||
+ | * Parcurgeti [[http://www.101computing.net/getting-started-with-pygame/|acest tutorial]] pentru informatii aditionale. | ||
+ | * Porniti de la acest schelet de cod: | ||
+ | <spoiler> | ||
<file python main.py> | <file python main.py> | ||
import pygame | import pygame | ||
+ | import sys | ||
WIDTH = 800 | WIDTH = 800 | ||
Line 169: | Line 182: | ||
COLOR_BLACK = (0, 0, 0) | COLOR_BLACK = (0, 0, 0) | ||
- | + | COLOR_RED = (255, 0, 0) | |
- | + | ||
- | """ Modify current game state """ | + | |
- | def update(): | + | |
- | pass | + | |
- | + | ||
- | """ Draw current game state """ | + | |
- | def render(): | + | |
- | pass | + | |
def main(): | def main(): | ||
Line 230: | Line 235: | ||
# Update game state | # Update game state | ||
- | update() | ||
# Render current game state | # Render current game state | ||
- | render() | + | pygame.draw.rect(background, |
+ | COLOR_RED, | ||
+ | pygame.Rect(100, 120, 200, 400)) | ||
+ | |||
+ | pygame.display.flip() | ||
+ | screen.blit(background, (0, 0)) | ||
if __name__ == '__main__': | if __name__ == '__main__': | ||
main() | main() | ||
- | |||
</file> | </file> | ||
- | + | </spoiler> | |
- | - JavaScript/Phaser | + | |
- | <file js main.js> | + | |
- | + | ||
- | </file> | + | |
- | + | ||
- | https://phaser.io/sandbox/ | + | |
- | + | ||
- | http://www.zekechan.net/getting-started-html5-game-development-pong1/ | + | |
- | + | ||
- | https://github.com/zekechan/phaser-html5-tutorial-pong | + |