How did you start learning?

General FreeBASIC programming questions.
coderJeff
Site Admin
Posts: 3388
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Postby coderJeff » Apr 16, 2010 22:34

I first got in to programming with Atari (600XL) basic. I started off by typing in examples and programs from BYTE magazine. Most of my early learning came from experimentation: changing a few lines of code, and seeing what I could get the computer to do. Two of my "projects" that come to mind are 1) a hot-wheels race clock that would time the start/end and winner of a race using the joystick inputs as start/stop event triggers and 2) an AD&D character generator - the program was too big to fit in 16K of memory so had to be loaded (from tape, no less) in seperate steps (especially the equipment list). When I got a 386 with 1MB of memory, and soon after QB and QC, I was in heaven. Later I took programming in school (at various levels) which helped improve my skills.

Even now, when looking at new programming languages, that is still a first step for me: look at what other people have written (open source is great for that), and use that as a starting point for writing something new.
Dinosaur
Posts: 1362
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Postby Dinosaur » Apr 17, 2010 3:12

Hi all

My original start was in the early seventies, and like JohnB it was with an S100 bus kit,
casette (aah crc errors ) and TV modulator.At the time I was reconditioning old valve instruments,
and one was a B40 radio receiver(the kind with a crystal oven). Morse code really interested me,
so I made a little audio to digital board and connected it to the S100 cpu board.(dont remember how)
Now the challenge was to write a program to translate it.
It took a lot of Z80 asm books and countless months of experimenting, when I finally had a working program.
However, it couldnt diffrentiate between the experienced fast transmitters and the beginners, and I had to
adjust timing each night. Years later I found out that I was breaking the law with the Navy ships logs
that were appearing on my tv screen. (some really saucy stuff)

Some years later, the japanese brought out shop retail scales with Z80's in them, and with necessity being the mother of invention, modified the code to connect 6 of them together.
Now I had the bug for making machines do things that the manufacturer hadnt intended.
By looking over the shoulder of a basic programmer, I realised that it was a lot easier and faster then assembly.
Again lots of books, sample programs and countless hours locked in the cellar with my toys.
I still have all those books today.

I guess the moral of the story is, that if you feel passionate enough about what you are trying to achieve, then to learn programming, you will beg , borrow steal the info to help you get there.
For me it was always a tool to achieve the end result, it was never programming for programming's sake.

Regards
BasicCoder2
Posts: 3614
Joined: Jan 01, 2009 7:03
Location: Australia

Re: How did you start learning?

Postby BasicCoder2 » Apr 17, 2010 14:43

dchapman wrote:Thanks for stopping by the thread guys, I appreciate it.

BasicCoder2 wrote:From your second last thread I see you are interested in
programming some kind of game?
What have you done so far?

JohnC


Yes, the impetus for me wanting to learn programming is to program a game. Specifically, the end goal is to recreate (as best as I can) the experience of playing a table-top RPG. In this case, I'm leaning towards basing it on the first edition of Advanced Dungeons and Dragons (TSR).
~David


This is just a bare bones program I whipped up tonight which
is meant to be a simple as possible example of an RPG game.

I haven't added text because that would require adding some
characters to talk to and some text processing which would
make the program much larger but it can be added later.

You move the player, represented by the o character, using
the cursor keys. You interact with the objects by trying to
move onto them. I only have three objects and they are very
simple to keep the program small.

m monster (kill with bullet by moving onto monster if you
have no bullets your health will drop toward zero).

b bullet (pick up by moving onto it to add to inventory)

h health token (pick up by moving onto it)

X exit to another world (not implemented yet)

JohnC

Code: Select all


screenres 640,480,32

dim as integer world(50,50)   'world map
dim as string  s        'used in reading world data
dim as integer dx,dy    'change in position
dim as string  key      'keyboard character
dim as integer k        'asc of string key
dim as integer bground  'saved back ground
dim as integer object   'asc code of object

type PlayerType
    px as integer
    py as integer
    health as integer
    bullets as integer
end type

dim player as PlayerType

'INTIALIZE DATA

player.px = 25
player.py = 25
player.health = 10
player.bullets = 0

'read world data
for y as integer = 0 to 49
    read s
    for x as integer = 0 to 49
        world(x,y) = asc(mid(s,x+1,1))
    next x
next y

bground = world(player.px,player.py)  'save background
world(player.px,player.py) = asc("O") 'insert character

' MAIN LOOP

do
    'display world
    locate 1,1
    for y as integer = 0 to 49
        for x as integer = 0 to 49
            print chr(world(x,y));
        next x
        print
    next y
   
    'print player inventory
    locate 55,1
    print "health =";player.health;"          "
    print "bullets =";player.bullets;"          "

    key = INKEY$   'get asc key
    dx = 0         'zero change in direction
    dy = 0
    'is it a cursor key?
    IF LEN(key) = 2 THEN
        k = ASC(MID$(key, 2))
        IF k = 80 THEN dy = +1  'SOUTH
        IF k = 72 THEN dy = -1  'NORTH
        IF k = 77 THEN dx = +1  'EAST
        IF k = 75 THEN dx = -1  'WEST
     END IF
     
    'have we moved?
    if (dx<>0 or dy<>0) then
        'clear line to print identification of object
        locate 52,1
        print "Player coodinates x =";player.px;" y=";player.py;"                             "
        'IF hit we have hit obstacle THEN identify ELSE move character
        if (world(player.px+dx,player.py+dy)<>asc(".")) then
            object = world(player.px+dx,player.py+dy)
            if object = asc("m") then
                if player.bullets > 0 then
                    player.bullets = player.bullets - 1
                    world(player.px+dx,player.py+dy)=asc(".") 'kill monster
                else                   
                    player.health = player.health - 1
                end if
            end if
            if object = asc("h") then
                player.health = player.health + 1
                world(player.px+dx,player.py+dy)=asc(".") 'remove health token
            end if
            if object = asc("b") then
                player.bullets = player.bullets + 1
                world(player.px+dx,player.py+dy)=asc(".") 'remove bullet
            end if
            if object = asc("X") then
                locate 52,1
                print "THIS IS AN EXIT TO ANOTHER LEVEL"
            end if
            if object = asc("#") then
                locate 52,1
                print "THIS IS A WALL                  "
            end if
        else
            'restore background erasing character
            world(player.px,player.py) = bground
            'update character position
            player.px = player.px + dx
            player.py = player.py + dy
            bground = world(player.px,player.py)  'save background
            world(player.px,player.py)=asc("O")   'insert character
        end if
    end if
    'hit ESC key to exit loop
loop until multikey(&H01) or player.health = 0

end

'    00000000001111111111222222222233333333334444444444
'    01234567890123456789012345678901234567890123456789
DATA "##################################################" '00
DATA "#........................#.......................#" '01
DATA "#...X....................#.......b...............#" '02
DATA "#.......m........b.......#..................m....#" '03
DATA "#........................#...........m...........#" '04
DATA "#........................#.......................#" '05
DATA "#...h....#################################.......#" '06
DATA "#........#...............................#.......#" '07
DATA "#........#...............h...............#.......#" '08
DATA "#........#...............................#.......#" '09
DATA "#...............#......#...#......#..............#" '10
DATA "#...........m...#......#...#......#..............#" '11
DATA "#...............#...m..#...#......#..............#" '12
DATA "#...b....########......#...#......########...b...#" '13
DATA "#........#......#......#...#......#......#.......#" '14
DATA "#........#...X..#......#...#......#..X...#.......#" '15
DATA "#........#......########...########......#.......#" '16
DATA "#.m......#...............................#...m...#" '17
DATA "#........#...b...........h..........b....#.......#" '18
DATA "#........#...............................#.......#" '19
DATA "##########...###########...###########...#########" '20
DATA "#......................#...#.....................#" '21
DATA "#.......h..............#...#.............p.......#" '22
DATA "#..............m.......#...#.....h...............#" '23
DATA "#...#..................#...#.................#...#" '24
DATA "#...#....#...###########...###########...#...#...#" '25
DATA "#...#....#...#.......................#...#...#...#" '26
DATA "#...#....#...#....b......m.......b...#...#...#...#" '27
DATA "#...#....#...#.......................#...#...#...#" '28
DATA "#...#....#...#########################...#...#...#" '29
DATA "#...#....#...............#...............#...#...#" '30
DATA "#...#....#....b..........#.......b.......#...#...#" '31
DATA "#...#....#...............#...............#...#...#" '32
DATA "#...#....#################################...#...#" '33
DATA "#...#................#...#...#...............#...#" '34
DATA "#...#...h............#...#...#......h........#...#" '35
DATA "#...#................#...#...#...............#...#" '36
DATA "#...##############...#...#...#...#############...#" '37
DATA "#...#................#.......#...............#...#" '38
DATA "#...#...m............#...h...#..m............#...#" '39
DATA "#...#................#.......#...............#...#" '40
DATA "#...#...##############...#...#############...#...#" '41
DATA "#...#................#...#...#...............#...#" '42
DATA "#...#......b.........#...#...#...............#...#" '43
DATA "#...#................#...#...#......b........#...#" '44
DATA "#...#................#...#...#...............#...#" '45
DATA "#.......b................#.......................#" '46
DATA "#.h......................#.....h........m.....b..#" '47
DATA "#....m...................#.......................#" '48
DATA "##################################################" '49

dchapman
Posts: 19
Joined: Apr 01, 2010 9:44
Location: Dallas Texas

Postby dchapman » Apr 17, 2010 20:06

BasicCoder2

Wow, that's neat. Haven't looked through the code just yet, just ran it, but thanks this might be a great starting point for me.

~David
BasicCoder2
Posts: 3614
Joined: Jan 01, 2009 7:03
Location: Australia

Postby BasicCoder2 » Apr 18, 2010 0:22

dchapman wrote:BasicCoder2

Wow, that's neat. Haven't looked through the code just yet, just ran it, but thanks this might be a great starting point for me.

~David


Your game cannot be Dungeons and Dragons as that would be
copy write. I haven't actually played the game so I am at
some disadvantage knowing exactly the kind of game you want
to write while learning some programming. I will spend some
time learning about D&D to get a feel for what it is you
are interested in. At this stage I am interested enough
to work on the project myself and share programming ideas.

In this incarnation you can see I have moved most of the
code outside the main loop into subroutines (modules)
making it easier to read. I have also enhanced the draw
player module to show the direction of the player. In a
better graphics display the string characters would be
replaced with "printing" sprites (images). The next step
would be to represent the objects as types and initialize
them at the start of the program.

Notice at the start we now have global (shared) variables
that are visible inside the modules. It is best to keep
the number of global variables to a minimum.

JohnC

Code: Select all

screenres 640,480,32

'global variables
dim shared world(50,50) as integer   'world map
dim shared bground as integer 'saved back ground

type PlayerType
    px as integer  'position of player
    py as integer
    dx as integer  'direction of player
    dy as integer
    direction as string  'north,south,east or west
    health as integer
    bullets as integer
end type

dim shared player as PlayerType

'ROUTINES
sub displayWorld()
    locate 1,1
    for y as integer = 0 to 49
        for x as integer = 0 to 49
            print chr(world(x,y));
        next x
        print
    next y
end sub

sub printInventory()
    locate 55,1  'move cursor to row 55, column 1
    print "PLAYER INVENTORY:"
    print "health  =";player.health;"          "
    print "bullets =";player.bullets;"          "
end sub

sub drawPlayer()
    bground = world(player.px,player.py)  'save background
    if player.direction = "west" then
        world(player.px,player.py) = asc("<") 'insert character
    else
        if player.direction = "north" then
            world(player.px,player.py) = asc("^") 'insert character
        else
            if player.direction = "east" then
                world(player.px,player.py) = asc(">") 'insert character
            else
                if player.direction = "south" then
                    world(player.px,player.py) = asc("V") 'insert character
                end if
            end if
        end if
    end if
end sub

sub getMove()
    dim as string key
    dim as integer k
    key = INKEY$   'get asc key
    player.dx = 0  'stop player
    player.dy = 0   
    'is it a cursor key?
    if LEN(key) = 2 then
        k = ASC(MID$(key, 2))
        IF k = 80 then
            player.dy = +1  'SOUTH
            player.direction = "south"
        end if
       
        if k = 72 then
            player.dy = -1
            player.direction = "north"
        end if
       
        if k = 77 then
            player.dx = +1
            player.direction = "east"
        end if
       
       
        if k = 75 then
            player.dx = -1
            player.direction = "west"
        end if
       
    end if
end sub
 
sub hitObject()
    dim as integer object
    object = world(player.px+player.dx,player.py+player.dy)
    if object = asc("m") then
        if player.bullets > 0 then
            player.bullets = player.bullets - 1
            world(player.px+player.dx,player.py+player.dy)=asc(".") 'kill monster
        else                   
            player.health = player.health - 1
        end if
    end if
    if object = asc("h") then
        player.health = player.health + 1
        world(player.px+player.dx,player.py+player.dy)=asc(".") 'remove health token
    end if
    if object = asc("b") then
        player.bullets = player.bullets + 1
        world(player.px+player.dx,player.py+player.dy)=asc(".") 'remove bullet
    end if
    if object = asc("X") then
        locate 52,1
        print "THIS IS AN EXIT TO ANOTHER LEVEL"
    end if
    if object = asc("#") then
        locate 52,1
        print "THIS IS A WALL                  "
    end if
end sub

sub movePlayer()
    'restore background erasing character
    world(player.px,player.py) = bground
    'update character position
    player.px = player.px + player.dx
    player.py = player.py + player.dy
    drawPlayer()
end sub

sub readWorldData()
    dim as string  s
    for y as integer = 0 to 49
        read s
        for x as integer = 0 to 49
            world(x,y) = asc(mid(s,x+1,1))
        next x
    next y
end sub

'INTIALIZE DATA

readWorldData()

player.px = 25
player.py = 25
player.health = 10
player.bullets = 0
player.direction = "south"


'initalize player position in world
drawPlayer()

' MAIN LOOP

do
    displayWorld()
    printInventory()
    getMove()   
    'have we moved?
    if (player.dx<>0 or player.dy<>0) then
        if (world(player.px+player.dx,player.py+player.dy)<>asc(".")) then
            hitObject()
        else
            movePlayer()
        end if
    end if
    'hit ESC key to exit loop
loop until multikey(&H01) or player.health = 0

end

'    00000000001111111111222222222233333333334444444444
'    01234567890123456789012345678901234567890123456789
DATA "##################################################" '00
DATA "#........................#.......................#" '01
DATA "#...X....................#.......b...............#" '02
DATA "#.......m........b.......#..................m....#" '03
DATA "#........................#...........m...........#" '04
DATA "#........................#.......................#" '05
DATA "#...h....#################################.......#" '06
DATA "#........#...............................#.......#" '07
DATA "#........#...............h...............#.......#" '08
DATA "#........#...............................#.......#" '09
DATA "#...............#......#...#......#..............#" '10
DATA "#...........m...#......#...#......#..............#" '11
DATA "#...............#...m..#...#......#..............#" '12
DATA "#...b....########......#...#......########...b...#" '13
DATA "#........#......#......#...#......#......#.......#" '14
DATA "#........#...X..#......#...#......#..X...#.......#" '15
DATA "#........#......########...########......#.......#" '16
DATA "#.m......#...............................#...m...#" '17
DATA "#........#...b...........h..........b....#.......#" '18
DATA "#........#...............................#.......#" '19
DATA "##########...###########...###########...#########" '20
DATA "#......................#...#.....................#" '21
DATA "#.......h..............#...#.............p.......#" '22
DATA "#..............m.......#...#.....h...............#" '23
DATA "#...#..................#...#.................#...#" '24
DATA "#...#....#...###########...###########...#...#...#" '25
DATA "#...#....#...#.......................#...#...#...#" '26
DATA "#...#....#...#....b......m.......b...#...#...#...#" '27
DATA "#...#....#...#.......................#...#...#...#" '28
DATA "#...#....#...#########################...#...#...#" '29
DATA "#...#....#...............#...............#...#...#" '30
DATA "#...#....#....b..........#.......b.......#...#...#" '31
DATA "#...#....#...............#...............#...#...#" '32
DATA "#...#....#################################...#...#" '33
DATA "#...#................#...#...#...............#...#" '34
DATA "#...#...h............#...#...#......h........#...#" '35
DATA "#...#................#...#...#...............#...#" '36
DATA "#...##############...#...#...#...#############...#" '37
DATA "#...#................#.......#...............#...#" '38
DATA "#...#...m............#...h...#..m............#...#" '39
DATA "#...#................#.......#...............#...#" '40
DATA "#...#...##############...#...#############...#...#" '41
DATA "#...#................#...#...#...............#...#" '42
DATA "#...#......b.........#...#...#...............#...#" '43
DATA "#...#................#...#...#......b........#...#" '44
DATA "#...#................#...#...#...............#...#" '45
DATA "#.......b................#.......................#" '46
DATA "#.h......................#.....h........m.....b..#" '47
DATA "#....m...................#.......................#" '48
DATA "##################################################" '49

anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Postby anonymous1337 » Apr 18, 2010 3:51

Your game cannot be Dungeons and Dragons as that would be
copy write.
So long as copywrited material isn't heavily distributed, problems seldom arise. Second, if it's not for profit, request for removals are more common than court orders, and those more common than lawsuits. Third, I'm not sure how heavily protected D&D is or what its owner's policy is on "protecting" "assets".

Not to be rude, but D&D's Open Game License seems to permit third-party development.
BasicCoder2
Posts: 3614
Joined: Jan 01, 2009 7:03
Location: Australia

text only role playing game

Postby BasicCoder2 » Apr 18, 2010 20:31

Thinking about what a pure text game would be I
reduced it to a set of locations, each with a
description of the location and its contents,
and a set of actions that could be taken to
change the state or existence of those contents,
or pick up objects or exit the location.

I have kept the descriptions short and shown
how an action can change the description
(e.g. chest open, chest closed) change the
player's description (hair red to green),
state of objects (troll alive or dead).

The example is called spaghetti coding but the
goto's are kind of intuitive in this case.
However the code can be greatly improved with
OOP like techniques which I may work on later.
I was just trying to get an idea of what the
generic framework of a text based role playing
game would be.


JohnC

Code: Select all

'Simple text based world game


dim as integer action_select
dim as integer icount 'number of items in inventory

dim as string hair_color
hair_color = "red"
dim as string troll
troll = "alive"
dim as string chest
chest = "closed"
dim as string chest_contents
chest_contents = "sword"
dim as string passage_content
passage_content = "vase"
dim as string mountain_content
mountain_content = "cup of mountain dew"
dim as string inventory(10) 'up to 10 items

sub printWorld()
   print
   print " --------  west  east ----------- "
   print "| Forest |  W <--> E | Mountains |"
   print " --------             ----------- "
   print "  N ^                     ^ north"
   print "    |                     |"
   print "  S v                     v south"
   print " --------             -----------"
   print "| Cavern |  W <--> E |Passageway |"
   print " --------             -----------"
   print
end sub

Cavern:
   printWorld()
   'print description
   print "You are standing in a large cavern."
   if chest = "open" then
      print "Chest contains ";chest_contents
   else
      print "There is a large closed chest"
   end if

   'print possible actions
   print "[0] exit game"
   if chest = "open" then
      print "[1] close chest"
   else
      print "[1] open chest"
   end if
   
   print "[2] exit north"
   print "[3] exit east"
   if chest_contents <> "nothing" and chest = "open" then
      print "[4] take ";chest_contents;" out of chest"
   end if

   input action_select

   'carry out selected action
   if action_select = 2 then GOTO Forest
   if action_select = 3 then GOTO Passageway
   if action_select = 4 then
       inventory(icount) = "sword"
       icount = icount + 1
       chest_contents = "nothing"
   end if
   
   if action_select = 1 then
      if chest = "open" then
         chest = "closed"
      else
         chest = "open"
      end if
   end if
   if action_select = 0 then end
   goto Cavern


Passageway:
   printWorld()
   'print description
   print "You are in a long passage"
   print "There is "; passage_content; " in the passage"
   
   'print possible actions
   print "[0] exit game"
   print "[1] exit north"
   print "[2] exit west"
   if passage_content <> "nothing" then
       print "[3] pick up ";passage_content
   end if
   
   input action_select

   'carry out selected action
   if action_select = 1 then goto Mountains
   if action_select = 2 then goto Cavern
   if action_select = 0 then end
   if action_select = 3 then
       inventory(icount) = passage_content
       icount = icount + 1
       passage_content = "nothing"
   end if
   
   goto Passageway

Forest:
   printWorld()
   'print description
   print "You are in a Forest"
   if troll = "alive" then
      print "Savage troll"
  else
      print "Dead troll"
   end if

   'print possible actions
   print "[0] exit game"
   print "[1] exit south"
   print "[2] exit east"
   if troll = "alive" then
      print "[3] kill troll"
      troll = "dead"
   end if

   input action_select

   'carry out selected action
   if action_select = 2 then goto Mountains
   if action_select = 1 then goto Cavern
   if action_select = 3 then troll = "dead"
   if action_select = 0 then end
   goto Forest


Mountains:
   printWorld()
   'print description
   print "You are in the mountains"
   
   'print possible actions
   print "[0] exit game"
   print "[1] exit west"
   print "[2] exit south"
   if mountain_content <> "nothing" then
       print "[3] drink ";mountain_content
   end if
   
   input action_select

   'carry out action
   if action_select = 0 then end
   if action_select = 1 then goto Forest
   if action_select = 2 then goto Passageway
   if action_select = 3 then
       mountain_content = "nothing"
       hair_color = "green"
   end if
   
   goto Mountains

Return to “General”

Who is online

Users browsing this forum: No registered users and 15 guests