diff --git a/.flake8 b/.flake8
new file mode 100644
index 0000000..7ad7395
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,6 @@
+[flake8]
+
+# E402 module level import not at top of file
+# gi.require_version() is required before later imports
+
+ignore = E402
diff --git a/activity.py b/activity.py
index fbcc682..93082fd 100644
--- a/activity.py
+++ b/activity.py
@@ -5,34 +5,35 @@
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import pygame
-import sugargame
-import sugargame.canvas
-from sugar3.activity import activity
+
+from sugar3.activity.activity import Activity
from sugar3.graphics.toolbarbox import ToolbarBox
from sugar3.activity.widgets import ActivityToolbarButton
from sugar3.graphics.toolbutton import ToolButton
from sugar3.activity.widgets import StopButton
+
+import sugargame.canvas
+
from gettext import gettext as _
-import main
+from main import MakeThemFallGame
-class Activity(activity.Activity):
+class MakeThemFallActivity(Activity):
def __init__(self, handle):
- activity.Activity.__init__(self, handle)
+ Activity.__init__(self, handle)
self.max_participants = 1
self.sound = True
- self.game = main.game()
+ self.game = MakeThemFallGame()
+ self.build_toolbar()
self.game.canvas = sugargame.canvas.PygameCanvas(
self,
main=self.game.run,
modules=[pygame.display, pygame.font, pygame.mixer])
self.set_canvas(self.game.canvas)
self.game.canvas.grab_focus()
- self.build_toolbar()
def build_toolbar(self):
-
toolbar_box = ToolbarBox()
self.set_toolbar_box(toolbar_box)
toolbar_box.show()
@@ -63,8 +64,6 @@ def build_toolbar(self):
stop_button.show()
stop_button.connect('clicked', self._stop_cb)
- self.show_all()
-
def sound_control(self, button):
self.sound = not self.sound
self.game.sound = self.sound
@@ -76,6 +75,6 @@ def sound_control(self, button):
button.set_tooltip(_('Sound'))
def _stop_cb(self, button):
- self.game.crashed = True
+ self.game.running = False
if self.game.running_mode:
- self.game.running_mode.crashed = True
+ self.game.running_mode.running = False
diff --git a/activity/activity.info b/activity/activity.info
index de537af..9f075b4 100644
--- a/activity/activity.info
+++ b/activity/activity.info
@@ -3,7 +3,7 @@ name = Make Them Fall
activity_version = 2
bundle_id = org.sugarlabs.makethemfall
icon = makethem
-exec = sugar-activity3 activity.Activity
+exec = sugar-activity3 activity.MakeThemFallActivity
license = GPLv3+
summary = An arcade game
repository = https://github.com/sugarlabs/make-them-fall-activity.git
diff --git a/button.py b/button.py
new file mode 100644
index 0000000..c18484f
--- /dev/null
+++ b/button.py
@@ -0,0 +1,66 @@
+# Copyright (C) 2023 Riya Jain
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+
+import pygame
+
+
+class Button:
+
+ def __init__(self, x, y, image_path, action, text=None):
+ self.graphic = pygame.image.load(image_path)
+ self.rect = self.graphic.get_rect()
+
+ self.x = x - self.rect.width // 2
+ self.y = y - self.rect.height // 2
+ self.rect.x = self.x
+ self.rect.y = self.y
+
+ self.text = text
+ self.gameDisplay = pygame.display.get_surface()
+
+ self.action = action
+
+ self.press = False
+
+ self.draw()
+
+ def draw(self):
+ if self.hovered():
+ scaled_graphic = pygame.transform.scale(
+ self.graphic, (self.rect.width + 10, self.rect.height + 5))
+ self.gameDisplay.blit(scaled_graphic, (self.x - 5, self.y))
+ else:
+ self.gameDisplay.blit(self.graphic, (self.x, self.y))
+
+ if self.text is not None:
+ text_rect = self.text.get_rect()
+ m_x = self.x + self.rect.width // 2 - text_rect.width // 2
+ m_y = self.y + self.rect.height - 1.5 * text_rect.height
+ self.gameDisplay.blit(self.text, (m_x, m_y))
+
+ def hovered(self):
+ return self.rect.collidepoint(pygame.mouse.get_pos())
+
+ def update(self):
+ self.draw()
+ pressed_btn = pygame.mouse.get_pressed()[0]
+ if self.press and self.hovered() and pressed_btn != 1:
+ self.action()
+
+ if self.hovered() and pressed_btn == 1:
+ self.press = True
+ else:
+ self.press = False
diff --git a/cardiac.py b/cardiac.py
index 4f67052..49d7085 100644
--- a/cardiac.py
+++ b/cardiac.py
@@ -1,11 +1,9 @@
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-import pickle
-import pygame
-import sys
from random import *
+import sys
+import pygame
+import pickle
+from gi.repository import Gtk
class pane2heartwindow:
@@ -69,7 +67,7 @@ def run(self, gameDisplay, info):
scoremusic = pygame.mixer.Sound("data/sound/score.wav")
collide = pygame.mixer.Sound("data/sound/fall.wav")
- while not self.crashed:
+ while self.running:
# Gtk events
while Gtk.events_pending():
@@ -136,7 +134,7 @@ def run(self, gameDisplay, info):
rightmove -= 34
time2 += 1
- #[350,608] [659, 916]
+ # [350,608] [659, 916]
# Guy Display
@@ -206,26 +204,26 @@ def run(self, gameDisplay, info):
flag = 0
speed += 0.1
- if (y_axis1 <= -40 and flag1 != 1) or (y_axis2 <= -40 and flag2 != 1) or (y_axisa <= -40 and flag3 != 1)or (y_axisb <= -40 and flag4 != 1):
+ if (y_axis1 <= -40 and flag1 != 1) or (y_axis2 <= -40 and flag2 != 1) or (y_axisa <= -40 and flag3 != 1) or (y_axisb <= -40 and flag4 != 1):
collide.play(0)
numberofhearts += 1
- if(y_axis1 < -40):
+ if (y_axis1 < -40):
orientation1 = randint(0, 1)
flag1 = 0
y_axis1 = 700
- if(y_axis2 < -40):
+ if (y_axis2 < -40):
orientation2 = randint(0, 1)
flag2 = 0
y_axis2 = 700
- if(y_axisa < -40):
+ if (y_axisa < -40):
orientation4 = randint(0, 1)
flag3 = 0
y_axisa = 700
- if(y_axisb < -40):
+ if (y_axisb < -40):
orientation5 = randint(0, 1)
flag4 = 0
y_axisb = 700
diff --git a/fear.py b/fear.py
deleted file mode 100644
index 5ce1fda..0000000
--- a/fear.py
+++ /dev/null
@@ -1,311 +0,0 @@
-
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-import pickle
-import pygame
-import sys
-from random import *
-
-
-class pane4window:
-
- def run(self, gameDisplay, info):
-
- orientation1 = 0
- orientation2 = 0
- orientation3 = 0
- orientation4 = 0
- orientation5 = 0
- orientation6 = 0
-
- leftmove = leftdownmove = 350
- rightmove = rightdownmove = 659
- limit1 = limit2 = 0
-
- leftman = pygame.image.load("data/images/man.png")
- rightman = pygame.transform.flip(leftman, True, False)
- background = pygame.image.load("data/images/up4.png")
- background1 = pygame.image.load("data/images/down4.png")
-
- lspike = pygame.image.load("data/images/Spike.png")
- rspike = pygame.transform.flip(lspike, True, False)
- background = pygame.transform.scale(
- background, (600, info.current_h // 2))
- background1 = pygame.transform.scale(
- background1, (600, info.current_h // 2))
- y_axis1 = 400 + 100
- y_axis2 = 750 + 100
-
- y_axisa = 430 + 100
- y_axisb = 800 + 100
-
- leftquad = leftdown = leftman
- rightquad = rightdown = leftman
- f1 = f2 = f3 = f4 = 0
- m1 = m2 = m3 = m4 = 0
- time1 = time2 = 0
-
- font_path = "fonts/arial.ttf"
- font_size = 50
- font1 = pygame.font.Font(font_path, font_size)
- score = 0
-
- x_axis1 = x_axis2 = 350
- x_axisa = x_axisb = 659
- speed = 5
- flag = 1
-
- black = (0, 0, 0)
- white = (255, 255, 255)
- clock = pygame.time.Clock()
- timer = pygame.time.Clock()
-
- sound = True
-
- jump = pygame.mixer.Sound("data/sound/jump.wav")
- scoremusic = pygame.mixer.Sound("data/sound/score.wav")
- collide = pygame.mixer.Sound("data/sound/fall.wav")
-
- while not self.crashed:
- # Gtk events
-
- while Gtk.events_pending():
- Gtk.main_iteration()
- event = pygame.event.poll()
- # totaltime+=timer.tick()
- if event.type == pygame.QUIT:
- return
-
- # print event
-
- gameDisplay.fill(black)
- gameDisplay.blit(background, (0 + 350, 0))
-
- # Keypress orientation change
-
- if event.type == pygame.KEYDOWN and event.key == 97 and f1 == 0:
- jump.play(0)
- f1 = 1
- m1 = 1 # start moving
-
- if event.type == pygame.KEYDOWN and event.key == 100 and f2 == 0:
- jump.play(0)
- f2 = 1
- m2 = 1 # start moving
-
- if event.type == pygame.KEYDOWN and event.key == 276 and f3 == 0:
- jump.play(0)
- f3 = 1
- m3 = 1 # start moving
-
- if event.type == pygame.KEYDOWN and event.key == 275 and f4 == 0:
- jump.play(0)
- f4 = 1
- m4 = 1
-
- # Check for when to stop
-
- if leftmove > 608:
- leftquad = rightman
- m1 = f1 = 0
- leftmove = 608
- time1 = 0
-
- if leftmove < 350:
- leftquad = leftman
- m1 = f1 = 0
- leftmove = 350
- time1 = 0
-
- if rightmove < 659:
- rightquad = leftman
- m2 = f2 = 0
- rightmove = 659
- time2 = 0
-
- if rightmove > 916:
- rightquad = rightman
- m2 = f2 = 0
- rightmove = 916
- time2 = 0
-
- # down orintation change and stop moves
-
- if leftdownmove > 608:
- leftdown = rightman
- m3 = f3 = 0
- leftdownmove = 608
- time1 = 0
-
- if leftdownmove < 350:
- leftdown = leftman
- m3 = f3 = 0
- leftdownmove = 350
- time1 = 0
-
- if rightdownmove < 659:
- rightdown = leftman
- m4 = f4 = 0
- rightdownmove = 659
- time2 = 0
-
- if rightdownmove > 916:
- rightdown = rightman
- m4 = f4 = 0
- rightdownmove = 916
- time2 = 0
-
- if m1 == 1:
-
- if leftquad == leftman:
- leftmove += 30
- if leftquad == rightman:
- leftmove -= 30
- time1 += 1
-
- if m2 == 1:
-
- if rightquad == leftman:
- rightmove += 30
- if rightquad == rightman:
- rightmove -= 30
- time2 += 1
-
- if m3 == 1:
-
- if leftdown == leftman:
- leftdownmove += 30
- if leftdown == rightman:
- leftdownmove -= 30
- time2 += 1
-
- if m4 == 1:
-
- if rightdown == leftman:
- rightdownmove += 30
- if rightdown == rightman:
- rightdownmove -= 30
- time2 += 1
-
- #[350,608] [659, 916]
-
- # upper Guys Display
-
- if leftquad == leftman or leftquad == rightman:
- gameDisplay.blit(leftquad, (leftmove, 30))
-
- if rightquad == leftman or rightquad == rightman:
- gameDisplay.blit(rightquad, (rightmove, 30))
-
- ######### SPIKE PART###########
-
- if orientation1 == 0 and y_axis1 < 400: # orientation change
- x_axis1 = 350
- gameDisplay.blit(lspike, (x_axis1, y_axis1))
-
- if orientation1 == 1 and y_axis1 < 400:
- x_axis1 = 589
- gameDisplay.blit(rspike, (x_axis1, y_axis1))
-
- # right side spikes
- if orientation4 == 0 and y_axisa < 400:
- x_axisa = 659
- gameDisplay.blit(lspike, (x_axisa, y_axisa))
-
- if orientation4 == 1 and y_axisa < 400:
- x_axisa = 659 + 238
- gameDisplay.blit(rspike, (x_axisa, y_axisa))
-
- gameDisplay.blit(background1, (0 + 350, 380)
- ) # bottom part display
-
- # bottom guys display
-
- if leftdown == leftman or leftdown == rightman:
- gameDisplay.blit(leftdown, (leftdownmove, 400))
-
- if rightdown == leftman or rightdown == rightman:
- gameDisplay.blit(rightdown, (rightdownmove, 400))
-
- # bottom spikes
-
- if orientation2 == 0 and y_axis2 > 380:
- x_axis2 = 350
- gameDisplay.blit(lspike, (x_axis2, y_axis2))
-
- if orientation2 == 1 and y_axis2 > 380:
- x_axis2 = 589
- gameDisplay.blit(rspike, (x_axis2, y_axis2))
-
- if orientation5 == 0 and y_axisb > 380:
- x_axisb = 659
- gameDisplay.blit(lspike, (x_axisb, y_axisb))
-
- if orientation5 == 1 and y_axisb > 380:
- x_axisb = 659 + 238
- gameDisplay.blit(rspike, (x_axisb, y_axisb))
-
- y_axis1 -= speed
- y_axis2 -= speed
-
- y_axisa -= speed
- y_axisb -= speed
- '''
- if score==25 or score==55 or score==70:
- flag=1
-
- if score==60 and flag==1 :
- flag=0
- speed+=0.1
- '''
-
- # score count
-
- if y_axis1 < -40 or y_axis2 < 380 or y_axisa < -40 or y_axisb < 380:
- scoremusic.play(0)
- score += 1
-
- if(y_axis1 < -40):
- orientation1 = randint(0, 1)
-
- y_axis1 = 400
-
- if(y_axis2 < 380):
- orientation2 = randint(0, 1)
-
- y_axis2 = 700
-
- if(y_axisa < -40):
- orientation4 = randint(0, 1)
-
- y_axisa = 400
-
- if(y_axisb < 380):
- orientation5 = randint(0, 1)
-
- y_axisb = 700
-
- scores = font1.render(str(score), 1, (0, 0, 0))
- gameDisplay.blit(scores, (200 + 650, 30))
-
- # Collision detection
-
- if leftquad.get_rect(center=(leftmove + 5, 30 + 10)).collidepoint(x_axis1 + 8, y_axis1):
- collide.play(0)
- return score
-
- if rightquad.get_rect(center=(rightmove + 5, 30 + 10)).collidepoint(x_axisa + 8, y_axisa):
- collide.play(0)
- return score
-
- if leftdown.get_rect(center=(leftdownmove + 5, 400 + 10)).collidepoint(x_axis2 + 8, y_axis2):
- collide.play(0)
- return score
-
- if rightdown.get_rect(center=(rightdownmove + 5, 400 + 10)).collidepoint(x_axisb + 8, y_axisb):
- collide.play(0)
- return score
-
- pygame.display.update()
- clock.tick(60)
diff --git a/game.py b/game.py
new file mode 100644
index 0000000..68e33ba
--- /dev/null
+++ b/game.py
@@ -0,0 +1,159 @@
+# Copyright (C) 2023 Riya Jain
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+
+import pygame
+from gi.repository import Gtk
+from generator import Generator
+from guy import Guy
+
+BLACK = (0, 0, 0)
+SPAWN_SPIKE_EVENT = pygame.USEREVENT + 1
+
+
+class Game:
+
+ def __init__(self, bg_image_path, keymap, border_width=16, speed=7):
+ info = pygame.display.Info()
+ self.background = pygame.image.load(bg_image_path)
+ self.background = pygame.transform.scale(self.background,
+ (600, info.current_h))
+ self.border_width = border_width
+ self.speed = speed // (len(keymap))
+
+ # Keys which control each guy (in order of 'guys' array)
+ self.keymap = [i for row in keymap for i in row]
+
+ self.bg_rect = self.background.get_rect()
+ self.gameDisplay = pygame.display.get_surface()
+ self.display_rect = self.gameDisplay.get_rect()
+ self.offset = [0, 0]
+ self.offset[0] = (self.display_rect.width - self.bg_rect.width) // 2
+
+ rows = [len(i) for i in keymap]
+
+ pane_coordinates = self.get_pane_coordinates(rows)
+ guy_offset = 100 / (1 + (len(rows) - 1))
+
+ # format -> [left_spike_coords, right_spike_coords,
+ # path_length, max_spikes]
+ spikes_config = []
+
+ pane_height = self.bg_rect.height / len(rows)
+ for pane in pane_coordinates:
+ spikes_config.append([[pane[0][0], pane[1][1]],
+ [pane[1][0], pane[1][1]],
+ pane_height, 4])
+
+ self.generator = Generator()
+ self.generator.configure(spikes_config)
+ if len(rows) == 1:
+ self.generator.generate()
+
+ self.spike_spawn_delay = ((self.display_rect.height / 2)
+ / self.speed) * 20
+ pygame.time.set_timer(SPAWN_SPIKE_EVENT, int(self.spike_spawn_delay))
+
+ guys_config = []
+ self.guys = []
+
+ for pane in pane_coordinates:
+ guys_config.append([[pane[0][0], pane[1][0]],
+ pane[0][1] + guy_offset])
+
+ for guy in guys_config:
+ self.guys.append(Guy(guy[0], guy[1]))
+
+ font_path = "fonts/arial.ttf"
+ font_size = 50
+ self.font1 = pygame.font.Font(font_path, font_size)
+
+ self.score = 0
+
+ self.clock = pygame.time.Clock()
+ self.last_spawned = pygame.time.get_ticks()
+
+ self.sounds = {
+ "jump": pygame.mixer.Sound("data/sound/jump.wav"),
+ "score": pygame.mixer.Sound("data/sound/score.wav"),
+ "collide": pygame.mixer.Sound("data/sound/fall.wav")
+ }
+
+ def get_pane_coordinates(self, rows):
+ coordinates = []
+ pane_height = self.bg_rect.height / len(rows)
+ for i in range(len(rows)):
+ for j in range(rows[i]):
+ pane_width = self.bg_rect.width / rows[i]
+ origin = [self.offset[0] + pane_width * j, pane_height * i]
+ if j > 0 and j <= rows[i] - 1:
+ origin[0] += self.border_width / 2
+ end = origin.copy()
+ end[0] += pane_width
+ end[1] += pane_height
+ if (j <= rows[i] - 1):
+ end[0] -= self.border_width / 2
+ coordinates.append([origin, end])
+ return coordinates # Array of [top-left coords, bottom-right coords]
+
+ def show_score(self):
+ scores = self.font1.render(str(self.score), 1, (0, 0, 0))
+ self.gameDisplay.blit(scores, (200 + 650, 30))
+
+ def play_sound(self, sound_name):
+ self.sounds[sound_name].play()
+
+ def run(self):
+ while self.running:
+ # Gtk events
+ while Gtk.events_pending():
+ Gtk.main_iteration()
+
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ return
+ # Manage jumps
+ if event.type == pygame.KEYDOWN:
+ for i, key in enumerate(self.keymap):
+ if event.key == key:
+ self.play_sound("jump")
+ self.guys[i].move()
+
+ # Assign speed as per score
+ self.speed = 7 + self.score // 8
+ self.spike_spawn_delay = ((self.display_rect.height / 2)
+ / self.speed) * 18
+
+ self.gameDisplay.fill(BLACK)
+ self.gameDisplay.blit(self.background, self.offset)
+
+ # Generate spikes and increase score
+ if self.last_spawned + self.spike_spawn_delay < pygame.time.get_ticks():
+ self.generator.generate(self.speed)
+ self.score += 1
+ self.play_sound("score")
+ self.last_spawned = pygame.time.get_ticks()
+
+ self.show_score()
+
+ # updates
+ if self.generator.update(self.guys):
+ # returns true if player is dead
+ return self.score
+ for guy in self.guys:
+ guy.update()
+
+ pygame.display.update()
+ self.clock.tick(60)
diff --git a/generator.py b/generator.py
new file mode 100644
index 0000000..96b84ef
--- /dev/null
+++ b/generator.py
@@ -0,0 +1,51 @@
+# Copyright (C) 2023 Riya Jain
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+
+from spike import Spike
+from random import randint
+
+
+class Generator:
+
+ def __init__(self):
+ self.spikes_config = []
+ self.spikes = []
+
+ def configure(self, config):
+ self.spikes = []
+ self.spikes_config = config
+ for _ in range(len(self.spikes_config)):
+ self.spikes.append([])
+
+ def generate(self, speed=7):
+ for i, config in enumerate(self.spikes_config):
+ if len(self.spikes[i]) < config[3]:
+ side = int(randint(0, 1))
+ self.spikes[i].append(Spike(config[side][0],
+ config[side][1],
+ side, speed, config[2]))
+
+ def update(self, guys=[]):
+ for i, section_spikes in enumerate(self.spikes):
+ for j, spike in enumerate(section_spikes):
+ for guy in guys:
+ if guy.check_collision(spike.x, spike.y,
+ spike.rect.width,
+ spike.rect.height):
+ return True
+ if spike.update():
+ del self.spikes[i][j]
+ return False
diff --git a/guy.py b/guy.py
new file mode 100644
index 0000000..d590ed9
--- /dev/null
+++ b/guy.py
@@ -0,0 +1,70 @@
+# Copyright (C) 2023 Riya Jain
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+# Contact information:
+# Riya Jain riya1jain567@gmail.com
+
+
+import pygame
+
+
+class Guy:
+
+ def __init__(self, x_range, y):
+ self.graphic = pygame.image.load("data/images/man.png")
+ self.rect = self.graphic.get_rect()
+
+ self.y = y
+ self.x_range = x_range
+ self.x = self.x_range[0]
+ self.x_range[1] = self.x_range[1] - self.rect.width
+
+ self.gameDisplay = pygame.display.get_surface()
+
+ self.moving = False
+ self.position = 1 # 1 -> left (x_range[0]) ; -1 -> right (x_range[1])
+ self.speed = 25
+
+ def move(self):
+ if not self.moving:
+ self.moving = True
+
+ def update(self):
+ if self.moving:
+ self.x += self.position * self.speed
+ if self.x > self.x_range[1]:
+ self.graphic = pygame.transform.flip(self.graphic, True, False)
+ self.x = self.x_range[1]
+ self.position = -1
+ self.moving = False
+ if self.x < self.x_range[0]:
+ self.graphic = pygame.transform.flip(self.graphic, True, False)
+ self.x = self.x_range[0]
+ self.moving = False
+ self.position = 1
+ self.draw()
+
+ def draw(self):
+ self.gameDisplay.blit(self.graphic, (self.x, self.y))
+
+ def check_collision(self, other_x, other_y, other_width, other_height):
+ self_rect = pygame.Rect(self.x, self.y,
+ self.rect.width,
+ self.rect.height)
+ other_rect = pygame.Rect(other_x, other_y,
+ other_width,
+ other_height)
+ if self_rect.colliderect(other_rect):
+ return True
diff --git a/howtoplay.py b/howtoplay.py
index 8999c28..cbdfa13 100644
--- a/howtoplay.py
+++ b/howtoplay.py
@@ -1,15 +1,13 @@
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-import pickle
-import pygame
-import sys
+
from random import *
+import pygame
+import pickle
+from gi.repository import Gtk
class rules:
- def run(self, gameDisplay, info):
+ def run(self, gameDisplay, bg_dimensions, offset):
disp_width = 600
@@ -22,12 +20,12 @@ def run(self, gameDisplay, info):
back = pygame.image.load("data/images/back.png")
background = pygame.transform.scale(
- background, (disp_width - 100, info.current_h - 40))
+ background, bg_dimensions)
back = pygame.transform.scale(back, (70, 40))
sound = True
-
- while not self.crashed:
+
+ while self.running:
# Gtk events
while Gtk.events_pending():
@@ -40,12 +38,12 @@ def run(self, gameDisplay, info):
mos_x, mos_y = pygame.mouse.get_pos()
gameDisplay.fill(black)
- gameDisplay.blit(background, (0 + 350, 0))
+ gameDisplay.blit(background, offset)
if back.get_rect(center=(750 + 35, 10 + 15)).collidepoint(mos_x, mos_y):
gameDisplay.blit(pygame.transform.scale(
back, (75, 45)), (725, 5))
- if(pygame.mouse.get_pressed())[0] == 1 and press == 0:
+ if (pygame.mouse.get_pressed())[0] == 1 and press == 0:
press = 1
return
@@ -55,7 +53,7 @@ def run(self, gameDisplay, info):
else:
gameDisplay.blit(back, (725, 5))
- #pygame.draw.circle(gameDisplay,(255,255,255), (750+35,20+15),5,2)
+ # pygame.draw.circle(gameDisplay,(255,255,255), (750+35,20+15),5,2)
pygame.display.update()
clock.tick(60)
diff --git a/impossible.py b/impossible.py
deleted file mode 100644
index 2c9c51b..0000000
--- a/impossible.py
+++ /dev/null
@@ -1,447 +0,0 @@
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-import pickle
-import pygame
-import sys
-from random import *
-
-
-class pane6window:
-
- def run(self, gameDisplay, info):
-
- orientation1 = 0
- orientation2 = 0
- orientation3 = 0
- orientation4 = 0
- orientation5 = 0
- orientation6 = 0
-
- leftmove = leftdownmove = 350
- midmove = middownmove = 555
- rightmove = rightdownmove = 761
-
- limit1 = limit2 = 0
-
- leftman = pygame.image.load("data/images/man.png")
- rightman = pygame.transform.flip(leftman, True, False)
-
- background = pygame.image.load("data/images/6up.png")
- background1 = pygame.image.load("data/images/6down.png")
-
- lspike = pygame.image.load("data/images/Spike.png")
- rspike = pygame.transform.flip(lspike, True, False)
-
- background = pygame.transform.scale(
- background, (600, info.current_h // 2))
- background1 = pygame.transform.scale(
- background1, (600, info.current_h // 2))
-
- y_axis1 = 700
- y_axis2 = 800
-
- y_axisa = 750
- y_axisb = 890
-
- y_axisx = 761
- y_axisy = 920
-
- leftquad = leftman
- midquad = leftman
- rightquad = leftman
-
- leftdown = middown = rightdown = leftman
-
- f1 = f2 = f3 = f4 = f5 = f6 = 0
- m1 = m2 = m3 = m4 = m5 = m6 = 0
- time1 = time2 = 0
-
- font_path = "fonts/arial.ttf"
- font_size = 50
- font1 = pygame.font.Font(font_path, font_size)
- score = 0
-
- x_axis1 = x_axis2 = 350
- x_axisa = x_axisb = 659
- x_axisx = x_axisy = 761
- speed = 4
- flag = 1
-
- black = (0, 0, 0)
- white = (255, 255, 255)
- clock = pygame.time.Clock()
- timer = pygame.time.Clock()
-
- sound = True
-
- jump = pygame.mixer.Sound("data/sound/jump.wav")
- scoremusic = pygame.mixer.Sound("data/sound/score.wav")
- collide = pygame.mixer.Sound("data/sound/fall.wav")
-
- while not self.crashed:
- # Gtk events
-
- while Gtk.events_pending():
- Gtk.main_iteration()
- event = pygame.event.poll()
- # totaltime+=timer.tick()
- if event.type == pygame.QUIT:
- return
- # print event
-
- gameDisplay.fill(black)
- gameDisplay.blit(background, (0 + 350, 0))
-
- # Keypress orientation change
-
- if event.type == pygame.KEYDOWN and event.key == 97 and f1 == 0:
- jump.play(0)
- f1 = 1
- m1 = 1 # start moving
-
- if event.type == pygame.KEYDOWN and event.key == 115 and f2 == 0:
- jump.play(0)
- f2 = 1
- m2 = 1 # start moving
-
- if event.type == pygame.KEYDOWN and event.key == 100 and f3 == 0:
- jump.play(0)
- f3 = 1
- m3 = 1 # start moving
-
- # down control
-
- if event.type == pygame.KEYDOWN and event.key == 276 and f4 == 0:
- jump.play(0)
- f4 = 1
- m4 = 1 # start moving
-
- if event.type == pygame.KEYDOWN and event.key == 274 and f5 == 0:
- jump.play(0)
- f5 = 1
- m5 = 1 # start moving
-
- if event.type == pygame.KEYDOWN and event.key == 275 and f6 == 0:
- jump.play(0)
- f6 = 1
- m6 = 1
-
- # Check for when to stop
-
- if leftmove > 484 + 20: # left move
- leftquad = rightman
- m1 = f1 = 0
- leftmove = 484 + 20
- time1 = 0
-
- if leftmove < 350:
- leftquad = leftman
- m1 = f1 = 0
- leftmove = 350
- time1 = 0
-
- if midmove < 555: # mid move
- midquad = leftman
- m2 = f2 = 0
- midmove = 555
- time2 = 0
-
- if midmove > 690 + 20:
- midquad = rightman
- m2 = f2 = 0
- midmove = 690 + 20
- time2 = 0
-
- if rightmove < 761: # right move
- rightquad = leftman
- m3 = f3 = 0
- rightmove = 761
- time2 = 0
-
- if rightmove > 761 + 156:
- rightquad = rightman
- m3 = f3 = 0
- rightmove = 761 + 156
- time2 = 0
-
- # Check for when to stop
-
- if leftdownmove > 484 + 20: # left down move
- leftdown = rightman
- m4 = f4 = 0
- leftdownmove = 484 + 20
- time1 = 0
-
- if leftdownmove < 350:
- leftdown = leftman
- m4 = f4 = 0
- leftdownmove = 350
- time1 = 0
-
- if middownmove < 555: # mid down move
- middown = leftman
- m5 = f5 = 0
- middownmove = 555
- time2 = 0
-
- if middownmove > 690 + 20:
- middown = rightman
- m5 = f5 = 0
- middownmove = 690 + 20
- time2 = 0
-
- if rightdownmove < 761: # right down move
- rightdown = leftman
- m6 = f6 = 0
- rightdownmove = 761
- time2 = 0
-
- if rightdownmove > 761 + 156:
- rightdown = rightman
- m6 = f6 = 0
- rightdownmove = 761 + 156
- time2 = 0
-
- # Upper section
-
- if m1 == 1:
-
- if leftquad == leftman:
- leftmove += 30
- if leftquad == rightman:
- leftmove -= 30
- time1 += 1
-
- if m2 == 1:
-
- if midquad == leftman:
- midmove += 30
- if midquad == rightman:
- midmove -= 30
- time2 += 1
-
- if m3 == 1:
-
- if rightquad == leftman:
- rightmove += 30
- if rightquad == rightman:
- rightmove -= 30
- time2 += 1
-
- # lower section
-
- if m4 == 1:
-
- if leftdown == leftman:
- leftdownmove += 30
- if leftdown == rightman:
- leftdownmove -= 30
- time1 += 1
-
- if m5 == 1:
-
- if middown == leftman:
- middownmove += 30
- if middown == rightman:
- middownmove -= 30
- time2 += 1
-
- if m6 == 1:
-
- if rightdown == leftman:
- rightdownmove += 30
- if rightdown == rightman:
- rightdownmove -= 30
- time2 += 1
-
- #[350,608] [659, 916]
-
- # upper Guy Display
-
- if leftquad == leftman or leftquad == rightman:
- gameDisplay.blit(leftquad, (leftmove, 30))
-
- if midquad == leftman or midquad == rightman:
- gameDisplay.blit(midquad, (midmove, 30))
-
- if rightquad == leftman or rightquad == rightman:
- gameDisplay.blit(rightquad, (rightmove, 30))
-
- ######### UPPER SPIKE PART###########
-
- if orientation1 == 0: # orientation change
- x_axis1 = 350
- gameDisplay.blit(lspike, (x_axis1, y_axis1))
-
- if orientation1 == 1:
- x_axis1 = 485
- gameDisplay.blit(rspike, (x_axis1, y_axis1))
-
- # mid side spikes
- if orientation2 == 0:
- x_axisa = 555
- gameDisplay.blit(lspike, (x_axisa, y_axisa))
-
- if orientation2 == 1:
- x_axisa = 691
- gameDisplay.blit(rspike, (x_axisa, y_axisa))
-
- # right side spikes
-
- if orientation3 == 0:
- x_axisx = 761
- gameDisplay.blit(lspike, (x_axisx, y_axisx))
-
- if orientation3 == 1:
- x_axisx = 761 + 136
- gameDisplay.blit(rspike, (x_axisx, y_axisx))
-
- y_axis1 -= speed
- y_axis2 -= speed
-
- y_axisa -= speed
- y_axisb -= speed
-
- y_axisx -= speed
- y_axisy -= speed
-
- # Scores increment
-
- if y_axis1 <= -40 or y_axis2 <= 380 or y_axisa <= -40 or y_axisb <= 380 or \
- y_axisx <= -40 or y_axisy <= 380:
- scoremusic.play(0)
- score += 1
-
- if(y_axis1 < -40):
- orientation1 = randint(0, 1)
-
- y_axis1 = 400
-
- if(y_axis2 < 380):
- orientation4 = randint(0, 1)
-
- y_axis2 = 700
-
- if(y_axisa < -40):
- orientation2 = randint(0, 1)
-
- y_axisa = 400
-
- if(y_axisb < 380):
- orientation5 = randint(0, 1)
-
- y_axisb = 700
-
- if(y_axisx < -40):
- orientation3 = randint(0, 1)
-
- y_axisx = 400
-
- if(y_axisy < 380):
- orientation6 = randint(0, 1)
-
- y_axisy = 700
-
- scores = font1.render(str(score), 1, (0, 0, 0))
- gameDisplay.blit(scores, (200 + 650, 30))
-
- gameDisplay.blit(background1, (0 + 350, 380))
-
- ######### LOWER SPIKE PART###########
-
- # left side spike
-
- if orientation4 == 0:
- x_axis2 = 350
- gameDisplay.blit(lspike, (x_axis2, y_axis2))
-
- if orientation4 == 1:
- x_axis2 = 485
- gameDisplay.blit(rspike, (x_axis2, y_axis2))
-
- # mid side spikes
-
- if orientation5 == 0:
- x_axisb = 555
- gameDisplay.blit(lspike, (x_axisb, y_axisb))
-
- if orientation5 == 1:
- x_axisb = 691
- gameDisplay.blit(rspike, (x_axisb, y_axisb))
-
- # right side spikes
-
- if orientation6 == 0:
- x_axisy = 761
- gameDisplay.blit(lspike, (x_axisy, y_axisy))
-
- if orientation6 == 1:
- x_axisy = 761 + 136
- gameDisplay.blit(rspike, (x_axisy, y_axisy))
-
- # lower guys display
-
- if leftdown == leftman or leftdown == rightman:
- gameDisplay.blit(leftdown, (leftdownmove, 400))
-
- if middown == leftman or middown == rightman:
- gameDisplay.blit(middown, (middownmove, 400))
-
- if rightdown == leftman or rightdown == rightman:
- gameDisplay.blit(rightdown, (rightdownmove, 400))
-
- # upper half detection
-
- if leftquad.get_rect(center=(leftmove + 5, 30 + 10)).collidepoint(x_axis1 + 8, y_axis1):
- # or
- # leftquad.get_rect(center=(leftmove+5,100+10)).collidepoint(x_axis2+8,y_axis2):
- pygame.mixer.music.load("data/sound/fall.wav")
- pygame.mixer.music.play(0)
- # collide.play(0)
- return score
-
- if midquad.get_rect(center=(midmove + 5, 30 + 10)).collidepoint(x_axisa + 8, y_axisa):
- # or
- # midquad.get_rect(center=(midmove+5,100+10)).collidepoint(x_axisb+8,y_axisb):
- pygame.mixer.music.load("data/sound/fall.wav")
- pygame.mixer.music.play(0)
- # collide.play(0)
- return score
-
- if rightquad.get_rect(center=(rightmove + 5, 30 + 10)).collidepoint(x_axisx + 8, y_axisx):
- # or
- # rightquad.get_rect(center=(rightmove+5,100+10)).collidepoint(x_axisy+8,y_axisy):
- pygame.mixer.music.load("data/sound/fall.wav")
- pygame.mixer.music.play(0)
- # collide.play(0)
- return score
-
- # lower section detection
-
- if leftdown.get_rect(center=(leftdownmove + 5, 400 + 10)).collidepoint(x_axis2 + 8, y_axis2):
- # or
- # leftquad.get_rect(center=(leftmove+5,100+10)).collidepoint(x_axis2+8,y_axis2):
- pygame.mixer.music.load("data/sound/fall.wav")
- pygame.mixer.music.play(0)
- # collide.play(0)
- return score
-
- if middown.get_rect(center=(middownmove + 5, 400 + 10)).collidepoint(x_axisb + 8, y_axisb):
- # or
- # midquad.get_rect(center=(midmove+5,100+10)).collidepoint(x_axisb+8,y_axisb):
- pygame.mixer.music.load("data/sound/fall.wav")
- pygame.mixer.music.play(0)
- # collide.play(0)
- return score
-
- if rightdown.get_rect(center=(rightdownmove + 5, 400 + 10)).collidepoint(x_axisy + 8, y_axisy):
- # or
- # rightquad.get_rect(center=(rightmove+5,100+10)).collidepoint(x_axisy+8,y_axisy):
- pygame.mixer.music.load("data/sound/fall.wav")
- pygame.mixer.music.play(0)
- # collide.play(0)
- return score
-
- pygame.display.update()
- clock.tick(60)
diff --git a/inferno.py b/inferno.py
deleted file mode 100644
index d6e4e51..0000000
--- a/inferno.py
+++ /dev/null
@@ -1,401 +0,0 @@
-
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-import pickle
-import pygame
-import sys
-from random import *
-
-
-class pane5window:
-
- def run(self, gameDisplay, info):
-
- orientation1 = 0
- orientation2 = 0
- orientation3 = 0
- orientation4 = 0
- orientation5 = 0
- orientation6 = 0
-
- leftmove = leftdownmove = 350
- rightdownmove = 659
- midmove = 555
- rightmove = 761
-
- limit1 = limit2 = 0
-
- leftman = pygame.image.load("data/images/man.png")
- rightman = pygame.transform.flip(leftman, True, False)
- background = pygame.image.load("data/images/up3.png")
- background1 = pygame.image.load("data/images/down2.png")
-
- lspike = pygame.image.load("data/images/Spike.png")
- rspike = pygame.transform.flip(lspike, True, False)
-
- background = pygame.transform.scale(
- background, (600, info.current_h // 2))
- background1 = pygame.transform.scale(
- background1, (600, info.current_h // 2))
-
- y_axis1 = 400 + 100
- y_axis2 = 700 + 80
-
- y_axisa = 430 + 150
- y_axisb = 700 + 150
-
- y_axisx = 460 + 80
-
- leftquad = leftman
- midquad = leftman
- rightquad = leftman
-
- leftdown = leftman
- rightdown = leftman
-
- f1 = f2 = f3 = f4 = f5 = 0
- m1 = m2 = m3 = m4 = m5 = 0
- time1 = time2 = 0
-
- font_path = "fonts/arial.ttf"
- font_size = 50
- font1 = pygame.font.Font(font_path, font_size)
- score = 0
-
- x_axis1 = x_axis2 = 350
- x_axisa = x_axisb = 659
- x_axisx = x_axisy = 761
- speed = 4
- flag = 1
-
- black = (0, 0, 0)
- white = (255, 255, 255)
- clock = pygame.time.Clock()
- timer = pygame.time.Clock()
-
- sound = True
-
- jump = pygame.mixer.Sound("data/sound/jump.wav")
- scoremusic = pygame.mixer.Sound("data/sound/score.wav")
- collide = pygame.mixer.Sound("data/sound/fall.wav")
-
- while not self.crashed:
- # Gtk events
-
- while Gtk.events_pending():
- Gtk.main_iteration()
- event = pygame.event.poll()
- # totaltime+=timer.tick()
- if event.type == pygame.QUIT:
- return
-
- # print event
-
- gameDisplay.fill(black)
- gameDisplay.blit(background, (0 + 350, 0))
-
- # Keypress orientation change
-
- if event.type == pygame.KEYDOWN and event.key == 97 and f1 == 0:
- jump.play(0)
- f1 = 1
- m1 = 1 # start moving
-
- if event.type == pygame.KEYDOWN and event.key == 115 and f2 == 0:
- jump.play(0)
- f2 = 1
- m2 = 1 # start moving
-
- if event.type == pygame.KEYDOWN and event.key == 100 and f3 == 0:
- jump.play(0)
- f3 = 1
- m3 = 1 # start moving
-
- # down key structure
-
- if event.type == pygame.KEYDOWN and event.key == 276 and f4 == 0:
- jump.play(0)
- f4 = 1
- m4 = 1 # start moving
-
- if event.type == pygame.KEYDOWN and event.key == 275 and f5 == 0:
- jump.play(0)
- f5 = 1
- m5 = 1 # start moving
-
- # Check for when to stop
-
- if leftmove > 484 + 20: # left move
- leftquad = rightman
- m1 = f1 = 0
- leftmove = 484 + 20
- time1 = 0
-
- if leftmove < 350:
- leftquad = leftman
- m1 = f1 = 0
- leftmove = 350
- time1 = 0
-
- if midmove < 555: # mid move
- midquad = leftman
- m2 = f2 = 0
- midmove = 555
- time2 = 0
-
- if midmove > 690 + 20:
- midquad = rightman
- m2 = f2 = 0
- midmove = 690 + 20
- time2 = 0
-
- if rightmove < 761: # right move move
- rightquad = leftman
- m3 = f3 = 0
- rightmove = 761
- time2 = 0
-
- if rightmove > 761 + 156:
- rightquad = rightman
- m3 = f3 = 0
- rightmove = 761 + 156
- time2 = 0
-
- # down orintation change and stop moves
-
- if leftdownmove > 608:
- leftdown = rightman
- m4 = f4 = 0
- leftdownmove = 608
- time1 = 0
-
- if leftdownmove < 350:
- leftdown = leftman
- m4 = f4 = 0
- leftdownmove = 350
- time1 = 0
-
- if rightdownmove < 659:
- rightdown = leftman
- m5 = f5 = 0
- rightdownmove = 659
- time2 = 0
-
- if rightdownmove > 916:
- rightdown = rightman
- m5 = f5 = 0
- rightdownmove = 916
- time2 = 0
-
- if m1 == 1:
-
- if leftquad == leftman:
- leftmove += 30
- if leftquad == rightman:
- leftmove -= 30
- time1 += 1
-
- if m2 == 1:
-
- if midquad == leftman:
- midmove += 30
- if midquad == rightman:
- midmove -= 30
- time2 += 1
-
- if m3 == 1:
-
- if rightquad == leftman:
- rightmove += 30
- if rightquad == rightman:
- rightmove -= 30
- time2 += 1
-
- if m4 == 1:
-
- if leftdown == leftman:
- leftdownmove += 30
- if leftdown == rightman:
- leftdownmove -= 30
- time2 += 1
-
- if m5 == 1:
-
- if rightdown == leftman:
- rightdownmove += 30
- if rightdown == rightman:
- rightdownmove -= 30
- time2 += 1
-
- #[350,608] [659, 916]
-
- # up Guys Display
-
- if leftquad == leftman or leftquad == rightman:
- gameDisplay.blit(leftquad, (leftmove, 30))
-
- if midquad == leftman or midquad == rightman:
- gameDisplay.blit(midquad, (midmove, 30))
-
- if rightquad == leftman or rightquad == rightman:
- gameDisplay.blit(rightquad, (rightmove, 30))
-
- ######### SPIKE PART###########
-
- if orientation1 == 0: # orientation change
- x_axis1 = 350
- gameDisplay.blit(lspike, (x_axis1, y_axis1))
-
- if orientation1 == 1:
- x_axis1 = 485
- gameDisplay.blit(rspike, (x_axis1, y_axis1))
-
- # mid side spikes
- if orientation3 == 0:
- x_axisa = 555
- gameDisplay.blit(lspike, (x_axisa, y_axisa))
-
- if orientation3 == 1:
- x_axisa = 691
- gameDisplay.blit(rspike, (x_axisa, y_axisa))
-
- # right side spikes
-
- if orientation5 == 0:
- x_axisx = 761
- gameDisplay.blit(lspike, (x_axisx, y_axisx))
-
- if orientation5 == 1:
- x_axisx = 761 + 136
- gameDisplay.blit(rspike, (x_axisx, y_axisx))
-
- # bottom spikes
-
- if orientation2 == 0 and y_axis2 > 380:
- x_axis2 = 350
- gameDisplay.blit(lspike, (x_axis2, y_axis2))
-
- if orientation2 == 1 and y_axis2 > 380:
- x_axis2 = 589
- gameDisplay.blit(rspike, (x_axis2, y_axis2))
-
- if orientation4 == 0 and y_axisb > 380:
- x_axisb = 659
- gameDisplay.blit(lspike, (x_axisb, y_axisb))
-
- if orientation4 == 1 and y_axisb > 380:
- x_axisb = 659 + 238
- gameDisplay.blit(rspike, (x_axisb, y_axisb))
-
- y_axis1 -= speed
- y_axis2 -= speed
-
- y_axisa -= speed
- y_axisb -= speed
-
- y_axisx -= speed
-
- if y_axis1 <= -40 or y_axis2 <= 380 or y_axisa <= -40 or y_axisb <= 380 or \
- y_axisx <= -40:
- scoremusic.play(0)
- score += 1
-
- if(y_axis1 < -40):
- orientation1 = randint(0, 1)
-
- y_axis1 = 400
-
- if(y_axis2 < 380):
- orientation2 = randint(0, 1)
-
- y_axis2 = 700
-
- if(y_axisa < -40):
- orientation3 = randint(0, 1)
-
- y_axisa = 400
-
- if(y_axisb < 380):
- orientation4 = randint(0, 1)
-
- y_axisb = 700
-
- if(y_axisx < -40):
- orientation5 = randint(0, 1)
-
- y_axisx = 400
-
- gameDisplay.blit(background1, (0 + 350, 380)
- ) # bottom part display
-
- # bottom guys display
-
- if leftdown == leftman or leftdown == rightman:
- gameDisplay.blit(leftdown, (leftdownmove, 400))
-
- if rightdown == leftman or rightdown == rightman:
- gameDisplay.blit(rightdown, (rightdownmove, 400))
-
- # bottom spikes
-
- if orientation2 == 0 and y_axis2 > 380:
- x_axis2 = 350
- gameDisplay.blit(lspike, (x_axis2, y_axis2))
-
- if orientation2 == 1 and y_axis2 > 380:
- x_axis2 = 589
- gameDisplay.blit(rspike, (x_axis2, y_axis2))
-
- if orientation4 == 0 and y_axisb > 380:
- x_axisb = 659
- gameDisplay.blit(lspike, (x_axisb, y_axisb))
-
- if orientation4 == 1 and y_axisb > 380:
- x_axisb = 659 + 238
- gameDisplay.blit(rspike, (x_axisb, y_axisb))
-
- scores = font1.render(str(score), 1, (0, 0, 0))
- gameDisplay.blit(scores, (200 + 650, 30))
-
- if leftquad.get_rect(center=(leftmove + 5, 30 + 10)).collidepoint(x_axis1 + 8, y_axis1):
- # or
- # leftquad.get_rect(center=(leftmove+5,100+10)).collidepoint(x_axis2+8,y_axis2):
- pygame.mixer.music.load("data/sound/fall.wav")
- pygame.mixer.music.play(0)
- # collide.play(0)
- return score
-
- if midquad.get_rect(center=(midmove + 5, 30 + 10)).collidepoint(x_axisa + 8, y_axisa):
- # or
- # midquad.get_rect(center=(midmove+5,100+10)).collidepoint(x_axisb+8,y_axisb):
- pygame.mixer.music.load("data/sound/fall.wav")
- pygame.mixer.music.play(0)
- # collide.play(0)
- return score
-
- if rightquad.get_rect(center=(rightmove + 5, 30 + 10)).collidepoint(x_axisx + 8, y_axisx):
-
- pygame.mixer.music.load("data/sound/fall.wav")
- pygame.mixer.music.play(0)
- # collide.play(0)
- return score
-
- # bottom boy collision collision detection
-
- if leftdown.get_rect(center=(leftdownmove + 5, 400 + 10)).collidepoint(x_axis2 + 8, y_axis2):
-
- pygame.mixer.music.load("data/sound/fall.wav")
- pygame.mixer.music.play(0)
- # collide.play(0)
- return score
-
- if rightdown.get_rect(center=(rightdownmove + 5, 400 + 10)).collidepoint(x_axisb + 8, y_axisb):
-
- pygame.mixer.music.load("data/sound/fall.wav")
- pygame.mixer.music.play(0)
- # collide.play(0)
- return score
-
- pygame.display.update()
- clock.tick(60)
diff --git a/main.py b/main.py
index 81824db..60c6dd7 100644
--- a/main.py
+++ b/main.py
@@ -22,329 +22,232 @@
import os
+import pygame
+import pickle
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
-import pickle
-import pygame
-import sys
-from gettext import gettext as _
-from sugar3.activity.activity import get_activity_root
+from sugar3.activity.activity import get_activity_root
-from normal import *
-from nightmare import *
-from fear import *
-from cardiac import *
-from impossible import *
-from inferno import *
-from scorescreen import *
-from howtoplay import *
+from cardiac import pane2heartwindow
+from scorescreen import scorewindow
+from howtoplay import rules
+from button import Button
+from game import Game
+disp_width = 600
+disp_height = 600
-class game:
+try:
+ score_path = os.path.join(get_activity_root(), 'data', 'score.pkl')
+except KeyError:
+ score_path = '/tmp/score.pkl'
- sound = True
+black = (0, 0, 0)
+white = (255, 255, 255)
- def run(self):
- self.crashed = False
+class MakeThemFallGame:
+
+ sound = True
+
+ def __init__(self):
+ self.running = True
self.running_mode = None
- black = (0, 0, 0)
- white = (255, 255, 255)
- clock = pygame.time.Clock()
- timer = pygame.time.Clock()
+ self.clock = pygame.time.Clock()
+
+ self.gameDisplay = None
+ self.info = None
+ self.offset = [0, 0]
+ self.bg_dimensions = [0, 0]
+
+ self.buttons = []
+
+ self.maxscore = [0, 0, 0, 0, 0, 0]
+
+ def run_game(self, gamenumber, bg_image_path, keymap, border_width=16):
+ self.running_mode = Game(bg_image_path, keymap,
+ border_width=border_width)
+ self.running_mode.running = self.running
+ score_data = self.running_mode.run()
+
+ if scorewindow(self.gameDisplay, score_data, gamenumber, self).run():
+ self.run_game(gamenumber, bg_image_path,
+ keymap, border_width=border_width)
+
+ self.start()
+
+ def show_help(self):
+ self.running_mode = rules()
+ self.running_mode.running = self.running
+ self.running_mode = self.running_mode.run(self.gameDisplay,
+ self.bg_dimensions,
+ self.offset)
+
+ self.start()
+
+ def update_highscore(self):
+ if os.path.getsize(score_path) > 0:
+ with open(score_path, 'rb') as inp: # Reading
+ self.maxscore = pickle.load(inp)
+
+ def vw(self, x):
+ return self.offset[0] + (x / 100) * self.bg_dimensions[0]
- disp_width = 600
- disp_height = 600
+ def vh(self, y):
+ return self.offset[1] + (y / 100) * self.bg_dimensions[1]
- press = 0
+ def blit_centre(self, surf, x, y):
+ rect = surf.get_rect()
+ centered_coords = (x - rect.width // 2, y - rect.height // 2)
+ self.gameDisplay.blit(surf, centered_coords)
- info = pygame.display.Info()
- gameDisplay = pygame.display.get_surface()
+ def start(self):
- if not(gameDisplay):
+ self.gameDisplay = pygame.display.get_surface()
- gameDisplay = pygame.display.set_mode(
- (info.current_w, info.current_h))
+ self.info = pygame.display.Info()
+
+ if not (self.gameDisplay):
+
+ self.gameDisplay = pygame.display.set_mode(
+ (self.info.current_w, self.info.current_h))
pygame.display.set_caption("Make Them Fall")
gameicon = pygame.image.load('data/images/icon.png')
pygame.display.set_icon(gameicon)
- title = pygame.image.load("data/images/welcomescreen/title.png")
- pane2 = pygame.image.load("data/images/welcomescreen/2pane.png")
- pane3 = pygame.image.load("data/images/welcomescreen/3pane.png")
- pane4 = pygame.image.load("data/images/welcomescreen/4pane.png")
- pane5 = pygame.image.load("data/images/welcomescreen/5pane.png")
- pane6 = pygame.image.load("data/images/welcomescreen/6pane.png")
- hlp = pygame.image.load("data/images/welcomescreen/help.png")
- howto = pygame.image.load("data/images/welcomescreen/howtoplay.png")
- paneheart2 = pygame.image.load(
- "data/images/welcomescreen/2paneheart.png")
+ self.gameDisplay.fill(black)
+
background = pygame.image.load(
"data/images/welcomescreen/background.png")
- maxnormal = 0
- maxnightmare = 0
- maxfear = 0
- maxcardiac = 0
- maximpossible = 0
- maxinferno = 0
- f = 1
- maxscore = [0, 0, 0, 0, 0, 0]
+ bg_rect = background.get_rect()
+ display_rect = self.gameDisplay.get_rect()
+
+ self.offset[0] = (display_rect.width - bg_rect.width) // 2
+ self.bg_dimensions = [bg_rect.width, bg_rect.height]
+
+ self.gameDisplay.blit(background, self.offset)
font_path = "fonts/arial.ttf"
font_size = 18
font1 = pygame.font.Font(font_path, font_size)
font1.set_bold(True)
- score_path = os.path.join(get_activity_root(), 'data', 'score.pkl')
if not os.path.exists(score_path):
- open(score_path,'w+')
-
- if os.path.getsize(score_path) > 0:
+ open(score_path, 'w+')
- with open(score_path, 'rb') as input: # REading
- maxscore = pickle.load(input)
+ self.update_highscore()
- maxnormal = maxscore[0]
- maxnightmare = maxscore[1]
- maxfear = maxscore[2]
- maxinferno = maxscore[3]
- maximpossible = maxscore[4]
- maxcardiac = maxscore[5]
-
- maxnormal = font1.render(_("Best: ") + str(maxnormal), 1, (0, 0, 0))
+ maxnormal = font1.render("Best: " + str(self.maxscore[0]), True, black)
maxnightmare = font1.render(
- _("Best: ") + str(maxnightmare), 1, (0, 0, 0))
- maxcardiac = font1.render(_("Best: ") + str(maxcardiac), 1, (0, 0, 0))
- maxfear = font1.render(_("Best: ") + str(maxfear), 1, (0, 0, 0))
- maxinferno = font1.render(_("Best: ") + str(maxinferno), 1, (0, 0, 0))
+ "Best: " + str(self.maxscore[1]), True, black)
+ maxfear = font1.render("Best: " + str(self.maxscore[2]), True, black)
+ maxinferno = font1.render(
+ "Best: " + str(self.maxscore[3]), True, black)
maximpossible = font1.render(
- _("Best: ") + str(maximpossible), 1, (0, 0, 0))
+ "Best: " + str(self.maxscore[4]), True, black)
+ maxcardiac = font1.render(
+ "Best: " + str(self.maxscore[5]), True, black)
+
+ self.buttons.append(Button(self.vw(50), self.vh(26),
+ "data/images/welcomescreen/2pane.png",
+ lambda:
+ self.run_game(1, "data/images/2pane.png",
+ [[pygame.K_LEFT,
+ pygame.K_RIGHT]]),
+ maxnormal))
+
+ self.buttons.append(Button(self.vw(50), self.vh(38),
+ "data/images/welcomescreen/3pane.png",
+ lambda:
+ self.run_game(2, "data/images/3pane.png",
+ [[pygame.K_LEFT,
+ pygame.K_DOWN,
+ pygame.K_RIGHT]]),
+ maxnightmare))
+
+ self.buttons.append(Button(self.vw(20), self.vh(38),
+ "data/images/welcomescreen/4pane.png",
+ lambda:
+ self.run_game(3, "data/images/4pane.png",
+ [[pygame.K_a, pygame.K_d],
+ [pygame.K_LEFT,
+ pygame.K_RIGHT]]),
+ maxfear))
+
+ self.buttons.append(Button(self.vw(80), self.vh(38),
+ "data/images/welcomescreen/5pane.png",
+ lambda:
+ self.run_game(4, "data/images/5pane.png",
+ [[pygame.K_a,
+ pygame.K_s,
+ pygame.K_d],
+ [pygame.K_LEFT,
+ pygame.K_RIGHT]]),
+ maxinferno))
+
+ self.buttons.append(Button(self.vw(50), self.vh(50),
+ "data/images/welcomescreen/6pane.png",
+ lambda:
+ self.run_game(5, "data/images/6pane.png",
+ [[pygame.K_a,
+ pygame.K_s,
+ pygame.K_d],
+ [pygame.K_LEFT,
+ pygame.K_DOWN,
+ pygame.K_RIGHT]]),
+ maximpossible))
+
+ self.buttons.append(Button(self.vw(50), self.vh(62),
+ "data/images/welcomescreen/2paneheart.png",
+ lambda:
+ self.run_game(pane2heartwindow, 6),
+ maxcardiac))
+
+ self.buttons.append(Button(self.vw(50), self.vh(74),
+ "data/images/welcomescreen/help.png",
+ self.show_help))
- while not self.crashed:
- # Gtk events
+ howto = pygame.image.load("data/images/welcomescreen/howtoplay.png")
+
+ self.blit_centre(howto, self.vw(50), self.vh(82))
+ def run(self):
+ self.start()
+
+ while self.running:
+ # Gtk events
while Gtk.events_pending():
Gtk.main_iteration()
- if self.crashed:
+ if not self.running:
break
- event = pygame.event.poll()
- # totaltime+=timer.tick()
- if event.type == pygame.QUIT:
- return
-
- mos_x, mos_y = pygame.mouse.get_pos()
-
- # print event
+ # Pump PyGame messages.
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ return
+ elif event.type == pygame.VIDEORESIZE:
+ pass
- gameDisplay.fill(black)
- gameDisplay.blit(background, (350, 0))
-
- # 2 pane game
- if pane2.get_rect(center=(390 + 80 + 120, 150 + 50)).collidepoint(mos_x, mos_y):
- gameDisplay.blit(pygame.transform.scale(
- pane2, (420, 90)), (385, 150))
- if(pygame.mouse.get_pressed())[0] == 1 and press == 0:
- # print 'yes'
- press = 1
- while f == 1:
-
- a = pane2window()
- self.running_mode = a
- self.running_mode.crashed = self.crashed
- a = a.run(gameDisplay, info)
-
- f = scorewindow()
- self.running_mode = f
- self.running_mode.crashed = self.crashed
- f = f.run(gameDisplay, a, 1)
-
- if event.type == pygame.MOUSEBUTTONUP:
- press = 0
-
- else:
- gameDisplay.blit(pane2, (390, 150)) # 2pane
-
- if pane3.get_rect(center=(390 + 60, 250 + 50)).collidepoint(mos_x, mos_y): # 3pane game
- gameDisplay.blit(pygame.transform.scale(
- pane3, (135, 95)), (385, 250))
- if(pygame.mouse.get_pressed())[0] == 1 and press == 0:
- press = 1
- while f == 1:
-
- a = pane3window()
- self.running_mode = a
- self.running_mode.crashed = self.crashed
- a = a.run(gameDisplay, info)
-
- f = scorewindow()
- self.running_mode = f
- self.running_mode.crashed = self.crashed
- f = f.run(gameDisplay, a, 2)
-
- if event.type == pygame.MOUSEBUTTONUP:
- press = 0
-
- else:
- gameDisplay.blit(pane3, (390, 250)) # 3pane
-
- if pane4.get_rect(center=(530 + 60, 250 + 50)).collidepoint(mos_x, mos_y):
- gameDisplay.blit(pygame.transform.scale(
- pane4, (135, 95)), (525, 250))
- # 4Pane Window
- if(pygame.mouse.get_pressed())[0] == 1 and press == 0:
-
- press = 1
- while f == 1:
-
- a = pane4window()
- self.running_mode = a
- self.running_mode.crashed = self.crashed
- a = a.run(gameDisplay, info)
-
- f = scorewindow()
- self.running_mode = f
- self.running_mode.crashed = self.crashed
- f = f.run(gameDisplay, a, 3)
-
- if event.type == pygame.MOUSEBUTTONUP:
- press = 0
-
- else:
- gameDisplay.blit(pane4, (530, 250)) # 4pane
-
- if pane5.get_rect(center=(670 + 60, 250 + 50)).collidepoint(mos_x, mos_y): # 5pane Windoe
- gameDisplay.blit(pygame.transform.scale(
- pane5, (135, 95)), (665, 250))
-
- if(pygame.mouse.get_pressed())[0] == 1 and press == 0:
- press = 1
- while f == 1:
-
- a = pane5window()
- self.running_mode = a
- self.running_mode.crashed = self.crashed
- a = a.run(gameDisplay, info)
-
- f = scorewindow()
- self.running_mode = f
- self.running_mode.crashed = self.crashed
- f = f.run(gameDisplay, a, 4)
-
- if event.type == pygame.MOUSEBUTTONUP:
- press = 0
-
- else:
- gameDisplay.blit(pane5, (670, 250)) # 5pane
-
- # Impossible module connect
- if pane6.get_rect(center=(390 + 200, 350 + 50)).collidepoint(mos_x, mos_y):
- gameDisplay.blit(pygame.transform.scale(
- pane6, (420, 90)), (385, 350))
- if(pygame.mouse.get_pressed())[0] == 1 and press == 0:
- press = 1
- while f == 1:
-
- a = pane6window()
- self.running_mode = a
- self.running_mode.crashed = self.crashed
- a = a.run(gameDisplay, info)
-
- f = scorewindow()
- self.running_mode = f
- self.running_mode.crashed = self.crashed
- f = f.run(gameDisplay, a, 5)
-
- if event.type == pygame.MOUSEBUTTONUP:
- press = 0
-
- else:
- gameDisplay.blit(pane6, (390, 350)) # 6pane
-
- # heart collect game
- if paneheart2.get_rect(center=(390 + 200, 450 + 50)).collidepoint(mos_x, mos_y):
- gameDisplay.blit(pygame.transform.scale(
- paneheart2, (420, 90)), (385, 450))
- if(pygame.mouse.get_pressed())[0] == 1 and press == 0:
- press = 1
- while f == 1:
-
- a = pane2heartwindow()
- self.running_mode = a
- self.running_mode.crashed = self.crashed
- a = a.run(gameDisplay, info)
-
- f = scorewindow()
- self.running_mode = f
- self.running_mode.crashed = self.crashed
- f = f.run(gameDisplay, a, 6)
-
- if event.type == pygame.MOUSEBUTTONUP:
- press = 0
-
- else:
- gameDisplay.blit(paneheart2, (390, 450)) # paneheart
-
- gameDisplay.blit(howto, (490, 550))
-
- if hlp.get_rect(center=(550 + 20, 580 + 20)).collidepoint(mos_x, mos_y): # RULES
- gameDisplay.blit(pygame.transform.scale(
- hlp, (88, 88)), (548, 580))
-
- if(pygame.mouse.get_pressed())[0] == 1 and press == 0:
- press = 1
- a = rules()
- self.running_mode = a
- self.running_mode.crashed = self.crashed
- a = a.run(gameDisplay, info)
-
- if event.type == pygame.MOUSEBUTTONUP:
- press = 0
-
- else:
-
- gameDisplay.blit(hlp, (550, 580)) # help
-
- maxnormal = font1.render("Best: " + str(maxnormal), 1, (0, 0, 0))
- maxnightmare = font1.render(
- "Best: " + str(maxnightmare), 1, (0, 0, 0))
- maxfear = font1.render("Best: " + str(maxfear), 1, (0, 0, 0))
- maxinferno = font1.render("Best: " + str(maxinferno), 1, (0, 0, 0))
- maximpossible = font1.render(
- "Best: " + str(maximpossible), 1, (0, 0, 0))
- maxcardiac = font1.render("Best: " + str(maxcardiac), 1, (0, 0, 0))
-
- # Scores Display
-
- gameDisplay.blit(maxnormal, (540, 200))
- gameDisplay.blit(maxnightmare, (410, 300))
- gameDisplay.blit(maxfear, (560, 300))
- gameDisplay.blit(maxinferno, (700, 300))
- gameDisplay.blit(maximpossible, (560, 410))
- gameDisplay.blit(maxcardiac, (560, 510))
-
- if os.path.getsize(score_path) > 0:
-
- with open(score_path, 'rb') as input: # REading
- maxscore = pickle.load(input)
-
- maxnormal = maxscore[0]
- maxnightmare = maxscore[1]
- maxfear = maxscore[2]
- maxinferno = maxscore[3]
- maximpossible = maxscore[4]
- maxcardiac = maxscore[5]
-
- f = 1
- # press=0
+ for btn in self.buttons:
+ btn.update()
+
+ self.f = 1
pygame.display.update()
- clock.tick(60)
-
+ self.clock.tick(30)
+
+ return
+
+
+def main():
+ pygame.init()
+ pygame.display.set_mode((0, 0), pygame.RESIZABLE)
+ game = MakeThemFallGame()
+ game.run()
+
if __name__ == "__main__":
- g = game()
- g.run()
+ main()
diff --git a/nightmare.py b/nightmare.py
deleted file mode 100644
index 7ca26d6..0000000
--- a/nightmare.py
+++ /dev/null
@@ -1,318 +0,0 @@
-
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-import pickle
-import pygame
-import sys
-from random import *
-
-
-class pane3window:
-
- def run(self, gameDisplay, info):
-
- orientation1 = 0
- orientation2 = 0
- orientation3 = 0
- orientation4 = 0
- orientation5 = 0
- orientation6 = 0
-
- leftmove = 350
- midmove = 555
- rightmove = 761
-
- limit1 = limit2 = 0
-
- leftman = pygame.image.load("data/images/man.png")
- rightman = pygame.transform.flip(leftman, True, False)
- background = pygame.image.load("data/images/3pane.png")
- lspike = pygame.image.load("data/images/Spike.png")
- rspike = pygame.transform.flip(lspike, True, False)
- background = pygame.transform.scale(background, (600, info.current_h))
- y_axis1 = 700
- y_axis2 = y_axis1 + 370
-
- y_axisa = 750
- y_axisb = y_axisa + 370
-
- y_axisx = 761
- y_axisy = y_axisx + 370
-
- leftquad = leftman
- midquad = leftman
- rightquad = leftman
-
- f1 = f2 = f3 = 0
- m1 = m2 = m3 = 0
- time1 = time2 = 0
-
- font_path = "fonts/arial.ttf"
- font_size = 50
- font1 = pygame.font.Font(font_path, font_size)
- score = 0
-
- x_axis1 = x_axis2 = 350
- x_axisa = x_axisb = 659
- x_axisx = x_axisy = 761
- speed = 7
- flag = 1
-
- black = (0, 0, 0)
- white = (255, 255, 255)
- clock = pygame.time.Clock()
- timer = pygame.time.Clock()
-
- sound = True
-
- jump = pygame.mixer.Sound("data/sound/jump.wav")
- scoremusic = pygame.mixer.Sound("data/sound/score.wav")
- collide = pygame.mixer.Sound("data/sound/fall.wav")
-
- while not self.crashed:
- # Gtk events
-
- while Gtk.events_pending():
- Gtk.main_iteration()
- event = pygame.event.poll()
- # totaltime+=timer.tick()
- if event.type == pygame.QUIT:
- return
-
- gameDisplay.fill(black)
- gameDisplay.blit(background, (0 + 350, 0))
-
- # Keypress orientation change
-
- if event.type == pygame.KEYDOWN and event.key == 276 and f1 == 0:
- jump.play(0)
- f1 = 1
- m1 = 1 # start moving
-
- if event.type == pygame.KEYDOWN and event.key == 274 and f2 == 0:
- jump.play(0)
- f2 = 1
- m2 = 1 # start moving
-
- if event.type == pygame.KEYDOWN and event.key == 275 and f3 == 0:
- jump.play(0)
- f3 = 1
- m3 = 1 # start moving
-
- # Check for when to stop
-
- if leftmove > 484 + 20: # left move
- leftquad = rightman
- m1 = f1 = 0
- leftmove = 484 + 20
- time1 = 0
-
- if leftmove < 350:
- leftquad = leftman
- m1 = f1 = 0
- leftmove = 350
- time1 = 0
-
- if midmove < 555: # mid move
- midquad = leftman
- m2 = f2 = 0
- midmove = 555
- time2 = 0
-
- if midmove > 690 + 20:
- midquad = rightman
- m2 = f2 = 0
- midmove = 690 + 20
- time2 = 0
-
- if rightmove < 761: # right move move
- rightquad = leftman
- m3 = f3 = 0
- rightmove = 761
- time2 = 0
-
- if rightmove > 761 + 156:
- rightquad = rightman
- m3 = f3 = 0
- rightmove = 761 + 156
- time2 = 0
-
- if m1 == 1:
-
- if leftquad == leftman:
- leftmove += 30
- if leftquad == rightman:
- leftmove -= 30
- time1 += 1
-
- if m2 == 1:
-
- if midquad == leftman:
- midmove += 30
- if midquad == rightman:
- midmove -= 30
- time2 += 1
-
- if m3 == 1:
-
- if rightquad == leftman:
- rightmove += 30
- if rightquad == rightman:
- rightmove -= 30
- time2 += 1
-
- #[350,608] [659, 916]
-
- # Guy Display
-
- if leftquad == leftman or leftquad == rightman:
- gameDisplay.blit(leftquad, (leftmove, 100))
-
- if midquad == leftman or midquad == rightman:
- gameDisplay.blit(midquad, (midmove, 100))
-
- if rightquad == leftman or rightquad == rightman:
- gameDisplay.blit(rightquad, (rightmove, 100))
-
- ######### SPIKE PART###########
-
- if orientation1 == 0: # orientation change
- x_axis1 = 350
- gameDisplay.blit(lspike, (x_axis1, y_axis1))
-
- if orientation1 == 1:
- x_axis1 = 485
- gameDisplay.blit(rspike, (x_axis1, y_axis1))
-
- if orientation2 == 0:
- x_axis2 = 350
- gameDisplay.blit(lspike, (x_axis2, y_axis2))
-
- if orientation2 == 1:
- x_axis2 = 485
- gameDisplay.blit(rspike, (x_axis2, y_axis2))
-
- # mid side spikes
- if orientation3 == 0:
- x_axisa = 555
- gameDisplay.blit(lspike, (x_axisa, y_axisa))
-
- if orientation3 == 1:
- x_axisa = 691
- gameDisplay.blit(rspike, (x_axisa, y_axisa))
-
- if orientation4 == 0:
- x_axisb = 555
- gameDisplay.blit(lspike, (x_axisb, y_axisb))
-
- if orientation4 == 1:
- x_axisb = 691
- gameDisplay.blit(rspike, (x_axisb, y_axisb))
-
- # right side spikes
-
- if orientation5 == 0:
- x_axisx = 761
- gameDisplay.blit(lspike, (x_axisx, y_axisx))
-
- if orientation5 == 1:
- x_axisx = 761 + 136
- gameDisplay.blit(rspike, (x_axisx, y_axisx))
-
- if orientation6 == 0:
- x_axisy = 761
- gameDisplay.blit(lspike, (x_axisy, y_axisy))
-
- if orientation6 == 1:
- x_axisy = 761 + 136
- gameDisplay.blit(rspike, (x_axisy, y_axisy))
-
- y_axis1 -= speed
- y_axis2 -= speed
-
- y_axisa -= speed
- y_axisb -= speed
-
- y_axisx -= speed
- y_axisy -= speed
-
- '''
-
- if score==15 or score==45 or score==70:
- flag=1
-
- if score==15 and flag==1 :
- flag=0
- speed+=0.1
-
- if score==45 and flag==1:
- flag=0
- speed+=0.1
-
- if score==70 and flag==1:
- flag=0
- speed+=0.1
- '''
-
- if y_axis1 <= -40 or y_axis2 <= -40 or y_axisa <= -40 or y_axisb <= -40 or \
- y_axisx <= -40 or y_axisy <= -40:
- scoremusic.play(0)
- score += 1
-
- if(y_axis1 < -40):
- orientation1 = randint(0, 1)
-
- y_axis1 = 700
-
- if(y_axis2 < -40):
- orientation2 = randint(0, 1)
-
- y_axis2 = 700
-
- if(y_axisa < -40):
- orientation3 = randint(0, 1)
-
- y_axisa = 700
-
- if(y_axisb < -40):
- orientation4 = randint(0, 1)
-
- y_axisb = 700
-
- if(y_axisx < -40):
- orientation5 = randint(0, 1)
-
- y_axisx = 700
-
- if(y_axisy < -40):
- orientation6 = randint(0, 1)
-
- y_axisy = 700
-
- scores = font1.render(str(score), 1, (0, 0, 0))
- gameDisplay.blit(scores, (200 + 650, 30))
-
- if leftquad.get_rect(center=(leftmove + 5, 100 + 10)).collidepoint(x_axis1 + 8, y_axis1) \
- or leftquad.get_rect(center=(leftmove + 5, 100 + 10)).collidepoint(x_axis2 + 8, y_axis2):
- pygame.mixer.music.load("data/sound/fall.wav")
- pygame.mixer.music.play(0)
- # collide.play(0)
- return score
-
- if midquad.get_rect(center=(midmove + 5, 100 + 10)).collidepoint(x_axisa + 8, y_axisa) \
- or midquad.get_rect(center=(midmove + 5, 100 + 10)).collidepoint(x_axisb + 8, y_axisb):
- pygame.mixer.music.load("data/sound/fall.wav")
- pygame.mixer.music.play(0)
- # collide.play(0)
- return score
-
- if rightquad.get_rect(center=(rightmove + 5, 100 + 10)).collidepoint(x_axisx + 8, y_axisx) \
- or rightquad.get_rect(center=(rightmove + 5, 100 + 10)).collidepoint(x_axisy + 8, y_axisy):
- pygame.mixer.music.load("data/sound/fall.wav")
- pygame.mixer.music.play(0)
- # collide.play(0)
- return score
-
- pygame.display.update()
- clock.tick(60)
diff --git a/normal.py b/normal.py
deleted file mode 100644
index bde86b5..0000000
--- a/normal.py
+++ /dev/null
@@ -1,239 +0,0 @@
-
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-import pickle
-import pygame
-import sys
-from random import *
-
-
-class pane2window:
-
- def run(self, gameDisplay, info):
-
- orientation1 = 0
- orientation2 = 0
- orientation3 = 0
- orientation4 = 0
- orientation5 = 0
- orientation6 = 0
-
- leftmove = 350
- rightmove = 659
- limit1 = limit2 = 0
-
- leftman = pygame.image.load("data/images/man.png")
- rightman = pygame.transform.flip(leftman, True, False)
- background = pygame.image.load("data/images/2pane.png")
- lspike = pygame.image.load("data/images/Spike.png")
- rspike = pygame.transform.flip(lspike, True, False)
- background = pygame.transform.scale(background, (600, info.current_h))
- y_axis1 = 700
- y_axis2 = y_axis1 + 370
-
- y_axisa = 750
- y_axisb = y_axisa + 370
-
- leftquad = leftman
- rightquad = leftman
- f1 = f2 = 0
- m1 = m2 = 0
- time1 = time2 = 0
-
- font_path = "fonts/arial.ttf"
- font_size = 50
- font1 = pygame.font.Font(font_path, font_size)
- score = 0
-
- x_axis1 = x_axis2 = 350
- x_axisa = x_axisb = 659
- speed = 7
- flag = 1
-
- black = (0, 0, 0)
- white = (255, 255, 255)
- clock = pygame.time.Clock()
- timer = pygame.time.Clock()
-
- sound = True
-
- jump = pygame.mixer.Sound("data/sound/jump.wav")
- scoremusic = pygame.mixer.Sound("data/sound/score.wav")
- collide = pygame.mixer.Sound("data/sound/fall.wav")
-
- while not self.crashed:
- # Gtk events
- while Gtk.events_pending():
- Gtk.main_iteration()
- event = pygame.event.poll()
- # totaltime+=timer.tick()
- if event.type == pygame.QUIT:
- return
-
- gameDisplay.fill(black)
- gameDisplay.blit(background, (0 + 350, 0))
-
- # Keypress orientation change
-
- if event.type == pygame.KEYDOWN and event.key == 276 and f1 == 0:
- jump.play(0)
- f1 = 1
- m1 = 1 # start moving
-
- if event.type == pygame.KEYDOWN and event.key == 275 and f2 == 0:
- jump.play(0)
- f2 = 1
- m2 = 1 # start moving
-
- # Check for when to stop
-
- if leftmove > 608:
- leftquad = rightman
- m1 = f1 = 0
- leftmove = 608
- time1 = 0
-
- if leftmove < 350:
- leftquad = leftman
- m1 = f1 = 0
- leftmove = 350
- time1 = 0
-
- if rightmove < 659:
- rightquad = leftman
- m2 = f2 = 0
- rightmove = 659
- time2 = 0
-
- if rightmove > 916:
- rightquad = rightman
- m2 = f2 = 0
- rightmove = 916
- time2 = 0
-
- if m1 == 1:
-
- if leftquad == leftman:
- leftmove += 30
- if leftquad == rightman:
- leftmove -= 30
- time1 += 1
-
- if m2 == 1:
-
- if rightquad == leftman:
- rightmove += 30
- if rightquad == rightman:
- rightmove -= 30
- time2 += 1
-
- #[350,608] [659, 916]
-
- # Guy Display
-
- if leftquad == leftman or leftquad == rightman:
- gameDisplay.blit(leftquad, (leftmove, 100))
-
- if rightquad == leftman or rightquad == rightman:
- gameDisplay.blit(rightquad, (rightmove, 100))
-
- ######### SPIKE PART###########
-
- if orientation1 == 0: # orientation change
- x_axis1 = 350
- gameDisplay.blit(lspike, (x_axis1, y_axis1))
-
- if orientation1 == 1:
- x_axis1 = 589
- gameDisplay.blit(rspike, (x_axis1, y_axis1))
-
- if orientation2 == 0:
- x_axis2 = 350
- gameDisplay.blit(lspike, (x_axis2, y_axis2))
-
- if orientation2 == 1:
- x_axis2 = 589
- gameDisplay.blit(rspike, (x_axis2, y_axis2))
-
- # right side spikes
- if orientation4 == 0:
- x_axisa = 659
- gameDisplay.blit(lspike, (x_axisa, y_axisa))
-
- if orientation4 == 1:
- x_axisa = 659 + 238
- gameDisplay.blit(rspike, (x_axisa, y_axisa))
-
- if orientation5 == 0:
- x_axisb = 659
- gameDisplay.blit(lspike, (x_axisb, y_axisb))
-
- if orientation5 == 1:
- x_axisb = 659 + 238
- gameDisplay.blit(rspike, (x_axisb, y_axisb))
-
- y_axis1 -= speed
- y_axis2 -= speed
-
- y_axisa -= speed
- y_axisb -= speed
-
- if score == 15 or score == 35 or score == 50 or score == 80:
- flag = 1
-
- if score == 15 and flag == 1:
- flag = 0
- speed += 0.1
-
- if score == 35 and flag == 1:
- flag = 0
- speed += 0.1
-
- if score == 50 and flag == 1:
- flag = 0
- speed += 0.1
-
- if score == 80 and flag == 1:
- flag = 0
- speed += 0.1
-
- if y_axis1 <= -40 or y_axis2 <= -40 or y_axisa <= -40 or y_axisb <= -40:
- scoremusic.play(0)
- score += 1
-
- if(y_axis1 < -40):
- orientation1 = randint(0, 1)
-
- y_axis1 = 700
-
- if(y_axis2 < -40):
- orientation2 = randint(0, 1)
-
- y_axis2 = 700
-
- if(y_axisa < -40):
- orientation4 = randint(0, 1)
-
- y_axisa = 700
-
- if(y_axisb < -40):
- orientation5 = randint(0, 1)
-
- y_axisb = 700
-
- scores = font1.render(str(score), 1, (0, 0, 0))
- gameDisplay.blit(scores, (200 + 650, 30))
-
- if leftquad.get_rect(center=(leftmove + 5, 100 + 10)).collidepoint(x_axis1 + 8, y_axis1) \
- or leftquad.get_rect(center=(leftmove + 5, 100 + 10)).collidepoint(x_axis2 + 8, y_axis2):
- collide.play(0)
- return score
-
- if rightquad.get_rect(center=(rightmove + 5, 100 + 10)).collidepoint(x_axisa + 8, y_axisa) \
- or rightquad.get_rect(center=(rightmove + 5, 100 + 10)).collidepoint(x_axisb + 8, y_axisb):
- collide.play(0)
- return score
-
- pygame.display.update()
- clock.tick(60)
diff --git a/scorescreen.py b/scorescreen.py
index c12c374..93e2431 100644
--- a/scorescreen.py
+++ b/scorescreen.py
@@ -1,32 +1,28 @@
import os
-import gi
-gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import pickle
import pygame
-import sys
-from random import *\
-from sugar3.activity.activity import get_activity_root
+from sugar3.activity.activity import get_activity_root
+from button import Button
+
+black = (0, 0, 0)
+white = (255, 255, 255)
class scorewindow:
- def run(self, gameDisplay, score, gamenumber):
- if self.crashed:
- return
+ def __init__(self, gameDisplay, score, gamenumber, game):
background = pygame.image.load(
"data/images/scorescreen/whitebackground.png")
gameover = pygame.image.load("data/images/scorescreen/gameover.png")
newbestscore = pygame.image.load(
"data/images/scorescreen/newbestscore.png")
- tryagain = pygame.image.load("data/images/scorescreen/tryagain.png")
- backhome = pygame.image.load("data/images/scorescreen/back.png")
scoreboard = pygame.image.load(
"data/images/scorescreen/scoreboard.png")
- background = pygame.transform.scale(background, (600 - 100, 768))
+ background = pygame.transform.scale(background, game.bg_dimensions)
font_path = "fonts/arial.ttf"
font_size = 50
@@ -37,44 +33,84 @@ def run(self, gameDisplay, score, gamenumber):
font2 = pygame.font.Font(font_path, font_size_large)
font2.set_bold(True)
- press = 0
- black = (0, 0, 0)
- white = (255, 255, 255)
+ self.tryagain = False
+ self.backhome = False
ifbest = False
- clock = pygame.time.Clock()
- timer = pygame.time.Clock()
maxscore = [0, 0, 0, 0, 0, 0]
- sound = True
+ try:
+ score_path = os.path.join(get_activity_root(), 'data', 'score.pkl')
+ except KeyError:
+ score_path = '/tmp/score.pkl'
- score_path = os.path.join(get_activity_root(), 'data', 'score.pkl')
-
- if os.path.getsize(score_path) == 0:
+ if not os.path.exists(score_path):
+ open(score_path, 'w+')
- with open(score_path, 'wb') as output:
- pickle.dump(maxscore, output, pickle.HIGHEST_PROTOCOL)
+ if os.path.getsize(score_path) > 0:
- with open(score_path, 'rb') as input: # REading
- maxscore = pickle.load(input)
+ with open(score_path, 'rb') as inp: # Reading
+ maxscore = pickle.load(inp)
- if score > maxscore[gamenumber - 1]:
+ if score is not None and score > maxscore[gamenumber - 1]:
best = score
ifbest = True
maxscore[gamenumber - 1] = score
with open(score_path, 'wb') as output: # Writiing if max
pickle.dump(maxscore, output, pickle.HIGHEST_PROTOCOL)
-
else:
best = maxscore[gamenumber - 1]
- # print best
- # print best
score = font2.render(str(score), 1, (255, 255, 255))
best = font2.render(str(best), 1, white)
- while not self.crashed:
+ gameDisplay.fill(black)
+ gameDisplay.blit(background, game.offset)
+ game.blit_centre(gameover, game.vw(50), game.vh(10))
+
+ self.buttons = []
+
+ if ifbest is True:
+ game.blit_centre(newbestscore, game.vw(50), game.vh(20))
+ game.blit_centre(best, game.vw(50), game.vh(22))
+ self.buttons.append(Button(game.vw(50), game.vh(30),
+ "data/images/scorescreen/tryagain.png",
+ self._try_again_cb))
+ self.buttons.append(Button(game.vw(50), game.vh(40),
+ "data/images/scorescreen/back.png",
+ self._back_home_cb))
+ else:
+ game.blit_centre(scoreboard, game.vw(50), game.vh(28))
+ game.blit_centre(score, game.vw(50), game.vh(24))
+ game.blit_centre(best, game.vw(50), game.vh(36))
+ self.buttons.append(Button(game.vw(50), game.vh(48),
+ "data/images/scorescreen/tryagain.png",
+ self._try_again_cb))
+ self.buttons.append(Button(game.vw(50), game.vh(60),
+ "data/images/scorescreen/back.png",
+ self._back_home_cb))
+
+ self.running = True
+
+ def _try_again_cb(self):
+ self.tryagain = True
+
+ def _back_home_cb(self):
+ self.backhome = True
+
+ def run(self):
+ if not self.running:
+ return
+
+ clock = pygame.time.Clock()
+
+ while self.running:
+ if self.tryagain:
+ return 1
+ if self.backhome:
+ return 0
+
# Gtk events
while Gtk.events_pending():
Gtk.main_iteration()
@@ -85,88 +121,8 @@ def run(self, gameDisplay, score, gamenumber):
if event.type == pygame.QUIT:
return
- mos_x, mos_y = pygame.mouse.get_pos()
-
- if ifbest == True:
-
- gameDisplay.fill(black)
- gameDisplay.blit(background, (0 + 350, 0))
- gameDisplay.blit(gameover, (350 + 60, 50 + 30))
-
- gameDisplay.blit(newbestscore, (450, 160))
-
- # tryagain
- if tryagain.get_rect(center=(450 + 80, 250 + 10)).collidepoint(mos_x, mos_y):
- gameDisplay.blit(pygame.transform.scale(
- tryagain, (293, 84)), (448, 250))
- if(pygame.mouse.get_pressed())[0] == 1 and press == 0:
- press = 1
- return 1
-
- if event.type == pygame.MOUSEBUTTONUP:
- press = 0
-
- else:
-
- gameDisplay.blit(tryagain, (450, 250))
-
- # back home
- if backhome.get_rect(center=(450 + 80, 340 + 10)).collidepoint(mos_x, mos_y):
- gameDisplay.blit(pygame.transform.scale(
- backhome, (291, 84)), (448, 340))
- if (pygame.mouse.get_pressed())[0] == 1 and press == 0:
- press = 1
- return 0
-
- if event.type == pygame.MOUSEBUTTONUP:
- press = 0
-
- else:
-
- gameDisplay.blit(backhome, (450, 340))
-
- gameDisplay.blit(best, (560, 190))
-
- else:
-
- gameDisplay.fill(black)
- gameDisplay.blit(background, (0 + 350, 0))
- gameDisplay.blit(gameover, (350 + 80, 50))
- gameDisplay.blit(scoreboard, (450 + 5, 160))
-
- # try again
- if tryagain.get_rect(center=(450 + 80 + 5, 250 + 10 + 150)).collidepoint(mos_x, mos_y):
- gameDisplay.blit(pygame.transform.scale(
- tryagain, (293, 84)), (448 + 5, 250 + 150))
- if(pygame.mouse.get_pressed())[0] == 1 and press == 0:
- press = 1
- return 1
-
- if event.type == pygame.MOUSEBUTTONUP:
- press = 0
-
- else:
-
- gameDisplay.blit(tryagain, (450 + 5, 250 + 150))
-
- # backhome
- if backhome.get_rect(center=(450 + 80 + 5, 340 + 10 + 150)).collidepoint(mos_x, mos_y):
- gameDisplay.blit(pygame.transform.scale(
- backhome, (291, 84)), (448 + 5, 340 + 150))
- if (pygame.mouse.get_pressed())[0] == 1 and press == 0:
- press = 1
- return 0
-
- if event.type == pygame.MOUSEBUTTONUP:
- press = 0
-
- else:
-
- gameDisplay.blit(backhome, (450 + 5, 340 + 150))
-
- gameDisplay.blit(score, (570, 210))
- gameDisplay.blit(best, (570, 320))
-
+ for btn in self.buttons:
+ btn.update()
pygame.display.update()
clock.tick(60)
diff --git a/spike.py b/spike.py
new file mode 100644
index 0000000..856e92f
--- /dev/null
+++ b/spike.py
@@ -0,0 +1,48 @@
+# Copyright (C) 2023 Riya Jain
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+
+import pygame
+
+
+class Spike:
+
+ def __init__(self, x, y, flip, speed, path_length):
+ self.x = x
+ self.initial = y
+
+ self.graphic = pygame.image.load("data/images/Spike.png")
+ if flip == 1:
+ self.graphic = pygame.transform.flip(self.graphic, True, False)
+ self.rect = self.graphic.get_rect()
+
+ if flip:
+ self.x -= self.rect.width
+ self.y = y - self.rect.height
+
+ self.gameDisplay = pygame.display.get_surface()
+
+ self.speed = speed
+ self.path_length = path_length
+
+ def update(self):
+ self.draw()
+ self.y -= self.speed
+ if self.y < (self.initial - self.path_length):
+ return True
+ return False
+
+ def draw(self):
+ self.gameDisplay.blit(self.graphic, (self.x, self.y))