├── Complete ├── basics │ ├── assets │ │ ├── Zero Hour.otf │ │ ├── animation │ │ │ ├── 0.png │ │ │ ├── 1.png │ │ │ ├── 2.png │ │ │ ├── 3.png │ │ │ ├── 4.png │ │ │ ├── 5.png │ │ │ ├── 6.png │ │ │ └── 7.png │ │ ├── laser.wav │ │ ├── music.wav │ │ └── spaceship.png │ └── code │ │ ├── 10_animations.py │ │ ├── 1_base.py │ │ ├── 2_move.py │ │ ├── 3_input.py │ │ ├── 4_collisions.py │ │ ├── 5_camera.py │ │ ├── 6_audio.py │ │ ├── 7_classes.py │ │ ├── 8_collision_resolution.py │ │ └── 9_timer.py ├── basics_3D │ ├── 1_base.py │ ├── 2_imports.py │ ├── 3_collision.py │ ├── 4_shader.py │ ├── models │ │ ├── nagon_texture.png │ │ ├── rupee.gltf │ │ ├── rupee_red.bin │ │ ├── ship.glb │ │ └── ship_fail.glb │ └── shaders │ │ ├── flash.fs │ │ └── grayscale.fs ├── game_2D │ ├── audio │ │ ├── explosion.wav │ │ ├── laser.wav │ │ └── music.wav │ ├── code │ │ ├── __pycache__ │ │ │ ├── custom_timer.cpython-313.pyc │ │ │ ├── settings.cpython-313.pyc │ │ │ └── sprites.cpython-313.pyc │ │ ├── custom_timer.py │ │ ├── main.py │ │ ├── settings.py │ │ └── sprites.py │ ├── font │ │ └── Stormfaze.otf │ └── images │ │ ├── explosion │ │ ├── 1.png │ │ ├── 10.png │ │ ├── 11.png │ │ ├── 12.png │ │ ├── 13.png │ │ ├── 14.png │ │ ├── 15.png │ │ ├── 16.png │ │ ├── 17.png │ │ ├── 18.png │ │ ├── 19.png │ │ ├── 2.png │ │ ├── 20.png │ │ ├── 21.png │ │ ├── 22.png │ │ ├── 23.png │ │ ├── 24.png │ │ ├── 25.png │ │ ├── 26.png │ │ ├── 27.png │ │ ├── 28.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ ├── 6.png │ │ ├── 7.png │ │ ├── 8.png │ │ └── 9.png │ │ ├── laser.png │ │ ├── meteor.png │ │ ├── spaceship.png │ │ └── star.png └── game_3D │ ├── audio │ ├── explosion.wav │ ├── laser.wav │ └── music.wav │ ├── code │ ├── __pycache__ │ │ ├── custom_timer.cpython-313.pyc │ │ ├── models.cpython-313.pyc │ │ └── settings.cpython-313.pyc │ ├── custom_timer.py │ ├── main.py │ ├── models.py │ └── settings.py │ ├── font │ └── Stormfaze.otf │ ├── models │ ├── laser.glb │ └── ship.glb │ ├── shaders │ └── flash.fs │ └── textures │ ├── dark.png │ ├── green.png │ ├── light.png │ ├── orange.png │ ├── purple.png │ └── red.png ├── README.md └── start ├── basics ├── assets │ ├── Zero Hour.otf │ ├── animation │ │ ├── 0.png │ │ ├── 1.png │ │ ├── 2.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ ├── 6.png │ │ └── 7.png │ ├── laser.wav │ ├── music.wav │ └── spaceship.png └── code │ ├── 10_animations.py │ ├── 1_base.py │ ├── 2_move.py │ ├── 3_input.py │ ├── 4_collisions.py │ ├── 5_camera.py │ ├── 6_audio.py │ ├── 7_classes.py │ ├── 8_collision_resolution.py │ └── 9_timer.py ├── basics_3D ├── 1_base.py ├── 2_imports.py ├── 3_collision.py ├── 4_shader.py ├── models │ ├── nagon_texture.png │ ├── rupee.gltf │ ├── rupee_red.bin │ ├── ship.glb │ └── ship_fail.glb └── shaders │ ├── flash.fs │ └── grayscale.fs ├── game_2D ├── audio │ ├── explosion.wav │ ├── laser.wav │ └── music.wav ├── code │ ├── __pycache__ │ │ ├── custom_timer.cpython-313.pyc │ │ ├── settings.cpython-313.pyc │ │ └── sprites.cpython-313.pyc │ ├── custom_timer.py │ ├── main.py │ └── settings.py ├── font │ └── Stormfaze.otf └── images │ ├── explosion │ ├── 1.png │ ├── 10.png │ ├── 11.png │ ├── 12.png │ ├── 13.png │ ├── 14.png │ ├── 15.png │ ├── 16.png │ ├── 17.png │ ├── 18.png │ ├── 19.png │ ├── 2.png │ ├── 20.png │ ├── 21.png │ ├── 22.png │ ├── 23.png │ ├── 24.png │ ├── 25.png │ ├── 26.png │ ├── 27.png │ ├── 28.png │ ├── 3.png │ ├── 4.png │ ├── 5.png │ ├── 6.png │ ├── 7.png │ ├── 8.png │ └── 9.png │ ├── laser.png │ ├── meteor.png │ ├── spaceship.png │ └── star.png └── game_3D ├── audio ├── explosion.wav ├── laser.wav └── music.wav ├── code ├── __pycache__ │ ├── custom_timer.cpython-313.pyc │ ├── models.cpython-313.pyc │ └── settings.cpython-313.pyc ├── custom_timer.py ├── main.py └── settings.py ├── font └── Stormfaze.otf ├── models ├── laser.glb └── ship.glb ├── shaders └── flash.fs └── textures ├── dark.png ├── green.png ├── light.png ├── orange.png ├── purple.png └── red.png /Complete/basics/assets/Zero Hour.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics/assets/Zero Hour.otf -------------------------------------------------------------------------------- /Complete/basics/assets/animation/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics/assets/animation/0.png -------------------------------------------------------------------------------- /Complete/basics/assets/animation/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics/assets/animation/1.png -------------------------------------------------------------------------------- /Complete/basics/assets/animation/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics/assets/animation/2.png -------------------------------------------------------------------------------- /Complete/basics/assets/animation/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics/assets/animation/3.png -------------------------------------------------------------------------------- /Complete/basics/assets/animation/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics/assets/animation/4.png -------------------------------------------------------------------------------- /Complete/basics/assets/animation/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics/assets/animation/5.png -------------------------------------------------------------------------------- /Complete/basics/assets/animation/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics/assets/animation/6.png -------------------------------------------------------------------------------- /Complete/basics/assets/animation/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics/assets/animation/7.png -------------------------------------------------------------------------------- /Complete/basics/assets/laser.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics/assets/laser.wav -------------------------------------------------------------------------------- /Complete/basics/assets/music.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics/assets/music.wav -------------------------------------------------------------------------------- /Complete/basics/assets/spaceship.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics/assets/spaceship.png -------------------------------------------------------------------------------- /Complete/basics/code/10_animations.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from os.path import join 4 | 5 | class AnimatedSprite: 6 | def __init__(self): 7 | self.animation_frames = [load_texture(join('assets', 'animation', f'{i}.png')) for i in range(8)] 8 | self.animation_index, self.animation_speed = 0, 5 9 | 10 | def update(self, dt): 11 | self.animation_index += self.animation_speed * dt 12 | 13 | def draw(self): 14 | draw_texture(self.animation_frames[int(self.animation_index) % len(self.animation_frames)],0,0,WHITE) 15 | 16 | init_window(1920,1080, 'Animations') 17 | # animation_frames = [load_texture(join('assets', 'animation', f'{i}.png')) for i in range(8)] 18 | # animation_index = 0 19 | # animation_speed = 5 20 | animated_sprite = AnimatedSprite() 21 | 22 | while not window_should_close(): 23 | dt = get_frame_time() 24 | # animation_index += animation_speed * dt 25 | animated_sprite.update(dt) 26 | begin_drawing() 27 | clear_background(BLACK) 28 | animated_sprite.draw() 29 | # draw_texture(animation_frames[int(animation_index) % len(animation_frames)],0,0,WHITE) 30 | end_drawing() 31 | 32 | close_window() -------------------------------------------------------------------------------- /Complete/basics/code/1_base.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from os.path import join 4 | 5 | init_window(1920,1080, 'Base') 6 | 7 | # import images/textures 8 | spaceship_texture = load_texture(join('assets', 'spaceship.png')) 9 | spaceship_image = load_image(join('assets', 'spaceship.png')) 10 | image_color_grayscale(spaceship_image) 11 | new_texture = load_texture_from_image(spaceship_image) 12 | 13 | cowboy_image = load_image(join('assets','animation', '0.png')) 14 | image_color_invert(cowboy_image) 15 | cowboy_texture = load_texture_from_image(cowboy_image) 16 | 17 | # import font 18 | font = load_font(join('assets', 'Zero Hour.otf')) 19 | 20 | while not window_should_close(): 21 | begin_drawing() 22 | clear_background(BLACK) 23 | 24 | # custom shape drawing 25 | draw_pixel(100, 200, RED) 26 | draw_pixel_v(Vector2(200,200),WHITE) 27 | draw_circle_v(Vector2(1000,600), 200, YELLOW) 28 | draw_circle(1000, 600, 100, GREEN) 29 | draw_line_ex(Vector2(0,0), Vector2(500,200), 10, (50,0,0,255)) 30 | 31 | # display images 32 | draw_texture(spaceship_texture, 0, 0, WHITE) 33 | draw_texture_v(new_texture,Vector2(100,0),WHITE) 34 | draw_texture(cowboy_texture, 1800, 900, WHITE) 35 | 36 | # displaying text 37 | draw_text('Some text',0, 400, 100, WHITE) 38 | draw_text_ex(font, 'Some more text', Vector2(0,600), 20, 0, BLUE) 39 | 40 | end_drawing() 41 | 42 | close_window() -------------------------------------------------------------------------------- /Complete/basics/code/2_move.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from os.path import join 4 | 5 | init_window(1920, 1080, "Move") 6 | # set_target_fps(100) 7 | 8 | # imports 9 | ship = load_texture(join('assets', 'spaceship.png')) 10 | ship_pos = Vector2(0,0) 11 | ship_direction = Vector2(1,1) 12 | ship_speed = 800 13 | 14 | while not window_should_close(): 15 | 16 | # updates 17 | if ship_pos.y >= 1080 - 40: 18 | ship_direction.y = -1 19 | if ship_pos.x >= 1920 - 100: 20 | ship_direction.x = -1 21 | if ship_pos.y <= 0: 22 | ship_direction.y = 1 23 | if ship_pos.x <= 0: 24 | ship_direction.x = 1 25 | 26 | dt = get_frame_time() 27 | ship_pos.x += ship_direction.x * ship_speed * dt 28 | ship_pos.y += ship_direction.y * ship_speed * dt 29 | 30 | # drawing 31 | begin_drawing() 32 | clear_background(BLACK) 33 | draw_texture_v(ship, ship_pos, WHITE) 34 | draw_fps(0,0) 35 | end_drawing() 36 | close_window() -------------------------------------------------------------------------------- /Complete/basics/code/3_input.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from os.path import join 4 | 5 | init_window(1920, 1080, "Input") 6 | set_exit_key(KEY_ESCAPE) 7 | 8 | ship_texture = load_texture(join('assets', 'spaceship.png')) 9 | ship_pos = Vector2(0,0) 10 | ship_direction = Vector2(0,0) 11 | ship_speed = 800 12 | 13 | while not window_should_close(): 14 | # input 15 | # mouse input 16 | # ship_pos = get_mouse_position() 17 | # print(is_mouse_button_down(1)) # state of the mouse button 18 | # if is_mouse_button_released(0): 19 | # print('mouse button pressed') 20 | 21 | # keyboard input 22 | # print(is_key_down(KEY_A)) 23 | # if is_key_pressed(KEY_A): 24 | # print('a') 25 | 26 | # ship input 27 | ship_direction.x = int(is_key_down(KEY_RIGHT)) - int(is_key_down(KEY_LEFT)) 28 | ship_direction.y = int(is_key_down(KEY_DOWN)) - int(is_key_down(KEY_UP)) 29 | ship_direction = Vector2Normalize(ship_direction) 30 | 31 | # update 32 | dt = get_frame_time() 33 | ship_pos.x += ship_direction.x * ship_speed * dt 34 | ship_pos.y += ship_direction.y * ship_speed * dt 35 | 36 | # drawing 37 | begin_drawing() 38 | clear_background(BLACK) 39 | draw_texture_v(ship_texture, ship_pos, WHITE) 40 | end_drawing() 41 | close_window() -------------------------------------------------------------------------------- /Complete/basics/code/4_collisions.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | 4 | init_window(1920, 1080, "Collisions") 5 | player_pos = Vector2(0,0) 6 | obstacle_pos = Vector2(500,400) 7 | player_radius = 50 8 | obstacle_radius = 30 9 | 10 | r1 = Rectangle(0,0,100,200) 11 | r2 = Rectangle(800,500, 200,300) 12 | 13 | while not window_should_close(): 14 | 15 | # input 16 | player_pos = get_mouse_position() 17 | r1.x = get_mouse_x() 18 | r1.y = get_mouse_y() 19 | 20 | # collision 21 | # print(check_collision_circles(player_pos, player_radius, obstacle_pos, obstacle_radius)) 22 | # print(check_collision_circle_rec(player_pos, player_radius, r1)) 23 | print(check_collision_recs(r1, r2)) 24 | overlap_rec = get_collision_rec(r1, r2) 25 | 26 | # drawing 27 | begin_drawing() 28 | clear_background(BLACK) 29 | # draw_circle_v(player_pos, player_radius, WHITE) 30 | draw_circle_v(obstacle_pos, obstacle_radius, RED) 31 | draw_rectangle_rec(r1,BLUE) 32 | draw_rectangle_rec(r2, GREEN) 33 | 34 | if overlap_rec: 35 | draw_rectangle_rec(overlap_rec, RED) 36 | 37 | end_drawing() 38 | 39 | close_window() -------------------------------------------------------------------------------- /Complete/basics/code/5_camera.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from random import randint, choice 4 | 5 | init_window(1920, 1080, "Camera") 6 | 7 | # player 8 | pos = Vector2() 9 | radius = 50 10 | direction = Vector2() 11 | speed = 400 12 | 13 | # circles 14 | circles = [ 15 | ( 16 | Vector2(randint(-2000,2000),randint(-1000,1000)), # pos 17 | randint(50,200), # radius 18 | choice([RED, GREEN, BLUE, YELLOW, ORANGE]) # color 19 | ) 20 | for i in range(100) 21 | ] 22 | 23 | # camera 24 | camera = Camera2D() 25 | camera.zoom = 1 26 | camera.target = pos 27 | camera.offset = Vector2(1920 / 2, 1080 / 2) 28 | camera.rotation = 0 29 | 30 | while not window_should_close(): 31 | 32 | # input 33 | direction.x = int(is_key_down(KEY_RIGHT)) - int(is_key_down(KEY_LEFT)) 34 | direction.y = int(is_key_down(KEY_DOWN)) - int(is_key_down(KEY_UP)) 35 | direction = vector2_normalize(direction) 36 | 37 | # movement 38 | dt = get_frame_time() 39 | pos.x += direction.x * speed * dt 40 | pos.y += direction.y * speed * dt 41 | 42 | # camera update 43 | rotate_direction = int(is_key_down(KEY_S)) - int(is_key_down(KEY_A)) 44 | camera.rotation += rotate_direction * dt * 50 45 | 46 | zoom_direction = int(is_key_down(KEY_W)) - int(is_key_down(KEY_Q)) 47 | camera.zoom += zoom_direction * dt * 2 48 | camera.zoom = max(0.2, min(2,camera.zoom)) 49 | camera.target = pos 50 | 51 | # drawing 52 | begin_drawing() 53 | begin_mode_2d(camera) 54 | clear_background(WHITE) 55 | for circle in circles: 56 | draw_circle_v(*circle) 57 | draw_circle_v(pos, radius, BLACK) 58 | end_mode_2d() 59 | end_drawing() 60 | 61 | close_window() -------------------------------------------------------------------------------- /Complete/basics/code/6_audio.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from os.path import join 4 | 5 | init_window(1920,1080, 'Sound') 6 | 7 | while not window_should_close(): 8 | begin_drawing() 9 | clear_background(BLACK) 10 | end_drawing() 11 | 12 | close_window() -------------------------------------------------------------------------------- /Complete/basics/code/7_classes.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from os.path import join 4 | 5 | class Sprite: 6 | def __init__(self, pos, speed): 7 | self.pos = pos 8 | self.speed = speed 9 | 10 | def move(self, dt): 11 | self.pos.x += self.direction.x * self.speed * dt 12 | self.pos.y += self.direction.y * self.speed * dt 13 | 14 | class Player(Sprite): 15 | def __init__(self, pos): 16 | super().__init__(pos, 400) 17 | self.texture = load_texture(join('assets','spaceship.png')) 18 | self.direction = Vector2() 19 | 20 | def update(self, dt): 21 | self.direction.x = int(is_key_down(KEY_RIGHT)) - int(is_key_down(KEY_LEFT)) 22 | self.direction.y = int(is_key_down(KEY_DOWN)) - int(is_key_down(KEY_UP)) 23 | self.direction = Vector2Normalize(self.direction) 24 | 25 | # update 26 | self.move(dt) 27 | 28 | def draw(self): 29 | draw_texture_v(self.texture, self.pos, WHITE) 30 | 31 | class Block(Sprite): 32 | def __init__(self, pos, speed): 33 | super().__init__(pos, speed) 34 | self.direction = Vector2(1,0) 35 | self.size = Vector2(100,200) 36 | 37 | def update(self, dt): 38 | self.move(dt) 39 | 40 | def draw(self): 41 | draw_rectangle_v(self.pos,self.size, RED) 42 | 43 | init_window(1920,1080, 'OOP') 44 | sprites = [Player(Vector2(500,200)), Block(Vector2(700,0), 200)] 45 | 46 | while not window_should_close(): 47 | 48 | dt = get_frame_time() 49 | for sprite in sprites: 50 | sprite.update(dt) 51 | 52 | begin_drawing() 53 | clear_background(BLACK) 54 | for sprite in sprites: 55 | sprite.draw() 56 | end_drawing() 57 | 58 | close_window() -------------------------------------------------------------------------------- /Complete/basics/code/8_collision_resolution.py: -------------------------------------------------------------------------------- 1 | from raylib import * 2 | from pyray import * 3 | 4 | def collision(axis): 5 | for block in blocks: 6 | if check_collision_recs(block, player): 7 | if axis == 'x': 8 | if direction.x > 0: # moving right 9 | player.x = block.x - player.width 10 | if direction.x < 0: # moving left 11 | player.x = block.x + block.width 12 | else: 13 | if direction.y < 0: # moving up 14 | player.y = block.y + block.height 15 | if direction.y > 0: # moving down 16 | player.y = block.y - player.height 17 | 18 | init_window(1920, 1080, "Collision resolution") 19 | 20 | level_map = [ 21 | '1111111111111111111', 22 | '1010000000000000001', 23 | '1010000000001111111', 24 | '1000000000000000111', 25 | '1000000200000000011', 26 | '1000000000000100001', 27 | '1000000000000100001', 28 | '1001100000000100001', 29 | '1001100000000100001', 30 | '1001100000000100001', 31 | '1111111111111111111' 32 | ] 33 | 34 | player = Rectangle(400,300,60,60) 35 | speed = 300 36 | direction = Vector2() 37 | 38 | blocks = [] 39 | block_size = 100 40 | for row_index, row in enumerate(level_map): 41 | for col_index, cell in enumerate(row): 42 | if cell == '1': 43 | x = col_index * block_size 44 | y = row_index * block_size 45 | block = Rectangle(x,y,block_size,block_size) 46 | blocks.append(block) 47 | 48 | 49 | while not window_should_close(): 50 | direction.x = int(is_key_down(KEY_RIGHT)) - int(is_key_down(KEY_LEFT)) 51 | direction.y = int(is_key_down(KEY_DOWN)) - int(is_key_down(KEY_UP)) 52 | 53 | # movement 54 | dt = get_frame_time() 55 | player.x += direction.x * speed * dt 56 | collision('x') 57 | player.y += direction.y * speed * dt 58 | collision('y') 59 | 60 | begin_drawing() 61 | clear_background(BLACK) 62 | for block in blocks: 63 | draw_rectangle_rec(block, GRAY) 64 | draw_rectangle_rec(player, RED) 65 | end_drawing() 66 | close_window() -------------------------------------------------------------------------------- /Complete/basics/code/9_timer.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from random import choice 4 | 5 | class Timer: 6 | def __init__(self, duration: int, repeat = False, autostart = False, func = None): 7 | self.duration = duration 8 | self.start_time = 0 9 | self.active = False 10 | self.repeat = repeat 11 | self.func = func 12 | 13 | if autostart: 14 | self.activate() 15 | 16 | def activate(self): 17 | self.active = True 18 | self.start_time = get_time() 19 | 20 | def deactivate(self): 21 | self.active = False 22 | self.start_time = 0 23 | if self.repeat: 24 | self.activate() 25 | 26 | def update(self): 27 | if self.active: 28 | if get_time() - self.start_time >= self.duration: 29 | if self.func and self.start_time: self.func() 30 | self.deactivate() 31 | 32 | class Sprite: 33 | def __init__(self, pos, size): 34 | self.rec = Rectangle(pos[0], pos[1], size[0], size[1]) 35 | self.color = WHITE 36 | 37 | def randomize_color(self): 38 | self.color = choice([RED, YELLOW, GREEN, ORANGE, MAGENTA, BLUE, GRAY, MAROON]) 39 | 40 | def draw(self): 41 | draw_rectangle_rec(self.rec, self.color) 42 | 43 | init_window(1920,1080, 'Timer') 44 | 45 | while not window_should_close(): 46 | begin_drawing() 47 | clear_background(BLACK) 48 | end_drawing() 49 | 50 | close_window() -------------------------------------------------------------------------------- /Complete/basics_3D/1_base.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | 4 | init_window(1920, 1080, "3D base") 5 | 6 | # camera 7 | camera = Camera3D() 8 | camera.position = Vector3(0,5.0,5.0) 9 | camera.target = Vector3() 10 | camera.up = Vector3(0,1,0) 11 | camera.fovy = 45.0 12 | camera.projection = CAMERA_PERSPECTIVE 13 | 14 | # models 15 | mesh = gen_mesh_cube(1,1,1) 16 | model = load_model_from_mesh(mesh) 17 | 18 | # cylinder 19 | mesh_cylinder = gen_mesh_cylinder(1,2,20) 20 | model_cylinder = load_model_from_mesh(mesh_cylinder) 21 | 22 | # texture 23 | image = gen_image_gradient_linear(20,20,1,RED, YELLOW) 24 | texture = load_texture_from_image(image) 25 | set_material_texture(model_cylinder.materials[0],MATERIAL_MAP_ALBEDO,texture) 26 | 27 | # move 28 | pos = Vector3() 29 | rotation = 0 30 | 31 | while not window_should_close(): 32 | dt = get_frame_time() 33 | # pos.z += 2 * dt 34 | rotation += 4 * dt 35 | model_cylinder.transform = matrix_rotate_x(rotation) 36 | 37 | clear_background(WHITE) 38 | begin_drawing() 39 | 40 | begin_mode_3d(camera) 41 | draw_grid(10,0.5) 42 | draw_model(model_cylinder, pos,1,WHITE) 43 | draw_line_3d(Vector3(-4,0,-2),Vector3(5,2,3), BLACK) 44 | end_mode_3d() 45 | 46 | end_drawing() 47 | close_window() -------------------------------------------------------------------------------- /Complete/basics_3D/2_imports.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from os.path import join 4 | 5 | init_window(1920, 1080, "3D imports") 6 | camera = Camera3D() 7 | camera.position = Vector3(0.0, 3.0, 5.0) 8 | camera.target = Vector3(0.0, 0.0, 0.0) 9 | camera.up = Vector3(0.0, 1.0, 0.0) 10 | camera.fovy = 45.0 11 | camera.projection = CAMERA_PERSPECTIVE 12 | 13 | # imports 14 | ship = load_model(join('models','ship.glb')) 15 | rupee = load_model(join('models','rupee.gltf')) # texture and bin file must be there 16 | ship_fail = load_model(join('models','ship_fail.glb')) # far from origin point 17 | rotation = 0 18 | 19 | while not window_should_close(): 20 | # ship.transform = matrix_scale(10,10,10) 21 | dt = get_frame_time() 22 | rotation += 20 * dt 23 | begin_drawing() 24 | clear_background(WHITE) 25 | begin_mode_3d(camera) 26 | draw_grid(10,1.0) 27 | draw_model_ex(ship, Vector3(),Vector3(0,1,0),rotation,Vector3(1.4,1.4,1.4),WHITE) 28 | end_mode_3d() 29 | end_drawing() 30 | 31 | close_window() -------------------------------------------------------------------------------- /Complete/basics_3D/3_collision.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | 4 | def get_bounding_box(model, pos): 5 | bounding_box = get_mesh_bounding_box(model.meshes[0]) 6 | min_boundary = Vector3Add(pos,bounding_box.min) 7 | max_boundary = Vector3Add(pos,bounding_box.max) 8 | return BoundingBox(min_boundary, max_boundary) 9 | 10 | def check_collision(axis): 11 | player_bbox = get_bounding_box(player, pos) 12 | boundary_bbox = get_bounding_box(obstacle, obstacle_pos) 13 | if check_collision_boxes(player_bbox, boundary_bbox): 14 | if axis == 'x': 15 | if direction.x > 0: 16 | pos.x = boundary_bbox.min.x - 0.5001 17 | if direction.x < 0: 18 | pos.x = boundary_bbox.max.x + 0.5001 19 | if axis == 'z': 20 | if direction.z > 0: 21 | pos.z = boundary_bbox.min.z - 0.5001 22 | if direction.z < 0: 23 | pos.z = boundary_bbox.max.z + 0.5001 24 | 25 | init_window(1920, 1080, "3D collisions") 26 | camera = Camera3D() 27 | camera.position = Vector3(0.0, 5.0, 5.0) 28 | camera.target = Vector3(0.0, 0.0, 0.0) 29 | camera.up = Vector3(0.0, 1.0, 0.0) 30 | camera.fovy = 45.0 31 | camera.projection = CAMERA_PERSPECTIVE 32 | 33 | player = load_model_from_mesh(gen_mesh_cube(1,1,1)) 34 | pos = Vector3() 35 | direction = Vector3() 36 | speed = 5 37 | bbox = get_mesh_bounding_box(player.meshes[0]) 38 | 39 | obstacle = load_model_from_mesh(gen_mesh_cube(2,1,4)) 40 | obstacle_pos = Vector3(3,0,0) 41 | 42 | while not window_should_close(): 43 | # input 44 | direction.x = int(is_key_down(KEY_RIGHT)) - int(is_key_down(KEY_LEFT)) 45 | direction.z = int(is_key_down(KEY_DOWN)) - int(is_key_down(KEY_UP)) 46 | 47 | # movement & collision 48 | dt = get_frame_time() 49 | pos.x += direction.x * speed * dt 50 | check_collision('x') 51 | pos.z += direction.z * speed * dt 52 | check_collision('z') 53 | 54 | # collision 55 | # print(check_collision_spheres(pos, 0.5, obstacle_pos, 2)) 56 | # print(check_collision_box_sphere(get_bounding_box(player, pos), obstacle_pos, 2)) 57 | # print(check_collision_boxes(get_bounding_box(player, pos),get_bounding_box(obstacle, obstacle_pos))) 58 | 59 | # drawing 60 | begin_drawing() 61 | clear_background(WHITE) 62 | begin_mode_3d(camera) 63 | draw_grid(10,1) 64 | draw_model(player, pos,1.0,RED) 65 | draw_model(obstacle, obstacle_pos,1.0,GRAY) 66 | draw_bounding_box(get_bounding_box(player, pos), GREEN) 67 | end_mode_3d() 68 | end_drawing() 69 | close_window() -------------------------------------------------------------------------------- /Complete/basics_3D/4_shader.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from os.path import join 4 | 5 | init_window(1920, 1080, "Shader") 6 | camera = Camera3D() 7 | camera.position = Vector3(0.0, 5.0, 5.0) 8 | camera.target = Vector3(0.0, 0.0, 0.0) 9 | camera.up = Vector3(0.0, 1.0, 0.0) 10 | camera.fovy = 45.0 11 | camera.projection = CAMERA_PERSPECTIVE 12 | 13 | #create model 14 | model = load_model_from_mesh(gen_mesh_cylinder(1,2,5)) 15 | texture = load_texture_from_image(gen_image_gradient_linear(100,100,1,RED,YELLOW)) 16 | set_material_texture(model.materials[0], MATERIAL_MAP_ALBEDO, texture) 17 | 18 | # shaders 19 | shader = load_shader(ffi.NULL, join('shaders', 'flash.fs')) 20 | model.materials[0].shader = shader 21 | flash_loc = get_shader_location(shader, 'flash') 22 | flash_amount = ffi.new('struct Vector2*', [1,0]) 23 | 24 | while not window_should_close(): 25 | if is_key_pressed(KEY_A): 26 | set_shader_value(shader, flash_loc, flash_amount, SHADER_UNIFORM_VEC2) 27 | 28 | begin_drawing() 29 | begin_mode_3d(camera) 30 | clear_background(BLACK) 31 | draw_model(model, Vector3(0.0, 0.0, 0.0),1.0,WHITE) 32 | end_mode_3d() 33 | end_drawing() 34 | close_window() -------------------------------------------------------------------------------- /Complete/basics_3D/models/nagon_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics_3D/models/nagon_texture.png -------------------------------------------------------------------------------- /Complete/basics_3D/models/rupee.gltf: -------------------------------------------------------------------------------- 1 | { 2 | "asset" : { 3 | "generator" : "Khronos glTF Blender I/O v3.4.50", 4 | "version" : "2.0" 5 | }, 6 | "scene" : 0, 7 | "scenes" : [ 8 | { 9 | "name" : "Scene", 10 | "nodes" : [ 11 | 0 12 | ] 13 | } 14 | ], 15 | "nodes" : [ 16 | { 17 | "mesh" : 0, 18 | "name" : "rupee_red" 19 | } 20 | ], 21 | "materials" : [ 22 | { 23 | "name" : "nagonford", 24 | "pbrMetallicRoughness" : { 25 | "baseColorTexture" : { 26 | "index" : 0 27 | }, 28 | "metallicFactor" : 0, 29 | "roughnessFactor" : 0.5 30 | } 31 | } 32 | ], 33 | "meshes" : [ 34 | { 35 | "name" : "rupee_red", 36 | "primitives" : [ 37 | { 38 | "attributes" : { 39 | "POSITION" : 0, 40 | "TEXCOORD_0" : 1, 41 | "NORMAL" : 2 42 | }, 43 | "indices" : 3, 44 | "material" : 0 45 | } 46 | ] 47 | } 48 | ], 49 | "textures" : [ 50 | { 51 | "sampler" : 0, 52 | "source" : 0 53 | } 54 | ], 55 | "images" : [ 56 | { 57 | "mimeType" : "image/png", 58 | "name" : "nagon_texture", 59 | "uri" : "nagon_texture.png" 60 | } 61 | ], 62 | "accessors" : [ 63 | { 64 | "bufferView" : 0, 65 | "componentType" : 5126, 66 | "count" : 377, 67 | "max" : [ 68 | 0.5944601893424988, 69 | 0.9373665452003479, 70 | 0.24908025562763214 71 | ], 72 | "min" : [ 73 | -0.5944598913192749, 74 | -0.9373663663864136, 75 | -0.24907921254634857 76 | ], 77 | "type" : "VEC3" 78 | }, 79 | { 80 | "bufferView" : 1, 81 | "componentType" : 5126, 82 | "count" : 377, 83 | "type" : "VEC2" 84 | }, 85 | { 86 | "bufferView" : 2, 87 | "componentType" : 5126, 88 | "count" : 377, 89 | "type" : "VEC3" 90 | }, 91 | { 92 | "bufferView" : 3, 93 | "componentType" : 5123, 94 | "count" : 708, 95 | "type" : "SCALAR" 96 | } 97 | ], 98 | "bufferViews" : [ 99 | { 100 | "buffer" : 0, 101 | "byteLength" : 4524, 102 | "byteOffset" : 0, 103 | "target" : 34962 104 | }, 105 | { 106 | "buffer" : 0, 107 | "byteLength" : 3016, 108 | "byteOffset" : 4524, 109 | "target" : 34962 110 | }, 111 | { 112 | "buffer" : 0, 113 | "byteLength" : 4524, 114 | "byteOffset" : 7540, 115 | "target" : 34962 116 | }, 117 | { 118 | "buffer" : 0, 119 | "byteLength" : 1416, 120 | "byteOffset" : 12064, 121 | "target" : 34963 122 | } 123 | ], 124 | "samplers" : [ 125 | { 126 | "magFilter" : 9729, 127 | "minFilter" : 9987 128 | } 129 | ], 130 | "buffers" : [ 131 | { 132 | "byteLength" : 13480, 133 | "uri" : "rupee_red.bin" 134 | } 135 | ] 136 | } 137 | -------------------------------------------------------------------------------- /Complete/basics_3D/models/rupee_red.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics_3D/models/rupee_red.bin -------------------------------------------------------------------------------- /Complete/basics_3D/models/ship.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics_3D/models/ship.glb -------------------------------------------------------------------------------- /Complete/basics_3D/models/ship_fail.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/basics_3D/models/ship_fail.glb -------------------------------------------------------------------------------- /Complete/basics_3D/shaders/flash.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 fragTexCoord; 4 | in vec4 fragColor; 5 | 6 | uniform sampler2D texture0; 7 | uniform vec2 flash; 8 | 9 | out vec4 finalColor; 10 | 11 | void main() { 12 | vec4 texelColor = texture(texture0, fragTexCoord); 13 | finalColor = mix(texelColor, vec4(1.0, 1.0, 1.0, texelColor.a), flash.x); 14 | } -------------------------------------------------------------------------------- /Complete/basics_3D/shaders/grayscale.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | void main() 17 | { 18 | // Texel color fetching from texture sampler 19 | vec4 texelColor = texture(texture0, fragTexCoord)*colDiffuse*fragColor; 20 | 21 | // Convert texel color to grayscale using NTSC conversion weights 22 | float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); 23 | 24 | // Calculate final fragment color 25 | finalColor = vec4(gray, gray, gray, texelColor.a); 26 | } -------------------------------------------------------------------------------- /Complete/game_2D/audio/explosion.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/audio/explosion.wav -------------------------------------------------------------------------------- /Complete/game_2D/audio/laser.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/audio/laser.wav -------------------------------------------------------------------------------- /Complete/game_2D/audio/music.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/audio/music.wav -------------------------------------------------------------------------------- /Complete/game_2D/code/__pycache__/custom_timer.cpython-313.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/code/__pycache__/custom_timer.cpython-313.pyc -------------------------------------------------------------------------------- /Complete/game_2D/code/__pycache__/settings.cpython-313.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/code/__pycache__/settings.cpython-313.pyc -------------------------------------------------------------------------------- /Complete/game_2D/code/__pycache__/sprites.cpython-313.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/code/__pycache__/sprites.cpython-313.pyc -------------------------------------------------------------------------------- /Complete/game_2D/code/custom_timer.py: -------------------------------------------------------------------------------- 1 | from settings import get_time 2 | 3 | class Timer: 4 | def __init__(self, duration: int, repeat = False, autostart = False, func = None): 5 | self.duration = duration 6 | self.start_time = 0 7 | self.active = False 8 | self.repeat = repeat 9 | self.func = func 10 | 11 | if autostart: 12 | self.activate() 13 | 14 | def activate(self): 15 | self.active = True 16 | self.start_time = get_time() 17 | 18 | def deactivate(self): 19 | self.active = False 20 | self.start_time = 0 21 | if self.repeat: 22 | self.activate() 23 | 24 | def update(self): 25 | if self.active: 26 | if get_time() - self.start_time >= self.duration: 27 | if self.func and self.start_time: self.func() 28 | self.deactivate() -------------------------------------------------------------------------------- /Complete/game_2D/code/main.py: -------------------------------------------------------------------------------- 1 | from settings import * 2 | from custom_timer import Timer 3 | from sprites import Player, Laser, Meteor, ExplosionAnimation 4 | 5 | class Game: 6 | def __init__(self): 7 | init_window(WINDOW_WIDTH, WINDOW_HEIGHT, 'Space shooter') 8 | init_audio_device() 9 | self.import_assets() 10 | self.lasers, self.meteors, self.explosions = [], [], [] 11 | self.meteor_timer = Timer(METEOR_TIMER_DURATION, True, True,self.create_meteor) 12 | self.player = Player(self.assets['player'], Vector2(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2), self.shoot_laser) 13 | play_music_stream(self.audio['music']) 14 | 15 | def import_assets(self): 16 | self.assets = { 17 | 'player': load_texture(join('images', 'spaceship.png')), 18 | 'star': load_texture(join('images', 'star.png')), 19 | 'laser': load_texture(join('images', 'laser.png')), 20 | 'meteor': load_texture(join('images', 'meteor.png')), 21 | 'explosion': [load_texture(join('images', 'explosion', f'{i}.png')) for i in range(1,29)], 22 | 'font': load_font_ex(join('font', 'Stormfaze.otf'),FONT_SIZE,ffi.NULL, 0) 23 | } 24 | 25 | self.audio = { 26 | 'laser': load_sound(join('audio','laser.wav')), 27 | 'explosion': load_sound(join('audio','explosion.wav')), 28 | 'music': load_music_stream(join('audio', 'music.wav')) 29 | } 30 | 31 | self.star_data = [ 32 | ( 33 | Vector2(randint(0, WINDOW_WIDTH),randint(0, WINDOW_HEIGHT)), # pos 34 | uniform(0.5, 1.6) # size 35 | ) for i in range(30) 36 | ] 37 | 38 | def draw_stars(self): 39 | for star in self.star_data: 40 | draw_texture_ex(self.assets['star'],star[0], 0, star[1], WHITE) 41 | 42 | def shoot_laser(self, pos): 43 | self.lasers.append(Laser(self.assets['laser'], pos)) 44 | play_sound(self.audio['laser']) 45 | 46 | def create_meteor(self): 47 | self.meteors.append(Meteor(self.assets['meteor'])) 48 | 49 | def discard_sprites(self): 50 | self.lasers = [laser for laser in self.lasers if not laser.discard] 51 | self.meteors = [meteor for meteor in self.meteors if not meteor.discard] 52 | self.explosions = [explosion for explosion in self.explosions if not explosion.discard] 53 | 54 | def check_collisions(self): 55 | # lasers and meteors 56 | for laser in self.lasers: 57 | for meteor in self.meteors: 58 | if check_collision_circle_rec(meteor.get_center(), meteor.collision_radius, laser.get_rect()): 59 | laser.discard, meteor.discard = True, True 60 | pos = Vector2(laser.pos.x - laser.size.x / 2,laser.pos.y) 61 | self.explosions.append(ExplosionAnimation(pos, self.assets['explosion'])) 62 | play_sound(self.audio['explosion']) 63 | 64 | # player and meteors 65 | for meteor in self.meteors: 66 | if check_collision_circles(self.player.get_center(), self.player.collision_radius, meteor.get_center(), meteor.collision_radius): 67 | close_window() 68 | 69 | def draw_score(self): 70 | score = int(get_time()) 71 | text_size = measure_text_ex(self.assets['font'],str(score),FONT_SIZE,0) 72 | draw_text_ex(self.assets['font'], str(score), Vector2(WINDOW_WIDTH / 2 - text_size.x / 2,100),FONT_SIZE,0,WHITE) 73 | 74 | def update(self): 75 | dt = get_frame_time() 76 | self.meteor_timer.update() 77 | self.player.update(dt) 78 | self.discard_sprites() 79 | for sprite in self.lasers + self.meteors + self.explosions: 80 | sprite.update(dt) 81 | self.check_collisions() 82 | update_music_stream(self.audio['music']) 83 | 84 | def draw(self): 85 | begin_drawing() 86 | clear_background(BG_COLOR) 87 | self.draw_stars() 88 | self.draw_score() 89 | self.player.draw() 90 | for sprite in self.lasers + self.meteors + self.explosions: 91 | sprite.draw() 92 | end_drawing() 93 | 94 | def run(self): 95 | while not window_should_close(): 96 | self.update() 97 | self.draw() 98 | unload_music_stream(self.audio['music']) 99 | close_audio_device() 100 | close_window() 101 | 102 | if __name__ == '__main__': 103 | game = Game() 104 | game.run() -------------------------------------------------------------------------------- /Complete/game_2D/code/settings.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from random import randint, uniform 4 | from os.path import join 5 | 6 | WINDOW_WIDTH, WINDOW_HEIGHT = 1920, 1080 7 | BG_COLOR = (15,10,25,255) 8 | PLAYER_SPEED = 500 9 | LASER_SPEED = 600 10 | METEOR_SPEED_RANGE = [300,400] 11 | METEOR_TIMER_DURATION = 0.4 12 | FONT_SIZE = 120 -------------------------------------------------------------------------------- /Complete/game_2D/code/sprites.py: -------------------------------------------------------------------------------- 1 | from settings import * 2 | 3 | class Sprite: 4 | def __init__(self, texture, pos, speed, direction): 5 | self.texture = texture 6 | self.pos = pos 7 | self.speed = speed 8 | self.direction = direction 9 | self.size = Vector2(texture.width, texture.height) 10 | self.discard = False 11 | self.collision_radius = self.size.y / 2 12 | 13 | def move(self, dt): 14 | self.pos.x += self.direction.x * self.speed * dt 15 | self.pos.y += self.direction.y * self.speed * dt 16 | 17 | def check_discard(self): 18 | self.discard = not -300 < self.pos.y < WINDOW_HEIGHT + 300 19 | 20 | def get_center(self): 21 | return Vector2( 22 | self.pos.x + self.size.x / 2, 23 | self.pos.y + self.size.y / 2, 24 | ) 25 | 26 | def update(self, dt): 27 | self.move(dt) 28 | self.check_discard() 29 | 30 | def draw(self): 31 | draw_texture_v(self.texture, self.pos, WHITE) 32 | 33 | class Player(Sprite): 34 | def __init__(self, texture, pos, shoot_laser): 35 | super().__init__(texture, pos, PLAYER_SPEED, Vector2()) 36 | self.shoot_laser = shoot_laser 37 | 38 | def input(self): 39 | self.direction.x = int(is_key_down(KEY_RIGHT)) - int(is_key_down(KEY_LEFT)) 40 | self.direction.y = int(is_key_down(KEY_DOWN)) - int(is_key_down(KEY_UP)) 41 | self.direction = Vector2Normalize(self.direction) 42 | 43 | if is_key_pressed(KEY_SPACE): 44 | self.shoot_laser(Vector2(self.pos.x + self.size.x / 2, self.pos.y - 60)) 45 | 46 | def constraint(self): 47 | self.pos.x = max(0, min(self.pos.x, WINDOW_WIDTH - self.size.x)) 48 | self.pos.y = max(0, min(self.pos.y, WINDOW_HEIGHT - self.size.y)) 49 | 50 | def update(self, dt): 51 | self.input() 52 | self.move(dt) 53 | self.constraint() 54 | 55 | class Laser(Sprite): 56 | def __init__(self, texture, pos): 57 | super().__init__(texture, pos, LASER_SPEED, Vector2(0,-1)) 58 | 59 | def get_rect(self): 60 | return Rectangle(self.pos.x, self.pos.y, self.size.x, self.size.y) 61 | 62 | class Meteor(Sprite): 63 | def __init__(self, texture): 64 | pos = Vector2(randint(0, WINDOW_WIDTH), randint(-150,-50)) 65 | speed = randint(*METEOR_SPEED_RANGE) 66 | direction = Vector2(uniform(-0.5, 0.5),1) 67 | super().__init__(texture, pos, speed, direction) 68 | self.rotation = 0 69 | self.rect = Rectangle(0, 0, self.size.x, self.size.y) 70 | 71 | def update(self, dt): 72 | super().update(dt) 73 | self.rotation += 50 * dt 74 | 75 | def get_center(self): 76 | return self.pos 77 | 78 | def draw(self): 79 | target_rect = Rectangle(self.pos.x, self.pos.y, self.size.x, self.size.y) 80 | draw_texture_pro(self.texture,self.rect,target_rect,Vector2(self.size.x / 2, self.size.y / 2),self.rotation, WHITE) 81 | 82 | class ExplosionAnimation: 83 | def __init__(self, pos, textures): 84 | self.textures = textures 85 | self.size = Vector2(textures[0].width, textures[0].height) 86 | self.pos = Vector2(pos.x - self.size.x / 2, pos.y - self.size.y / 2) 87 | self.index = 0 88 | self.discard = False 89 | 90 | def update(self, dt): 91 | if self.index < len(self.textures) - 1: 92 | self.index += 20 * dt 93 | else: 94 | self.discard = True 95 | 96 | 97 | def draw(self): 98 | draw_texture_v(self.textures[int(self.index)], self.pos, WHITE) -------------------------------------------------------------------------------- /Complete/game_2D/font/Stormfaze.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/font/Stormfaze.otf -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/1.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/10.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/11.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/12.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/13.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/14.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/15.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/16.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/17.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/18.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/19.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/2.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/20.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/21.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/22.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/23.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/24.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/25.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/26.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/27.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/28.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/3.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/4.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/5.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/6.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/7.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/8.png -------------------------------------------------------------------------------- /Complete/game_2D/images/explosion/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/explosion/9.png -------------------------------------------------------------------------------- /Complete/game_2D/images/laser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/laser.png -------------------------------------------------------------------------------- /Complete/game_2D/images/meteor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/meteor.png -------------------------------------------------------------------------------- /Complete/game_2D/images/spaceship.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/spaceship.png -------------------------------------------------------------------------------- /Complete/game_2D/images/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_2D/images/star.png -------------------------------------------------------------------------------- /Complete/game_3D/audio/explosion.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_3D/audio/explosion.wav -------------------------------------------------------------------------------- /Complete/game_3D/audio/laser.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_3D/audio/laser.wav -------------------------------------------------------------------------------- /Complete/game_3D/audio/music.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_3D/audio/music.wav -------------------------------------------------------------------------------- /Complete/game_3D/code/__pycache__/custom_timer.cpython-313.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_3D/code/__pycache__/custom_timer.cpython-313.pyc -------------------------------------------------------------------------------- /Complete/game_3D/code/__pycache__/models.cpython-313.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_3D/code/__pycache__/models.cpython-313.pyc -------------------------------------------------------------------------------- /Complete/game_3D/code/__pycache__/settings.cpython-313.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_3D/code/__pycache__/settings.cpython-313.pyc -------------------------------------------------------------------------------- /Complete/game_3D/code/custom_timer.py: -------------------------------------------------------------------------------- 1 | from settings import * 2 | 3 | class Timer: 4 | def __init__(self, duration: int, repeat = False, autostart = False, func = None): 5 | self.duration = duration 6 | self.start_time = 0 7 | self.active = False 8 | self.repeat = repeat 9 | self.func = func 10 | 11 | if autostart: 12 | self.activate() 13 | 14 | def __bool__(self): 15 | return self.active 16 | 17 | def activate(self): 18 | self.active = True 19 | self.start_time = get_time() 20 | 21 | def deactivate(self): 22 | self.active = False 23 | self.start_time = 0 24 | if self.repeat: 25 | self.activate() 26 | 27 | def update(self): 28 | if self.active: 29 | if get_time() - self.start_time >= self.duration: 30 | if self.func and self.start_time: self.func() 31 | self.deactivate() -------------------------------------------------------------------------------- /Complete/game_3D/code/main.py: -------------------------------------------------------------------------------- 1 | from settings import * 2 | from models import Floor, Player, Laser, Meteor 3 | 4 | class Game: 5 | def __init__(self): 6 | init_window(WINDOW_WIDTH, WINDOW_HEIGHT, "Space shooter") 7 | init_audio_device() 8 | self.import_assets() 9 | 10 | # camera 11 | self.camera = Camera3D() 12 | self.camera.position = Vector3(-4.0, 8.0, 6.0) 13 | self.camera.target = Vector3(0.0, 0.0, -1.0) 14 | self.camera.up = Vector3(0.0, 1.0, 0.0) 15 | self.camera.fovy = 45.0 16 | self.camera.projection = CAMERA_PERSPECTIVE 17 | 18 | # setup 19 | self.floor = Floor(self.dark_texture) 20 | self.player = Player(self.models['player'], self.shoot_laser) 21 | self.lasers, self.meteors = [], [] 22 | self.meteor_timer = Timer(METEOR_TIMER_DURATION, True, True, self.create_meteor) 23 | play_music_stream(self.audio['music']) 24 | 25 | def create_meteor(self): 26 | self.meteors.append(Meteor(choice(self.textures))) 27 | 28 | def shoot_laser(self, pos): 29 | self.lasers.append(Laser(self.models['laser'], pos, self.light_texture)) 30 | play_sound(self.audio['laser']) 31 | 32 | def import_assets(self): 33 | self.models = { 34 | 'player': load_model(join('models','ship.glb')), 35 | 'laser': load_model(join('models','laser.glb')), 36 | } 37 | 38 | self.audio = { 39 | 'laser': load_sound(join('audio','laser.wav')), 40 | 'explosion': load_sound(join('audio','explosion.wav')), 41 | 'music': load_music_stream(join('audio','music.wav')), 42 | } 43 | 44 | self.textures = [load_texture(join('textures', f'{color}.png')) for color in ('red', 'green', 'orange', 'purple')] 45 | self.dark_texture = load_texture(join('textures', 'dark.png')) 46 | self.light_texture = load_texture(join('textures', 'light.png')) 47 | 48 | self.font = load_font_ex('Stormfaze.otf', FONT_SIZE, ffi.NULL,0) 49 | 50 | def check_discard(self): 51 | self.lasers = [laser for laser in self.lasers if not laser.discard] 52 | self.meteors = [meteor for meteor in self.meteors if not meteor.discard] 53 | 54 | def check_collisions(self): 55 | # player -> meteor 56 | for meteor in self.meteors: 57 | if check_collision_spheres(self.player.pos, 0.8, meteor.pos, meteor.radius): 58 | close_window() 59 | 60 | # laser -> meteor 61 | for laser in self.lasers: 62 | for meteor in self.meteors: 63 | laser_bbox = get_mesh_bounding_box(laser.model.meshes[0]) 64 | col_bbox = BoundingBox( 65 | Vector3Add(laser_bbox.min, laser.pos), # min 66 | Vector3Add(laser_bbox.max, laser.pos), # max 67 | ) 68 | if check_collision_box_sphere(col_bbox, meteor.pos, meteor.radius): 69 | meteor.hit = True 70 | laser.discard = True 71 | meteor.death_timer.activate() 72 | meteor.flash() 73 | play_sound(self.audio['explosion']) 74 | 75 | def update(self): 76 | dt = get_frame_time() 77 | self.check_collisions() 78 | self.check_discard() 79 | self.meteor_timer.update() 80 | self.player.update(dt) 81 | for model in self.lasers + self.meteors: 82 | model.update(dt) 83 | update_music_stream(self.audio['music']) 84 | 85 | def draw_shadows(self): 86 | player_radius = 0.5 + self.player.pos.y 87 | draw_cylinder(Vector3(self.player.pos.x, -1.5, self.player.pos.z), player_radius,player_radius,0.1,20,(0,0,0,50)) 88 | 89 | for meteor in self.meteors: 90 | draw_cylinder(Vector3(meteor.pos.x, -1.5, meteor.pos.z), meteor.radius * 0.8, meteor.radius * 0.8, 0.1,20, (0,0,0,50)) 91 | 92 | def draw_score(self): 93 | score = str(int(get_time())) 94 | draw_text_ex(self.font, score, Vector2(WINDOW_WIDTH - FONT_PADDING, WINDOW_HEIGHT - FONT_PADDING), FONT_SIZE,2, WHITE) 95 | 96 | def draw(self): 97 | clear_background(BG_COLOR) 98 | begin_drawing() 99 | begin_mode_3d(self.camera) 100 | self.floor.draw() 101 | self.draw_shadows() 102 | self.player.draw() 103 | for model in self.lasers + self.meteors: 104 | model.draw() 105 | end_mode_3d() 106 | self.draw_score() 107 | end_drawing() 108 | 109 | def run(self): 110 | while not window_should_close(): 111 | self.update() 112 | self.draw() 113 | unload_music_stream(self.audio['music']) 114 | close_audio_device() 115 | close_window() 116 | 117 | if __name__ == '__main__': 118 | game = Game() 119 | game.run() -------------------------------------------------------------------------------- /Complete/game_3D/code/models.py: -------------------------------------------------------------------------------- 1 | from settings import * 2 | from math import sin 3 | 4 | class Model: 5 | def __init__(self, model, pos, speed, direction = Vector3()): 6 | self.model = model 7 | self.pos = pos 8 | self.speed = speed 9 | self.direction = direction 10 | self.discard = False 11 | 12 | def move(self, dt): 13 | self.pos.x += self.direction.x * self.speed * dt 14 | self.pos.y += self.direction.y * self.speed * dt 15 | self.pos.z += self.direction.z * self.speed * dt 16 | 17 | def update(self, dt): 18 | self.move(dt) 19 | 20 | def draw(self): 21 | draw_model(self.model, self.pos, 1, WHITE) 22 | 23 | class Floor(Model): 24 | def __init__(self, texture): 25 | model = load_model_from_mesh(gen_mesh_cube(32,1,32)) 26 | set_material_texture(model.materials[0], MATERIAL_MAP_ALBEDO, texture) 27 | super().__init__(model, Vector3(6.5,-2,-8), 0) 28 | 29 | class Player(Model): 30 | def __init__(self, model, shoot_laser): 31 | super().__init__(model, Vector3(), PLAYER_SPEED) 32 | self.shoot_laser = shoot_laser 33 | self.angle = 0 34 | 35 | def input(self): 36 | self.direction.x = int(is_key_down(KEY_RIGHT)) - int(is_key_down(KEY_LEFT)) 37 | if is_key_pressed(KEY_SPACE): 38 | self.shoot_laser(Vector3Add(self.pos, Vector3(0,0,-1))) 39 | 40 | def update(self, dt): 41 | self.input() 42 | super().update(dt) 43 | self.angle -= self.direction.x * 10 * dt 44 | self.pos.y += sin(get_time() * 5) * dt * 0.1 45 | 46 | # constraints 47 | self.pos.x = max(-6, min(self.pos.x,7)) 48 | self.angle = max(-15, min(self.angle, 15)) 49 | 50 | def draw(self): 51 | draw_model_ex(self.model, self.pos, Vector3(0,0,1), self.angle, Vector3(1,1,1),WHITE) 52 | 53 | class Laser(Model): 54 | def __init__(self, model, pos, texture): 55 | super().__init__(model, pos, LASER_SPEED,Vector3(0,0,-1)) 56 | set_material_texture(self.model.materials[0], MATERIAL_MAP_ALBEDO, texture) 57 | 58 | class Meteor(Model): 59 | def __init__(self, texture): 60 | # setup 61 | pos = Vector3(uniform(-6,7),0,-20) 62 | self.radius = uniform(0.6, 1.5) 63 | model = load_model_from_mesh(gen_mesh_sphere(self.radius, 8,8)) 64 | set_material_texture(model.materials[0], MATERIAL_MAP_ALBEDO, texture) 65 | super().__init__(model, pos, uniform(*METEOR_SPEED_RANGE), Vector3(0,0,uniform(0.75,1.25))) 66 | 67 | # rotation 68 | self.rotation = Vector3(uniform(-5,5),uniform(-5,5),uniform(-5,5)) 69 | self.rotation_speed = Vector3(uniform(-1,1),uniform(-1,1),uniform(-1,1)) 70 | 71 | # discard logic 72 | self.hit = False 73 | self.death_timer = Timer(0.25, False, False, self.activate_discard) 74 | 75 | # shader 76 | self.shader = load_shader(ffi.NULL, join('shaders', 'flash.fs')) 77 | model.materials[0].shader = self.shader 78 | self.flash_loc = get_shader_location(self.shader, 'flash') 79 | self.flash_amount = ffi.new('struct Vector2 *', [1,0]) 80 | 81 | def flash(self): 82 | set_shader_value(self.shader, self.flash_loc, self.flash_amount, SHADER_UNIFORM_VEC2) 83 | 84 | def activate_discard(self): 85 | self.discard = True 86 | 87 | def update(self, dt): 88 | self.death_timer.update() 89 | if not self.hit: 90 | super().update(dt) 91 | self.rotation.x += self.rotation_speed.x * dt 92 | self.rotation.y += self.rotation_speed.y * dt 93 | self.rotation.z += self.rotation_speed.z * dt 94 | self.model.transform = matrix_rotate_xyz(self.rotation) -------------------------------------------------------------------------------- /Complete/game_3D/code/settings.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from random import randint, uniform, choice 4 | from os.path import join 5 | from custom_timer import Timer 6 | 7 | WINDOW_WIDTH, WINDOW_HEIGHT = 1920, 1080 8 | BG_COLOR = BLACK 9 | PLAYER_SPEED = 7 10 | LASER_SPEED = 9 11 | METEOR_SPEED_RANGE = [3,4] 12 | METEOR_TIMER_DURATION = 0.4 13 | FONT_SIZE = 60 14 | FONT_PADDING = 60 -------------------------------------------------------------------------------- /Complete/game_3D/font/Stormfaze.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_3D/font/Stormfaze.otf -------------------------------------------------------------------------------- /Complete/game_3D/models/laser.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_3D/models/laser.glb -------------------------------------------------------------------------------- /Complete/game_3D/models/ship.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_3D/models/ship.glb -------------------------------------------------------------------------------- /Complete/game_3D/shaders/flash.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 fragTexCoord; 4 | in vec4 fragColor; 5 | 6 | uniform sampler2D texture0; 7 | uniform vec2 flash = vec2(0.0,0.0); 8 | 9 | out vec4 finalColor; 10 | 11 | void main() { 12 | vec4 texelColor = texture(texture0, fragTexCoord); 13 | finalColor = mix(texelColor, vec4(1.0, 1.0, 1.0, texelColor.a), flash.x); 14 | } -------------------------------------------------------------------------------- /Complete/game_3D/textures/dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_3D/textures/dark.png -------------------------------------------------------------------------------- /Complete/game_3D/textures/green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_3D/textures/green.png -------------------------------------------------------------------------------- /Complete/game_3D/textures/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_3D/textures/light.png -------------------------------------------------------------------------------- /Complete/game_3D/textures/orange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_3D/textures/orange.png -------------------------------------------------------------------------------- /Complete/game_3D/textures/purple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_3D/textures/purple.png -------------------------------------------------------------------------------- /Complete/game_3D/textures/red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/Complete/game_3D/textures/red.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Project made by Clear Code/ Christian Koch with the artwork being from Kenney. 2 | 3 | The code for this project is CC0, you can use it for any purpose, private and commercial, without accreditations. 4 | More information here: https://creativecommons.org/publicdomain/zero/1.0/deed.en 5 | 6 | For more info on the artwork check: kenney.nl 7 | -------------------------------------------------------------------------------- /start/basics/assets/Zero Hour.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics/assets/Zero Hour.otf -------------------------------------------------------------------------------- /start/basics/assets/animation/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics/assets/animation/0.png -------------------------------------------------------------------------------- /start/basics/assets/animation/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics/assets/animation/1.png -------------------------------------------------------------------------------- /start/basics/assets/animation/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics/assets/animation/2.png -------------------------------------------------------------------------------- /start/basics/assets/animation/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics/assets/animation/3.png -------------------------------------------------------------------------------- /start/basics/assets/animation/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics/assets/animation/4.png -------------------------------------------------------------------------------- /start/basics/assets/animation/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics/assets/animation/5.png -------------------------------------------------------------------------------- /start/basics/assets/animation/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics/assets/animation/6.png -------------------------------------------------------------------------------- /start/basics/assets/animation/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics/assets/animation/7.png -------------------------------------------------------------------------------- /start/basics/assets/laser.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics/assets/laser.wav -------------------------------------------------------------------------------- /start/basics/assets/music.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics/assets/music.wav -------------------------------------------------------------------------------- /start/basics/assets/spaceship.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics/assets/spaceship.png -------------------------------------------------------------------------------- /start/basics/code/10_animations.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from os.path import join 4 | 5 | init_window(1920,1080, 'Animations') 6 | 7 | while not window_should_close(): 8 | dt = get_frame_time() 9 | begin_drawing() 10 | clear_background(BLACK) 11 | end_drawing() 12 | 13 | close_window() -------------------------------------------------------------------------------- /start/basics/code/1_base.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics/code/1_base.py -------------------------------------------------------------------------------- /start/basics/code/2_move.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from os.path import join 4 | 5 | init_window(1920, 1080, "Move") 6 | 7 | ship = load_texture(join('assets', 'spaceship.png')) 8 | pos_x = 0 9 | pos_y = 0 10 | 11 | while not window_should_close(): 12 | begin_drawing() 13 | clear_background(BLACK) 14 | draw_texture(ship, pos_x, pos_y, WHITE) 15 | end_drawing() 16 | close_window() -------------------------------------------------------------------------------- /start/basics/code/3_input.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from os.path import join 4 | 5 | init_window(1920, 1080, "Input") 6 | ship_texture = load_texture(join('assets', 'spaceship.png')) 7 | ship_pos = Vector2(0,0) 8 | ship_direction = Vector2(0,0) 9 | ship_speed = 800 10 | 11 | while not window_should_close(): 12 | begin_drawing() 13 | clear_background(BLACK) 14 | draw_texture_v(ship_texture, ship_pos, WHITE) 15 | end_drawing() 16 | close_window() -------------------------------------------------------------------------------- /start/basics/code/4_collisions.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | 4 | init_window(1920, 1080, "Collisions") 5 | player_pos = Vector2(0,0) 6 | obstacle_pos = Vector2(500,400) 7 | player_radius = 50 8 | obstacle_radius = 30 9 | 10 | while not window_should_close(): 11 | 12 | # input 13 | player_pos = get_mouse_position() 14 | 15 | # drawing 16 | begin_drawing() 17 | clear_background(BLACK) 18 | draw_circle_v(player_pos, player_radius, WHITE) 19 | draw_circle_v(obstacle_pos, obstacle_radius, RED) 20 | end_drawing() 21 | 22 | close_window() -------------------------------------------------------------------------------- /start/basics/code/5_camera.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from random import randint, choice 4 | 5 | init_window(1920, 1080, "Camera") 6 | 7 | # player 8 | pos = Vector2() 9 | radius = 50 10 | direction = Vector2() 11 | speed = 400 12 | 13 | # circles 14 | circles = [ 15 | ( 16 | Vector2(randint(-2000,2000),randint(-1000,1000)), # pos 17 | randint(50,200), # radius 18 | choice([RED, GREEN, BLUE, YELLOW, ORANGE]) # color 19 | ) 20 | for i in range(100) 21 | ] 22 | 23 | while not window_should_close(): 24 | 25 | # input 26 | direction.x = int(is_key_down(KEY_RIGHT)) - int(is_key_down(KEY_LEFT)) 27 | direction.y = int(is_key_down(KEY_DOWN)) - int(is_key_down(KEY_UP)) 28 | direction = vector2_normalize(direction) 29 | 30 | # movement 31 | dt = get_frame_time() 32 | pos.x += direction.x * speed * dt 33 | pos.y += direction.y * speed * dt 34 | 35 | # drawing 36 | begin_drawing() 37 | clear_background(WHITE) 38 | for circle in circles: 39 | draw_circle_v(*circle) 40 | draw_circle_v(pos, radius, BLACK) 41 | end_drawing() 42 | 43 | close_window() -------------------------------------------------------------------------------- /start/basics/code/6_audio.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from os.path import join 4 | 5 | init_window(1920,1080, 'Sound') 6 | 7 | while not window_should_close(): 8 | begin_drawing() 9 | clear_background(BLACK) 10 | end_drawing() 11 | 12 | close_window() -------------------------------------------------------------------------------- /start/basics/code/7_classes.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from os.path import join 4 | 5 | init_window(1920,1080, 'OOP') 6 | 7 | while not window_should_close(): 8 | begin_drawing() 9 | clear_background(BLACK) 10 | end_drawing() 11 | 12 | close_window() -------------------------------------------------------------------------------- /start/basics/code/8_collision_resolution.py: -------------------------------------------------------------------------------- 1 | from raylib import * 2 | from pyray import * 3 | 4 | init_window(1920, 1080, "Collision resolution") 5 | 6 | level_map = [ 7 | '1111111111111111111', 8 | '1010000000000000001', 9 | '1010000000001111111', 10 | '1000000000000000111', 11 | '1000000200000000011', 12 | '1000000000000100001', 13 | '1000000000000100001', 14 | '1001100000000100001', 15 | '1001100000000100001', 16 | '1001100000000100001', 17 | '1111111111111111111' 18 | ] 19 | 20 | player = Rectangle(400,300,60,60) 21 | speed = 300 22 | direction = Vector2() 23 | 24 | blocks = [] 25 | block_size = 100 26 | for row_index, row in enumerate(level_map): 27 | for col_index, cell in enumerate(row): 28 | if cell == '1': 29 | x = col_index * block_size 30 | y = row_index * block_size 31 | block = Rectangle(x,y,block_size,block_size) 32 | blocks.append(block) 33 | 34 | 35 | while not window_should_close(): 36 | direction.x = int(is_key_down(KEY_RIGHT)) - int(is_key_down(KEY_LEFT)) 37 | direction.y = int(is_key_down(KEY_DOWN)) - int(is_key_down(KEY_UP)) 38 | 39 | # movement 40 | dt = get_frame_time() 41 | player.x += direction.x * speed * dt 42 | player.y += direction.y * speed * dt 43 | 44 | begin_drawing() 45 | clear_background(BLACK) 46 | for block in blocks: 47 | draw_rectangle_rec(block, GRAY) 48 | draw_rectangle_rec(player, RED) 49 | end_drawing() 50 | close_window() -------------------------------------------------------------------------------- /start/basics/code/9_timer.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from random import choice 4 | 5 | class Timer: 6 | def __init__(self, duration: int, repeat = False, autostart = False, func = None): 7 | self.duration = duration 8 | self.start_time = 0 9 | self.active = False 10 | self.repeat = repeat 11 | self.func = func 12 | 13 | if autostart: 14 | self.activate() 15 | 16 | def activate(self): 17 | self.active = True 18 | self.start_time = get_time() 19 | 20 | def deactivate(self): 21 | self.active = False 22 | self.start_time = 0 23 | if self.repeat: 24 | self.activate() 25 | 26 | def update(self): 27 | if self.active: 28 | if get_time() - self.start_time >= self.duration: 29 | if self.func and self.start_time: self.func() 30 | self.deactivate() 31 | 32 | class Sprite: 33 | def __init__(self, pos, size): 34 | self.rec = Rectangle(pos[0], pos[1], size[0], size[1]) 35 | self.color = WHITE 36 | 37 | def randomize_color(self): 38 | self.color = choice([RED, YELLOW, GREEN, ORANGE, MAGENTA, BLUE, GRAY, MAROON]) 39 | 40 | def draw(self): 41 | draw_rectangle_rec(self.rec, self.color) 42 | 43 | init_window(1920,1080, 'Timer') 44 | 45 | while not window_should_close(): 46 | begin_drawing() 47 | clear_background(BLACK) 48 | end_drawing() 49 | 50 | close_window() -------------------------------------------------------------------------------- /start/basics_3D/1_base.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | 4 | init_window(1920, 1080, "3D base") 5 | 6 | while not window_should_close(): 7 | dt = get_frame_time() 8 | clear_background(WHITE) 9 | begin_drawing() 10 | end_drawing() 11 | close_window() -------------------------------------------------------------------------------- /start/basics_3D/2_imports.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | 4 | init_window(1920, 1080, "3D imports") 5 | camera = Camera3D() 6 | camera.position = Vector3(0.0, 3.0, 5.0) 7 | camera.target = Vector3(0.0, 0.0, 0.0) 8 | camera.up = Vector3(0.0, 1.0, 0.0) 9 | camera.fovy = 45.0 10 | camera.projection = CAMERA_PERSPECTIVE 11 | 12 | while not window_should_close(): 13 | begin_drawing() 14 | clear_background(WHITE) 15 | begin_mode_3d(camera) 16 | draw_grid(10,1.0) 17 | end_mode_3d() 18 | end_drawing() 19 | 20 | close_window() -------------------------------------------------------------------------------- /start/basics_3D/3_collision.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | 4 | init_window(1920, 1080, "3D collisions") 5 | camera = Camera3D() 6 | camera.position = Vector3(0.0, 5.0, 5.0) 7 | camera.target = Vector3(0.0, 0.0, 0.0) 8 | camera.up = Vector3(0.0, 1.0, 0.0) 9 | camera.fovy = 45.0 10 | camera.projection = CAMERA_PERSPECTIVE 11 | 12 | player = load_model_from_mesh(gen_mesh_cube(1,1,1)) 13 | pos = Vector3() 14 | direction = Vector3() 15 | speed = 5 16 | 17 | obstacle = load_model_from_mesh(gen_mesh_cube(2,1,4)) 18 | obstacle_pos = Vector3(3,0,0) 19 | 20 | while not window_should_close(): 21 | # input 22 | direction.x = int(is_key_down(KEY_RIGHT)) - int(is_key_down(KEY_LEFT)) 23 | direction.z = int(is_key_down(KEY_DOWN)) - int(is_key_down(KEY_UP)) 24 | 25 | # movement & collision 26 | dt = get_frame_time() 27 | pos.x += direction.x * speed * dt 28 | pos.z += direction.z * speed * dt 29 | 30 | # drawing 31 | begin_drawing() 32 | clear_background(WHITE) 33 | begin_mode_3d(camera) 34 | draw_grid(10,1) 35 | draw_model(player, pos,1.0,RED) 36 | draw_model(obstacle, obstacle_pos,1.0,GRAY) 37 | end_mode_3d() 38 | end_drawing() 39 | close_window() -------------------------------------------------------------------------------- /start/basics_3D/4_shader.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from os.path import join 4 | 5 | init_window(1920, 1080, "Shader") 6 | camera = Camera3D() 7 | camera.position = Vector3(0.0, 5.0, 5.0) 8 | camera.target = Vector3(0.0, 0.0, 0.0) 9 | camera.up = Vector3(0.0, 1.0, 0.0) 10 | camera.fovy = 45.0 11 | camera.projection = CAMERA_PERSPECTIVE 12 | 13 | #create model 14 | model = load_model_from_mesh(gen_mesh_cylinder(1,2,5)) 15 | texture = load_texture_from_image(gen_image_gradient_linear(100,100,1,RED,YELLOW)) 16 | set_material_texture(model.materials[0], MATERIAL_MAP_ALBEDO, texture) 17 | 18 | 19 | while not window_should_close(): 20 | if is_key_pressed(KEY_A): 21 | pass 22 | 23 | begin_drawing() 24 | begin_mode_3d(camera) 25 | clear_background(BLACK) 26 | draw_model(model, Vector3(0.0, 0.0, 0.0),1.0,WHITE) 27 | end_mode_3d() 28 | end_drawing() 29 | close_window() -------------------------------------------------------------------------------- /start/basics_3D/models/nagon_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics_3D/models/nagon_texture.png -------------------------------------------------------------------------------- /start/basics_3D/models/rupee.gltf: -------------------------------------------------------------------------------- 1 | { 2 | "asset" : { 3 | "generator" : "Khronos glTF Blender I/O v3.4.50", 4 | "version" : "2.0" 5 | }, 6 | "scene" : 0, 7 | "scenes" : [ 8 | { 9 | "name" : "Scene", 10 | "nodes" : [ 11 | 0 12 | ] 13 | } 14 | ], 15 | "nodes" : [ 16 | { 17 | "mesh" : 0, 18 | "name" : "rupee_red" 19 | } 20 | ], 21 | "materials" : [ 22 | { 23 | "name" : "nagonford", 24 | "pbrMetallicRoughness" : { 25 | "baseColorTexture" : { 26 | "index" : 0 27 | }, 28 | "metallicFactor" : 0, 29 | "roughnessFactor" : 0.5 30 | } 31 | } 32 | ], 33 | "meshes" : [ 34 | { 35 | "name" : "rupee_red", 36 | "primitives" : [ 37 | { 38 | "attributes" : { 39 | "POSITION" : 0, 40 | "TEXCOORD_0" : 1, 41 | "NORMAL" : 2 42 | }, 43 | "indices" : 3, 44 | "material" : 0 45 | } 46 | ] 47 | } 48 | ], 49 | "textures" : [ 50 | { 51 | "sampler" : 0, 52 | "source" : 0 53 | } 54 | ], 55 | "images" : [ 56 | { 57 | "mimeType" : "image/png", 58 | "name" : "nagon_texture", 59 | "uri" : "nagon_texture.png" 60 | } 61 | ], 62 | "accessors" : [ 63 | { 64 | "bufferView" : 0, 65 | "componentType" : 5126, 66 | "count" : 377, 67 | "max" : [ 68 | 0.5944601893424988, 69 | 0.9373665452003479, 70 | 0.24908025562763214 71 | ], 72 | "min" : [ 73 | -0.5944598913192749, 74 | -0.9373663663864136, 75 | -0.24907921254634857 76 | ], 77 | "type" : "VEC3" 78 | }, 79 | { 80 | "bufferView" : 1, 81 | "componentType" : 5126, 82 | "count" : 377, 83 | "type" : "VEC2" 84 | }, 85 | { 86 | "bufferView" : 2, 87 | "componentType" : 5126, 88 | "count" : 377, 89 | "type" : "VEC3" 90 | }, 91 | { 92 | "bufferView" : 3, 93 | "componentType" : 5123, 94 | "count" : 708, 95 | "type" : "SCALAR" 96 | } 97 | ], 98 | "bufferViews" : [ 99 | { 100 | "buffer" : 0, 101 | "byteLength" : 4524, 102 | "byteOffset" : 0, 103 | "target" : 34962 104 | }, 105 | { 106 | "buffer" : 0, 107 | "byteLength" : 3016, 108 | "byteOffset" : 4524, 109 | "target" : 34962 110 | }, 111 | { 112 | "buffer" : 0, 113 | "byteLength" : 4524, 114 | "byteOffset" : 7540, 115 | "target" : 34962 116 | }, 117 | { 118 | "buffer" : 0, 119 | "byteLength" : 1416, 120 | "byteOffset" : 12064, 121 | "target" : 34963 122 | } 123 | ], 124 | "samplers" : [ 125 | { 126 | "magFilter" : 9729, 127 | "minFilter" : 9987 128 | } 129 | ], 130 | "buffers" : [ 131 | { 132 | "byteLength" : 13480, 133 | "uri" : "rupee_red.bin" 134 | } 135 | ] 136 | } 137 | -------------------------------------------------------------------------------- /start/basics_3D/models/rupee_red.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics_3D/models/rupee_red.bin -------------------------------------------------------------------------------- /start/basics_3D/models/ship.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics_3D/models/ship.glb -------------------------------------------------------------------------------- /start/basics_3D/models/ship_fail.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/basics_3D/models/ship_fail.glb -------------------------------------------------------------------------------- /start/basics_3D/shaders/flash.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 fragTexCoord; 4 | in vec4 fragColor; 5 | 6 | uniform sampler2D texture0; 7 | uniform vec2 flash; 8 | 9 | out vec4 finalColor; 10 | 11 | void main() { 12 | vec4 texelColor = texture(texture0, fragTexCoord); 13 | finalColor = mix(texelColor, vec4(1.0, 1.0, 1.0, texelColor.a), flash.x); 14 | } -------------------------------------------------------------------------------- /start/basics_3D/shaders/grayscale.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // Input vertex attributes (from vertex shader) 4 | in vec2 fragTexCoord; 5 | in vec4 fragColor; 6 | 7 | // Input uniform values 8 | uniform sampler2D texture0; 9 | uniform vec4 colDiffuse; 10 | 11 | // Output fragment color 12 | out vec4 finalColor; 13 | 14 | // NOTE: Add here your custom variables 15 | 16 | void main() 17 | { 18 | // Texel color fetching from texture sampler 19 | vec4 texelColor = texture(texture0, fragTexCoord)*colDiffuse*fragColor; 20 | 21 | // Convert texel color to grayscale using NTSC conversion weights 22 | float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); 23 | 24 | // Calculate final fragment color 25 | finalColor = vec4(gray, gray, gray, texelColor.a); 26 | } -------------------------------------------------------------------------------- /start/game_2D/audio/explosion.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/audio/explosion.wav -------------------------------------------------------------------------------- /start/game_2D/audio/laser.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/audio/laser.wav -------------------------------------------------------------------------------- /start/game_2D/audio/music.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/audio/music.wav -------------------------------------------------------------------------------- /start/game_2D/code/__pycache__/custom_timer.cpython-313.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/code/__pycache__/custom_timer.cpython-313.pyc -------------------------------------------------------------------------------- /start/game_2D/code/__pycache__/settings.cpython-313.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/code/__pycache__/settings.cpython-313.pyc -------------------------------------------------------------------------------- /start/game_2D/code/__pycache__/sprites.cpython-313.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/code/__pycache__/sprites.cpython-313.pyc -------------------------------------------------------------------------------- /start/game_2D/code/custom_timer.py: -------------------------------------------------------------------------------- 1 | from settings import get_time 2 | 3 | class Timer: 4 | def __init__(self, duration: int, repeat = False, autostart = False, func = None): 5 | self.duration = duration 6 | self.start_time = 0 7 | self.active = False 8 | self.repeat = repeat 9 | self.func = func 10 | 11 | if autostart: 12 | self.activate() 13 | 14 | def activate(self): 15 | self.active = True 16 | self.start_time = get_time() 17 | 18 | def deactivate(self): 19 | self.active = False 20 | self.start_time = 0 21 | if self.repeat: 22 | self.activate() 23 | 24 | def update(self): 25 | if self.active: 26 | if get_time() - self.start_time >= self.duration: 27 | if self.func and self.start_time: self.func() 28 | self.deactivate() -------------------------------------------------------------------------------- /start/game_2D/code/main.py: -------------------------------------------------------------------------------- 1 | from settings import * 2 | from custom_timer import Timer 3 | -------------------------------------------------------------------------------- /start/game_2D/code/settings.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from random import randint, uniform 4 | from os.path import join 5 | 6 | WINDOW_WIDTH, WINDOW_HEIGHT = 1920, 1080 7 | BG_COLOR = (15,10,25,255) 8 | PLAYER_SPEED = 500 9 | LASER_SPEED = 600 10 | METEOR_SPEED_RANGE = [300,400] 11 | METEOR_TIMER_DURATION = 0.4 12 | FONT_SIZE = 120 -------------------------------------------------------------------------------- /start/game_2D/font/Stormfaze.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/font/Stormfaze.otf -------------------------------------------------------------------------------- /start/game_2D/images/explosion/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/1.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/10.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/11.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/12.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/13.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/14.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/15.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/16.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/17.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/18.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/19.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/2.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/20.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/21.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/22.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/23.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/24.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/25.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/26.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/27.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/28.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/3.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/4.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/5.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/6.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/7.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/8.png -------------------------------------------------------------------------------- /start/game_2D/images/explosion/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/explosion/9.png -------------------------------------------------------------------------------- /start/game_2D/images/laser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/laser.png -------------------------------------------------------------------------------- /start/game_2D/images/meteor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/meteor.png -------------------------------------------------------------------------------- /start/game_2D/images/spaceship.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/spaceship.png -------------------------------------------------------------------------------- /start/game_2D/images/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_2D/images/star.png -------------------------------------------------------------------------------- /start/game_3D/audio/explosion.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_3D/audio/explosion.wav -------------------------------------------------------------------------------- /start/game_3D/audio/laser.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_3D/audio/laser.wav -------------------------------------------------------------------------------- /start/game_3D/audio/music.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_3D/audio/music.wav -------------------------------------------------------------------------------- /start/game_3D/code/__pycache__/custom_timer.cpython-313.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_3D/code/__pycache__/custom_timer.cpython-313.pyc -------------------------------------------------------------------------------- /start/game_3D/code/__pycache__/models.cpython-313.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_3D/code/__pycache__/models.cpython-313.pyc -------------------------------------------------------------------------------- /start/game_3D/code/__pycache__/settings.cpython-313.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_3D/code/__pycache__/settings.cpython-313.pyc -------------------------------------------------------------------------------- /start/game_3D/code/custom_timer.py: -------------------------------------------------------------------------------- 1 | from settings import * 2 | 3 | class Timer: 4 | def __init__(self, duration: int, repeat = False, autostart = False, func = None): 5 | self.duration = duration 6 | self.start_time = 0 7 | self.active = False 8 | self.repeat = repeat 9 | self.func = func 10 | 11 | if autostart: 12 | self.activate() 13 | 14 | def __bool__(self): 15 | return self.active 16 | 17 | def activate(self): 18 | self.active = True 19 | self.start_time = get_time() 20 | 21 | def deactivate(self): 22 | self.active = False 23 | self.start_time = 0 24 | if self.repeat: 25 | self.activate() 26 | 27 | def update(self): 28 | if self.active: 29 | if get_time() - self.start_time >= self.duration: 30 | if self.func and self.start_time: self.func() 31 | self.deactivate() -------------------------------------------------------------------------------- /start/game_3D/code/main.py: -------------------------------------------------------------------------------- 1 | from settings import * 2 | 3 | class Game: 4 | def __init__(self): 5 | init_window(WINDOW_WIDTH, WINDOW_HEIGHT, "Space shooter") 6 | init_audio_device() 7 | self.import_assets() 8 | 9 | # camera 10 | self.camera = Camera3D() 11 | self.camera.position = Vector3(-4.0, 8.0, 6.0) 12 | self.camera.target = Vector3(0.0, 0.0, -1.0) 13 | self.camera.up = Vector3(0.0, 1.0, 0.0) 14 | self.camera.fovy = 45.0 15 | self.camera.projection = CAMERA_PERSPECTIVE 16 | 17 | def import_assets(self): 18 | self.models = { 19 | 'player': load_model(join('models','ship.glb')), 20 | 'laser': load_model(join('models','laser.glb')), 21 | } 22 | 23 | self.audio = { 24 | 'laser': load_sound(join('audio','laser.wav')), 25 | 'explosion': load_sound(join('audio','explosion.wav')), 26 | 'music': load_music_stream(join('audio','music.wav')), 27 | } 28 | 29 | self.textures = [load_texture(join('textures', f'{color}.png')) for color in ('red', 'green', 'orange', 'purple')] 30 | self.dark_texture = load_texture(join('textures', 'dark.png')) 31 | self.light_texture = load_texture(join('textures', 'light.png')) 32 | 33 | self.font = load_font_ex('Stormfaze.otf', FONT_SIZE, ffi.NULL,0) 34 | 35 | def update(self): 36 | dt = get_frame_time() 37 | 38 | def draw(self): 39 | clear_background(BG_COLOR) 40 | begin_drawing() 41 | begin_mode_3d(self.camera) 42 | end_mode_3d() 43 | end_drawing() 44 | 45 | def run(self): 46 | while not window_should_close(): 47 | self.update() 48 | self.draw() 49 | close_audio_device() 50 | close_window() 51 | 52 | if __name__ == '__main__': 53 | game = Game() 54 | game.run() -------------------------------------------------------------------------------- /start/game_3D/code/settings.py: -------------------------------------------------------------------------------- 1 | from pyray import * 2 | from raylib import * 3 | from random import randint, uniform, choice 4 | from os.path import join 5 | from custom_timer import Timer 6 | 7 | WINDOW_WIDTH, WINDOW_HEIGHT = 1920, 1080 8 | BG_COLOR = BLACK 9 | PLAYER_SPEED = 7 10 | LASER_SPEED = 9 11 | METEOR_SPEED_RANGE = [3,4] 12 | METEOR_TIMER_DURATION = 0.4 13 | FONT_SIZE = 60 14 | FONT_PADDING = 60 -------------------------------------------------------------------------------- /start/game_3D/font/Stormfaze.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_3D/font/Stormfaze.otf -------------------------------------------------------------------------------- /start/game_3D/models/laser.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_3D/models/laser.glb -------------------------------------------------------------------------------- /start/game_3D/models/ship.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_3D/models/ship.glb -------------------------------------------------------------------------------- /start/game_3D/shaders/flash.fs: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 fragTexCoord; 4 | in vec4 fragColor; 5 | 6 | uniform sampler2D texture0; 7 | uniform vec2 flash = vec2(0.0,0.0); 8 | 9 | out vec4 finalColor; 10 | 11 | void main() { 12 | vec4 texelColor = texture(texture0, fragTexCoord); 13 | finalColor = mix(texelColor, vec4(1.0, 1.0, 1.0, texelColor.a), flash.x); 14 | } -------------------------------------------------------------------------------- /start/game_3D/textures/dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_3D/textures/dark.png -------------------------------------------------------------------------------- /start/game_3D/textures/green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_3D/textures/green.png -------------------------------------------------------------------------------- /start/game_3D/textures/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_3D/textures/light.png -------------------------------------------------------------------------------- /start/game_3D/textures/orange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_3D/textures/orange.png -------------------------------------------------------------------------------- /start/game_3D/textures/purple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_3D/textures/purple.png -------------------------------------------------------------------------------- /start/game_3D/textures/red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clear-code-projects/raylib_intro/6cabffb20155a768bce8ae59d8dbe2bac30e26d8/start/game_3D/textures/red.png --------------------------------------------------------------------------------