Sprites on a Raycasting game in Python with Pygame - Tutorial Devlog

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ต.ค. 2024

ความคิดเห็น • 11

  • @GregoryMark29
    @GregoryMark29 2 ปีที่แล้ว

    Great video! I have a question though, when I run your code from github it gives an error: Traceback (most recent call last):
    File "C:\Users\Desktop
    aycast\testing.py", line 285, in
    main()
    File "C:\Users\Desktop
    aycast\testing.py", line 50, in main
    surf, en = draw_sprites(surf, sprites, enemies, spsize, hres, halfvres, ticks, sword, swordsp)
    File "C:\Users\Desktop
    aycast\testing.py", line 276, in draw_sprites
    spsurf = pg.transform.scale(sprites[types][cycle][dir2p], scale)
    TypeError: integer argument expected, got float
    I have not modified the code so I am not sure why it is doing this?
    Thank you! :D

    • @FinFET
      @FinFET  2 ปีที่แล้ว

      Thanks! Make sure that your indexes are all integers (types, cycle and dir2p)

  • @CXLCaleb
    @CXLCaleb ปีที่แล้ว +1

    hey i have a this part is broken when i run it and get close to monsters they run away
    code -
    for en in range(100):
    enx, eny = enemies[en][0], enemies[en][1]
    angle = np.arctan((eny-posy)/(enx-posx))
    if abs(posx+np.cos(angle)-enx) > abs(posx-enx):
    angle = (angle - np.pi)%(2*np.pi)
    anglediff = (rot-angle)%(2*np.pi)
    if anglediff > 11*np.pi/6 or anglediff < np.pi/6:
    dist = np.sqrt((posx-enx)**2+(posx-eny)**2)
    cos2 = np.cos(anglediff)
    scaling = min(1/dist, 2)/cos2
    vert = 300 + 300*scaling - scaling*spsize[1]/2
    hor = 400 - 800*np.sin(anglediff)- scaling*spsize[0]/2
    spsurf = pg.transform.scale(sprite, scaling*spsize)
    surf.blit(spsurf, (hor, vert))

    • @FinFET
      @FinFET  ปีที่แล้ว

      what do you mean? they stop growing? its limited to a factor of two when calculating scale so they don't grow too much or else you eventually run out of memory

    • @CXLCaleb
      @CXLCaleb ปีที่แล้ว

      @@FinFET no they started to move to the left and go far away

    • @FinFET
      @FinFET  ปีที่แล้ว

      @@CXLCaleb i think that's expected because you are getting too close to them, to avoid that you have to detect collisions with enemies and push them back when you are too close. That is on the AI part

  • @OneEgg42
    @OneEgg42 2 ปีที่แล้ว +2

    this is very impressive! Can you recommend any other learning resources for someone trying to implement sprites?

    • @FinFET
      @FinFET  2 ปีที่แล้ว +2

      Pygame actually has a module dedicated to sprites, I found it a bit complicated for this project, and the documentation is a bit lacking, but there are some more in depth videos on the subject on TH-cam
      If you want to draw them properly with occlusions, you have to draw them pixel by pixel and have a z-buffer, take a look at lodev.org/cgtutor/raycasting3.html

  • @anntakamaki1960
    @anntakamaki1960 ปีที่แล้ว +1

    Yay, IDLE 😃

    • @FinFET
      @FinFET  ปีที่แล้ว +1

      =), nowadays I use mostly VS Code, but the simplicity of IDLE is great for small projects and beginners

  • @SkyFly19853
    @SkyFly19853 2 ปีที่แล้ว +1

    Just like Doom 1...
    Very very nice... ✅✅✅✅✅✅✅✅