Forum Sveta kompjutera  

Nazad   Forum Sveta kompjutera > Test Run > Programiranje > Pravljenje igara

Pravljenje igara Programski jezici, tehnike, alatke u službi pravljenja igara...

Odgovor
 
Alatke vezane za temu Vrste prikaza
Stara 14.1.2006, 17:44   #1
Darkvud
Novi član
 
Član od: 14.1.2006.
Poruke: 9
Zahvalnice: 0
Zahvaljeno 0 puta na 0 poruka
Smile Pygame game dev.

Kao sto u naslovu pise radi se o pygame game developmentu.Svi zainteresovani koji znaju(ili krecu)da rade u pygameu neka pisu ispod radi razmene iskustava,ideja,a mozda padne neki ozbiljan projekat.
Darkvud je offline   Odgovor sa citatom ove poruke
Stara 14.1.2006, 21:02   #2
Darkvud
Novi član
 
Član od: 14.1.2006.
Poruke: 9
Zahvalnice: 0
Zahvaljeno 0 puta na 0 poruka
Određen forumom Re: Pygame game dev.

Evo da pocnem sa najosnovnijim delom koda koji "pokrece" pygame iz pythona definise kontrolu loadimage,folder sa podacima(sprajtovi..),rezoluciju i caption:
####################################something##### ##############################

import random, string, math, time
import pygame
from pygame.locals import *
pygame.init()

pygame.display.set_mode([640,480])
screen = pygame.display.get_surface()

def loadimage(name):

image = None

fileName = 'data/' + name

image = pygame.image.load(fileName).convert()
image.set_colorkey(image.get_at([0, 0]), RLEACCEL)

return image

def __init__(self):
pygame.display.init()
pygame.display.set_icon(pygame.image.load("icon.gi f"))
pygame.display.set_caption("something")
Darkvud je offline   Odgovor sa citatom ove poruke
Stara 15.1.2006, 18:53   #3
Andross
Kekule Mekule
 
Avatar korisnika Andross
 
Član od: 8.12.2005.
Lokacija: Beograd
Poruke: 3.508
Zahvalnice: 542
Zahvaljeno 925 puta na 493 poruka
Slanje poruke preko Skypea korisniku Andross
Određen forumom Re: Pygame game dev.

Evo od mene neka vrsta tutorijala(koju sam nasao na netu)O sprajtovima:

import pygame

class Box(pygame.sprite.Sprite):
def __init__(self, color, initial_position):

# All sprite classes should extend pygame.sprite.Sprite. This
# gives you several important internal methods that you probably
# don't need or want to write yourself. Even if you do rewrite
# the internal methods, you should extend Sprite, so things like
# isinstance(obj, pygame.sprite.Sprite) return true on it.
pygame.sprite.Sprite.__init__(self)

# Create the image that will be displayed and fill it with the
# right color.
self.image = pygame.Surface([15, 15])
self.image.fill(color)

# Make our top-left corner the passed-in location.
self.rect = self.image.get_rect()
self.rect.topleft = initial_position

Snimite rad kao kocke.Da bi je prikazali uzmite novi window i pisite:

import pygame
from pygame.locals import *
from kocke import Box

pygame.init()
screen = pygame.display.set_mode([150, 150])
b = Box([255, 0, 0], [0, 0]) # Make the box red in the top left
screen.blit(b.image, b.rect)
pygame.display.update()
while pygame.event.poll().type != KEYDOWN: pygame.time.delay(10)

Snimite rad kao prikazikocku.Ovo omogucuje prikaz jedne kocke.Za prikaz tri kocke otvorite novi prozor i upisite:

import pygame
from pygame.locals import *
from kocke import Box

pygame.init()
boxes = []
for color, location in [([255, 0, 0], [0, 0]),
([0, 255, 0], [0, 60]),
([0, 0, 255], [0, 120])]:
boxes.append(Box(color, location))

screen = pygame.display.set_mode([150, 150])
for b in boxes: screen.blit(b.image, b.rect)
pygame.display.update()
while pygame.event.poll().type != KEYDOWN: pygame.time.delay(10)

rectlist = [screen.blit(b.image, b.rect) for b in boxes]
pygame.display.update(rectlist)

Snimite rad kao prikazikocke.
Andross je offline   Odgovor sa citatom ove poruke
Stara 15.1.2006, 18:54   #4
Andross
Kekule Mekule
 
Avatar korisnika Andross
 
Član od: 8.12.2005.
Lokacija: Beograd
Poruke: 3.508
Zahvalnice: 542
Zahvaljeno 925 puta na 493 poruka
Slanje poruke preko Skypea korisniku Andross
Određen forumom Re: Pygame game dev.

U postojecem kocke odvojite red i dodajte kod:

import pygame

class UpDownBox(pygame.sprite.Sprite):
def __init__(self, color, initial_position):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface([15, 15])
self.image.fill(color)
self.rect = self.image.get_rect()
self.rect.topleft = initial_position
self.going_down = True # Start going downwards
self.next_update_time = 0 # update() hasn't been called yet.

def update(self, current_time, bottom):
# Update every 10 milliseconds = 1/100th of a second.
if self.next_update_time < current_time:

# If we're at the top or bottom of the screen, switch directions.
if self.rect.bottom == bottom - 1: self.going_down = False
elif self.rect.top == 0: self.going_down = True

# Move our position up or down by one pixel
if self.going_down: self.rect.top += 1
else: self.rect.top -= 1

self.next_update_time = current_time + 10

Snimite rad i otvorite novi prozor.Upisite kod:

import pygame
from pygame.locals import *
from kocke import UpDownBox

pygame.init()
boxes = []
for color, location in [([255, 0, 0], [0, 0]),
([0, 255, 0], [60, 60]),
([0, 0, 255], [120, 120])]:
boxes.append(UpDownBox(color, location))

screen = pygame.display.set_mode([150, 150])
while pygame.event.poll().type != KEYDOWN:
screen.fill([0, 0, 0]) # blank the screen.

# Save time by only calling this once
time = pygame.time.get_ticks()
for b in boxes:
b.update(time, 150)
screen.blit(b.image, b.rect)

pygame.display.update()

Snimite rad kao prikazipomerajucekocke.To je to.
Andross je offline   Odgovor sa citatom ove poruke
Odgovor

Bookmarks sajtovi

Alatke vezane za temu
Vrste prikaza

Vaš status
Ne možete postavljati teme
Ne možete odgovarati na poruke
Ne možete slati priloge uz poruke
Ne možete prepravljati svoje poruke

BB kod: uključeno
Smajliji: uključeno
[IMG] kod: uključeno
HTML kod: isključeno


Slične teme
tema temu započeo forum Odgovora Poslednja poruka
F.E.A.R. Rocker Akcione igre 261 19.1.2009 16:55


Sva vremena su po Griniču +2 h. Sada je 8:19.


Powered by vBulletin® verzija 3.8.7
Copyright ©2000–2019, vBulletin Solutions, Inc.
Hosted by Beograd.com