Hi to all, I am new to this forum and new to the development of RL. Aside from some bits of php, I am a complete newcomer to programming.
I started writing a RL with Python and libtcod, using this totally awesome tutorial on roguebasin:
http://roguebasin.roguelikedevelopment.org/index.php/Complete_Roguelike_Tutorial,_using_python%2BlibtcodI finished it, understanding quite everything and learning the basics of the language quite fast. Now I stepped out, and wanted to go working towards some own RLs, each becoming more complex.
My first one should be some kind of Sci-Fi-Survival (a bit into the direction of Unreal World). However, I need to implement different things, one after another. To some of you, this may be not too hard, using all the experience you have about general programming. To me, this is a completely new world. I know the theory about game design and similiar stuff, but programming is very new to me.
My first problem is the following:
I spent hours of searching the web and reading existing code to finally write a Projectile system, inside a sandbox I created just for testing such things. I used libtcod's line_step() method.
However, I want to add some kind of speed feature, something that says how fast my projectiles travel.
I understand that I need to multiply some coordinates with a speed factor.
However, my logic fails and I just can't think of where to put this speed factor (maybe I am just too tired).
Could any of you please read through my Projectile class and tell me where to put the speed?
In case you need to know: the game runs in real-time, with 20fps
the prints are just for control, it took me hours to get the drawing of the Projectiles the right way
I am also open for anything else you can see in my code (maybe something that will cause errors at a later point?)
class Projectile(Object):
def __init__(self, x, y, start_x, start_y, end_x, end_y, char, speed, color=libtcod.red):
self.x = x
self.y = y
self.start_x = start_x
self.start_y = start_y
self.end_x = end_x
self.end_y = end_y
self.speed = speed
self.color = color
self.char = char
libtcod.line_init(start_x, start_y, end_x, end_y)
def proj_draw(self):
libtcod.console_set_foreground_color(con, libtcod.red)
libtcod.console_put_char(con, self.current_x, self.current_y, '*', libtcod.BKGND_NONE)
projectiles.append(self)
render_all()
print('projectile drawn')
libtcod.console_flush()
def proj_clear(self, x, y):
libtcod.console_put_char(con,x,y, ' ', libtcod.BKGND_NONE)
def proj_step(self):
#follow line in steps
self.current_x, self.current_y = libtcod.line_step()
self.proj_draw()
if self.current_x == None or self.current_y == None:
print('dungalung... hits the floor..')
return None, None
#check objects on the way
if is_blocked(self.current_x, self.current_y):
print('katsching! the projectile hits')
return None, None
#out of map - ignore
#elif map_out(self.current_x, self.current_y):
# print('The projectile is gone forever')
# return None, None
return self.current_x, self.current_y
def proj_shoot(self):
x, y = self.proj_step()
ox, oy = self.current_x, self.current_y
while(not x is None and not y is None):
print ('duringshot')
ox, oy = x, y
x, y = self.proj_step()
self.proj_clear(ox, oy)
self.proj_clear(x, y)
print ('aftershot')
self.proj_clear(ox, oy)