Skip to content
Open

ahmed #119

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions X_tasks.txt

This file was deleted.

Binary file removed assets/images/background.jpg
Binary file not shown.
Binary file added assets/images/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/images/gameOver.jpg
Binary file not shown.
Binary file added assets/images/gameOver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/images/start.jpg
Binary file not shown.
Binary file added assets/images/start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified component/__pycache__/heart.cpython-311.pyc
Binary file not shown.
Binary file modified component/__pycache__/texture.cpython-311.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion component/heart.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def draw_old_heart(self, speed):
glColor3d(1, 1, 0)
glTranslate(self.heart_x[i], 0, self.heart_z[i])
self.heart_z[i] -= speed
glScale(3, 2.5, 0)
glScale(4, 3.5, 0)
self.heart_draw()
glBindTexture(GL_TEXTURE_2D, -1)
glPopMatrix()
Expand Down
6 changes: 3 additions & 3 deletions component/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from OpenGL.GL import *

image_name = [
'start.jpg',
'background.jpg',
'start.png',
'background.png',
'obstacle.jpeg',
'heart.png',
'fuel.png',
'gameOver.jpg'
'gameOver.png'
]
textureList = [0, 1, 2, 3, 4, 5]

Expand Down
39 changes: 23 additions & 16 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
MILLISECONDS = 15

factory = {}

text = 'press P to pause'
obstacles = Obstacle(texture_name=TEXTURE_NAMES['obstacle'])
fuel = Fuel(texture_name=TEXTURE_NAMES['fuel'])
heart = Heart(texture_name=TEXTURE_NAMES['heart'])
Expand All @@ -66,7 +66,7 @@ def restart():
generate = 0
fuel_generate = 0
fuel_level = 100
background_sound = pygame.mixer.Sound("assets/sound/gamePlay.mp3.mp3")
background_sound = pygame.mixer.Sound("assets/sound/gamePlay.mp3")


#########################################################################
Expand Down Expand Up @@ -145,9 +145,9 @@ def draw_screen():
state = fuel.fuel_level_bar(fuel_level, state)
score = (generate // 100) * 100
draw_text(f"SCORE: {score}", -.9, .7)
draw_text("press P to pause ", -.9, .6, 4)
# draw_text( text, -.9, .6, 4)

init_my_scene(1500, 900)
init_my_scene(1365, 720)
glPopMatrix()


Expand Down Expand Up @@ -226,7 +226,7 @@ def draw_text(string, x=0.0, y=0.0, size=5.0, size_line=2):
string = string.encode()
for c in string:
glutStrokeCharacter(GLUT_STROKE_ROMAN, c)
init_my_scene(1000, 900)
init_my_scene(1365, 720)
glPopMatrix()


Expand All @@ -240,9 +240,9 @@ def switch():

if not num_of_heart:
state = "gameOver"
if pause:
draw_text("press R to continue ", -.3, 0, 6)
glutSwapBuffers()
# if pause:
# draw_text("press R to continue ", -.3, 0, 6)
# glutSwapBuffers()
if (state == 'intro' or state == "3" or state == "5") and pause == False:
game()
if not pause:
Expand All @@ -255,6 +255,7 @@ def camera_setup():
if state == 'intro':
if camera_coordinates['x-eye'] >= 0:
camera_coordinates['x-eye'] -= 0.1

camera_coordinates['z-eye'] -= 0.1
camera_coordinates['y_center'] += 11 / 250
print(camera_coordinates)
Expand All @@ -278,6 +279,9 @@ def game():
camera_setup()

if state != 'intro':
draw_text(text, -.9, .6, 4)
if pause:
speed = 0,
if generate % 120 == 0:
speed = obstacles.generate_obstacle(num_of_rail=int(state), speed=speed)
obstacles.draw_obstacles(speed=speed)
Expand All @@ -301,7 +305,6 @@ def game():
flash -= 1
if flash % 15 == 0:
draw_vehicle()

if speed < 3:
STEP = 3
else:
Expand All @@ -317,18 +320,22 @@ def game():

#########################################################################
def keyboard_callback(key, x, y):
global state, pause, background_sound, num_of_heart, fuel_level
global state, pause, background_sound, text
if key == b'\r' and state == "start":
state = 'intro'
background_sound.stop()
background_sound = pygame.mixer.Sound(
"assets/sound/gamePlay.mp3")
background_sound.play(-1)
if key == b'p':
print("pause")
if key == b'p' and state != 'intro':
text = 'press R to continue '
print(text)
# draw_text(text, -.9, .6, 4)
pause = True
if key == b'r':
print("resume")
text = 'press P to pause '
print(text)
# draw_text(text, -.9, .6, 4)
pause = False
if key == b'\r' and state == 'gameOver':
restart()
Expand All @@ -339,7 +346,7 @@ def mouse_callback(x, y):
global spaceship_position
print(x)
if state == '3' or state == '5':
spaceship_position = (-x + 750) / 45
spaceship_position = (-x + 650) / 45
if spaceship_position > 8 and state == '3':
spaceship_position = 8
elif spaceship_position < -8 and state == '3':
Expand All @@ -364,15 +371,15 @@ def main():
glfw.init()
background_sound.play(-1)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
glutInitWindowSize(1500, 900)
glutInitWindowSize(1365, 720)
glutInitWindowPosition(0, 0)
glutCreateWindow(b"Race The Sun !")
glutDisplayFunc(switch)
glutTimerFunc(MILLISECONDS, anim_timer, 1)
texture.init_textures()
glutKeyboardFunc(keyboard_callback)
glutPassiveMotionFunc(mouse_callback)
init_my_scene(1500, 900)
init_my_scene(1365, 720)
glutMainLoop()


Expand Down