-
Notifications
You must be signed in to change notification settings - Fork 119
A small, simple jungle-themed jump and duck side-scroller #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3e9b243
e770910
16f4d16
ffb852e
eb485e1
7722ac4
823ae10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,263 @@ | ||||||
| from badgeware import screen, Image, PixelFont, brushes, shapes, io, run | ||||||
| import random | ||||||
|
|
||||||
| # Constants | ||||||
| WIDTH = 160 | ||||||
| HEIGHT = 120 | ||||||
| GROUND_Y = 90 | ||||||
| PLAYER_X = 30 | ||||||
| SCROLL_SPEED = 2 | ||||||
| OBSTACLE_SPAWN_MIN = 70 | ||||||
| OBSTACLE_SPAWN_MAX = 120 | ||||||
| OBSTACLE_REMOVAL_THRESHOLD = -50 # X position at which off-screen obstacles are removed | ||||||
| AIR_GAP = 8 # Vertical gap above ground that the branch bottom sits at (duck to clear) | ||||||
| GRASS_PATTERN_WIDTH = 8 # Width of the repeating grass pattern | ||||||
|
|
||||||
| # Collision box adjustments for forgiving gameplay | ||||||
| COLLISION_MARGIN = 2 # Pixels reduced from each side of collision boxes | ||||||
| COLLISION_Y_MARGIN = 2 # Y-offset for standing player collision box | ||||||
| DUCKING_Y_OFFSET = 10 # Y-offset for ducking player collision box | ||||||
| DUCKING_SPRITE_Y_OFFSET = 8 # Y-offset for rendering ducking sprite (visual position) | ||||||
| PLAYER_COLLISION_WIDTH = 16 - (COLLISION_MARGIN * 2) # Player collision box width (12) | ||||||
| PLAYER_COLLISION_HEIGHT = 16 - (COLLISION_MARGIN * 2) # Standing player collision box height (12) | ||||||
| PLAYER_DUCKING_COLLISION_HEIGHT = 8 - (COLLISION_MARGIN * 2) # Ducking player collision box height (4) | ||||||
|
|
||||||
| # Jungle theme colors | ||||||
| SKY_COLOR = brushes.color(135, 206, 235) # Sky blue | ||||||
| GROUND_COLOR = brushes.color(34, 139, 34) # Forest green | ||||||
| GRASS_COLOR = brushes.color(50, 205, 50) # Lime green | ||||||
| TEXT_COLOR = brushes.color(255, 255, 255) # White | ||||||
| GAMEOVER_BG = brushes.color(0, 0, 0, 200) # Semi-transparent black | ||||||
|
|
||||||
| # Set up font | ||||||
| screen.font = PixelFont.load("/system/assets/fonts/ark.ppf") | ||||||
|
|
||||||
| # Load sprites | ||||||
| player_img = Image.load("/system/apps/jungle/sprites/player.png") | ||||||
| log_img = Image.load("/system/apps/jungle/sprites/log.png") | ||||||
| creature_img = Image.load("/system/apps/jungle/sprites/creature.png") | ||||||
| branch_img = Image.load("/system/apps/jungle/sprites/branch.png") | ||||||
|
|
||||||
| # Game state | ||||||
| state = { | ||||||
| "game_state": "playing", # "playing" or "gameover" | ||||||
| "score": 0, | ||||||
| "player_y": GROUND_Y - 16, # Player standing on ground | ||||||
| "player_vel_y": 0, | ||||||
| "is_jumping": False, | ||||||
| "is_ducking": False, | ||||||
| "obstacles": [], | ||||||
| "next_spawn": OBSTACLE_SPAWN_MIN, | ||||||
| "scroll_offset": 0 | ||||||
| } | ||||||
|
|
||||||
| # Obstacle types: (image, type, ground_height) | ||||||
| # type: "ground" (jump over) or "air" (duck under) | ||||||
| # ground_height: for ground obstacles, this should equal sprite height so bottom rests at GROUND_Y | ||||||
| # (calculation: y_pos = GROUND_Y - ground_height, so bottom = y_pos + height = GROUND_Y) | ||||||
| # Coordinate system: y = top of sprite. Collision boxes use margins and offsets. | ||||||
| # Air obstacles: branch placed with bottom at GROUND_Y - AIR_GAP (90 - 8 = 82) | ||||||
| # Standing player: player_y = 74 (sprite top), collision box top = 74 + COLLISION_Y_MARGIN = 76, | ||||||
| # collision box height = 12, so collision box bottom = 88 (HITS branch at 82) | ||||||
| # Ducking player: player_y = 74 (sprite top), collision box top = 74 + DUCKING_Y_OFFSET = 84, | ||||||
| # collision box height = 4, so collision box bottom = 88 (CLEARS branch at 82) | ||||||
|
||||||
| # collision box height = 4, so collision box bottom = 88 (CLEARS branch at 82) | |
| # collision box height = 4, so collision box bottom = 88 (HITS branch at 82; does NOT clear) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The calculation comment is incorrect. The formula shows
y_pos + height = GROUND_Y, but this would only be true ifground_heightequals the sprite's height. The actual relationship isy_pos = GROUND_Y - ground_height, sobottom = GROUND_Y - ground_height + sprite_height. The comment should clarify thatground_heightmust equal sprite height for this to work correctly.