diff --git a/asd.py b/asd.py new file mode 100644 index 0000000..e69de29 diff --git a/config.py b/config.py index a0d5fb3..e093e84 100644 --- a/config.py +++ b/config.py @@ -3,7 +3,7 @@ import pygame from pygame.locals import * # Runtime settings -WINDOW_WIDTH = 1280 +WINDOW_WIDTH = 720 WINDOW_HEIGHT = 720 FPS = 30 WIN_NAME = "Kostschevsky's shooter" diff --git a/data/graphics/bullet.png b/data/graphics/bullet.png index 6e6b50d..80b77dd 100644 Binary files a/data/graphics/bullet.png and b/data/graphics/bullet.png differ diff --git a/data/graphics/p1.png b/data/graphics/p1.png new file mode 100644 index 0000000..084830e Binary files /dev/null and b/data/graphics/p1.png differ diff --git a/data/graphics/p2.png b/data/graphics/p2.png new file mode 100644 index 0000000..2c48ebf Binary files /dev/null and b/data/graphics/p2.png differ diff --git a/map_player_collision.txt b/map_player_collision.txt new file mode 100644 index 0000000..e864d45 --- /dev/null +++ b/map_player_collision.txt @@ -0,0 +1,45 @@ +111111111111111111111111111111111111 +100000000001111111111111000000000001 +111111100000011111111100000000000001 +101001000000011111110000000000000001 +100000000000001110000000000000000001 +100000000000000110000000000000000001 +100000000000000110000000000100000001 +100000010000000110000000001111000001 +100000111000000110000000001111100001 +100001110000000111000000011111000001 +100011100000000000000000001111000001 +100001000000000000000000000011000001 +100000000000000000000000000011100001 +100000000000000011100000000001000001 +100000000000000001100000000000000001 +100000000000000000110000000000000001 +100000000010000000110000000000000001 +100000000111100000110000000000000001 +100000000011110000011000000000000001 +100000000000100000011000000000000001 +100000000000000000011000000000000001 +100000000000000000011100000000000001 +100000000000000000001100000000000001 +110000000000000000001111101000000001 +111000000000000000001111111100000001 +110000000000000000111111111000000001 +100000010000000001111111110000000001 +100000111000000001111111111100000001 +110000010000100011111111111110000001 +111000000001110111111111111100000001 +111110000000111111111111111100000001 +111111000000111100000011111100000001 +111111000000010000000000011000000001 +111111100100000000000000000000000001 +111111111110000000000000000000000001 +111111111111111111111111111111111111 + + + + + + + + + diff --git a/maps.py b/maps.py index e69de29..4a919f0 100644 --- a/maps.py +++ b/maps.py @@ -0,0 +1,27 @@ +from os import path +import pygame + +walls=pygame.sprite.Group() + +class Hitbox(pygame.sprite.Sprite): + def __init__(self, x, y): + self.groups=walls + pygame.sprite.Sprite.__init__(self, self.groups) + self.image=pygame.Surface((20,20)) + self.rect=self.image.get_rect() + self.x=x + self.y=y + self.rect.x=x*20 + self.rect.y=y*20 + +game_folder=path.dirname(__file__) +map_pdata=[] + +with open(path.join(game_folder, 'map_player_collision.txt')) as f: + for line in f: + map_pdata.append(line) + +for row, tiles in enumerate(map_pdata): + for col, tile in enumerate(tiles): + if tile=='1': + Hitbox(col, row) diff --git a/mygame.py b/mygame.py index ff25448..b918b04 100644 --- a/mygame.py +++ b/mygame.py @@ -2,14 +2,14 @@ from config import * from sprites import * from colours import * +import maps import events # import modules +from os import path import os, sys import pygame from pygame.locals import * -# JEChANE - # initialization pygame.init() @@ -20,8 +20,8 @@ clock=pygame.time.Clock() # initialize two players -events.players.append(Player('asd', 400, 100, 10)) -events.players.append(Player('qwe', 400, 500, 10)) +events.players.append(Player('p1', 400, 100, 10)) +events.players.append(Player('p2', 430, 300, 10)) events.p1_group.add(events.players[0]) events.p2_group.add(events.players[1]) all_sprites.add(events.players) diff --git a/sprites.py b/sprites.py index 8df3689..d1f1f9d 100644 --- a/sprites.py +++ b/sprites.py @@ -1,5 +1,6 @@ # import all files from config import * +import maps #import events # import modules import os, sys @@ -39,6 +40,7 @@ class Player(pygame.sprite.Sprite): self.friction=-0.25 self.facing=0 # where the player is looking (0-north, 1-east, 2-south, 3-west) self.colliding=False + self.lastpos=self.rect.center def moveup(self): if self.facing!=0: @@ -71,28 +73,28 @@ class Player(pygame.sprite.Sprite): def stopmoving(self): self.acc=vec(0, 0) + def wallcollide(self): + for wall in maps.walls: + if self.rect.colliderect(wall.rect): + return True + return False + def move(self): - if self.colliding: - if self.facing==0: - self.pos.y+=1 - elif self.facing==1: - self.pos.x-=1 - elif self.facing==2: - self.pos.y-=1 - elif self.facing==3: - self.pos.x+=1 - self.rect.center=self.pos + if self.colliding or self.wallcollide(): + self.rect.center=self.lastpos + self.pos=self.lastpos self.speed=vec(0, 0) self.acc=vec(0, 0) self.colliding=False else: + self.lastpos=self.rect.center self.acc+=self.speed*self.friction self.speed+=self.acc self.pos+=self.speed+0.5*self.acc self.rect.center=self.pos def update(self): - self.move() + self.move() class Bullet(pygame.sprite.Sprite): def __init__(self, fname, x, y, direction):