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
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))
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 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
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
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
Thanks! Make sure that your indexes are all integers (types, cycle and dir2p)
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))
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
@@FinFET no they started to move to the left and go far away
@@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
this is very impressive! Can you recommend any other learning resources for someone trying to implement sprites?
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
Yay, IDLE 😃
=), nowadays I use mostly VS Code, but the simplicity of IDLE is great for small projects and beginners
Just like Doom 1...
Very very nice... ✅✅✅✅✅✅✅✅