Compare commits
2 Commits
7161aa144c
...
ff68e5c206
| Author | SHA1 | Date |
|---|---|---|
|
|
ff68e5c206 | |
|
|
89928e3a65 |
|
|
@ -0,0 +1,400 @@
|
|||
{ "frames": {
|
||||
"GoblinWorker #Birth 0.aseprite": {
|
||||
"frame": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Birth 1.aseprite": {
|
||||
"frame": { "x": 48, "y": 0, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Birth 2.aseprite": {
|
||||
"frame": { "x": 96, "y": 0, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Birth 3.aseprite": {
|
||||
"frame": { "x": 144, "y": 0, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Birth 4.aseprite": {
|
||||
"frame": { "x": 192, "y": 0, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Birth 5.aseprite": {
|
||||
"frame": { "x": 240, "y": 0, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Birth 6.aseprite": {
|
||||
"frame": { "x": 288, "y": 0, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Birth 7.aseprite": {
|
||||
"frame": { "x": 0, "y": 48, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Birth 8.aseprite": {
|
||||
"frame": { "x": 48, "y": 48, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Birth 9.aseprite": {
|
||||
"frame": { "x": 48, "y": 48, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Idle 0.aseprite": {
|
||||
"frame": { "x": 48, "y": 48, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Idle 1.aseprite": {
|
||||
"frame": { "x": 48, "y": 48, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Idle 2.aseprite": {
|
||||
"frame": { "x": 96, "y": 48, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Idle 3.aseprite": {
|
||||
"frame": { "x": 144, "y": 48, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Walk 0.aseprite": {
|
||||
"frame": { "x": 48, "y": 48, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Walk 1.aseprite": {
|
||||
"frame": { "x": 192, "y": 48, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Walk 2.aseprite": {
|
||||
"frame": { "x": 240, "y": 48, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Walk 3.aseprite": {
|
||||
"frame": { "x": 288, "y": 48, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Walk 4.aseprite": {
|
||||
"frame": { "x": 48, "y": 48, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Walk 5.aseprite": {
|
||||
"frame": { "x": 0, "y": 96, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Walk 6.aseprite": {
|
||||
"frame": { "x": 48, "y": 96, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Walk 7.aseprite": {
|
||||
"frame": { "x": 288, "y": 48, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #JumpRise 0.aseprite": {
|
||||
"frame": { "x": 96, "y": 96, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #JumpRise 1.aseprite": {
|
||||
"frame": { "x": 144, "y": 96, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #JumpRise 2.aseprite": {
|
||||
"frame": { "x": 192, "y": 96, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Fall.aseprite": {
|
||||
"frame": { "x": 240, "y": 96, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Attack 0.aseprite": {
|
||||
"frame": { "x": 288, "y": 96, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Attack 1.aseprite": {
|
||||
"frame": { "x": 0, "y": 144, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Attack 2.aseprite": {
|
||||
"frame": { "x": 48, "y": 144, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Attack 3.aseprite": {
|
||||
"frame": { "x": 96, "y": 144, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Attack 4.aseprite": {
|
||||
"frame": { "x": 144, "y": 144, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Attack 5.aseprite": {
|
||||
"frame": { "x": 192, "y": 144, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Attack 6.aseprite": {
|
||||
"frame": { "x": 240, "y": 144, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Attack 7.aseprite": {
|
||||
"frame": { "x": 288, "y": 144, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Attack 8.aseprite": {
|
||||
"frame": { "x": 288, "y": 96, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Hurt 0.aseprite": {
|
||||
"frame": { "x": 0, "y": 192, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Hurt 1.aseprite": {
|
||||
"frame": { "x": 48, "y": 192, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Hurt 2.aseprite": {
|
||||
"frame": { "x": 96, "y": 192, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Hurt 3.aseprite": {
|
||||
"frame": { "x": 144, "y": 192, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Hurt 4.aseprite": {
|
||||
"frame": { "x": 192, "y": 192, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Death 0.aseprite": {
|
||||
"frame": { "x": 0, "y": 192, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Death 1.aseprite": {
|
||||
"frame": { "x": 240, "y": 192, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Death 2.aseprite": {
|
||||
"frame": { "x": 288, "y": 192, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Death 3.aseprite": {
|
||||
"frame": { "x": 0, "y": 240, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Death 4.aseprite": {
|
||||
"frame": { "x": 48, "y": 240, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
},
|
||||
"GoblinWorker #Death 5.aseprite": {
|
||||
"frame": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": { "x": 0, "y": 0, "w": 48, "h": 48 },
|
||||
"sourceSize": { "w": 48, "h": 48 },
|
||||
"duration": 80
|
||||
}
|
||||
},
|
||||
"meta": {
|
||||
"app": "https://www.aseprite.org/",
|
||||
"version": "1.3.14.4-x64",
|
||||
"image": "GoblinWorker.png",
|
||||
"format": "RGBA8888",
|
||||
"size": { "w": 336, "h": 288 },
|
||||
"scale": "1",
|
||||
"frameTags": [
|
||||
{ "name": "Birth", "from": 0, "to": 9, "direction": "forward", "color": "#000000ff" },
|
||||
{ "name": "Idle", "from": 10, "to": 13, "direction": "forward", "color": "#000000ff" },
|
||||
{ "name": "Walk", "from": 14, "to": 21, "direction": "forward", "color": "#000000ff" },
|
||||
{ "name": "JumpRise", "from": 22, "to": 24, "direction": "forward", "color": "#000000ff" },
|
||||
{ "name": "Fall", "from": 25, "to": 25, "direction": "forward", "color": "#000000ff" },
|
||||
{ "name": "Attack", "from": 26, "to": 34, "direction": "forward", "color": "#fe5b59ff" },
|
||||
{ "name": "Hurt", "from": 35, "to": 39, "direction": "forward", "color": "#fe5b59ff" },
|
||||
{ "name": "Death", "from": 40, "to": 45, "direction": "forward", "color": "#fe5b59ff" }
|
||||
],
|
||||
"layers": [
|
||||
{ "name": "BackPart", "opacity": 255, "blendMode": "normal" },
|
||||
{ "name": "Body", "opacity": 255, "blendMode": "normal" },
|
||||
{ "name": "Head", "opacity": 255, "blendMode": "normal" },
|
||||
{ "name": "FrontPart", "opacity": 255, "blendMode": "normal" },
|
||||
{ "name": "Weapon", "opacity": 255, "blendMode": "normal" },
|
||||
{ "name": "Effect1", "opacity": 255, "blendMode": "normal" },
|
||||
{ "name": "Effect2", "opacity": 255, "blendMode": "normal" }
|
||||
],
|
||||
"slices": [
|
||||
]
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 7.7 KiB |
|
After Width: | Height: | Size: 500 B |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 908 B |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 754 B |
220
main.py
|
|
@ -4,26 +4,71 @@ pygame.init()
|
|||
|
||||
CLOCK = pygame.time.Clock()
|
||||
SCREEN = pygame.display.set_mode((1000, 800))
|
||||
|
||||
X_POS, Y_POS = 100, 700
|
||||
Y_GRAVITY = 1
|
||||
JUMP_HEIGHT = 20
|
||||
Y_VELOCITY = 20
|
||||
jumping = False
|
||||
|
||||
STANDING_SURFACE = pygame.transform.scale(pygame.image.load("images/character1.png"), (48, 64))
|
||||
JUMPING_SURFACE = pygame.transform.scale(pygame.image.load("images/character2.png"), (48, 64))
|
||||
BLACK = (0,0,0)
|
||||
BACKGROUND = pygame.image.load("images/back.png")
|
||||
BACKGROUND_MAIN = pygame.image.load("images/back_main")
|
||||
|
||||
crest = STANDING_SURFACE.get_rect(center = (X_POS, Y_POS))
|
||||
G_X, G_Y = 100, 800
|
||||
G_GRAVITY = 1
|
||||
G_JUMP_HEIGHT = 20
|
||||
g_y_velocity = 20
|
||||
g_jumping = False
|
||||
g_facing_right = True
|
||||
|
||||
K_X, K_Y = 300, 800
|
||||
K_GRAVITY = 1
|
||||
K_JUMP_HEIGHT = 20
|
||||
k_y_velocity = 20
|
||||
k_jumping = False
|
||||
k_facing_right = True
|
||||
|
||||
def get_image(sheet,frame_w, frame_h, width, height, scale, color):
|
||||
image = pygame.Surface((width, height)).convert_alpha()
|
||||
image.blit(sheet, (0,0),((frame_w*width),(frame_h*height), width, height))
|
||||
image = pygame.transform.scale(image, (width*scale, height*scale)).convert_alpha()
|
||||
if color is not None:
|
||||
image.set_colorkey(color)
|
||||
return image
|
||||
|
||||
# GOBLIN
|
||||
goblin = pygame.image.load("images/GoblinWorker/GoblinWorker.png").convert_alpha()
|
||||
STANDING_SURFACE = get_image(goblin, 1, 1, 48, 48, 3, BLACK)
|
||||
|
||||
frame_0 = get_image(goblin, 0,0, 48, 48, 3, BLACK)
|
||||
frame_1 = get_image(goblin, 4,2 , 48, 48, 3, BLACK)
|
||||
walk_a = get_image(goblin, 5, 1, 48, 48, 3, BLACK)
|
||||
walk_b = get_image(goblin, 0, 2, 48, 48, 3, BLACK)
|
||||
|
||||
# KNIGHT
|
||||
knight = pygame.image.load("images/sprites/knight.png").convert_alpha()
|
||||
K_STAND = get_image(knight, 2, 0, 32, 32, 3, BLACK)
|
||||
k_walk_a = get_image(knight, 1, 2, 32, 32, 3, BLACK)
|
||||
k_walk_b = get_image(knight, 5, 2, 32, 32, 3, BLACK)
|
||||
|
||||
|
||||
k_jump_start = get_image(knight, 3, 5, 32, 32, 3, BLACK)
|
||||
k_jump_apex = get_image(knight, 4, 5, 32, 32, 3, BLACK)
|
||||
k_jump_fall = get_image(knight, 5, 5, 32, 32, 3, BLACK)
|
||||
|
||||
# SPRITES / WORLD
|
||||
door_image = pygame.image.load("images/door.png")
|
||||
door_rect = door_image.get_rect(center = (800, 700))
|
||||
wall_image = pygame.image.load("images/wall.png")
|
||||
wall_right = pygame.Rect(1000, 0, 1, 800)
|
||||
wall_left = pygame.Rect(0, 0, 1, 800)
|
||||
wall_bottom = pygame.Rect(0, 800, 1000, 1)
|
||||
wall_up = pygame.Rect(0, 0, 1000, 1)
|
||||
|
||||
#PLATFORM
|
||||
platform_image = pygame.image.load("images/sprites/platforms.png")
|
||||
platform = get_image(platform_image, 0, 0, 16, 9, 3, BLACK)
|
||||
platform_rect = platform.get_rect(topleft=(400, 700))
|
||||
|
||||
# ANIMATION
|
||||
g_anim_counter = 0
|
||||
k_anim_counter = 0
|
||||
ANIM_SPEED = 8
|
||||
|
||||
# GAME LOOP
|
||||
while True:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
|
|
@ -32,43 +77,146 @@ while True:
|
|||
|
||||
keys_pressed = pygame.key.get_pressed()
|
||||
|
||||
if keys_pressed[pygame.K_SPACE]:
|
||||
# remember previous vertical positions to detect landing direction
|
||||
prev_G_Y = G_Y
|
||||
prev_K_Y = K_Y
|
||||
|
||||
g_moving = False
|
||||
if keys_pressed[pygame.K_d]:
|
||||
G_X += 5
|
||||
g_facing_right = True
|
||||
g_moving = True
|
||||
if keys_pressed[pygame.K_a]:
|
||||
G_X -= 5
|
||||
g_facing_right = False
|
||||
g_moving = True
|
||||
if keys_pressed[pygame.K_SPACE] and not g_jumping:
|
||||
g_jumping = True
|
||||
g_y_velocity = G_JUMP_HEIGHT
|
||||
|
||||
|
||||
k_moving = False
|
||||
if keys_pressed[pygame.K_KP6]:
|
||||
K_X += 5
|
||||
k_facing_right = True
|
||||
k_moving = True
|
||||
if keys_pressed[pygame.K_KP4]:
|
||||
K_X -= 5
|
||||
k_facing_right = False
|
||||
k_moving = True
|
||||
if keys_pressed[pygame.K_KP8] and not k_jumping:
|
||||
k_jumping = True
|
||||
k_y_velocity = K_JUMP_HEIGHT
|
||||
|
||||
|
||||
jumping = True
|
||||
SCREEN.blit(wall_image, wall_right)
|
||||
SCREEN.blit(wall_image, wall_left)
|
||||
SCREEN.blit(BACKGROUND_MAIN, (0, 0))
|
||||
SCREEN.blit(wall_image, wall_up)
|
||||
SCREEN.blit(wall_image, wall_bottom)
|
||||
SCREEN.blit(BACKGROUND, (0, 0))
|
||||
SCREEN.blit(door_image, door_rect)
|
||||
SCREEN.blit(platform, platform_rect)
|
||||
|
||||
if crest.colliderect(wall_right):
|
||||
X_POS -= 5
|
||||
if crest.colliderect(wall_left):
|
||||
X_POS += 5
|
||||
if g_jumping:
|
||||
G_Y -= g_y_velocity
|
||||
g_y_velocity -= G_GRAVITY
|
||||
if g_y_velocity < -G_JUMP_HEIGHT:
|
||||
g_jumping = False
|
||||
g_y_velocity = G_JUMP_HEIGHT
|
||||
|
||||
if keys_pressed[pygame.K_RIGHT] or keys_pressed[pygame.K_d]:
|
||||
X_POS += 5
|
||||
if k_jumping:
|
||||
K_Y -= k_y_velocity
|
||||
k_y_velocity -= K_GRAVITY
|
||||
if k_y_velocity < -K_JUMP_HEIGHT:
|
||||
k_jumping = False
|
||||
k_y_velocity = K_JUMP_HEIGHT
|
||||
|
||||
if keys_pressed[pygame.K_LEFT] or keys_pressed[pygame.K_a]:
|
||||
X_POS -= 5
|
||||
g_anim_counter = g_anim_counter + 1 if g_moving else 0
|
||||
k_anim_counter = k_anim_counter + 1 if k_moving else 0
|
||||
|
||||
|
||||
if jumping:
|
||||
Y_POS -= Y_VELOCITY
|
||||
Y_VELOCITY -= Y_GRAVITY
|
||||
if Y_VELOCITY < -JUMP_HEIGHT:
|
||||
jumping = False
|
||||
Y_VELOCITY = JUMP_HEIGHT
|
||||
crest = JUMPING_SURFACE.get_rect(center = (X_POS, Y_POS))
|
||||
SCREEN.blit(JUMPING_SURFACE, crest)
|
||||
if g_jumping:
|
||||
g_surface = frame_1
|
||||
elif g_moving:
|
||||
g_frame_index = (g_anim_counter // ANIM_SPEED) % 2
|
||||
g_surface = walk_a if g_frame_index == 0 else walk_b
|
||||
else:
|
||||
crest = STANDING_SURFACE.get_rect(center = (X_POS, Y_POS))
|
||||
SCREEN.blit(STANDING_SURFACE, crest)
|
||||
g_surface = STANDING_SURFACE
|
||||
|
||||
if crest.colliderect(door_rect) and keys_pressed[pygame.K_e]:
|
||||
print("You win!")
|
||||
if not g_facing_right:
|
||||
g_surface = pygame.transform.flip(g_surface, True, False).convert_alpha()
|
||||
|
||||
g_rect = g_surface.get_rect(center=(G_X, G_Y))
|
||||
|
||||
|
||||
if k_jumping:
|
||||
up_thresh = K_JUMP_HEIGHT // 3
|
||||
down_thresh = -up_thresh
|
||||
if k_y_velocity > up_thresh:
|
||||
k_surface = k_jump_start
|
||||
elif k_y_velocity > down_thresh:
|
||||
k_surface = k_jump_apex
|
||||
else:
|
||||
k_surface = k_jump_fall
|
||||
elif k_moving:
|
||||
k_frame_index = (k_anim_counter // ANIM_SPEED) % 2
|
||||
k_surface = k_walk_a if k_frame_index == 0 else k_walk_b
|
||||
else:
|
||||
k_surface = K_STAND
|
||||
|
||||
if not k_facing_right:
|
||||
k_surface = pygame.transform.flip(k_surface, True, False).convert_alpha()
|
||||
|
||||
k_rect = k_surface.get_rect(center=(K_X, K_Y))
|
||||
|
||||
|
||||
if g_rect.colliderect(wall_right):
|
||||
G_X -= 5
|
||||
if g_rect.colliderect(wall_left):
|
||||
G_X += 5
|
||||
if g_rect.colliderect(wall_bottom):
|
||||
G_Y -= 5
|
||||
if g_rect.colliderect(wall_up):
|
||||
G_Y += 5
|
||||
|
||||
if k_rect.colliderect(wall_right):
|
||||
K_X -= 5
|
||||
if k_rect.colliderect(wall_left):
|
||||
K_X += 5
|
||||
|
||||
# Goblin
|
||||
if g_rect.colliderect(platform_rect):
|
||||
if g_y_velocity < 0:
|
||||
G_Y = platform_rect.top - (g_rect.height / 2)
|
||||
g_jumping = False
|
||||
g_y_velocity = 0
|
||||
else:
|
||||
G_Y = platform_rect.bottom + (g_rect.height / 2)
|
||||
g_y_velocity = 0
|
||||
else:
|
||||
pass
|
||||
|
||||
# Knight
|
||||
if k_rect.colliderect(platform_rect):
|
||||
if k_y_velocity < 0:
|
||||
K_Y = platform_rect.top - (k_rect.height / 2)
|
||||
k_jumping = False
|
||||
k_y_velocity = 0
|
||||
else:
|
||||
K_Y = platform_rect.bottom + (k_rect.height / 2)
|
||||
k_y_velocity = 0
|
||||
else:
|
||||
pass
|
||||
SCREEN.blit(g_surface, g_rect)
|
||||
SCREEN.blit(k_surface, k_rect)
|
||||
|
||||
if g_rect.colliderect(door_rect) and keys_pressed[pygame.K_e]:
|
||||
print("Goblin wins!")
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
if k_rect.colliderect(door_rect) and keys_pressed[pygame.K_KP5]:
|
||||
print("Knight wins!")
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
|
||||
|
||||
pygame.display.update()
|
||||
CLOCK.tick(60)
|
||||