mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 17:18:35 -07:00
Jetpack joyride and NFC Maker apps
This commit is contained in:
81
applications/external/jetpack_joyride/includes/background_asset.c
vendored
Normal file
81
applications/external/jetpack_joyride/includes/background_asset.c
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
#include <jetpack_joyride_icons.h>
|
||||
|
||||
#include "background_assets.h"
|
||||
|
||||
static AssetProperties assetProperties[BG_ASSETS_MAX] = {
|
||||
{.width = 27, .spawn_chance = 1, .x_offset = 24, .y_offset = 36, .sprite = &I_door},
|
||||
{.width = 12, .spawn_chance = 6, .x_offset = 33, .y_offset = 14, .sprite = &I_air_vent}};
|
||||
|
||||
void background_assets_tick(BackgroundAsset* const assets) {
|
||||
// Move assets towards the player
|
||||
for(int i = 0; i < BG_ASSETS_MAX; i++) {
|
||||
if(assets[i].visible) {
|
||||
assets[i].point.x -= 1; // move left by 2 units
|
||||
if(assets[i].point.x <=
|
||||
-assets[i].properties->width) { // if the asset is out of screen
|
||||
assets[i].visible = false; // set asset x coordinate to 0 to mark it as "inactive"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void spawn_random_background_asset(BackgroundAsset* const assets) {
|
||||
// Calculate the total spawn chances for all assets
|
||||
int total_spawn_chance = 0;
|
||||
for(int i = 0; i < BG_ASSETS_MAX; ++i) {
|
||||
total_spawn_chance += assetProperties[i].spawn_chance;
|
||||
}
|
||||
|
||||
// Generate a random number between 0 and total_spawn_chance
|
||||
int random_number = rand() % total_spawn_chance;
|
||||
|
||||
// Select the asset based on the random number
|
||||
int chosen_asset = -1;
|
||||
int accumulated_chance = 0;
|
||||
for(int i = 0; i < BG_ASSETS_MAX; ++i) {
|
||||
accumulated_chance += assetProperties[i].spawn_chance;
|
||||
if(random_number < accumulated_chance) {
|
||||
chosen_asset = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If no asset is chosen, return
|
||||
if(chosen_asset == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Look for an available slot for the chosen asset
|
||||
for(int i = 0; i < BG_ASSETS_MAX; ++i) {
|
||||
if(assets[i].visible == false) {
|
||||
// Spawn the asset
|
||||
assets[i].point.x = 127 + assetProperties[chosen_asset].x_offset;
|
||||
assets[i].point.y = assetProperties[chosen_asset].y_offset;
|
||||
assets[i].properties = &assetProperties[chosen_asset];
|
||||
assets[i].visible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_background_assets(const BackgroundAsset* assets, Canvas* const canvas, int distance) {
|
||||
canvas_draw_box(canvas, 0, 6, 128, 1);
|
||||
canvas_draw_box(canvas, 0, 56, 128, 2);
|
||||
|
||||
// Calculate the pillar offset based on the traveled distance
|
||||
int pillar_offset = distance % 64;
|
||||
|
||||
// Draw pillars
|
||||
for(int x = -pillar_offset; x < 128; x += 64) {
|
||||
canvas_draw_icon(canvas, x, 6, &I_pillar);
|
||||
}
|
||||
|
||||
// Draw assets
|
||||
for(int i = 0; i < BG_ASSETS_MAX; ++i) {
|
||||
if(assets[i].visible) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_icon(
|
||||
canvas, assets[i].point.x, assets[i].point.y, assets[i].properties->sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
34
applications/external/jetpack_joyride/includes/background_assets.h
vendored
Normal file
34
applications/external/jetpack_joyride/includes/background_assets.h
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef BACKGROUND_ASSETS_H
|
||||
#define BACKGROUND_ASSETS_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <gui/gui.h>
|
||||
|
||||
#include "point.h"
|
||||
#include "states.h"
|
||||
#include "game_sprites.h"
|
||||
#include <jetpack_joyride_icons.h>
|
||||
|
||||
#define BG_ASSETS_MAX 3
|
||||
|
||||
typedef struct {
|
||||
int width;
|
||||
int spawn_chance;
|
||||
int x_offset;
|
||||
int y_offset;
|
||||
const Icon* sprite;
|
||||
} AssetProperties;
|
||||
|
||||
typedef struct {
|
||||
POINT point;
|
||||
AssetProperties* properties;
|
||||
bool visible;
|
||||
} BackgroundAsset;
|
||||
|
||||
void background_assets_tick(BackgroundAsset* const assets);
|
||||
void spawn_random_background_asset(BackgroundAsset* const assets);
|
||||
void draw_background_assets(const BackgroundAsset* assets, Canvas* const canvas, int distance);
|
||||
|
||||
#endif // BACKGROUND_ASSETS_H
|
||||
33
applications/external/jetpack_joyride/includes/barry.c
vendored
Normal file
33
applications/external/jetpack_joyride/includes/barry.c
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "barry.h"
|
||||
#include "game_sprites.h"
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include <furi.h>
|
||||
|
||||
void barry_tick(BARRY* const barry) {
|
||||
// Do jetpack things
|
||||
if(barry->isBoosting) {
|
||||
barry->gravity += GRAVITY_BOOST; // Increase upward momentum
|
||||
} else {
|
||||
barry->gravity += GRAVITY_FALL; // Increase downward momentum faster
|
||||
}
|
||||
|
||||
barry->point.y += barry->gravity;
|
||||
|
||||
// Constrain barry's height within sprite_height and 64 - sprite_height
|
||||
if(barry->point.y > (64 - BARRY_HEIGHT)) {
|
||||
barry->point.y = 64 - BARRY_HEIGHT;
|
||||
barry->gravity = 0; // stop upward momentum
|
||||
} else if(barry->point.y < 0) {
|
||||
barry->point.y = 0;
|
||||
barry->gravity = 0; // stop downward momentum
|
||||
}
|
||||
}
|
||||
|
||||
void draw_barry(const BARRY* barry, Canvas* const canvas, const GameSprites* sprites) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_icon_animation(canvas, barry->point.x, barry->point.y, sprites->barry);
|
||||
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_icon(canvas, barry->point.x, barry->point.y, sprites->barry_infill);
|
||||
}
|
||||
23
applications/external/jetpack_joyride/includes/barry.h
vendored
Normal file
23
applications/external/jetpack_joyride/includes/barry.h
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef BARRY_H
|
||||
#define BARRY_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include "point.h"
|
||||
#include "game_sprites.h"
|
||||
|
||||
#define GRAVITY_TICK 0.2
|
||||
#define GRAVITY_BOOST -0.4
|
||||
#define GRAVITY_FALL 0.3
|
||||
|
||||
typedef struct {
|
||||
float gravity;
|
||||
POINT point;
|
||||
bool isBoosting;
|
||||
} BARRY;
|
||||
|
||||
void barry_tick(BARRY* const barry);
|
||||
void draw_barry(const BARRY* barry, Canvas* const canvas, const GameSprites* sprites);
|
||||
|
||||
#endif // BARRY_H
|
||||
98
applications/external/jetpack_joyride/includes/coin.c
vendored
Normal file
98
applications/external/jetpack_joyride/includes/coin.c
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <jetpack_joyride_icons.h>
|
||||
#include <gui/gui.h>
|
||||
|
||||
#include "coin.h"
|
||||
#include "barry.h"
|
||||
|
||||
#define PATTERN_MAX_HEIGHT 40
|
||||
|
||||
// Patterns
|
||||
const COIN_PATTERN coin_patterns[] = {
|
||||
{// Square pattern
|
||||
.count = 9,
|
||||
.coins = {{0, 0}, {8, 0}, {16, 0}, {0, 8}, {8, 8}, {16, 8}, {0, 16}, {8, 16}, {16, 16}}},
|
||||
{// Wavy pattern (approximate sine wave)
|
||||
.count = 8,
|
||||
.coins = {{0, 8}, {8, 16}, {16, 24}, {24, 16}, {32, 8}, {40, 0}, {48, 8}, {56, 16}}},
|
||||
{// Diagonal pattern
|
||||
.count = 5,
|
||||
.coins = {{0, 0}, {8, 8}, {16, 16}, {24, 24}, {32, 32}}},
|
||||
// Add more patterns here
|
||||
};
|
||||
|
||||
void coin_tick(COIN* const coins, BARRY* const barry, int* const total_coins) {
|
||||
// Move coins towards the player
|
||||
for(int i = 0; i < COINS_MAX; i++) {
|
||||
if(coin_colides(&coins[i], barry)) {
|
||||
coins[i].point.x = 0; // Remove the coin
|
||||
(*total_coins)++;
|
||||
}
|
||||
if(coins[i].point.x > 0) {
|
||||
coins[i].point.x -= 1; // move left by 1 unit
|
||||
if(coins[i].point.x < -COIN_WIDTH) { // if the coin is out of screen
|
||||
coins[i].point.x = 0; // set coin x coordinate to 0 to mark it as "inactive"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool coin_colides(COIN* const coin, BARRY* const barry) {
|
||||
return !(
|
||||
barry->point.x > coin->point.x + COIN_WIDTH || // Barry is to the right of the coin
|
||||
barry->point.x + BARRY_WIDTH < coin->point.x || // Barry is to the left of the coin
|
||||
barry->point.y > coin->point.y + COIN_WIDTH || // Barry is below the coin
|
||||
barry->point.y + BARRY_HEIGHT < coin->point.y); // Barry is above the coin
|
||||
}
|
||||
|
||||
void spawn_random_coin(COIN* const coins) {
|
||||
// Select a random pattern
|
||||
int pattern_index = rand() % (sizeof(coin_patterns) / sizeof(coin_patterns[0]));
|
||||
const COIN_PATTERN* pattern = &coin_patterns[pattern_index];
|
||||
|
||||
// Count available slots for new coins
|
||||
int available_slots = 0;
|
||||
for(int i = 0; i < COINS_MAX; ++i) {
|
||||
if(coins[i].point.x <= 0) {
|
||||
++available_slots;
|
||||
}
|
||||
}
|
||||
|
||||
// If there aren't enough slots, return without spawning coins
|
||||
if(available_slots < pattern->count) return;
|
||||
|
||||
// Spawn coins according to the selected pattern
|
||||
int coin_index = 0;
|
||||
int random_offset = rand() % (SCREEN_HEIGHT - PATTERN_MAX_HEIGHT);
|
||||
int random_offset_x = rand() % 16;
|
||||
for(int i = 0; i < pattern->count; ++i) {
|
||||
// Find an available slot for a new coin
|
||||
while(coins[coin_index].point.x > 0 && coin_index < COINS_MAX) {
|
||||
++coin_index;
|
||||
}
|
||||
// If no slot is available, stop spawning coins
|
||||
if(coin_index == COINS_MAX) break;
|
||||
|
||||
// Spawn the coin
|
||||
coins[coin_index].point.x = SCREEN_WIDTH - 1 + pattern->coins[i].x + random_offset_x;
|
||||
coins[coin_index].point.y =
|
||||
random_offset +
|
||||
pattern->coins[i]
|
||||
.y; // The pattern is spawned at a random y position, but not too close to the screen edge
|
||||
}
|
||||
}
|
||||
|
||||
void draw_coins(const COIN* coins, Canvas* const canvas, const GameSprites* sprites) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
for(int i = 0; i < COINS_MAX; ++i) {
|
||||
if(coins[i].point.x > 0) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_icon(canvas, coins[i].point.x, coins[i].point.y, sprites->coin);
|
||||
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_icon(canvas, coins[i].point.x, coins[i].point.y, sprites->coin_infill);
|
||||
}
|
||||
}
|
||||
}
|
||||
26
applications/external/jetpack_joyride/includes/coin.h
vendored
Normal file
26
applications/external/jetpack_joyride/includes/coin.h
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef COIN_H
|
||||
#define COIN_H
|
||||
|
||||
#include <gui/gui.h>
|
||||
|
||||
#include "point.h"
|
||||
#include "barry.h"
|
||||
|
||||
#define COINS_MAX 15
|
||||
|
||||
typedef struct {
|
||||
float gravity;
|
||||
POINT point;
|
||||
} COIN;
|
||||
|
||||
typedef struct {
|
||||
int count;
|
||||
POINT coins[COINS_MAX];
|
||||
} COIN_PATTERN;
|
||||
|
||||
void coin_tick(COIN* const coins, BARRY* const barry, int* const poins);
|
||||
void spawn_random_coin(COIN* const coins);
|
||||
bool coin_colides(COIN* const coin, BARRY* const barry);
|
||||
void draw_coins(const COIN* coins, Canvas* const canvas, const GameSprites* sprites);
|
||||
|
||||
#endif // COIN_H
|
||||
35
applications/external/jetpack_joyride/includes/game_sprites.h
vendored
Normal file
35
applications/external/jetpack_joyride/includes/game_sprites.h
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef GAME_SPRITES_H
|
||||
#define GAME_SPRITES_H
|
||||
|
||||
#include "point.h"
|
||||
#include <gui/icon_animation.h>
|
||||
|
||||
#define SCREEN_WIDTH 128
|
||||
#define SCREEN_HEIGHT 64
|
||||
|
||||
#define BARRY_WIDTH 11
|
||||
#define BARRY_HEIGHT 15
|
||||
|
||||
#define MISSILE_WIDTH 26
|
||||
#define MISSILE_HEIGHT 12
|
||||
|
||||
#define SCIENTIST_WIDTH 9
|
||||
#define SCIENTIST_HEIGHT 14
|
||||
|
||||
#define COIN_WIDTH 7
|
||||
|
||||
typedef struct {
|
||||
IconAnimation* barry;
|
||||
const Icon* barry_infill;
|
||||
const Icon* scientist_left;
|
||||
const Icon* scientist_left_infill;
|
||||
const Icon* scientist_right;
|
||||
const Icon* scientist_right_infill;
|
||||
const Icon* coin;
|
||||
const Icon* coin_infill;
|
||||
IconAnimation* missile;
|
||||
IconAnimation* alert;
|
||||
const Icon* missile_infill;
|
||||
} GameSprites;
|
||||
|
||||
#endif // GAME_SPRITES_H
|
||||
5
applications/external/jetpack_joyride/includes/game_state.c
vendored
Normal file
5
applications/external/jetpack_joyride/includes/game_state.c
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "game_state.h"
|
||||
|
||||
void game_state_tick(GameState* const game_state) {
|
||||
game_state->distance++;
|
||||
}
|
||||
34
applications/external/jetpack_joyride/includes/game_state.h
vendored
Normal file
34
applications/external/jetpack_joyride/includes/game_state.h
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef GAMESTATE_H
|
||||
#define GAMESTATE_H
|
||||
|
||||
#include <gui/icon_animation.h>
|
||||
#include <furi.h>
|
||||
|
||||
#include "barry.h"
|
||||
#include "scientist.h"
|
||||
#include "coin.h"
|
||||
#include "particle.h"
|
||||
#include "game_sprites.h"
|
||||
#include "states.h"
|
||||
#include "missile.h"
|
||||
#include "background_assets.h"
|
||||
typedef struct {
|
||||
int total_coins;
|
||||
int distance;
|
||||
bool new_highscore;
|
||||
BARRY barry;
|
||||
COIN coins[COINS_MAX];
|
||||
PARTICLE particles[PARTICLES_MAX];
|
||||
SCIENTIST scientists[SCIENTISTS_MAX];
|
||||
MISSILE missiles[MISSILES_MAX];
|
||||
BackgroundAsset bg_assets[BG_ASSETS_MAX];
|
||||
State state;
|
||||
GameSprites sprites;
|
||||
FuriMutex* mutex;
|
||||
FuriTimer* timer;
|
||||
void (*death_handler)();
|
||||
} GameState;
|
||||
|
||||
void game_state_tick(GameState* const game_state);
|
||||
|
||||
#endif // GAMESTATE_H
|
||||
86
applications/external/jetpack_joyride/includes/missile.c
vendored
Normal file
86
applications/external/jetpack_joyride/includes/missile.c
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <jetpack_joyride_icons.h>
|
||||
#include <gui/gui.h>
|
||||
|
||||
#include "states.h"
|
||||
#include "game_sprites.h"
|
||||
#include "missile.h"
|
||||
#include "barry.h"
|
||||
|
||||
void missile_tick(MISSILE* const missiles, BARRY* const barry, void (*death_handler)()) {
|
||||
// Move missiles towards the player
|
||||
for(int i = 0; i < MISSILES_MAX; i++) {
|
||||
if(missiles[i].visible && missile_colides(&missiles[i], barry)) {
|
||||
death_handler();
|
||||
}
|
||||
if(missiles[i].visible) {
|
||||
missiles[i].point.x -= 2; // move left by 2 units
|
||||
if(missiles[i].point.x < -MISSILE_WIDTH) { // if the missile is out of screen
|
||||
missiles[i].visible = false; // set missile as "inactive"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void spawn_random_missile(MISSILE* const missiles) {
|
||||
// Check for an available slot for a new missile
|
||||
for(int i = 0; i < MISSILES_MAX; ++i) {
|
||||
if(!missiles[i].visible) {
|
||||
missiles[i].point.x = 2 * SCREEN_WIDTH;
|
||||
missiles[i].point.y = rand() % (SCREEN_HEIGHT - MISSILE_HEIGHT);
|
||||
missiles[i].visible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_missiles(const MISSILE* missiles, Canvas* const canvas, const GameSprites* sprites) {
|
||||
for(int i = 0; i < MISSILES_MAX; ++i) {
|
||||
if(missiles[i].visible) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
if(missiles[i].point.x > 128) {
|
||||
canvas_draw_icon_animation(
|
||||
canvas, SCREEN_WIDTH - 7, missiles[i].point.y, sprites->alert);
|
||||
} else {
|
||||
canvas_draw_icon_animation(
|
||||
canvas, missiles[i].point.x, missiles[i].point.y, sprites->missile);
|
||||
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_icon(
|
||||
canvas, missiles[i].point.x, missiles[i].point.y, sprites->missile_infill);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool missile_colides(MISSILE* const missile, BARRY* const barry) {
|
||||
return !(
|
||||
barry->point.x >
|
||||
missile->point.x + MISSILE_WIDTH - 14 || // Barry is to the right of the missile
|
||||
barry->point.x + BARRY_WIDTH - 3 <
|
||||
missile->point.x || // Barry is to the left of the missile
|
||||
barry->point.y > missile->point.y + MISSILE_HEIGHT || // Barry is below the missile
|
||||
barry->point.y + BARRY_HEIGHT < missile->point.y); // Barry is above the missile
|
||||
}
|
||||
|
||||
int get_rocket_spawn_distance(int player_distance) {
|
||||
// Define the start and end points for rocket spawn distance
|
||||
int start_distance = 256;
|
||||
int end_distance = 24;
|
||||
|
||||
// Define the maximum player distance at which the spawn distance should be at its minimum
|
||||
int max_player_distance = 5000; // Adjust this value based on your game's difficulty curve
|
||||
|
||||
if(player_distance >= max_player_distance) {
|
||||
return end_distance;
|
||||
}
|
||||
|
||||
// Calculate the linear interpolation factor
|
||||
float t = (float)player_distance / max_player_distance;
|
||||
|
||||
// Interpolate the rocket spawn distance
|
||||
return start_distance + t * (end_distance - start_distance);
|
||||
}
|
||||
24
applications/external/jetpack_joyride/includes/missile.h
vendored
Normal file
24
applications/external/jetpack_joyride/includes/missile.h
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef MISSILE_H
|
||||
#define MISSILE_H
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include "game_sprites.h"
|
||||
|
||||
#include "states.h"
|
||||
#include "point.h"
|
||||
#include "barry.h"
|
||||
|
||||
#define MISSILES_MAX 5
|
||||
|
||||
typedef struct {
|
||||
POINT point;
|
||||
bool visible;
|
||||
} MISSILE;
|
||||
|
||||
void missile_tick(MISSILE* const missiles, BARRY* const barry, void (*death_handler)());
|
||||
void spawn_random_missile(MISSILE* const MISSILEs);
|
||||
bool missile_colides(MISSILE* const MISSILE, BARRY* const barry);
|
||||
int get_rocket_spawn_distance(int player_distance);
|
||||
void draw_missiles(const MISSILE* missiles, Canvas* const canvas, const GameSprites* sprites);
|
||||
|
||||
#endif // MISSILE_H
|
||||
57
applications/external/jetpack_joyride/includes/particle.c
vendored
Normal file
57
applications/external/jetpack_joyride/includes/particle.c
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "particle.h"
|
||||
#include "scientist.h"
|
||||
#include "barry.h"
|
||||
|
||||
void particle_tick(PARTICLE* const particles, SCIENTIST* const scientists) {
|
||||
// Move particles
|
||||
for(int i = 0; i < PARTICLES_MAX; i++) {
|
||||
if(particles[i].point.y > 0) {
|
||||
particles[i].point.y += PARTICLE_VELOCITY;
|
||||
|
||||
// Check collision with scientists
|
||||
for(int j = 0; j < SCIENTISTS_MAX; j++) {
|
||||
if(scientists[j].state == ScientistStateAlive && scientists[j].point.x > 0) {
|
||||
// Check whether the particle lies within the scientist's bounding box
|
||||
if(!(particles[i].point.x > scientists[j].point.x + SCIENTIST_WIDTH ||
|
||||
particles[i].point.x < scientists[j].point.x ||
|
||||
particles[i].point.y > scientists[j].point.y + SCIENTIST_HEIGHT ||
|
||||
particles[i].point.y < scientists[j].point.y)) {
|
||||
scientists[j].state = ScientistStateDead;
|
||||
// (*points) += 2; // Increase the score by 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(particles[i].point.x < 0 || particles[i].point.x > SCREEN_WIDTH ||
|
||||
particles[i].point.y < 0 || particles[i].point.y > SCREEN_HEIGHT) {
|
||||
particles[i].point.y = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void spawn_random_particles(PARTICLE* const particles, BARRY* const barry) {
|
||||
for(int i = 0; i < PARTICLES_MAX; i++) {
|
||||
if(particles[i].point.y <= 0) {
|
||||
particles[i].point.x = barry->point.x + (rand() % 4);
|
||||
particles[i].point.y = barry->point.y + 14;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_particles(const PARTICLE* particles, Canvas* const canvas) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
for(int i = 0; i < PARTICLES_MAX; i++) {
|
||||
if(particles[i].point.y > 0) {
|
||||
canvas_draw_line(
|
||||
canvas,
|
||||
particles[i].point.x,
|
||||
particles[i].point.y,
|
||||
particles[i].point.x,
|
||||
particles[i].point.y + 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
21
applications/external/jetpack_joyride/includes/particle.h
vendored
Normal file
21
applications/external/jetpack_joyride/includes/particle.h
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
|
||||
#ifndef PARTICLE_H
|
||||
#define PARTICLE_H
|
||||
|
||||
#include "point.h"
|
||||
#include "scientist.h"
|
||||
#include "barry.h"
|
||||
|
||||
#define PARTICLES_MAX 50
|
||||
#define PARTICLE_VELOCITY 2
|
||||
|
||||
typedef struct {
|
||||
POINT point;
|
||||
} PARTICLE;
|
||||
|
||||
void particle_tick(PARTICLE* const particles, SCIENTIST* const scientists);
|
||||
void spawn_random_particles(PARTICLE* const particles, BARRY* const barry);
|
||||
void draw_particles(const PARTICLE* particles, Canvas* const canvas);
|
||||
|
||||
#endif // PARTICLE_H
|
||||
14
applications/external/jetpack_joyride/includes/point.h
vendored
Normal file
14
applications/external/jetpack_joyride/includes/point.h
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef POINT_H
|
||||
#define POINT_H
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
} POINT;
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
} POINTF;
|
||||
|
||||
#endif // POINT_H
|
||||
77
applications/external/jetpack_joyride/includes/scientist.c
vendored
Normal file
77
applications/external/jetpack_joyride/includes/scientist.c
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "scientist.h"
|
||||
#include "game_sprites.h"
|
||||
|
||||
#include <jetpack_joyride_icons.h>
|
||||
#include <gui/gui.h>
|
||||
|
||||
void scientist_tick(SCIENTIST* const scientists) {
|
||||
for(int i = 0; i < SCIENTISTS_MAX; i++) {
|
||||
if(scientists[i].visible) {
|
||||
if(scientists[i].point.x < 64) scientists[i].velocity_x = 0.5f;
|
||||
|
||||
scientists[i].point.x -= scientists[i].state == ScientistStateAlive ?
|
||||
1 - scientists[i].velocity_x :
|
||||
1; // move based on velocity_x
|
||||
int width = (scientists[i].state == ScientistStateAlive) ? SCIENTIST_WIDTH :
|
||||
SCIENTIST_HEIGHT;
|
||||
if(scientists[i].point.x <= -width) { // if the scientist is out of screen
|
||||
scientists[i].visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void spawn_random_scientist(SCIENTIST* const scientists) {
|
||||
float velocities[] = {-0.5f, 0.0f, 0.5f, -1.0f};
|
||||
// Check for an available slot for a new scientist
|
||||
for(int i = 0; i < SCIENTISTS_MAX; ++i) {
|
||||
if(!scientists[i].visible &&
|
||||
(rand() % 1000) < 10) { // Spawn rate is less frequent than coins
|
||||
scientists[i].state = ScientistStateAlive;
|
||||
scientists[i].point.x = 127;
|
||||
scientists[i].point.y = 49;
|
||||
scientists[i].velocity_x = velocities[rand() % 4];
|
||||
scientists[i].visible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_scientists(const SCIENTIST* scientists, Canvas* const canvas, const GameSprites* sprites) {
|
||||
for(int i = 0; i < SCIENTISTS_MAX; ++i) {
|
||||
if(scientists[i].visible) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
if(scientists[i].state == ScientistStateAlive) {
|
||||
canvas_draw_icon(
|
||||
canvas,
|
||||
(int)scientists[i].point.x,
|
||||
scientists[i].point.y,
|
||||
scientists[i].velocity_x >= 0 ? sprites->scientist_right :
|
||||
sprites->scientist_left);
|
||||
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_icon(
|
||||
canvas,
|
||||
(int)scientists[i].point.x,
|
||||
scientists[i].point.y,
|
||||
scientists[i].velocity_x >= 0 ? sprites->scientist_right_infill :
|
||||
sprites->scientist_left_infill);
|
||||
|
||||
} else {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_icon(
|
||||
canvas,
|
||||
(int)scientists[i].point.x,
|
||||
scientists[i].point.y + 5,
|
||||
&I_dead_scientist);
|
||||
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_icon(
|
||||
canvas,
|
||||
(int)scientists[i].point.x,
|
||||
scientists[i].point.y + 5,
|
||||
&I_dead_scientist_infill);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
applications/external/jetpack_joyride/includes/scientist.h
vendored
Normal file
29
applications/external/jetpack_joyride/includes/scientist.h
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef SCIENTIST_H
|
||||
#define SCIENTIST_H
|
||||
|
||||
#include "point.h"
|
||||
#include "game_sprites.h"
|
||||
#include <gui/gui.h>
|
||||
|
||||
#define SCIENTIST_VELOCITY_MIN -0.5f
|
||||
#define SCIENTIST_VELOCITY_MAX 0.5f
|
||||
|
||||
#define SCIENTISTS_MAX 6
|
||||
|
||||
typedef enum {
|
||||
ScientistStateAlive,
|
||||
ScientistStateDead,
|
||||
} ScientistState;
|
||||
|
||||
typedef struct {
|
||||
bool visible;
|
||||
POINTF point;
|
||||
float velocity_x;
|
||||
ScientistState state;
|
||||
} SCIENTIST;
|
||||
|
||||
void scientist_tick(SCIENTIST* const scientist);
|
||||
void spawn_random_scientist(SCIENTIST* const scientists);
|
||||
void draw_scientists(const SCIENTIST* scientists, Canvas* const canvas, const GameSprites* sprites);
|
||||
|
||||
#endif // SCIENTIST_H
|
||||
9
applications/external/jetpack_joyride/includes/states.h
vendored
Normal file
9
applications/external/jetpack_joyride/includes/states.h
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef STATE_H
|
||||
#define STATE_H
|
||||
|
||||
typedef enum {
|
||||
GameStateLife,
|
||||
GameStateGameOver,
|
||||
} State;
|
||||
|
||||
#endif // STATE_H
|
||||
Reference in New Issue
Block a user