Added robot

This commit is contained in:
theo@manjaro 2021-11-16 23:36:56 +01:00
parent 126c66a231
commit ce31c1afee
11 changed files with 276 additions and 169 deletions

BIN
gamedata/assets/robot/0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
gamedata/assets/robot/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 859 B

BIN
gamedata/assets/robot/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 909 B

BIN
gamedata/assets/robot/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
gamedata/assets/robot/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 859 B

BIN
gamedata/assets/robot/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 909 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -418,7 +418,7 @@
[-1],
[-1],
[6, 1],
[-1],
[9, 2],
[8, 0],
[-1],
[-1],
@ -507,7 +507,96 @@
[-1],
[-1],
[6, 1],
[7, 1],
[8, 1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1]
],
[
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[10, 3],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[6, 1],
[7, 1],
[8, 1],
[-1],
[-1],
@ -596,7 +685,7 @@
[-1],
[-1],
[6, 1],
[-1],
[7, 1],
[8, 1],
[-1],
[-1],
@ -685,96 +774,7 @@
[-1],
[-1],
[6, 1],
[-1],
[8, 1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1]
],
[
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[6, 1],
[-1],
[7, 1],
[8, 1],
[-1],
[-1],
@ -862,8 +862,8 @@
[-1],
[-1],
[6, 0],
[-1],
[-1],
[11, 2],
[7, 1],
[8, 1],
[-1],
[-1],
@ -950,9 +950,9 @@
[-1],
[6, 0],
[7, 0],
[-1],
[-1],
[-1],
[11, 2],
[7, 1],
[7, 1],
[8, 1],
[-1],
[-1],
@ -1038,10 +1038,10 @@
[-1],
[-1],
[6, 1],
[-1],
[-1],
[-1],
[-1],
[7, 1],
[7, 1],
[7, 1],
[7, 1],
[8, 1],
[-1],
[-1],
@ -1127,10 +1127,10 @@
[-1],
[-1],
[6, 1],
[-1],
[-1],
[-1],
[-1],
[7, 1],
[7, 1],
[7, 1],
[7, 1],
[8, 1],
[-1],
[-1],
@ -1216,9 +1216,9 @@
[-1],
[-1],
[6, 1],
[-1],
[-1],
[-1],
[7, 1],
[7, 1],
[7, 1],
[9, 0],
[8, 2],
[-1],
@ -1305,9 +1305,9 @@
[-1],
[-1],
[6, 1],
[-1],
[-1],
[-1],
[7, 1],
[7, 1],
[7, 1],
[8, 1],
[-1],
[-1],
@ -1735,16 +1735,16 @@
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[6, 1],
[7, 1],
[7, 1],
[9, 2],
[8, 0],
[1, 1],
[1, 1],
[1, 1],
[1, 1],
[1, 1],
[-1],
[-1],
[-1],
@ -1824,28 +1824,28 @@
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[6, 1],
[7, 1],
[7, 1],
[7, 1],
[9, 2],
[7, 0],
[8, 0],
[1, 1],
[1, 1],
[3, 2],
[2, 0],
[6, 0],
[7, 0],
[7, 0],
[7, 0],
[7, 0],
[7, 0],
[7, 0],
[7, 0],
[7, 0],
[7, 0],
[7, 0],
[-1],
[-1],
[-1],
@ -1913,28 +1913,28 @@
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[-1],
[6, 1],
[7, 1],
[7, 1],
[7, 1],
[7, 1],
[7, 1],
[9, 2],
[7, 0],
[7, 0],
[7, 0],
[7, 0],
[11, 2],
[7, 1],
[7, 1],
[7, 1],
[7, 1],
[7, 1],
[7, 1],
[7, 1],
[7, 1],
[7, 1],
[7, 1],
[-1],
[-1],
[-1],
@ -2433,8 +2433,8 @@
"gridCellsX": 87,
"gridCellsY": 27,
"entities": [
{"name": "Solid", "id": 25, "_eid": "17026310", "x": 16, "y": 224, "width": 208, "height": 64, "originX": 0, "originY": 0},
{"name": "Solid", "id": 26, "_eid": "17026310", "x": 432, "y": 224, "width": 160, "height": 48, "originX": 0, "originY": 0},
{"name": "Solid", "id": 25, "_eid": "17026310", "x": 16, "y": 224, "width": 208, "height": 80, "originX": 0, "originY": 0},
{"name": "Solid", "id": 26, "_eid": "17026310", "x": 432, "y": 224, "width": 160, "height": 128, "originX": 0, "originY": 0},
{"name": "Solid", "id": 27, "_eid": "17026310", "x": 480, "y": 192, "width": 112, "height": 32, "originX": 0, "originY": 0},
{"name": "SemiSolid", "id": 28, "_eid": "59763689", "x": 368, "y": 224, "width": 64, "height": 16, "originX": 0, "originY": 0},
{"name": "Solid", "id": 29, "_eid": "17026310", "x": 592, "y": 320, "width": 192, "height": 32, "originX": 0, "originY": 0},
@ -2457,6 +2457,31 @@
"entities": [
{"name": "Spawns", "id": 4, "_eid": "25816588", "x": 64, "y": 176, "originX": 0, "originY": 0}
]
},
{
"name": "Ennemies",
"_eid": "09737179",
"offsetX": 0,
"offsetY": 0,
"gridCellWidth": 16,
"gridCellHeight": 16,
"gridCellsX": 87,
"gridCellsY": 27,
"entities": [
{
"name": "Robot",
"id": 3,
"_eid": "09735943",
"x": 528,
"y": 160,
"originX": 0,
"originY": 0,
"nodes": [
{"x": 496, "y": 160},
{"x": 576, "y": 160}
]
}
]
}
]
}

View File

@ -0,0 +1,60 @@
from gamedata.objects.combat.movable import Movable
class Robot(Movable):
def __init__(self,x,y,game,nodes=None):
super().__init__(game,x,y)
self.sprites = game.getSpriteDir("robot/")
self.sprite = self.sprites[0]
self.deadsprite = game.sprite_lib["robot/death.png"]
self.rect[2],self.rect[3] = self.deadsprite.get_size()
self.speed = 30
self.falling = 20
self.spriteindex = 0
self.gravityway = 1 # Vertical flip
self.walkingway = 1 # Horizontal flip
# Offset it correctly
self.rect[0] = x+8-self.rect[2]/2
# Movement boundaries
if nodes:
self.endpoints = [x["x"] for x in nodes[:2]] # Get only x positions
self.endpoints.sort()
else:
self.endpoints = None
def step(self):
# Flipping vertically
if self.water and self.rect.center[1]>self.water.rect[1]:
self.gravityway = -1
else:
self.gravityway = 1
# Flipping horizontally
if self.endpoints:
if self.rect.center[0]>self.endpoints[1]:
self.walkingway = -1
if self.rect.center[0]<self.endpoints[0]:
self.walkingway = 1
speedmult = [1,0.5,0][int(self.spriteindex)%3]
self.horspd = self.walkingway*self.speed*self.game.dt*speedmult
self.verspd = self.gravityway*self.falling*self.game.dt
super().step() # Actually move
self.spriteindex += self.speed*self.game.dt*0.15
def draw(self):
self.sprite = self.sprites[int(self.spriteindex)%len(self.sprites)]
drawnsprite = self.game.pygame.transform.flip(self.sprite,self.walkingway==-1,self.gravityway==-1)
self.game.window.blit(drawnsprite,[self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]])

View File

@ -5,6 +5,7 @@ class Player(Movable):
def __init__(self,game):
super().__init__(game,0,0)
spawnpoint = game.lib.choice(self.tileset.spawns)
self.rect.move_ip(spawnpoint.center)
@ -12,6 +13,8 @@ class Player(Movable):
self.rect[2] = self.sprite.get_width()
self.rect[3] = self.sprite.get_height()
self.water = self.game.gameloop.findname("Water")[0]
self.speed = 200
self.controlled = True
@ -54,7 +57,7 @@ class Player(Movable):
if not self.hitpose:
if self.rect.y>self.water.rect.y: # Reverse gravity underwater
if self.water and self.rect.y>self.water.rect.y: # Reverse gravity underwater
if self.gravityway == 1:
self.gravityway = -1
# Décellerer
@ -67,7 +70,7 @@ class Player(Movable):
self.canfastfall = False
self.verspd *= 0.9
if self.water.rect.y-self.leapmargin<=self.rect.y<=self.water.rect.y+self.leapmargin:
if self.water and self.water.rect.y-self.leapmargin<=self.rect.y<=self.water.rect.y+self.leapmargin:
self.leaptimer-=self.game.dt # Inside the margin
else:
self.leaptimer = self.leapmaxtimer # Outside, reset the timer

View File

@ -1,4 +1,5 @@
from gamedata.objects.base import BaseObject
from gamedata.objects.combat.ennemies.robot import Robot
class TilesetRenderer(BaseObject):
@ -16,6 +17,13 @@ class TilesetRenderer(BaseObject):
if self.level["background"]:
self.bg = self.level["background"]
def step(self):
# Spawning ennemies
while len(self.queue)>0:
props = self.queue.pop()
e = props[0](props[1],props[2],self.game,nodes=props[3])
self.game.gameloop.summon(e)
def draw(self):
self.game.window.blit(self.game.pygame.transform.scale(self.bg,(self.game.globals["cameraw"],self.game.globals["camerah"])),[0,0])
for layer in self.layers:
@ -29,6 +37,8 @@ class TilesetRenderer(BaseObject):
self.layers = []
self.spawns = []
spawnlists = {"Spawns":self.spawns}
ennemies = {"Robot":Robot}
self.queue = [] # For spawning ennemies after beeing initialized
if "layers" in json.keys() and type(json["layers"]).__name__=="list":
solidlayer = False
for layer in json["layers"]:
@ -46,6 +56,15 @@ class TilesetRenderer(BaseObject):
h = entity["height"]
spawnlists[entity["name"]].append(self.game.pygame.Rect((x,y,w,h)))
elif layer["name"] == "Ennemies" and "entities" in layer.keys():
for entity in layer["entities"]:
x,y = entity["x"],entity["y"]
nodes = []
if "nodes" in entity.keys():
nodes = entity["nodes"]
self.queue.append((ennemies[entity["name"]],x,y,nodes))
else: # J'ajoute un layer de tiles
tileset = level["tilesets"][layer["tileset"]]
tilew,tileh = layer["gridCellWidth"],layer["gridCellHeight"]