Skip to content

Commit

Permalink
game almost finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Z4na14 committed Dec 12, 2023
1 parent d9c806b commit 12fe9ba
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 29 deletions.
Binary file modified resources/texture.pyxres
Binary file not shown.
2 changes: 1 addition & 1 deletion src/coins.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def movement(self, dimX):
if not self.isCollected:
self.posX += self.mX * self.direction

# Animating the enemies
# Animating the coin
self.currframe = self.currentSetFrames[self.currentPhaseFrame]

if pyxel.frame_count % 2 == 0:
Expand Down
30 changes: 19 additions & 11 deletions src/enemies.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __init__(self, enemy, collideX, collideY):
self.isDed, self.timeDed = False, 0
self.isSpawning, self.timeSpawning = False, 0
self.isFlipped, self.timeFlipped = False, 0
self.timesKicked = 0
self.enemy = enemy

# Status checks
Expand Down Expand Up @@ -156,29 +157,36 @@ def checkIsOver(self, currplatforms):
TO DO: Finish mario check when hes over the flipped enemies to kill them
"""

def kickFall(self, state, time=0):
if state == "turn" and not self.isFlipped:
def kickFall(self, state, kicksMain= 0, time=0):
if state == "turn" and not self.isDed:
self.currentPhaseFrame = 0
self.velY = 6
# Set state and animation
if self.enemy == "Turtle" and self.status == "angry":
self.currentSetFrames = self.fallenFramesAngry
self.isFlipped = True
self.timeFlipped = time
self.mX = 0

elif self.enemy == "Turtle" and self.status == "normal":
self.currentSetFrames = self.fallenFramesNormal
self.isFlipped = True
self.timeFlipped = time
self.mX = 0

elif self.enemy == "Crab" and self.status == "normal":
self.status = "angry"
self.currentSetFrames = self.movingFramesAngry
self.mX = 2
"""
else:
print("JODERRR")
self.timeFlipped = time
self.timesKicked = kicksMain

elif self.enemy == "Crab" and self.status == "angry" and kicksMain != self.timesKicked:
self.currentSetFrames = self.fallenFrames
self.isFlipped = True
self.timeFlipped = time
self.mX = 0
self.velY = 6
self.currentSetFrames = self.fallenFrames
"""

self.velY = 6
self.currentPhaseFrame = 0
self.timesKicked += 1

elif state == "fall" and not self.isDed:
# Create movement
Expand Down
27 changes: 15 additions & 12 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(self, dimx, dimy, mario: object, lives: object, screens: list, enem
self.currplatforms = self.screens[self.currlv].platforms
self.currenemies = self.enemies[self.currlv]
self.currpipes = self.screens[self.currlv].pipes
self.timesKickedPlatforms = 0

# Then set the location of the file with the top score
self.locationTopScore = f"{directory}/{topScore}"
Expand Down Expand Up @@ -131,6 +132,7 @@ def update(self):
# if aniKick returns True, there is no more animation
if i.aniKick():
self.mario.kickPos = [0, 0, None]
self.timesKickedPlatforms += 1

for i in self.activeCoins:
i.checkIsOver(self.currplatforms)
Expand All @@ -140,6 +142,7 @@ def update(self):
and not i.isCollected:
self.score += i.value

i.posY -= 4
i.currentSetFrames = i.pickedFrames
i.currentPhaseFrame = 0
i.isCollected = True
Expand Down Expand Up @@ -200,8 +203,8 @@ def draw(self):
pyxel.bltm(0, 0, 1, 0, 0, 240, 200, colkey=8)

# Scores at the top
pyxel.text(80, 4, str(self.score), 7)
pyxel.text(120, 4, str(self.topScore), 7)
pyxel.text(60, 4, f"Score: {str(self.score)}" , 7)
pyxel.text(120, 4, f"Top score: {str(self.topScore)}", 7)

# This was created for the animation of the kick
for i in self.currplatforms:
Expand All @@ -218,7 +221,7 @@ def draw(self):

# If there is no mario then check if it's because the game ended or because he died
except AttributeError:
if self.currlv == 3:
if self.currlv == 3 and self.currenemies == 0:
pyxel.text(94, 30, "YOU WON :)", 7)

elif self.mario is None:
Expand Down Expand Up @@ -250,7 +253,7 @@ def parseTime(self):
self.temptime = self.parsedtime

# Spawn enemies at a certain rate
if float(self.parsedtime) % 4 == 0 and len(self.currenemies) != 0:
if float(self.parsedtime) % 2 == 0 and len(self.currenemies) != 0:
self.activenemies.append(self.currenemies.pop())
self.activenemies[-1].isSpawning = True
self.activenemies[-1].timeSpawning = self.temptime
Expand All @@ -270,7 +273,7 @@ def enemiesCheck(self, i):
:return: Returns if the enemy is dead and out of computations
"""
if i.isDed:
if (float(self.parsedtime) - float(i.timeDed)) > 3:
if (float(self.parsedtime) - float(i.timeDed)) > 3.0:
return True

# If the enemy is not dead continue with the check
Expand Down Expand Up @@ -299,7 +302,7 @@ def enemiesCheck(self, i):
if (self.mario.kickPos[1] - 13) <= i.posY <= (self.mario.kickPos[1] - 5):
if self.mario.kickPos[0] - 5 <= (i.posX + i.collideX // 2) <= \
(self.mario.kickPos[0] + 16):
i.kickFall("turn", self.parsedtime)
i.kickFall("turn", self.timesKickedPlatforms, self.parsedtime)

# Check if mario is in the range of an enemy
if self.mario is not None and self.mario.checkEnemy(i.posX, i.posY, i.collideX, i.collideY):
Expand Down Expand Up @@ -379,12 +382,12 @@ def changeLv(self):
levels.Platform(0, 192, 240, 8)],
[[8, 24], [220, 24], [0, 180], [240, 180]])

screen2 = levels.Screen(2, [levels.Platform(2, 48, 140, 8),
levels.Platform(178, 48, 60, 8),
levels.Platform(2, 96, 100, 8),
levels.Platform(138, 96, 100, 8),
levels.Platform(2, 144, 60, 8),
levels.Platform(98, 144, 140, 8),
screen2 = levels.Screen(2, [levels.Platform(2, 48, 148, 8),
levels.Platform(202, 48, 36, 8),
levels.Platform(2, 96, 92, 8),
levels.Platform(146, 96, 92, 8),
levels.Platform(2, 144, 36, 8),
levels.Platform(90, 144, 148, 8),
levels.Platform(0, 192, 240, 8)],
[[8, 24], [220, 24], [0, 180], [240, 180]])

Expand Down
11 changes: 7 additions & 4 deletions src/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ def checkMovement(self, dimX, currplatforms, time):
if self.isDed:
if float(time) - float(self.timeDed) >= 3:
self.isDed = False
self.isFalling = False
self.velY = 6
self.posX = 110
self.posY = 170
self.posY = 20

else:

Expand Down Expand Up @@ -220,9 +222,10 @@ def checkIsParallel(self, currplatforms):

# Used to check whether Mario is in the range of the enemy
def checkEnemy(self, posXenemy, posYenemy, collideXenemy, collideYenemy):
if posYenemy <= self.posY + self.collideY <= (posYenemy + collideYenemy):
if posXenemy <= self.posX <= (posXenemy + collideXenemy) or posXenemy <= \
(self.posX + self.collideX) <= (posXenemy + collideXenemy):
if posYenemy <= self.posY + self.collideY <= (posYenemy + collideYenemy) or \
posYenemy <= self.posY <= (posYenemy + collideYenemy):
if posXenemy <= self.posX <= (posXenemy + collideXenemy) or \
posXenemy <= (self.posX + self.collideX) <= (posXenemy + collideXenemy):
return True

# Function to execute when Mario die
Expand Down
2 changes: 1 addition & 1 deletion topscore.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"topscore": 2100
"topscore": 33
}

0 comments on commit 12fe9ba

Please sign in to comment.