|
Pravljenje igara Programski jezici, tehnike, alatke u službi pravljenja igara... |
|
Alatke vezane za temu | Vrste prikaza |
14.1.2006, 17:44 | #1 |
Novi član
Član od: 14.1.2006.
Poruke: 9
Zahvalnice: 0
Zahvaljeno 0 puta na 0 poruka
|
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.
|
14.1.2006, 21:02 | #2 |
Novi član
Član od: 14.1.2006.
Poruke: 9
Zahvalnice: 0
Zahvaljeno 0 puta na 0 poruka
|
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") |
15.1.2006, 18:53 | #3 |
Kekule Mekule
|
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. |
15.1.2006, 18:54 | #4 |
Kekule Mekule
|
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. |
Bookmarks sajtovi |
Alatke vezane za temu | |
Vrste prikaza | |
|
|
Slične teme | ||||
tema | temu započeo | forum | Odgovora | Poslednja poruka |
F.E.A.R. | Rocker | Akcione igre | 261 | 19.1.2009 16:55 |