-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new file: blocks/dieBlock.png new file: blocks/portal1.png new file: blocks/portal2.png new file: blocks/princess_l.png new file: blocks/princess_r.png new file: monsters.py new file: monsters/fire1.png new file: monsters/fire2.png modified: platformerhabrahabr.py modified: player.py new file: setup.py
- Loading branch information
bvs
committed
Oct 7, 2013
1 parent
bf5db05
commit c48bda8
Showing
12 changed files
with
228 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from pygame import * | ||
import pyganim | ||
import os | ||
|
||
MONSTER_WIDTH = 32 | ||
MONSTER_HEIGHT = 32 | ||
MONSTER_COLOR = "#2110FF" | ||
ICON_DIR = os.path.dirname(__file__) # Полный путь к каталогу с файлами | ||
|
||
|
||
ANIMATION_MONSTERHORYSONTAL = [('%s/monsters/fire1.png' % ICON_DIR), | ||
('%s/monsters/fire2.png' % ICON_DIR )] | ||
|
||
class Monster(sprite.Sprite): | ||
def __init__(self, x, y, left, up, maxLengthLeft,maxLengthUp): | ||
sprite.Sprite.__init__(self) | ||
self.image = Surface((MONSTER_WIDTH, MONSTER_HEIGHT)) | ||
self.image.fill(Color(MONSTER_COLOR)) | ||
self.rect = Rect(x, y, MONSTER_WIDTH, MONSTER_HEIGHT) | ||
self.image.set_colorkey(Color(MONSTER_COLOR)) | ||
self.startX = x # начальные координаты | ||
self.startY = y | ||
self.maxLengthLeft = maxLengthLeft # максимальное расстояние, которое может пройти в одну сторону | ||
self.maxLengthUp= maxLengthUp # максимальное расстояние, которое может пройти в одну сторону, вертикаль | ||
self.xvel = left # cкорость передвижения по горизонтали, 0 - стоит на месте | ||
self.yvel = up # скорость движения по вертикали, 0 - не двигается | ||
boltAnim = [] | ||
for anim in ANIMATION_MONSTERHORYSONTAL: | ||
boltAnim.append((anim, 0.3)) | ||
self.boltAnim = pyganim.PygAnimation(boltAnim) | ||
self.boltAnim.play() | ||
|
||
def update(self, platforms): # по принципу героя | ||
|
||
self.image.fill(Color(MONSTER_COLOR)) | ||
self.boltAnim.blit(self.image, (0, 0)) | ||
|
||
self.rect.y += self.yvel | ||
self.rect.x += self.xvel | ||
|
||
self.collide(platforms) | ||
|
||
if (abs(self.startX - self.rect.x) > self.maxLengthLeft): | ||
self.xvel =-self.xvel # если прошли максимальное растояние, то идеи в обратную сторону | ||
if (abs(self.startY - self.rect.y) > self.maxLengthUp): | ||
self.yvel = -self.yvel # если прошли максимальное растояние, то идеи в обратную сторону, вертикаль | ||
|
||
def collide(self, platforms): | ||
for p in platforms: | ||
if sprite.collide_rect(self, p) and self != p: # если с чем-то или кем-то столкнулись | ||
self.xvel = - self.xvel # то поворачиваем в обратную сторону | ||
self.yvel = - self.yvel |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.