|
|
|
HTML - szablon strony głównej - zastosowanie tabeli <table></table>Kopiujemy kod poniżej, wklejamy do Notatnika (lub innego edytora tekstu), zapisujemy z nazwąS index.html Okno wybotu formatu pliku przełączamy na Wszystkie pliki.<!DOCTYPE html> <html lang="pl"> <head> <meta charset="utf-8"> <title>strona główna</title> <meta name="keywords" content="słowa kluczowe"> <meta name="description" content="opis zawartości strony"> <meta name="author" content="imię i nazwisko autora, adres email"> <!--<link rel="stylesheet" type="text/css" href="styl.css">--> </head> <body> <div style="text-align:center; width:800px; margin-left:auto; margin-right:auto;"> <table border="0" cellspacing="0" cellpadding="0"> <tr style="background-color:#009900"> <td height="175" colspan="2"> </td> </tr> <tr> <td width="175" height="625" style="background-color:#ffff00"> </td> <td width="625" height="625" style="background-color:#ff0000"> </td> </tr> </table> </div> </body> </html> Otrzymujemy następujący efekt:
Okno gry - tło, tytuł, ikonka
import pygame
import sys
pygame.init()
screen_game=pygame.display.set_mode((700,700))
ikonka=pygame.image.load("pliki/favicon.png")
pygame.display.set_icon(ikonka)
pygame.display.set_caption("stolik do kawy")
screen_game.fill((255, 0, 0))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
Okno gry - tekst
import pygame
import sys
from pygame.locals import *#QUIT zamiast pygame.QUIT
pygame.init()
screen_game=pygame.display.set_mode((700,700))
ikonka=pygame.image.load("pliki/favicon.png")
pygame.display.set_icon(ikonka)
pygame.display.set_caption("stolik do kawy")
screen_game.fill((0, 0, 0))
tekst=pygame.font.SysFont("Calibri",28)
tekst_pole=tekst.render("stolik do kawy pana Klockowskiego", True, (255, 0, 0))
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
screen_game.blit(tekst_pole, (100, 100))
pygame.display.update()
Okno gry - tekst w prawym górnym rogu
import pygame
import sys
pygame.init()
screen_game=pygame.display.set_mode((700,700))
screen_rect=screen_game.get_rect()
ikonka=pygame.image.load("pliki/favicon.png")
pygame.display.set_icon(ikonka)
pygame.display.set_caption("stolik do kawy")
screen_game.fill((0, 0, 0))
tekst=pygame.font.SysFont("Calibri",24)
tekst_pole=tekst.render("stolik do kawy pana Klockowskiego", True, (255, 0, 0))
tekst_rect=tekst_pole.get_rect()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
tekst_rect.topright=screen_rect.topright#tekst w gornym prawym rogu ekranu
screen_game.blit(tekst_pole, tekst_rect)
pygame.display.update()
Kwadrat w oknie gry + ruch (wasd)
import pygame
import sys
pygame.init()
screen_game=pygame.display.set_mode((700,700))
screen_rect=screen_game.get_rect()#tworzymy prostokat ekranu
ikonka=pygame.image.load("pliki/favicon.png")
pygame.display.set_icon(ikonka)
pygame.display.set_caption("stolik do kawy")
green = (15, 188, 15)
black = (0, 0, 0)
x=50#poczatkowe polozenie kubka
y=50#poczatkowe polozenie kubka
zegar=pygame.time.Clock()#ustawiamy zegar
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
przycisk=pygame.key.get_pressed()#nacisniecie przycisku
if przycisk[pygame.K_d] and x < screen_rect.width - 100:
x=x+4
if przycisk[pygame.K_a] and x > 0:
x=x-4
if przycisk[pygame.K_w] and y > 0:
y=y-4
if przycisk[pygame.K_s] and y < screen_rect.height - 100:
y=y+4
screen_game.fill(black)
pygame.draw.rect(screen_game, green, (x, y, 100, 100))
zegar.tick(60)#odswiezamy ekran po przesunieciu kubka
pygame.display.update()
Prostokąt w oknie gry + kwadrat (wasd)
import pygame
import sys
pygame.init()
screen_game=pygame.display.set_mode((700,700))
ikonka=pygame.image.load("pliki/favicon.png")
pygame.display.set_icon(ikonka)
pygame.display.set_caption("stolik do kawy")
screen_rect=screen_game.get_rect()#tworzymy prostokat ekranu
limegreen = (50, 205, 50)
black = (0, 0, 0)
chocolate = (210, 105, 30)
white = (255, 255, 255)
x=50#poczatkowe polozenie kubka
y=50#poczatkowe polozenie kubka
x_stolika=screen_rect.centerx - 110#minus polowa dlugosci stolika
y_stolika=screen_rect.bottom - 100#minus wysokosc stolika
zegar=pygame.time.Clock()#ustawiamy zegar
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
przycisk = pygame.key.get_pressed()#nacisniecie przycisku
if przycisk[pygame.K_d] and x < screen_rect.width - 100:
x=x+4
if przycisk[pygame.K_a] and x > 0:
x=x-4
if przycisk[pygame.K_w] and y > 0:
y=y-4
if przycisk[pygame.K_s] and y < screen_rect.height - 100:
y=y+4
screen_game.fill(black)
kawa = pygame.Rect(x,y,100,100)
stolik = pygame.Rect(x_stolika,y_stolika,220,100)
if kawa.colliderect(stolik):
if przycisk[pygame.K_d]:
x = 140
if przycisk[pygame.K_a]:
x = 460
if przycisk[pygame.K_w]:
pass
if przycisk[pygame.K_s]:
y = 500
kawa = pygame.Rect(x,y,100,100)
stolik = pygame.Rect(x_stolika,y_stolika,220,100)
pygame.draw.rect(screen_game, limegreen, kawa)
pygame.draw.rect(screen_game, chocolate, stolik)
zegar.tick(60)#odswiezamy ekran po przesunieciu kubka
pygame.display.update()
KAWA
import pygame
import sys
pygame.init()
screen_game=pygame.display.set_mode((700,700))
ikonka=pygame.image.load("pliki/favicon.png")
pygame.display.set_icon(ikonka)
pygame.display.set_caption("stolik do kawy")
screen_rect=screen_game.get_rect()#tworzymy prostokat ekranu
limegreen = (50, 205, 50)
black = (0, 0, 0)
chocolate = (210, 105, 30)
white = (255, 255, 255)
x=50#poczatkowe polozenie kubka
y=50#poczatkowe polozenie kubka
x_stolika=screen_rect.centerx - 110#minus polowa dlugosci stolika
y_stolika=screen_rect.bottom - 126#minus wysokosc stolika
stolik_image = pygame.image.load("pliki/stolik_220x126.png")
kawa_image = pygame.image.load("pliki/pani_fral_70x70.png")
zegar=pygame.time.Clock()#ustawiamy zegar
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
przycisk = pygame.key.get_pressed()#nacisniecie przycisku
if przycisk[pygame.K_d] and x < screen_rect.width - 70:
x=x+4
if przycisk[pygame.K_a] and x > 0:
x=x-4
if przycisk[pygame.K_w] and y > 0:
y=y-4
if przycisk[pygame.K_s] and y < screen_rect.height - 70:
y=y+4
screen_game.fill(black)
kawa = pygame.Rect(x,y,70,70)
stolik = pygame.Rect(x_stolika,y_stolika,220,120)
if kawa.colliderect(stolik):
if przycisk[pygame.K_d]:
x = 170
if przycisk[pygame.K_a]:
x = 460
if przycisk[pygame.K_w]:
pass
if przycisk[pygame.K_s]:
y = 504
screen_game.blit(kawa_image, (x,y))
screen_game.blit(stolik_image, (x_stolika,y_stolika))
zegar.tick(60)#odswiezamy ekran po przesunieciu kubka
pygame.display.update()
|