from ursina import * from ursina.prefabs.first_person_controller import FirstPersonController import random, math app = Ursina() window.title = "JP FLEISCH BUGFIX V2" Sky(color=color.rgb(135,206,235)) scene.fog_density = 0.018 ground = Entity(model='plane', scale=(2000,1,1500), color=color.rgb(35,70,35), collider='box') river = Entity(model='plane', scale=(2000,1,80), color=color.rgb(25,60,120), y=-0.5, z=80) for _ in range(80): x, z = random.randint(-900,900), random.randint(-600,600) if abs(z-80)<40: continue h=random.uniform(8,12) try: Entity(model='cube', color=color.rgb(60,35,15), scale=(1,h,1), x=x, z=z, y=h/2, collider='box') Entity(model='sphere', color=color.rgb(20,80,20), scale=3, x=x, y=h+0.8, z=z) except: pass player = FirstPersonController(x=0, y=2, z=-150, speed=5, mouse_sensitivity=Vec2(25,25), collider='box', jump_height=0.8) player.cursor.visible=False; player.cursor.enabled=False game_over=False # HANDY BUTTONS - BUGFIX: feste Positionen btn_forward=Button(text='▲', scale=(0.18,0.20), pos=(-0.70,-0.15), color=color.rgba(0,0,0,130)) btn_back=Button(text='▼', scale=(0.18,0.20), pos=(-0.70,-0.55), color=color.rgba(0,0,0,130)) btn_left=Button(text='◄', scale=(0.18,0.20), pos=(-0.88,-0.35), color=color.rgba(0,0,0,130)) btn_right=Button(text='►', scale=(0.18,0.20), pos=(-0.52,-0.35), color=color.rgba(0,0,0,130)) btn_look_left=Button(text='◄', scale=(0.14,0.15), pos=(0.52,-0.25), color=color.rgba(50,50,50,120)) btn_look_right=Button(text='►', scale=(0.14,0.15), pos=(0.80,-0.25), color=color.rgba(50,50,50,120)) btn_look_up=Button(text='▲', scale=(0.14,0.15), pos=(0.66,-0.08), color=color.rgba(50,50,50,120)) btn_look_down=Button(text='▼', scale=(0.14,0.15), pos=(0.66,-0.42), color=color.rgba(50,50,50,120)) btn_shoot=Button(text='FIRE', scale=(0.26,0.24), pos=(0.66,-0.68), color=color.rgba(200,0,0,220), text_color=color.white) btn_chest=Button(text='BOX', scale=(0.10,0.10), pos=(0.10,-0.35), color=color.rgba(101,67,33,180)) btn_pickup=Button(text='GUN', scale=(0.10,0.10), pos=(-0.06,-0.35), color=color.rgba(0,150,0,180)) btn_meat=Button(text='CUT', scale=(0.13,0.10), pos=(-0.24,-0.35), color=color.rgba(200,50,50,180)) btn_cook=Button(text='GRILL', scale=(0.12,0.10), pos=(0.26,-0.35), color=color.rgba(255,100,0,180)) btn_eat=Button(text='EAT', scale=(0.13,0.10), pos=(0.42,-0.35), color=color.rgba(0,180,0,180)) btn_reload=Button(text='RE', scale=(0.09,0.10), pos=(0.58,-0.35), color=color.rgba(80,80,80,180)) btn_w0=Button(text='MESSER', scale=(0.11,0.07), pos=(-0.65,0.45), color=color.lime) btn_w5=Button(text='LUFT', scale=(0.09,0.07), pos=(0.15,0.45), color=color.lime) day=1; day_time=0; is_day=True; DAY_DURATION=20*60; TOTAL_DAY=30*60 weapon_data={"messer":{"name":"Messer","mag":9999,"dmg":25},"luft":{"name":"Luft","mag":10,"dmg":10,"vel":250,"drop":3.5},"gew":{"name":"Rem700","mag":5,"dmg":85,"vel":820,"drop":0.8}} dino_data={"Raptor":{"len":3.5,"h":1.2,"hp":80,"kmh":20,"col":color.orange,"meat":2},"T-Rex":{"len":12,"h":3.5,"hp":200,"kmh":15,"col":color.rgb(50,50,50),"meat":4},"D-Rex":{"len":18,"h":4.5,"hp":800,"kmh":12,"col":color.rgb(40,10,10),"meat":6}} def kmh_to_speed(k): return k/6.0 # BUGFIX: Variablen initialisieren hunger=100; has_eaten_today=False; raw_meat=0; cooked_meat=0 meat_items=[]; buildings=[]; campfires=[]; weapons_on_map=[]; has_messer=True; has_luft=True; has_gew=False current="messer"; mag_size={"messer":9999,"luft":10,"gew":5}; mag_current={"messer":9999,"luft":10,"gew":5}; reserve_ammo={"messer":9999,"luft":100,"gew":25} bullets=[]; humans=[]; active=[] weapon_model=Entity(parent=camera, model='cube', color=color.rgb(200,200,200), scale=(0.05,0.02,0.4), position=(0.55,-0.35,0.9)) weapon_handle=Entity(parent=weapon_model, model='cube', color=color.rgb(100,30,20), scale=(1.5,1.2,1.5), position=(0,0,-0.8)) def safe_destroy(ent, lst=None): try: if ent: destroy(ent) if lst is not None: if ent in lst: lst.remove(ent) except: pass def spawn_weapon(): try: x=random.randint(-800,800); z=random.randint(-600,600) if abs(z-80)<40: return typ=random.choice(["messer","luft","luft","gew"]) col=color.rgb(200,200,200) if typ=="messer" else color.rgb(120,180,255) if typ=="luft" else color.gray w=Entity(model='cube', color=col, scale=(0.5,0.25,0.9), x=x, y=0.25, z=z, collider='box'); w.type=typ; weapons_on_map.append(w) except: pass for _ in range(8): spawn_weapon() def equip(typ): global current try: current=typ if typ=="messer": weapon_model.color=color.rgb(200,200,200); weapon_model.scale=(0.05,0.02,0.4); weapon_handle.visible=True else: weapon_handle.visible=False; weapon_model.scale=(0.12,0.12,1.1) cols={"gew":color.rgb(40,40,40),"luft":color.rgb(120,180,255)}; weapon_model.color=cols.get(typ, color.gray) btn_w0.color=color.lime if typ=="messer" else color.rgb(0,150,0) btn_w5.color=color.lime if typ=="luft" else color.gray except: pass chests=[] def spawn_chest(): try: x=random.randint(-800,800); z=random.randint(-600,600) if abs(z-80)<40: return typ=random.choice(["luft","gew"]); col=color.rgb(120,180,255) if typ=="luft" else color.rgb(100,70,30) c=Entity(model='cube', color=col, scale=(1.2,0.8,1), x=x, y=0.4, z=z, collider='box'); c.loot_type=typ; c.loot_amount=20; c.looted=False; chests.append(c) except: pass for _ in range(15): spawn_chest() # BUGFIX: Gebäude + Feuer sicher spawnen def spawn_buildings(): try: for i in range(5): x=random.randint(-800,800); z=random.randint(-600,600) if abs(z-80)<100: continue # Gebäude base=Entity(model='cube', color=color.rgb(75,75,80), scale=(16,4,12), x=x, y=2, z=z, collider='box') buildings.append(base) # Feuer in Mitte fx=x+random.uniform(-2,2); fz=z+random.uniform(-2,2) # Steinkreis - 6 Steine for a in range(6): ang=a*60; sx=fx+math.cos(math.radians(ang))*1.0; sz=fz+math.sin(math.radians(ang))*1.0 Entity(model='cube', color=color.rgb(70,70,70), scale=(0.4,0.3,0.4), x=sx, y=0.15, z=sz) flame=Entity(model='cube', color=color.rgb(255,120,0), scale=(0.5,0.6,0.5), x=fx, y=0.3, z=fz, collider='box') flame.is_fire=True flame.original_y=0.3 campfires.append(flame) # Licht PointLight(parent=flame, color=color.rgb(255,120,20), y=0.5) # Kiste dazu c=Entity(model='cube', color=color.rgb(100,70,30), scale=(1,0.7,0.9), x=x+5, y=0.35, z=z, collider='box'); c.loot_type="luft"; c.loot_amount=25; c.looted=False; chests.append(c) except Exception as e: print(f"build err {e}") spawn_buildings() def spawn_dino(): try: name = random.choice(["Raptor"]*6 + ["T-Rex"]*2 + ["D-Rex"]) d=dino_data[name] x=random.randint(-700,700); z=random.randint(-500,500) body=Entity(model='cube', color=d["col"], scale=(d["h"]*0.6,d["h"]*0.7,d["len"]*0.6), x=x, z=z, y=d["h"]*0.5, collider='box', name=name) head=Entity(parent=body, model='cube', color=d["col"], scale=(0.5,0.4,0.7), position=(0,0.2,0.7)) tail=Entity(parent=body, model='cube', color=d["col"], scale=(0.3,0.3,0.6), position=(0,0,-0.6)) body.hp=d["hp"]; body.max_hp=d["hp"]; body.speed=kmh_to_speed(d["kmh"]); body.real_length=d["len"]; body.dead=False; body.meat_amount=d["meat"]; body.meat_cut=False; body.name=name; body.tail=tail active.append(body) except: pass for _ in range(8): spawn_dino() def spawn_human(): try: x=random.randint(-700,700); z=random.randint(-500,500) body=Entity(model='cube', color=color.rgb(60,90,140), scale=(0.5,0.7,0.3), x=x, z=z, y=1.0, collider='box', name="Human") Entity(parent=body, model='sphere', color=color.rgb(220,180,140), scale=0.32, y=0.55) body.hp=50; body.speed=kmh_to_speed(12); body.shoot_timer=2; body.is_human=True; body.dead=False; humans.append(body) except: pass for _ in range(5): spawn_human() info=Text(pos=(-0.80,0.42), scale=0.32, background=True) w_text=Text(pos=(0.05,0.32), scale=0.42, color=color.yellow, background=True) day_text=Text(pos=(0,0.48), origin=(0,0), scale=0.70, color=color.yellow, background=True) hunger_text=Text(pos=(0.55,0.42), scale=0.38, color=color.orange, background=True) game_text=Text(pos=(0,0), origin=(0,0), scale=0.9, color=color.red, background=True, text="") # BUGFIX: Fleisch schneiden - sicher def cut_meat(): global raw_meat try: # 1. Toten Dino suchen for d in active: try: if d.dead and not d.meat_cut and distance(player,d)<4: amount=d.meat_amount raw_meat+=amount d.meat_cut=True # Rohes Fleisch spawnen neben Dino for i in range(amount): mx=d.x+random.uniform(-1.2,1.2); mz=d.z+random.uniform(-1.2,1.2) m=Entity(model='cube', color=color.rgb(180,30,30), scale=(0.35,0.15,0.4), x=mx, y=0.2, z=mz, collider='box') m.type="raw" meat_items.append(m) w_text.text=f"CUT {amount}x RAW von {d.name}!" # Dino nach 20s löschen wenn geschnitten def remove_dino(ent=d): try: if ent.meat_cut: safe_destroy(ent, active) except: pass invoke(remove_dino, delay=20) return elif d.dead and d.meat_cut and distance(player,d)<4: w_text.text="Schon geschnitten!" return except: continue # 2. Rohes Fleisch vom Boden for m in meat_items[:]: try: if hasattr(m,'type') and m.type=="raw" and distance(player,m)<3: raw_meat+=1 safe_destroy(m, meat_items) w_text.text=f"RAW aufgehoben! {raw_meat} roh" return except: continue w_text.text="Kein toter Dino nah! Erst töten" except Exception as e: w_text.text=f"CUT BUG {str(e)[:20]}" def cook_meat(): global raw_meat, cooked_meat try: if raw_meat<=0: w_text.text="Kein RAW! CUT zuerst!" return # Feuer suchen near_fire=None for fire in campfires: try: if distance(player,fire)<5: near_fire=fire break except: continue if not near_fire: w_text.text="Kein Feuer nah! Geh zu Ruine!" return raw_meat-=1 w_text.text="GRILLT 3s..." near_fire.color=color.yellow near_fire.animate_scale((0.7,1.0,0.7), duration=0.3) def finish_cook(): global cooked_meat try: cooked_meat+=1 near_fire.color=color.rgb(255,120,0) near_fire.scale=(0.5,0.6,0.5) # Gegrilltes spawnen mx=near_fire.x+random.uniform(-1,1); mz=near_fire.z+random.uniform(-1,1) m=Entity(model='cube', color=color.rgb(110,55,20), scale=(0.35,0.15,0.4), x=mx, y=0.25, z=mz, collider='box') m.type="cooked" meat_items.append(m) w_text.text=f"FERTIG! {cooked_meat} gegrillt! EAT!" except Exception as e: w_text.text=f"COOK END BUG {e}" invoke(finish_cook, delay=3) except Exception as e: w_text.text=f"COOK BUG {str(e)[:20]}" def eat_meat(): global cooked_meat, hunger, has_eaten_today, raw_meat try: if cooked_meat>0: cooked_meat-=1 hunger=min(100, hunger+50) has_eaten_today=True w_text.text=f"GEGESSEN! Hunger {hunger}%" return # Vom Boden for m in meat_items[:]: try: if hasattr(m,'type') and m.type=="cooked" and distance(player,m)<3: safe_destroy(m, meat_items) hunger=min(100, hunger+50) has_eaten_today=True w_text.text=f"Vom Boden! Hunger {hunger}%" return except: continue if raw_meat>0: raw_meat-=1 hunger=min(100, hunger+15) has_eaten_today=True w_text.text=f"ROH +15! {hunger}% Besser grillen!" return w_text.text="Kein Fleisch! CUT->GRILL->EAT" except Exception as e: w_text.text=f"EAT BUG {str(e)[:20]}" def shoot_one(): global game_over if game_over: return try: if current=="messer": # Wenn toter Dino in Nähe -> schneiden for d in active: try: if d.dead and distance(player,d)<4 and not d.meat_cut: cut_meat() return except: continue hit=raycast(camera.world_position, camera.forward, distance=3, ignore=[player]) try: weapon_model.animate_position((0.55,-0.25,1.1), duration=0.08) weapon_model.animate_position((0.55,-0.35,0.9), duration=0.12, delay=0.08) except: pass if hit.hit and hit.entity in active and not hit.entity.dead: ent=hit.entity ent.hp-=25 try: ent.blink(color.white, duration=0.1) except: pass w_text.text=f"MESSER {ent.name} {ent.hp}HP" if ent.hp<=0 and not ent.dead: ent.dead=True ent.rotation_z=90 ent.y=0.35 ent.collider=None w_text.text=f"TOT! CUT für Fleisch!" # NICHT löschen! Bleibt 30s zum Schneiden elif hit.hit and hit.entity in humans and not hit.entity.dead: ent=hit.entity; ent.hp-=25 if ent.hp<=0 and not ent.dead: ent.dead=True; ent.rotation_z=90; invoke(lambda e=ent: safe_destroy(e, humans), delay=3) else: w_text.text="*wisch*" return if not current or mag_current.get(current,0)<=0: w_text.text="LEER! RE!"; return mag_current[current]-=1 b=Entity(model='sphere', color=color.rgb(180,220,255) if current=="luft" else color.yellow, scale=0.022, position=camera.world_position+camera.forward*1.2) data={"luft":{"vel":250,"drop":3.5,"dmg":10},"gew":{"vel":820,"drop":0.8,"dmg":85}}.get(current, {"vel":250,"drop":3.5,"dmg":10}) b.velocity=camera.forward*data["vel"]/15; b.gravity=-data["drop"]; b.damage=data["dmg"]; b.life=4.0 bullets.append(b); w_text.text=f"{current} {mag_current[current]}/{mag_size[current]}" except Exception as e: w_text.text=f"SHOOT BUG {str(e)[:15]}" def reload(): try: if current=="messer": return if reserve_ammo.get(current,0)<=0 or mag_current[current]>=mag_size[current]: return need=mag_size[current]-mag_current[current]; take=min(need,reserve_ammo[current]); reserve_ammo[current]-=take; mag_current[current]+=take w_text.text=f"GELADEN {mag_current[current]}" except: pass def open_chest(): global has_gew, has_luft try: for c in chests[:]: if not c or c.looted: continue if distance(player,c)<4: c.looted=True if c.loot_type=="luft": has_luft=True; reserve_ammo["luft"]+=c.loot_amount elif c.loot_type=="gew": has_gew=True; reserve_ammo["gew"]+=c.loot_amount safe_destroy(c, chests); invoke(spawn_chest, delay=8) w_text.text=f"BOX {c.loot_type} +{c.loot_amount}"; return True except: pass return False def pickup_weapon(): global has_gew, has_luft try: for w in weapons_on_map[:]: if not w: continue if distance(player,w)<4: if w.type=="luft": has_luft=True; reserve_ammo["luft"]+=20 elif w.type=="gew": has_gew=True; reserve_ammo["gew"]+=10 if w.type!="messer": equip(w.type) safe_destroy(w, weapons_on_map); return True except: pass return False btn_shoot.on_click=shoot_one; btn_chest.on_click=open_chest; btn_pickup.on_click=pickup_weapon; btn_reload.on_click=reload btn_meat.on_click=cut_meat; btn_cook.on_click=cook_meat; btn_eat.on_click=eat_meat btn_w0.on_click=lambda: equip("messer"); btn_w5.on_click=lambda: equip("luft") def update(): global day, day_time, is_day, game_over, hunger, has_eaten_today if game_over: return try: day_time+=time.dt if day_time>TOTAL_DAY: day_time=0; day+=1 if not has_eaten_today: hunger-=40 w_text.text=f"NICHT GEGESSEN! -40 Hunger {hunger}%" if hunger<=0: game_text.text="VERHUNGERT! R=Restart"; game_over=True; return else: hunger-=10 if hunger<=0: game_text.text="VERHUNGERT! R"; game_over=True; return has_eaten_today=False if day>100: game_text.text="100 TAGE GEWONNEN!"; game_over=True; return is_day=day_time0: move=move.normalized(); fwd=Vec3(camera.forward.x,0,camera.forward.z).normalized(); right=Vec3(fwd.z,0,-fwd.x) player.position+=(fwd*move.z+right*move.x)*5*time.dt if btn_look_left.pressed: player.rotation_y-=70*time.dt if btn_look_right.pressed: player.rotation_y+=70*time.dt if btn_look_up.pressed: camera.rotation_x-=55*time.dt if btn_look_down.pressed: camera.rotation_x+=55*time.dt camera.rotation_x=max(-70,min(70,camera.rotation_x)); player.y=2 player.x=max(-950,min(950,player.x)); player.z=max(-700,min(700,player.z)) # Feuer flackern - BUGFIX: nur scale_y for fire in campfires: try: if random.random()<0.08: fire.scale_y=random.uniform(0.5,0.9) except: pass for b in bullets[:]: try: b.life-=time.dt if b.life<=0: safe_destroy(b, bullets); continue b.velocity.y+=b.gravity*time.dt; old=b.position; b.position+=b.velocity*time.dt if b.y<0.1: safe_destroy(b, bullets); continue hit=raycast(old, b.velocity.normalized(), distance=(b.position-old).length(), ignore=[player,b]) if hit.hit and hit.entity in active and not hit.entity.dead: ent=hit.entity; ent.hp-=b.damage try: ent.blink(color.red, duration=0.1) except: pass if ent.hp<=0 and not ent.dead: ent.dead=True; ent.rotation_z=90; ent.y=0.35; ent.collider=None w_text.text=f"{ent.name} TOT! CUT!" safe_destroy(b, bullets) elif hit.hit and hit.entity in humans and not hit.entity.dead: ent=hit.entity; ent.hp-=b.damage if ent.hp<=0 and not ent.dead: ent.dead=True; ent.rotation_z=90; invoke(lambda e=ent: safe_destroy(e, humans), delay=3) safe_destroy(b, bullets) except: try: safe_destroy(b, bullets) except: pass for d in active[:]: try: if d.dead: continue if distance(player,d)<85: try: d.look_at(player, axis='y'); d.position+=d.forward*2.2*time.dt; d.y=d.scale_y/2 except: pass if distance(player,d)60 else color.orange if hunger>30 else color.red hunger_text.color=hunger_color hunger_text.text=f"H {hunger}% {'YES' if has_eaten_today else 'NO'}" # Button Farben BUGFIX: try try: btn_chest.color=color.gold if any(not c.looted and distance(player,c)<5 for c in chests if c and hasattr(c,'looted')) else color.rgba(101,67,33,180) btn_pickup.color=color.lime if any(distance(player,w)<4 for w in weapons_on_map if w) else color.rgba(0,150,0,180) has_dead_near=any(d.dead and not d.meat_cut and distance(player,d)<5 for d in active if d) btn_meat.color=color.red if has_dead_near else color.rgba(200,50,50,120) near_fire=any(distance(player,f)<5 for f in campfires if f) btn_cook.color=color.rgb(255,150,0) if raw_meat>0 and near_fire else color.rgba(255,100,0,100) can_eat=cooked_meat>0 or any(hasattr(m,'type') and m.type=="cooked" and distance(player,m)<4 for m in meat_items if m) btn_eat.color=color.lime if can_eat else color.rgba(0,180,0,100) info.text=f"{len(active)}D {raw_meat}R {cooked_meat}G" except: pass except Exception as e: w_text.text=f"UPD BUG {str(e)[:20]}" def input(key): global game_over, day, day_time, hunger, has_eaten_today, raw_meat, cooked_meat try: if key=='e': if not open_chest(): pickup_weapon() if key=='f': cut_meat() if key=='g': cook_meat() if key=='h': eat_meat() if key=='0': equip("messer") if key=='5': equip("luft") if key=='left mouse down': shoot_one() if key=='r': if current and current!="messer": reload() if game_over: game_over=False; game_text.text=""; day=1; day_time=0; hunger=100; has_eaten_today=False; raw_meat=0; cooked_meat=0 for d in active[:]: safe_destroy(d, active) for h in humans[:]: safe_destroy(h, humans) for m in meat_items[:]: safe_destroy(m, meat_items) meat_items.clear() for _ in range(8): spawn_dino() for _ in range(5): spawn_human() player.x=0; player.z=-150; player.y=2 except: pass equip("messer") app.run()