Pages: 1 ... 24 25 [26]
  Print  
Author Topic: RL Coding Tutorial with libtcod  (Read 145173 times)
robotcentaur
Apprentice
*
Posts: 8


View Profile
« Reply #375 on: January 27, 2014, 11:36:56 pm »

Jotaf you guys are great.  I have little programming background and your code is teaching me the ropes.  I used your libraries for the Chronicles of Oryx!

Mutant Rogue
http://oryxdesignlab.com/trials/

Sam
Logged
Jotaf
Global Moderator
Master
*****
Posts: 1183


View Profile
« Reply #376 on: May 05, 2014, 02:38:03 am »

Thanks, that's great to hear! I loved the game BTW, it's really fun and the setting is awesome Smiley To make the game a bit more forgiving in the beginning without unbalancing it, maybe you could raise the HP of the heal doses and have more of them early on, but after the 5th level or so, have less of them? The same thing happens in the tutorial game, I might try something like this as well!
Logged
Ari
Apprentice
*
Posts: 1


View Profile
« Reply #377 on: March 11, 2015, 09:21:11 pm »

Hi! Hope it's okay to post in this thread. I'm new to programming and have been following the Python/libtcod tutorial. I saw there were some snippets of code involving a fix for mobs getting caught on corners earlier on in this thread, but I figured I'd try and come up with my own method.

Code:
def move(self, dx, dy):
if not is_blocked(self.x + dx, self.y + dy):
self.x += dx
self.y += dy

self.wait = self.speed

elif self is not player:
#It's blocked, can we get around it?

#-------------------------------------------------------
#Diagonal Shenanigans/Caught on corner
#-------------------------------------------------------

#Move RIGHT+UP
if dx == 1 and dy == 0 and player.y < self.y: dy = -1
#Move RIGHT+DOWN
elif dx == 1 and dy == 0 and player.y > self.y: dy = 1
#Move LEFT+UP
elif dx == -1 and dy == 0 and player.y < self.y: dy = -1
#Move LEFT+DOWN
elif dx == -1 and dy == 0 and player.y > self.y: dy = 1
#Move DOWN+LEFT
elif dx == 0 and dy == 1 and player.x < self.x: dx = -1
#Move DOWN+RIGHT
elif dx == 0 and dy == 1 and player.x > self.x: dx = 1
#Move UP+LEFT
elif dx == 0 and dy == -1 and player.x < self.x: dx = -1
#Move UP+RIGHT
elif dx == 0 and dy == -1 and player.x > self.x: dx = 1


#-------------------------------------------------------
#Mob probably stuck in a straight line
#
#This doesn't work when you end up with 4+ enemies in a
#line, but that might be a little too crazy to deal with
#-------------------------------------------------------

#Stuck going LEFT or RIGHT
if (dx == -1 and dy == 0 and player.y == self.y) or (dx == 1 and dy == 0 and player.y == self.y):
if not is_blocked(self.x + dx, self.y + 1):
dy = 1 #Move DOWN
elif not is_blocked(self.x + dx, self.y + -1):
dy = -1 #Move UP

#Stuck UP or DOWN
elif (dx == 0 and dy == -1 and player.x == self.x) or (dx == 0 and dy == 1 and player.x == self.x):
if not is_blocked(self.x + 1, self.y + dy):
dx = 1 #Move RIGHT
elif not is_blocked(self.x + -1, self.y + dy):
dx = -1 #Move LEFT

#Now try again
if not is_blocked(self.x + dx, self.y + dy):
self.x += dx
self.y += dy

self.wait = self.speed

I -kinda- feel like my code is a bit redundant, or maybe I should be working this into move_towards, but it works how I expect and makes things pretty fun.
I'd love to hear any tips or improvements.

Also! It seems that attachments on these forums all lead to a 404 page, would there be a repository anywhere for those files?

EDIT: Just realized I should make some checks so this doesn't affect the player. (Fixed now)

And just for fun, here it is in action: https://gfycat.com/FrenchPersonalAoudad
« Last Edit: March 11, 2015, 10:04:41 pm by Ari » Logged
Frednotbob
Defender
*****
Posts: 71


View Profile
« Reply #378 on: March 24, 2015, 07:18:55 am »

I -kinda- feel like my code is a bit redundant, or maybe I should be working this into move_towards, but it works how I expect and makes things pretty fun.
I'd love to hear any tips or improvements.

You can condense the 'if/then' statements into one canWalk check; just have the monster check the immediate 8 tiles surrounding it and (if canWalk(x,y)) on the diagonals.
Logged
Kaworu
Apprentice
*
Posts: 1


View Profile
« Reply #379 on: May 21, 2015, 09:58:16 pm »

Hi! ;-)

Can I please translate your tutorial into Polish and publish it over the net? I do not know when I will do that (because I have currently other translation projects) but someday I think I will do that ;-)
Logged
jice
Administrator
Master
*****
Posts: 1464


View Profile WWW
« Reply #380 on: June 11, 2015, 08:52:48 am »

Hey,

No problem, but be aware that there are lots of compilation issues with modern compilers. I think the tutorial needs a part that explains how to compile libtcod because most existing precompiled versions are obsolete.
Logged
suirlir
Apprentice
*
Posts: 1


View Profile
« Reply #381 on: July 04, 2015, 04:55:50 am »

New Movies Download, is an Entertainment site. In this site you can Watch and FreeDownload Thousands of New Movies, Dramas, Songs. Here You also get theresources about all kinds of Movies, Dramas, Songs. Enjoy..   Movie
Logged
Pages: 1 ... 24 25 [26]
  Print  
 
Jump to: