Putting the 'role' back in role-playing games since 2002.
Donate to Codex
Good Old Games
  • Welcome to rpgcodex.net, a site dedicated to discussing computer based role-playing games in a free and open fashion. We're less strict than other forums, but please refer to the rules.

    "This message is awaiting moderator approval": All new users must pass through our moderation queue before they will be able to post normally. Until your account has "passed" your posts will only be visible to yourself (and moderators) until they are approved. Give us a week to get around to approving / deleting / ignoring your mundane opinion on crap before hassling us about it. Once you have passed the moderation period (think of it as a test), you will be able to post normally, just like all the other retards.

Vapourware Trying to learn programming from ~0, realistic goals naturally help needed.

jagged-jimmy

Prophet
Joined
Jan 25, 2008
Messages
1,550
Location
Freeside
Codex 2012
Is it really normal that game-play is so quick and easily developed?

As anyone will tell you, mastering the chaos is what it's all about. Any hobo can code some formulas and number crunching.

For doing visuals: People are always trying to recommend some languages, frameworks etc. Seriously, for the level of game you are coding, simple drawing of images/font on grid is totally enough. I am sure python kivy can draw stuff on some "canvas". I would start there. All you need are free tiles from the internet (like something 32x32 pixels) and you can start drawing them according to you game logic.

Choose the size of field (10x10 tiles), draw the whole field with the "ground" tile. Draw "actors" tiles above - voila you have a map with actors on it. Now remember coordinates of "actors" - manipulate them. Redraw everything. You have movement. Now use your imagination. Basic thing to do would be to attach a mouse listener to the "canvas" and react on clicks in you game, moving, attacking etc. depending on the "game" state.

If anyone knows any simple but powerful enough (for ex. with doublebuffering) drawing libraries for different languages, well post'em. I would be interested too. So far i just used java 2D for graphics, because i am familiar with the java language/tools.
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
Doing logic for a generic "game" is easy. Every half decent programmer can make a prototype in a few days or weeks.
Making something look and behave the way you want (and not how the framework examples look) is much harder.
Making a GAME that anyone wants to play, is very hard I suppose!
That's where 90% of indie developers fail. They fire up a framework and build something around the things that are easily available = shit.
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
If anyone knows any simple but powerful enough (for ex. with doublebuffering) drawing libraries for different languages, well post'em. I would be interested too. So far i just used java 2D for graphics, because i am familiar with the java language/tools.

Why do you want different languages?
Most C++ libraries have have reliable bindings in other languages (for example Qt or Ogre3d) but in the end no one uses them.

P.S. Perhaps OpenGL is what you are looking for.
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,804
Ehh mu fucking ISP blocked youtube for few days...

I was watching some dude presentation "introduction to game design" and it was informative as hell along with how to create 2D graphics, collision detection (various types), how to deal with too fast execution of code, how to deal with code architecture and so on. Based on PyGame.
I wait for my ISP to unblock youtube to continue that.
As of Kivy it looks like it is still in works and it is hell of a thing to include it in standard library to use it for example in PyCharm so i dropped it for now.
 

baturinsky

Arcane
Joined
Apr 21, 2013
Messages
5,526
Location
Russia
That's some sucky ISP you have. There are all sort of proxies and download services for youtube out there, btw.
 

jagged-jimmy

Prophet
Joined
Jan 25, 2008
Messages
1,550
Location
Freeside
Codex 2012
If anyone knows any simple but powerful enough (for ex. with doublebuffering) drawing libraries for different languages, well post'em. I would be interested too. So far i just used java 2D for graphics, because i am familiar with the java language/tools.

Why do you want different languages?
Most C++ libraries have have reliable bindings in other languages (for example Qt or Ogre3d) but in the end no one uses them.

P.S. Perhaps OpenGL is what you are looking for.
I wanted to know how to draw in different languages. I am still searching for the easiest to use. Lightweight and straightforward. Also the OP could benefit, if someone knows an easy to use drawig library, ex. for Python.

Qt for example is nicely documented, easy to get into and IMHO one of the ways to easily do graphics with C++.
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
Easy, lightweight and straighforward is normally the antagonist of powerful, flexible and sophisticated. So there really is no perfect choice. But there is a good choice for everyone.

The questions are 2D or 3D? High level or low level? Mostly animation or GUI heavy?

Qt does everything in 2D very well and you can use it in either C++ or C# or Python bindings.

If you want a simple lighweight programming, have a look at SDL. Again, there are different language bindings.

If you want 3d graphics, learn and do a lot of low level stuff: OpenGL. OpenGL is for graphics only, but most powerful, and the skills are not wasted.

If you want something more high level but still powerful: a scene graph like Ogre 3D (OpenGL knowledge helps). To link sound and physics it is no big deal, but GUI is a lot of work (that's why I shelved it).
For a 1 man game it is not ideal, unless you want to invest a lot.

High level you have many game framework to choose, but I am no fan of that (games look too generic). High level is also worst for learning.

For what you describe, I recommend you look at SDL.
 

Destroid

Arcane
Joined
May 9, 2007
Messages
16,628
Location
Australia
And if you want to do that you look to the roguelike community with tools like libtcod, squidlib and rot.js.
 

jagged-jimmy

Prophet
Joined
Jan 25, 2008
Messages
1,550
Location
Freeside
Codex 2012
We are talking here about 1 man project, doing the most functional graphics. So 3D is out of question, same for isometric. IMHO the easiest way to go, is a turn-based tile-based game. The easiest design is Darklands-like:
1. Dialog like screen with Options to choose (can be a Location or a Conversation - does not matter technically and would look the same, just swap location icon with an NPC icon)
2. Combat view - a tiled top-down map where encounters play out

1. should be easy for anyone with a bit googling, for 2. you either create your own very basic "engine" for drawing tiles and text OR you use something like rot.js - you can paste it in any text file and execute immediately in a browser. That is what a single, inexperienced developer should aim for. That is what i mean by lightweight and straightforward. Such game can look as good as the chosen art.
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,804
GOAL3 achieved ! ========================================

I decided to release in this state "game". Game features bugs but i think like some people said i shouldn't focus on feature complete game as developing those features takes time and i don't really learn iterating over same stuff. Also you can't heal as developing it would be mundane and not something new. (though you can heal via cheat in main menu after starting new game (quit in game options to go to main menu))

I learned a lot in this goal. First of basic handling of loops, more advanced definitions and classes. Some tweaks to my procedural creation.

For Goal 4 i think i will do mentioned GUI or maybe PyGame (as it has GUI). To boost my morale i need to have some kind of UI that will deal with screen text bloat.

Compiled program: The Glow
you will need: python 2.7.8
pure .py file: The Glow

raw code:

Code:
__author__ = 'Perkel'

import random
import os

# Menu dictionaries

main_menu_list = {'new game': 1,
                  'quit': 4}

game_option_list = {'move': 1,
                    'check place': 2,
                    'combat': 3,
                    'inventory': 4,
                    'player stats': 5,
                    'merchant': 6,
                    'quit': 7}

cheats_list = {'+100 health': 1,
               'go to menu': 2}

combat_actions_list = {'attack': 1,
                       'inventory': 2,
                       'enemy description': 3,
                       'run': 4}
inventory_list = {'equip': 1,
                  'quit': 2}
vendor_options = {'buy': 1,
                  'sell': 2,
                  'quit': 3}

citi_names = ['the new camp', 'the orchard', 'junktown', 'the glow', 'los capri', 'zandara', 'roxenfurt']
village_names = ['sandy place', 'old scrapyard', 'cows pen', 'roccoti', 'windhill', 'shady sands', 'trek']
base_names = ['siera tin', 'pudric fort', 'spike fort', 'west fortifications']
other_names = ['sulfur cave', 'deep cave', 'old ranch', 'dirty shack', 'shady shack', 'west gas station']

cities = random.randint(1, 2)
villages = random.randint(3, 5)
bases = random.randint(1, 2)
others = random.randint(3, 5)

newplace = 0

enemyname1 = ['dirty', 'old', 'young', 'hungry', 'fat', 'strong', 'crazy', 'hard']
enemyname2 = ['beggar', 'raider', 'bandit', 'thief', 'scavenger']
sexchoice = ['woman', 'man']
# weapon - name - type - price - min_damage - max_damage
melee_weapons = [['knife', 'melee', 35, 3, 5],
                 ['combat knife', 'melee', 60, 4, 7],
                 ['steel pipe', 'melee', 45, 5, 6],
                 ['crowbar', 'melee', 90, 5, 9],
                 ['baseball bat', 'melee', 120, 6, 8],
                 ['fork', 'melee', 10, 1, 3],
                 ['wooden stick', 'melee', 5, 1, 6]]
# weapon - name - type - bullet_type - magazine_size - price - damage_min - damage_max - number_of_attacks_per_use
range_weapons = [['9mm pistol', 'gun', '9mm bullet', 10, 150, 5, 7, 1],
                 ['9mm sub-machine gun', 'gun', '9mm bullet', 25, 400, 3, 5, 5],
                 ['9mm home-made pistol','gun', '9mm bullet', 5, 80, 2, 7, 1],
                 ['20Ga home-made shotgun', 'gun', '20Ga shell', 1, 230, 10, 20, 1],
                 ['20Ga shotgun', 'gun', '20Ga shell', 2, 950, 15, 30, 1]]
# bullet - name - type - damage_multiplier - piercing_power
bullets = [['9mm bullet', '9mm bullet', 1, 1],
           ['9mm surplus bullet', '9mm bullet', 0.90, 1],
           ['9mm P+ bullet', '9mm bullet', 1, 0.5],
           ['20Ga shell', '20Ga shell', 1, 1]]

armor = {'plain clothes': 0,
         'leather armor': 3,
         'metal armor': 5,
         'combat armor': 7}
main_loop = True
game_loop = False
gameplay_loop = False
cheats = False
player_turn = False
vendor_loop = False
inventory_loop = False
choice = ""
player1 = ""
enemies = []
new_enemy = 0

# COMBAT VARS
turn_list = []


def combat():
    turn_list.append(player1)
    for enemy in player1.current.enemies:
        x = enemy
        turn_list.append(x)
    turn_list.sort(key=lambda z: z.initiative, reverse=True)
    count = 1
    dead_enemies = 0
    while len(turn_list) > 1 and player1 in turn_list:
        clrscreen()
        print
        print "==== TURN ", count, " ===="
        print
        for character in turn_list:
            if character == player1 and player1 in turn_list:
                player1.player_turn = True
                while player1.player_turn is True:
                    print "actions:"
                    print_options(combat_actions_list)
                    choice_1 = raw_input()
                    if choice_1 in combat_actions_list:
                        if choice_1 == 'attack':
                            player1.enemy_desc = True
                            while player1.enemy_desc is True:
                                clrscreen()
                                print "enemies:"
                                print
                                for enemy in player1.current.enemies:
                                    print enemy.name, " - ", "%d|%d" % (enemy.health, enemy.maxhealth)
                                print
                                choice_1 = raw_input()
                                for enemy in player1.current.enemies:
                                    if enemy.name == choice_1:
                                        combat_attack(player1, enemy)
                                        if enemy.health <= 0:
                                            turn_list.remove(enemy)
                                            player1.current.enemies.remove(enemy)
                                            dead_enemies += 1
                                        player1.enemy_desc = False
                                        player1.player_turn = False
                        elif choice_1 == 'inventory':
                            clrscreen()
                            player1.inv()
                            raw_input()
                        elif choice_1 == 'enemy description':
                            clrscreen()
                            print "enemies:"
                            print
                            for player_enemy in player1.current.enemies:
                                print player_enemy.name, " - ", "%d|%d" % (player_enemy.health, player_enemy.maxhealth)
                            print
                            raw_input()
                        elif choice_1 == 'run':
                            clrscreen()
                            player1.player_turn = False
                            for x in turn_list:
                                turn_list.remove(x)
                            print " you are running away from battle"
                            raw_input()
                            break
                        else:
                            clrscreen()
                            pass
            else:
                combat_attack(character, player1)
                if player1.health <= 0:
                    for x in turn_list:
                        turn_list.remove(x)
        count += 1
    clrscreen()
    print " ============= "
    print " Combat ended  "
    print " ============= "
    experience_gained = dead_enemies * 10
    money_gained = dead_enemies * random.randint(2, 9)
    player1.experience += experience_gained
    player1.money += money_gained
    print " experience gained: ", experience_gained, "exp"
    print " money found:       ", money_gained, "$"
    raw_input()


def combat_attack(character_1, character_2):
    # hit chance
    hit_chance = random.randint(1, 20)
    if character_1.weapon.weapon_type == "gun":
        if hit_chance <= (character_1.pre * 2) + 5 - int(character_2.agl / 2):
            clrscreen()
            damage = 0
            for x in range(0, character_1.weapon.attacks):
                cur_damage = int(random.randint(character_1.weapon.min_damage, character_1.weapon.max_damage) - character_2.armor.armor)
                damage += cur_damage
                print character_1.name, " shoots ", character_2.name,\
                    " for ", cur_damage, " points of damage"
                raw_input()
            character_2.health -= int(damage)
            print character_2.name, " health: ", "%d|%d" % (character_2.health, character_2.maxhealth)
            raw_input()
        else:
            clrscreen()
            print character_1.name, " misses"
            raw_input()
    elif character_1.weapon.weapon_type == "melee":
        if hit_chance <= (character_1.agl * 2) + 5 - int(character_2.agl / 2):
            clrscreen()
            damage = 0
            for x in range(0, character_1.weapon.attacks):
                cur_damage = int(random.randint(character_1.weapon.min_damage, character_1.weapon.max_damage) + (character_1.str / 2) - character_2.armor.armor)
                damage += cur_damage
                print character_1.name, " strikes ", character_2.name,\
                    " for ", cur_damage, " points of damage"
                raw_input()
            character_2.health -= damage
            print character_2.name, " health: ", "%d|%d" % (character_2.health, character_2.maxhealth)
            raw_input()
        else:
            clrscreen()
            print character_1.name, " misses"
            raw_input()


def print_options(option_dict):
    print
    for option in sorted(option_dict.items(), key=lambda option_1: option_1[1]):
        print "   ", option[0]
    print


def print_places(places_list):
    print
    places.sort(key=lambda class_object: class_object.size, reverse=True)
    for x in places_list:
        print x.type, " " * (7 - len(x.type)), "- ", x.name


def print_bullets(bullet_list):
    bullets_types = {}
    for x in bullet_list:
        if x.name not in bullets_types:
            bullets_types[x.name] = 1
        else:
            bullets_types[x.name] += 1
    bullet_vendor_list = []
    for key, value in bullets_types.iteritems():
        temp = [key, value]
        bullet_vendor_list.append(temp)
    for x in sorted(bullet_vendor_list):
        print "   ", x[1], " " * (2 - len(str(x[1]))), "-", x[0]


def clrscreen():
    if os.name in ("nt", "dos"):
        os.system('CLS')
    else:
        for position in range(49):
            print ""


def cur():
    print
    print "=" * (10 + len(player1.current.name))
    print "==== %s ====" % player1.current.name
    print "=" * (10 + len(player1.current.name))


def welcome_screen():
    print
    print "You are currently standing in your shack asking yourself different questions about future."
    print "Calculating your chance to live here you finally decided that this is no place where you can live safely."
    print "You decided that you need to move away from here. Problem is that you don't have supplies for it"
    print "After a while you calculated you will need at least 1200 pesters to buy enough supplies to reach"
    print "other safer zone"
    raw_input()


def the_glow_scr():
    print "============ THE GLOW ==============="
    print "====================================="
    print
    print_options(main_menu_list)


def world_gen():
    placesx = []
    for number in range(0, cities):
        new_place = PlaceCity()
        placesx.append(new_place)
    for number in range(0, villages):
        new_place = PlaceVillage()
        placesx.append(new_place)
    for number in range(0, bases):
        new_place = PlaceBase()
        placesx.append(new_place)
    for number in range(0, others):
        new_place = PlaceOther()
        placesx.append(new_place)
    return placesx


def buy(player, merchant):
    choice_buy = raw_input("make a choice:")
    for x in merchant.weapon_list:
        if x.name == choice_buy:
            if player.money < x.price:
                print " to expensive for me - ", x.price, "$", "my money:", player.money
                raw_input()
            else:
                player.inventory.append(x)
                player.money -= x.price
                print x.name, "bought"
                raw_input()


def sell(player, merchant):
    choice_sell = raw_input("make a choice:")
    for x in player.inventory:
        if x.name == choice_sell:
            if merchant.money < x.price:
                print "too expensive for merchant"
                raw_input()
            else:
                merchant.weapon_list.append(x)
                player.inventory.remove(x)
                player.money += x.price
                merchant.money -= x.price
                print x.name, "sold"
                raw_input()


class PlaceCity(object):
    def __init__(self):
        self.name = random.choice(citi_names)
        citi_names.remove(self.name)
        self.vendor = True
        self.type = "city"
        self.size = 5


class PlaceVillage(object):
    def __init__(self):
        self.name = random.choice(village_names)
        village_names.remove(self.name)
        self.enemies_count = random.randint(1, 5)
        self.enemies = []
        self.type = "village"
        for number in range(self.enemies_count):
            new_enemy_1 = Enemy()
            self.enemies.append(new_enemy_1)
        self.size = 2


class PlaceBase(object):
    def __init__(self):
        self.name = random.choice(base_names)
        base_names.remove(self.name)
        self.enemies_count = random.randint(5, 10)
        self.enemies = []
        self.type = "base"
        for number in range(self.enemies_count):
            new_enemy_1 = Enemy()
            self.enemies.append(new_enemy_1)
        self.size = 3


class PlaceOther(object):
    def __init__(self):
        self.name = random.choice(other_names)
        other_names.remove(self.name)
        self.enemies_count = random.randint(0, 4)
        self.enemies = []
        self.type = "other"
        for number in range(self.enemies_count):
            new_enemy_1 = Enemy()
            self.enemies.append(new_enemy_1)
        self.size = 1


class Weapon(object):
    def __init__(self, weapon_name, weapon_damage, weapon_type):
        self.name = weapon_name
        self.damage = weapon_damage
        self.weapon_type = weapon_type


class WeaponRange(object):
    def __init__(self, name, weapon_type, bullet_type, mag_size, price, min_damage, max_damage, attacks):
        self.name = name
        self.weapon_type = weapon_type
        self.bullet_type = bullet_type
        self.price = price
        self.min_damage = min_damage
        self.max_damage = max_damage
        self.attacks = attacks
        self.mag_size = mag_size
        self.mag_current = []

    def description(self):
        clrscreen()
        print
        print " === ", self.name, "=== "
        print "   ", "type        : ", self.weapon_type
        print "   ", "bullet type : ", self.bullet_type
        print "   ", "mag size    : ", self.mag_size
        print "   ", "damage      : ", "%d x %d-%d" % (self.attacks, self.min_damage, self.max_damage)
        print "   ", "base price  : ", self.price
        print
        raw_input()


class WeaponMelee(object):
    def __init__(self, name, weapon_type, price, min_damage, max_damage):
        self.name = name
        self.price = price
        self.weapon_type = weapon_type
        self.attacks = 1
        self.min_damage = min_damage
        self.max_damage = max_damage

    def description(self):
        clrscreen()
        print
        print " === ", self.name, "=== "
        print "   ", "type        : ", self.weapon_type
        print "   ", "damage      : ", "%d-%d" % (self.min_damage, self.max_damage)
        print "   ", "base price  : ", self.price
        print
        raw_input()


class Armor(object):
    def __init__(self, name, armor_value):
        self.name = name
        self.armor = armor_value


class Bullet(object):
    def __init__(self, name, bullet_type, damage_modifier, piercing_power):
        self.name = name
        self.bullet_type = bullet_type
        self.damage_modifier = damage_modifier
        self.piercing_power = piercing_power


class Player(object):
    def __init__(self):
        self.lvl = 1
        self.experience = 0
        self.name = raw_input("CHARACTER NAME: ")
        clrscreen()
        self.age = raw_input("CHARACTER AGE:  ")
        clrscreen()
        self.sex = raw_input("CHARACTER SEX:  ")
        clrscreen()
        self.str = random.randint(1, 5)
        self.pre = random.randint(1, 5)
        self.end = random.randint(1, 5)
        self.agl = random.randint(1, 5)
        self.initiative = (self.lvl * 5) + self.pre * 5
        # debug self.maxhealth = 10
        self.maxhealth = (self.lvl * 10) + 5 + self.end * 10 + self.str * 5
        self.health = self.maxhealth
        self.current = random.choice(places)
        self.player_turn = False
        self.enemy_desc = False
        self.money = random.randint(300, 500)
        self.weapon = WeaponRange('9mm pistol', 'gun', '9mm bullet', 10, 150, 5, 7, 1)
        self.armor = Armor("plain clothes", 0)
        self.inventory = []

    def desc(self):
        print
        print "================="
        print "  NAME : %s" % self.name
        print "  AGE  : %s" % self.age
        print "  SEX  : %s" % self.sex
        print "-----------------"
        print "  HEALTH    : %d|%d" % (self.health, self.maxhealth)
        print "  STRENGTH  : %s" % self.str
        print "  ENDURANCE : %s" % self.end
        print "  PRECISION : %s" % self.pre
        print "  AGILITY   : %s" % self.agl
        print "================="
        print "  EXPERIENCE: %dexp" % self.experience
        print "  LEVEL     : %d" % self.lvl

    def inv(self):
        print
        print "================="
        print "   WEAPON : ", self.weapon.name
        print "   ARMOR  : ", self.armor.name
        print "-----------------"
        print "inventory:"
        if len(self.inventory) > 0:
            print
            for item in self.inventory:
                print "   ", item.name
            print
        else:
            print
            print "    EMPTY       "
            print
        print "================="
        print "   MONEY : %d$" % self.money
        print "================="

    def equip(self):
        equip_choice = raw_input("what item ?: ")
        for x in self.inventory:
            if x.name == equip_choice:
                self.inventory.append(self.weapon)
                self.weapon = x
                self.inventory.remove(x)
                return False
            else:
                pass


class Enemy(object):
    def __init__(self):
        self.name = random.choice(enemyname1) + " " + random.choice(enemyname2)
        self.lvl = 1
        self.age = random.randint(20, 40)
        self.sex = random.choice(sexchoice)
        self.str = random.randint(1, 5)
        self.pre = random.randint(1, 5)
        self.end = random.randint(1, 5)
        self.agl = random.randint(1, 5)
        self.initiative = (self.lvl * 5) + self.pre * 5
        self.maxhealth = (self.lvl * 10) + self.end * 10 + self.str * 5
        self.health = self.maxhealth
        self.money = random.randint(1, 50)
        self.weapon = WeaponMelee('knife', 'melee', 35, 3, 5)
        self.armor = Armor('plain clothes', 0)
        self.inventory = [self.weapon, self.armor]

    def desc(self):
        print
        print "================="
        print "  NAME : %s" % self.name
        print "  AGE  : %s" % self.age
        print "  SEX  : %s" % self.sex
        print "-----------------"
        print "  STRENGTH  : %s" % self.str
        print "  ENDURANCE : %s" % self.end
        print "  PRECISION : %s" % self.pre
        print "  AGILITY   : %s" % self.agl
        print "================="
        print

    def inv(self):
        print
        print "================="
        print "   WEAPON : ", self.weapon.name
        print "   ARMOR  : ", self.armor.name
        print "-----------------"
        print "inventory:"
        if len(self.inventory) > 0:
            print
            for item in self.inventory:
                print "   ", item
            print
        else:
            print
            print "    EMPTY       "
            print
        print "================="


class Merchant(object):
    def __init__(self):
        amount_of_weapons = player1.current.size * random.randint(1, 4)
        amount_of_ammo = player1.current.size * random.randint(30, 100)
        amount_of_food = player1.current.size * random.randint(5,10)
        amount_of_drugs = player1.current.size * random.randint(3, 5)
        amount_of_money = player1.current.size * random.randint(100, 500)
        self.name = "zozek"
        self.weapon_list = []
        self.ammo_list = []
        self.food_list = []
        self.drugs_list = []
        self.money = amount_of_money

        for x in range(0, amount_of_ammo):
            bullet = random.choice(bullets)
            self.ammo_list.append(Bullet(bullet[0], bullet[1], bullet[2], bullet[3]))
        for x in range(0, amount_of_weapons):
            cat_choice = random.choice(sexchoice)
            if cat_choice == 'man':
                weapon = random.choice(range_weapons)
                self.weapon_list.append(WeaponRange(weapon[0], weapon[1], weapon[2], weapon[3], weapon[4], weapon[5], weapon[6], weapon[7]))
            else:
                weapon = random.choice(melee_weapons)
                self.weapon_list.append(WeaponMelee(weapon[0], weapon[1], weapon[2], weapon[3], weapon[4]))

    def inventory(self):
        clrscreen()
        print
        print "Hi my name is ", self.name
        print len(self.weapon_list), " weapons"
        print len(self.ammo_list), " bullets"
        print self.money, " money"
        print
        raw_input()

    def print_weapons(self):
        clrscreen()
        weapon_gun_list = []
        weapon_melee_list = []
        for x in self.weapon_list:
            if x.weapon_type == 'gun':
                weapon_gun_list.append(x)
            else:
                weapon_melee_list.append(x)
        weapon_gun_list.sort(key=lambda class_object: class_object.name, reverse=True)
        weapon_melee_list.sort(key=lambda class_object: class_object.name, reverse=True)
        print "=MERCHANT="
        print
        print "===GUNS==="
        for x in weapon_gun_list:
            print "   ", x.name, " - ", "%d$" % x.price, " - ", "%d x %d-%d" % (x.attacks, x.min_damage, x.max_damage)
        print "===MELEE=="
        for x in weapon_melee_list:
            print "   ", x.name, " - ", "%d$" % x.price, " - ", "%d-%d" % (x.min_damage, x.max_damage)
        self.ammo_list.sort(key=lambda class_object: class_object.bullet_type, reverse=True)
        # TODO MAKE BULLETS COUNT
        # variable that will count different types of bullets
        print "=BULLETS="
        print_bullets(self.ammo_list)
        print "=========="
        raw_input()


# MAIN LOOP // MAIN MENU #######################################
# MAIN MENU LOOP START ########################################
while main_loop is True:
    the_glow_scr()
    print
    choice = raw_input()
    clrscreen()
    if choice == 'new game':
        welcome_screen()
        places = world_gen()
        player1 = Player()
        player1.desc()
        print
        raw_input("press any key to continue")
        if 'continue' in main_menu_list:
            game_loop = True
        else:
            main_menu_list['continue'] = 2
            main_menu_list['cheats'] = 3
            game_loop = True
    elif choice == 'continue':
        game_loop = True
    elif choice == 'cheats':
        cheats = True
    elif choice == 'quit':
        clrscreen()
        break
    else:
        print
        clrscreen()
#   MAIN MENU LOOP END ########################################
#   GAME LOOP START  ##########################################
    while game_loop is True:
        if player1.health <= 0:
            clrscreen()
            print " You are dead as fuck"
            raw_input()
            break
        clrscreen()
        cur()
        print_options(game_option_list)
        print
        choice = raw_input()

        if choice in game_option_list:
            if choice == "move":
                clrscreen()
                print "Where :"
                print_places(places)
                print
                choice = raw_input()
                for place in places:
                    if choice == place.name:
                        player1.current = place
                        clrscreen()
            elif choice == "check place":
                clrscreen()
                print "Enemies"
                for enemy_l in player1.current.enemies:
                    print "   ", enemy_l.name, " - ", enemy_l.sex, " ", enemy_l.armor.name, enemy_l.weapon.name
                print
                raw_input()
            elif choice == 'combat':
                if len(player1.current.enemies) > 0:
                    clrscreen()
                    combat()
                else:
                    clrscreen()
                    print " NO ENEMY TO FIGHT"
                    raw_input()
            elif choice == "inventory":
                inventory_loop = True
                while inventory_loop is True:
                    clrscreen()
                    player1.inv()
                    print_options(inventory_list)
                    choice = raw_input()
                    if choice == "equip":
                        player1.inv()
                        player1.equip()
                    elif choice == "quit":
                        inventory_loop = False
                    else:
                        pass
                pass
            elif choice == "player stats":
                clrscreen()
                player1.desc()
                raw_input()
            elif choice == "merchant":
                vendor_loop = True
                while vendor_loop is True:
                    player1.current.vendor = Merchant()
                    player1.current.vendor.inventory()
                    player1.current.vendor.print_weapons()
                    raw_input()
                    print
                    print_options(vendor_options)
                    choice = raw_input()
                    if choice == "quit":
                        vendor_loop = False
                    elif choice == "buy":
                        buy(player1, player1.current.vendor)
                    elif choice == "sell":
                        sell(player1, player1.current.vendor)
                    else:
                        pass
            elif choice == "quit":
                game_loop = False
                clrscreen()
            else:
                clrscreen()
        else:
            clrscreen()
#   GAME LOOP END #################################################
#   CHEATS LOOP
    while cheats is True:
        clrscreen()
        print_options(cheats_list)
        print
        choice = raw_input()
        if choice == '+100 health':
            player1.health += 100
            clrscreen()
        elif choice == 'go to menu':
            cheats = False
        else:
            clrscreen()
#   CHEATS LOOP END ##############################################
 
Last edited:

7h30n

Augur
Joined
Aug 14, 2012
Messages
311
Just a few tips:

You should split your code into multiple files and import them when needed instead of having a single 1000 lines file.

You should avoid global variables. For example you have 'turn_list' declared globally and it is used only in function 'combat'. I see no reason why 'turn_list' couldn't have been declared inside the function. Having a lot of global state will be a nightmare when you try to change things.

You should notice code duplication. When you see yourself writing a lot of same or similiar code try to come up/ask/google for a solution how to reduce that via abstraction (functions, classes, existing functions in Python standard library ...).

For starters I suggest you break up the code into multiple files by their logical functions (e.g. combat stuff should be in combat.py, printing menus and stuff should be in rendering.py etc.).

Oh and congratulations for your first release! That is quite a lot of code for a beginner.

Edit: Have you looked into source version control? (git, svn)
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,804
thanks.

Questions:

Serpating code.
How to devide code into separate files ? and how to import it ? And how this works with compilation ? ( i am using py2exe currently)
What i mean is that i get that i can probably just import combat.py in main part but where do i need to put that file ? In the same folder as main one ?

Version control ?
You mean basically working on task based behavior and writing changelog + saving version of that code ?

eg:
current version is 0.12
today i need to do:
- combat balancing
- adding new type of bullet
- fixing health bug

I do that then i save my work as separate with 0.13 name + changelog.

Code duplication.
Yeah i noticed that and i did used some of methods to shorten my work like clrscr() which helped a lot to clear commandline. If i would continue that code i would probably move all in game menu options to entities so merchants would have merchant stuff and so on which would clear a lot my main loop code.

Golbal vars.
I know. When i started The Glow project i didn't really think about global vars and locals. This is something i learned hard way when i had to rename few variables in code which later lead to some bugs which i had to fix.

Though isn't saving really depend on them ? I mean with it i can "store" data where in local case after function is done that data is lost and i can't later for example use it for saving purpose. Making turn_list global should theoretically help later to implement saving in battle (hate that shit personally)


-----
-----

Update on goal4. I am trying to figure out kiwi instalation. Shit is rough when you want to include it as standard library intead of some additional app or something like that. If everything goes right i will start my goal4 tommorow which should be moving some of my older work to GUI instead of CMD. Since most of those stuff was short it shouldn't take long. Goal5 probably will be moving The Glow to GUI after i will earn experience in g4
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,804

Niektory

one of some
Patron
Joined
Mar 15, 2005
Messages
808
Location
the great potato in the sky
Serpating code.
How to devide code into separate files ? and how to import it ? And how this works with compilation ? ( i am using py2exe currently)
What i mean is that i get that i can probably just import combat.py in main part but where do i need to put that file ? In the same folder as main one ?
Just put your class/function/whatever definitions in a separate file. No special syntax needed. Then you can import it the same way as from the built-in modules (import combat if your module file is combat.py). The simplest way is to put it in the same folder as the main program.
Here are the details: https://docs.python.org/2/tutorial/modules.html
I haven't used py2exe but I think it will include your additional modules in the exe automatically.
 

7h30n

Augur
Joined
Aug 14, 2012
Messages
311
thanks.
Serpating code.
How to devide code into separate files ? and how to import it ? And how this works with compilation ? ( i am using py2exe currently)
What i mean is that i get that i can probably just import combat.py in main part but where do i need to put that file ? In the same folder as main one ?

Read the above link that Niektory linked thouroughly and with understanding. Ask if you can't understand parts of it.

Version control ?
You mean basically working on task based behavior and writing changelog + saving version of that code ?

Kinda. There are tools for that which are much better than what you have come up. You can easily revert to old version if you accidentaly mess something up.
You can also branch your code if you want to try something new and effectively have multiple different versions of the code. I suggest you look into git or svn. And with git you can host your code on github, bitbucket and the likes for free (publicaly).

Code duplication.
Yeah i noticed that and i did used some of methods to shorten my work like clrscr() which helped a lot to clear commandline. If i would continue that code i would probably move all in game menu options to entities so merchants would have merchant stuff and so on which would clear a lot my main loop code.
That's why I suggest google and standard library - https://docs.python.org/2/library/index.html -become your obligatory reading tools when coding.

Golbal vars.
I know. When i started The Glow project i didn't really think about global vars and locals. This is something i learned hard way when i had to rename few variables in code which later lead to some bugs which i had to fix.

Though isn't saving really depend on them ? I mean with it i can "store" data where in local case after function is done that data is lost and i can't later for example use it for saving purpose. Making turn_list global should theoretically help later to implement saving in battle (hate that shit personally)

Yes and no. What is usually done is the following. You start your game in a function (I'll call it 'main') which has local variables. One of the local variables tracks everything that needs to be saved (and hence loaded), I'll call it 'game manager'. When you save the game and later want to load it that same 'main' function loads the data inside your 'game manager' which tracks your game state and knows how to resume the game.
 

Twiglard

Poland Stronk
Patron
Staff Member
Joined
Aug 6, 2014
Messages
7,205
Location
Poland
Strap Yourselves In Codex Year of the Donut
thanks.
Version control ?
You mean basically working on task based behavior and writing changelog + saving version of that code ?

eg:
current version is 0.12
today i need to do:
- combat balancing
- adding new type of bullet
- fixing health bug

I do that then i save my work as separate with 0.13 name + changelog.

That's not version control.

Modern distributed version control systems like git or Mercurial allow for storing each change separately as a chain of events. If multiple subprojects are worked on, they can be merged as final product.

What NOT to do is to dump day's work as "here's version 0.2". Modern version control frontends like "git cola" allow for picking just lines, not files, as a logical change. Some projects require each in-between change to work by itself, but that's overkill for now.
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,804
Ok i am back to business.
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
GOAL 4 - MAKE IT LOOK LIKE A SHIT (GUI + GRAPHICS)
- create simple game where dude walks on flat ground
- create ui for it
- do some basic math like eating cake give you health
for now that will do.
-----------------------------------------------------------------
-----------------------------------------------------------------

I fiddled with kivy but it has big downside. It don't jive with pygame since it also uses OpenGL as PyGame to do stuff.
So for now i will deal with that in PyGame. So my goal for now is to create simple game and make it "vis

As of version control i noticed PyCharms has something like this. It track each and everyline of code i type and stores it:


iNGX2vxCPyZU9.jpg
 

Goliath

Arcane
Zionist Agent
Joined
Jul 18, 2004
Messages
17,830
You have made amazing progress. I am honestly surprised. If I were you would just use Tk for GUI/graphics though. It is part of the standard Python distribution so no need to install anything extra and it is fast enough for 2D turn-based games + it makes creating GUIs very easy. Another advantage is that if you only use standard Python stuff rolling a stand-alone .exe is much easier too. You know if you want to give your program to other people. Telling them to "first install Pyhton + than install this extension + than this - oh an do not forget to .. etc. etc." is usually a no-go. And trying to make a stand-lone bundle if you use extensions tends to be way trickier.

Here is a Python RPG which uses TK. I am not the author but built the stand-lone Windows binaries many years ago (was easy because of the lack of extensions): http://markdamonhughes.com/Umbra/index.php
starry_night.jpg

altar7.png

Note that the Python source will not work with modern versions of Python. That is one problem when using Python, the language is not standardized so there is no guarantee that the code you write right now will still work in 5 or 10 years.
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,804
I noticed that with Kivy as when i compiled it, it didn't run at all.

help needed:
So i am doing pygame tutorial and some stuff i need to figure yet out but this problem i driving me mad:

self.rect = pygame.rect.Rect((320, 240), self.image.get_size())
this part seems to be not defined. Which is weird as i just retyped it from tutorial (p2.7) where it i think works but for me it doesn't work. I think it is error in tutorial code.

full code:
Code:
__author__ = 'Perkel'


import pygame

class Game(object):
    def main(self, screen):
        clock = pygame.time.Clock()
        image = pygame.image.load('player.png')
        sprites = pygame.sprite.Group()
        self.player = Player(sprites)

        while 1:
            dt = clock.tick(60)
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    return
                if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    return

            sprites.update(dt / 1000.)
            screen.fill((200, 200, 200))
            screen.blit(image, (320, 240))
            sprites.draw(screen)
            pygame.display.flip()

class Player(pygame.sprite.Sprite):
    def __init__(self, *groups):
        super(Player, self).__init__(*groups)
        self.image = pygame.image.load('player.png')
        self.rect = pygame.rect.Rect((320, 240), self.image.get_size())

    def update(self, dt):
        key = pygame.key.get_pressed()
        if key[pygame.K_LEFT]:
            self.rect -= 10 * dt
        if key[pygame.K_RIGHT]:
            self.rect += 10 * dt
        if key[pygame.K_UP]:
            self.rect -= 10 * dt
        if key[pygame.K_DOWN]:
            self.rect += 10 * dt


if __name__ == '__main__':
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    Game().main(screen)

PyGame seems to have good thing for game stuff (clock tik stuff)
Also i learned a bit about inheritence mentioned earlier in this thread. Confusing stuff at start but useful as hell.
 
Last edited:

Twiglard

Poland Stronk
Patron
Staff Member
Joined
Aug 6, 2014
Messages
7,205
Location
Poland
Strap Yourselves In Codex Year of the Donut
Perkel, version control is something that needs to be read about and understood. It might be too soon though given you're just starting.

Consult pygame documentation for which namespace "Rect" class resides in.
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,804
Consult pygame documentation for which namespace "Rect" class resides in.

figured it out. It was error in tutorial it should be pygame.Rect() and in input phase i made an error as i didn't add positon x or y to rect and i did math on nothing.

it should be rect.x and rect.y in input phase.
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,804
weird up and left works but down and right doesn't work. Like it doesn't take -=
 

As an Amazon Associate, rpgcodex.net earns from qualifying purchases.
Back
Top Bottom