News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Fight simulation perfected - for now.

Started by Pagan Slim, June 14, 2010, 05:37:44 AM

Previous topic - Next topic

Pagan Slim

I think I have this thing perfected.  It needs polished but at least it works like I wanted.  :P  


PlayBASIC Code: [Select]
; PROJECT : PERFECT FIGHT ROUTINE
; AUTHOR : Pagan Slim
; CREATED : 6/13/2010
; EDITED : 6/13/2010
; ---------------------------------------------------------------------

;combat routine
CLS
;Initialize AND Randomize
;create stats


NPC_HITPOINTS = RNDRANGE (2,12)

HITPOINTS = RNDRANGE (3,12);WEIGHTED IN MY FAVOR.

PRINT "HIT POINTS " + Str$(HITPOINTS)

PRINT " "
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)

PRINT " "
sync
WAIT 3000

;Game Loop
DO
;Initiative:
;who's first
COINTOSS=RND (120)

PRINT "* INITIATIVE * " + Str$(COINTOSS)
PRINT " "
SYNC
IF COINTOSS>60
GOSUB MEFIRST:
ELSE
GOSUB NPCFIRST
ENDIF
LOOP


;npcfirst
NPCFIRST:
;attack (is it successful)
ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
HITPOINTS=HITPOINTS-ATTACK
;adjust health
;report results
PRINT "HIT POINTS " + Str$(HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_dead
IF HITPOINTS<1
PRINT "You're DEAD!"
PRINT " "
SYNC
WAIT 3000
ENDIF
IF HITPOINTS<1
GOSUB THE_END
ENDIF
RETURN


;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_NPC_dead
IF NPC_HITPOINTS<1
PRINT "NPC DEAD!"
PRINT " "
SYNC
WAIT 3000
ENDIF
IF NPC_HITPOINTS<1
GOSUB THE_END
ENDIF
RETURN


;TERMINATE THE GAME
;Obituary or Celebration
THE_END:
PRINT "It is over for now. The End."
PRINT " "
SYNC
WAIT 2000
END
RETURN









kevin

#1
 i'm glad you're showing progress, but please don't start a new thread for each related post.  

Pagan Slim

I knew I'd screw something up.  Sorry.

Pagan Slim

#3
This is several guys fighting.  It works.  I used a loop to create 1 to 5 npc's.


PlayBASIC Code: [Select]
; PROJECT : SEVERAL GUYS FIGHT
; AUTHOR : Pagan Slim
; CREATED : 6/13/2010
; EDITED : 6/13/2010
; ---------------------------------------------------------------------

;combat routine
CLS
;Initialize AND Randomize
;create stats

;Number of NPC's that you will fight.
NUM_GUYS = RND (5)

NPC_HITPOINTS = RNDRANGE (2,10)

HITPOINTS = RNDRANGE (2,10)

PRINT "HIT POINTS " + Str$(HITPOINTS)
PRINT " "
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
sync
WAIT 3000

;Game Loop
DO
;Initiative:
;who's first
COINTOSS=RND (120)

PRINT "* INITIATIVE * " + Str$(COINTOSS)
PRINT " "
SYNC
IF COINTOSS>60
GOSUB MEFIRST:
ELSE
GOSUB NPCFIRST
ENDIF
LOOP


;npcfirst
NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
FOR N = 1 TO NUM_GUYS
ATTACK=RNDRANGE (1,8)
PRINT "Guy Number " + Str$(N)
sync
;damage (HEALTH-ATTACK)
HITPOINTS=HITPOINTS-ATTACK
;adjust health
;report results
PRINT "HIT POINTS " + Str$(HITPOINTS)
PRINT " "
SYNC
WAIT 2000

NEXT

;if_dead
IF HITPOINTS<1
PRINT "You're DEAD!"
PRINT " "
SYNC
WAIT 3000
ENDIF
IF HITPOINTS<1
GOSUB THE_END
ENDIF
RETURN


;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_NPC_dead
IF NPC_HITPOINTS<1
PRINT "NPC DEAD!"
PRINT " "
SYNC
WAIT 3000
ENDIF
IF NPC_HITPOINTS<1
GOSUB THE_END
ENDIF
RETURN


;TERMINATE THE GAME
;Obituary or Celebration
THE_END:
PRINT "DEATH IS ALWAYS THE ONLY VICTOR."
PRINT " "
SYNC
WAITKEY
END
RETURN





  EDIT: use CODE in square brackets when showing code




Pagan Slim

#4
Super Improved.  Now dead NPC's are properly disposed of.  I need to figure out how to make the text either scroll when the screen is filled or something.  A long fight going to the bottom of the screen stops and does not allow me to see the conclusion.  This is how I learn - by finding new obstacles to overcome.

PlayBASIC Code: [Select]
; PROJECT : 3 GUYS FIGHT 2
; AUTHOR : Pagan Slim
; CREATED : 6/13/2010
; EDITED : 6/15/2010
; ---------------------------------------------------------------------

;combat routine
CLS
;Initialize AND Randomize
;create stats

;Number of NPC's that you will fight.
NUM_GUYS = RND (5)+ 1


NPC_HITPOINTS = RNDRANGE (2,10)

HITPOINTS = RNDRANGE (7,18);ADJUSTED TO EQUAL THE ODDS.

PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
sync
WAIT 3000

;Game Loop
DO
;Initiative:
;who's first
COINTOSS=RND (120)

PRINT "* INITIATIVE * " + Str$(COINTOSS)
PRINT " "
SYNC

PRINT "Number of NPCs " + Str$(NUM_GUYS)
print " "
SYNC

IF COINTOSS>60
PRINT "The initiative is yours."
ELSE
PRINT "NPC(S) has initiative."
ENDIF



IF COINTOSS>60
GOSUB MEFIRST:
ELSE
GOSUB NPCFIRST
ENDIF
LOOP


;npcfirst
NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
FOR N = 1 TO NUM_GUYS
ATTACK=RNDRANGE (1,8)
PRINT "NPC Number " + Str$(N)
sync
;damage (HEALTH-ATTACK)
HITPOINTS=HITPOINTS-ATTACK
;adjust health
;report results
PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
SYNC
WAIT 2000

;if_dead
IF HITPOINTS<1
PRINT "You're DEAD!"
PRINT " "
SYNC
WAIT 3000
ENDIF
IF HITPOINTS<1
GOSUB THE_END
ENDIF
RETURN

NEXT




;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_NPC_dead - GET RID OF HIM...
IF NPC_HITPOINTS < 1 THEN NUM_GUYS = NUM_GUYS - 1
IF NPC_HITPOINTS < 1
PRINT "ONE NPC DEAD!"
PRINT " "
SYNC
WAIT 3000
ENDIF

;When last npc is dead game over...
IF NUM_GUYS < 1
PRINT "You win."
ENDIF

IF NUM_GUYS < 1
GOSUB THE_END
ENDIF
RETURN


;TERMINATE THE GAME
;Obituary or Celebration
THE_END:
PRINT "DEATH IS ALWAYS THE ONLY VICTOR."
PRINT " "
SYNC
WAITKEY
END
RETURN








Pagan Slim

#5
This is the last post on this thread until I get the screen thing and arrays worked out.  I know I can make this awesome someday and apply it to a real game.  This one is this best up to this point.

PlayBASIC Code: [Select]
; PROJECT : Gangbang FIGHT 01
; AUTHOR : Pagan Slim
; CREATED : 6/13/2010
; EDITED : 6/15/2010
; ---------------------------------------------------------------------

;combat routine
CLS
;Initialize AND Randomize
;create stats

;Number of NPC's that you will fight.
NUM_GUYS = RND (5)+ 1


NPC_HITPOINTS = RNDRANGE (2,10)

HITPOINTS = RNDRANGE (7,18);ADJUSTED TO EQUAL THE ODDS.

PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
sync
WAIT 3000

;Game Loop
DO
;Initiative:
;who's first
COINTOSS=RND (120)

;PRINT "* INITIATIVE * " + Str$(COINTOSS)
;PRINT " "
;SYNC

PRINT "Number of NPCs " + Str$(NUM_GUYS)
print " "
SYNC

IF COINTOSS>60
PRINT "The initiative is yours."
PRINT " "
ELSE
PRINT "NPC(s) has initiative."
PRINT " "
ENDIF



IF COINTOSS>60
GOSUB MEFIRST:
ELSE
GOSUB NPCFIRST
ENDIF
LOOP


;npcfirst
NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
FOR N = 1 TO NUM_GUYS
ATTACK = RNDRANGE (1,6)+1
Print "NPC Number " + Str$(N)+" attacks you!"
PRINT " "
sync
;damage (HEALTH-ATTACK)
HITPOINTS=HITPOINTS-ATTACK
;adjust health
;report results
PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
SYNC
WAIT 2000

;if_dead
IF HITPOINTS<1
PRINT "You're DEAD!"
PRINT " "
SYNC
WAIT 3000
ENDIF
IF HITPOINTS<1
GOSUB THE_END
ENDIF
NEXT

RETURN






;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_NPC_dead - GET RID OF HIM...
IF NPC_HITPOINTS < 1 THEN NUM_GUYS = NUM_GUYS - 1
IF NPC_HITPOINTS < 1
PRINT "ONE NPC DEAD!"
PRINT " "
SYNC
WAIT 3000
ENDIF

;When last npc is dead game over...
IF NUM_GUYS < 1
PRINT "You win."
ENDIF

IF NUM_GUYS < 1
GOSUB THE_END
ENDIF
RETURN


;TERMINATE THE GAME
;Obituary or Celebration
THE_END:
PRINT "It's over boys."
PRINT " "
SYNC
WAITKEY
END
RETURN








Pagan Slim

#6
I repaired the screen problem and improved the combat.  So I lied about the last post on this topic.


PlayBASIC Code: [Select]
; PROJECT : GangFIGHT 01
; AUTHOR : Pagan Slim
; CREATED : 6/13/2010
; EDITED : 6/15/2010
; ---------------------------------------------------------------------

;combat routine
CLS
;Initialize AND Randomize
;create stats

;Number of NPC's that you will fight.
NUM_GUYS = RND (5)+ 1


NPC_HITPOINTS = RNDRANGE (2,10)

HITPOINTS = RNDRANGE (7,18);ADJUSTED TO EQUAL THE ODDS.

PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
sync
WAIT 3000

;Game Loop
DO
;Initiative:
;who's first
COINTOSS=RND (120)

;PRINT "* INITIATIVE * " + Str$(COINTOSS)
;PRINT " "
;SYNC

PRINT "Number of NPCs " + Str$(NUM_GUYS)
print " "
SYNC

IF COINTOSS>60
PRINT "The initiative is yours."
PRINT " "
ELSE
PRINT "NPC(s) has initiative."
PRINT " "
ENDIF



IF COINTOSS>60
GOSUB MEFIRST:
ELSE
GOSUB NPCFIRST
ENDIF

PRINT "Press a key to go on."
PRINT " "
SYNC
WAITKEY
CLS
LOOP


;npcfirst
NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
FOR N = 1 TO NUM_GUYS
ATTACK = RNDRANGE (1,6)+1
Print "NPC Number " + Str$(N)+" attacks you!"
PRINT " "
sync
;damage (HEALTH-ATTACK)
HITPOINTS=HITPOINTS-ATTACK
;adjust health
;report results
PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
SYNC
WAIT 2000

;if_dead
IF HITPOINTS<1
PRINT "You're DEAD!"
PRINT " "
SYNC
WAIT 3000
ENDIF
IF HITPOINTS<1
GOSUB THE_END
ENDIF
NEXT

RETURN






;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_NPC_dead - GET RID OF HIM...
IF NPC_HITPOINTS < 1 THEN NUM_GUYS = NUM_GUYS - 1
IF NPC_HITPOINTS < 1
PRINT "ONE NPC DEAD!"
PRINT " "
SYNC
WAIT 3000
ENDIF

;When last npc is dead game over...
IF NUM_GUYS < 1
PRINT "You win."
ENDIF

IF NUM_GUYS < 1
GOSUB THE_END
ENDIF
RETURN


;TERMINATE THE GAME
;Obituary or Celebration
THE_END:
PRINT "It's over boys."
PRINT " "
SYNC
WAITKEY
END
RETURN








Pagan Slim

#7
A fight simulation with a gang and the attackers have names.  This is the best thing I've done for a fight simulation yet.  I can see that old game shaping up right now.

PlayBASIC Code: [Select]
; PROJECT : Personalized Gang Fight 01
; AUTHOR : Pagan Slim
; CREATED : 6/13/2010
; EDITED : 6/16/2010
; ---------------------------------------------------------------------
LoadFont "Arial",1,18,0

Setfps 30


;combat routine
CLS
;Initialize AND Randomize
;create stats

;Number of NPC's that you will fight.
NUM_GUYS = RND (5)+ 1


NPC_HITPOINTS = RNDRANGE (2,10)

HITPOINTS = RNDRANGE (7,18);ADJUSTED TO EQUAL THE ODDS.

PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
sync
WAIT 3000

;Game Loop
DO
;Initiative:
;who's first
COINTOSS=RND (120)

;PRINT "* INITIATIVE * " + Str$(COINTOSS)
;PRINT " "
;SYNC

PRINT "Number of NPCs " + Str$(NUM_GUYS)
print " "
SYNC

IF COINTOSS>60
PRINT "The initiative is yours."
PRINT " "
ELSE
PRINT "NPC(s) has initiative."
PRINT " "
ENDIF



IF COINTOSS>60
GOSUB MEFIRST:
ELSE
GOSUB NPCFIRST
ENDIF

PRINT "Press a key to go on."
PRINT " "
SYNC
WAITKEY
CLS ;clear screen for next round of combat.
LOOP


;npcfirst
NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
FOR N = 1 TO NUM_GUYS
IF N = 1
PRINT "Bucktooth Sam Attacks."
ENDIF
IF N = 2
PRINT "Bad Bob Attacks You."
sync
ENDIF
IF N = 3
PRINT "Wicked Wanda Attacks You."
ENDIF
IF N = 4
PRINT "Evil Earl Attacks You."

ENDIF
IF N = 5
PRINT "Hatchet Molly Attacks You."

ENDIF
IF N = 6
PRINT"Deadly Dilford Attacks You."
ENDIF
IF N < 1
PRINT "The Mysterious Glitch attacks You."
PRINT " "
sync
ENDIF
ATTACK = RNDRANGE (1,6)+1
;Print "NPC Number " + Str$(N)+" attacks you!"
PRINT " "
sync
;damage (HEALTH-ATTACK)
HITPOINTS=HITPOINTS-ATTACK
;adjust health
;report results
PRINT "YOUR HIT POINTS " + Str$(HITPOINTS)
PRINT " "
SYNC
WAIT 2000

;if_dead
IF HITPOINTS<1
PRINT "You're DEAD!"
PRINT " "
SYNC
WAIT 3000
ENDIF
IF HITPOINTS<1
GOSUB THE_END
ENDIF
NEXT

RETURN

;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_NPC_dead - GET RID OF HIM...
IF NPC_HITPOINTS < 1 THEN NUM_GUYS = NUM_GUYS - 1
IF NPC_HITPOINTS < 1
PRINT "ONE NPC DEAD!"
PRINT " "
SYNC
WAIT 3000
ENDIF

;When last npc is dead game over...
Login required to view complete source code






Big C.

hey slim,

here are some tips from me...

first:
QuoteIF COINTOSS>60
   PRINT "The initiative is yours."
   PRINT " "
ELSE
   PRINT "NPC(s) has initiative."
   PRINT " "
ENDIF
     
IF COINTOSS>60
   GOSUB MEFIRST:
ELSE
   GOSUB NPCFIRST   
ENDIF

This two if-statements can you merge in one because the condition in both if statements is the same.
If COINTOSS>60
   Print "The initiative is yours."
   Print " "
   Gosub MEFIRST:
Else
   Print "NPC(s) has initiative."
   Print " "
   Gosub NPCFIRST:
EndIf


Second:
QuoteIF N = 1
         PRINT "Bucktooth Sam Attacks."
            ENDIF
      IF N = 2
      PRINT "Bad Bob Attacks You."
      sync
         ENDIF
      IF N = 3
      PRINT "Wicked Wanda Attacks You."
         ENDIF
      IF N = 4
      PRINT "Evil Earl Attacks You."
     
         ENDIF
      IF N = 5
      PRINT "Hatchet Molly Attacks You."
     
         ENDIF
      IF N = 6
      PRINT"Deadly Dilford Attacks You."
      ENDIF
   IF N < 1
      PRINT "The Mysterious Glitch attacks You."   
      PRINT " "
      sync
         ENDIF

Here you can summarize the particulars if-Statements if you use an array. Here another way:

;at the beginning of the code maybe for 'CLS' write this

Dim Guys$(6) ; Array Indexes are zero inclusive. That means 0,1,2, etc .. up to the Number of Elements are valid Indexes

For Guys_Name = 0 to 6 ; 0 will be the 'The Mysterious Glitch'
     Guys$(Guys_Name) = ReadData$()
Next Guys_Name

;this is the optimized piece of code which print the guy who attacks the player

  PRINT Guys$(N)
  Print " "

;write this at the end of your Program
Data "The Mysterious Glitch attacks You.", "Bucktooth Sam Attacks.", "Bad Bob Attacks You.", "Wicked Wanda Attacks You."
Data "Evil Earl Attacks You.", "Hatchet Molly Attacks You.", "The Mysterious Glitch attacks You."


third (the same under first)
Quote;if_dead
IF HITPOINTS<1
   PRINT "You're DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF
IF HITPOINTS<1
   GOSUB THE_END
ENDIF

can change to


IF HITPOINTS<1
   PRINT "You're DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
   Gosub THE_END
ENDIF


Fourth (the same as first)
Quote;if_NPC_dead - GET RID OF HIM...
IF NPC_HITPOINTS < 1 THEN NUM_GUYS = NUM_GUYS - 1
IF NPC_HITPOINTS < 1
   PRINT "ONE NPC DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF

can change to
;if_NPC_dead - GET RID OF HIM...
IF NPC_HITPOINTS < 1
   NUM_GUYS = NUM_GUYS - 1
   PRINT "ONE NPC DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF


fifth (also the same as first)
Quote
;When last npc is dead game over...
IF NUM_GUYS < 1
   PRINT "You win."
ENDIF

IF NUM_GUYS < 1
   GOSUB THE_END
ENDIF

can change to

;When last npc is dead game over...
IF NUM_GUYS < 1
   PRINT "You win."
   Gosub THE_END
ENDIF


Not a tip but a hint
Quote
IF N < 1
      PRINT "The Mysterious Glitch attacks You."   
      PRINT " "
      sync
ENDIF

The Condition N<1 will never reach because your For/Next Loop starts with the following line...

FOR N = 1 TO NUM_GUYS

If you follow the tips then you will get this..


; PROJECT : Personalized Gang Fight 01
; AUTHOR  : Pagan Slim
; CREATED : 6/13/2010
; EDITED  : 6/16/2010
; ---------------------------------------------------------------------
LoadFont "Arial",1,18,0

SetFPS 30

Dim Guys$(6) ; Array Indexes are zero inclusive. That means 0,1,2, etc .. up to the Number of Elements are valid Indexes

For Guys_Name = 0 to 6 ; 0 will be the 'The Mysterious Glitch'
     Guys$(Guys_Name) = ReadData$()
Next Guys_Name
   
;combat routine
Cls
;Initialize AND Randomize
;create stats

;Number of NPC's that you will fight.
NUM_GUYS = Rnd (5)+ 1


NPC_HITPOINTS = RndRange (2,10)

HITPOINTS = RndRange (7,18);ADJUSTED TO EQUAL THE ODDS.

Print "YOUR HIT POINTS " + Str$(HITPOINTS)
Print " "
Print "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
Print " "
Sync
Wait 3000

   ;Game Loop
   Do
;Initiative:
;who's first
COINTOSS=Rnd (120)

;PRINT "* INITIATIVE * " + Str$(COINTOSS)
   ;PRINT " "
   ;SYNC
   
   Print "Number of NPCs " + Str$(NUM_GUYS)
Print " "
Sync

If COINTOSS>60
   Print "The initiative is yours."
   Print " "
   Gosub MEFIRST:
Else
   Print "NPC(s) has initiative."
   Print " "
   Gosub NPCFIRST:
EndIf
     

   
;If COINTOSS>60
   ;Gosub MEFIRST:
;Else
   ;Gosub NPCFIRST   
;EndIf

Print "Press a key to go on."
Print " "
Sync
WaitKey
Cls ;clear screen for next round of combat.
Loop


;npcfirst
NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
For N = 1 To NUM_GUYS
PRINT Guys$(N)
Print " "
  If N < 1
  Print "The Mysterious Glitch attacks You."   
    PRINT " "
      sync
  ENDIF
ATTACK = RNDRANGE (1,6)+1
;Print "NPC Number " + Str$(N)+" attacks you!"
PRINT " "
sync
;damage (HEALTH-ATTACK)
HITPOINTS=HITPOINTS-ATTACK
;adjust health
;report results
Print "YOUR HIT POINTS " + Str$(HITPOINTS)
Print " "
Sync
Wait 2000
;if_dead
If HITPOINTS<1
  Print "You're DEAD!"
  Print " "
  Sync
    Wait 3000
    Gosub THE_END
EndIf

NEXT
   
RETURN

;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RNDRANGE (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
PRINT "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
PRINT " "
SYNC
WAIT 2000
;if_NPC_dead - GET RID OF HIM...
IF NPC_HITPOINTS < 1
NUM_GUYS = NUM_GUYS - 1
   PRINT "ONE NPC DEAD!"
   PRINT " "
   SYNC
   WAIT 3000
ENDIF

;When last npc is dead game over...
IF NUM_GUYS < 1
   PRINT "You win."
   GOSUB THE_END
ENDIF
RETURN


;TERMINATE THE GAME
;Obituary or Celebration
THE_END:
PRINT "It's over boys."
PRINT " "
SYNC
WAITKEY
END
RETURN

;write this at the end of your Program
Data "The Mysterious Glitch attacks You.", "Bucktooth Sam Attacks.", "Bad Bob Attacks You.", "Wicked Wanda Attacks You."
Data "Evil Earl Attacks You.", "Hatchet Molly Attacks You.", "The Mysterious Glitch attacks You."


Big C.

LemonWizard

#9

I don't get on here much, or that often anymore cause I work right now and I've moved around alot.
BUUUUUT


Here's some coding tips for you.

First of all try using functions.. things like kill_npc(npcnumber)
or like.. yeah.. other stuff
you could even create an array to store npc names, and then make the routine name specific based on the current npc number, so later you could refer to it and pull up the name like
[/color
print Npcname$(npcnumber)+" Has died"


I didn't really look at the code but what I'd reccomend is some really good core code that handles specific events. Ie.. is the npc stabbing, how much damage etc. You could really expand on how this engine works..

Also, try npc states.. like "Npc is wandering" etc.. I don't know just throwing ideas out there...

You can pretty much program anything you can imagine and make it as elaborate as you want so long as your willing to write the code for it.

You will only get as much as you put into your programming projects.


and you could even keep an array of how far away each npc is from another one so yeah.. just use your imagination.. and then make them act on whatever parameters you want to set up. also if you want to program npc behavior I'd look into tutorials about how basic battle engines work or even read some open source stuff, like maybe some dungeon crawler source code.. though that's probably more primitive

Error Missing Closing Square Bracket

Pagan Slim

Thanks for the advice.  I was reading articles on AI in game software but a lot of it was over my head.  I tried looking at how the ghosts in pacman worked.  That seemed simpler.  You're right.  I do need to study code more.  Up 'till now all of my programs have been simplistic.  I want to write something more complex and build on it.  I will take your advice.  Thanks.

Pagan Slim

#11
I have , somehow, managed to randomize the NPCs in the gangfight but cannot for the life of me do it the way I want.  It works but the npcs are too orderly yet.  Who attacks is random but the next attacker does not show up until the former npc is finished.  Still it works.  Will post again when I improve it.  Got to do a little at a time.


PlayBASIC Code: [Select]
; PROJECT : Random Gang_Fight
; AUTHOR : Pagan Slim
; CREATED : 6/16/2010
; EDITED : 6/22/2010
; ---------------------------------------------------------------------
; ---------------------------------------------------------------------

LoadFont "Arial",1,16,0

SetFPS 30

Cls RGB(95,0,0)
Print "You are walking the streets of a well known but feared neighborhood."
Print "You usually avoid this part of town but today is different."
Print "You feel braver today. Braver and perhaps a bit more foolish."
Print "You made your boast to your friends and they dared you to come here."
Print "You feel a chill. Maybe a shudder. You hear a garbage pail being knocked over."
Print "The sound jolts you to a higher awareness of your reality. "

Print " "
Print "You see someone ahead of you. It is dark and foggy tonight."
Print "Are you ready to throw down? Well. Are You?"
Print " "
Print "Press the ENTER key to get it on."
Print " "
Sync
WaitKey

Cls


Dim Guys$(6) ; Array Indexes are zero inclusive. That means 0,1,2, etc .. up to the Number of Elements are valid Indexes

For Guys_Name = 0 To 6 ; 0 will be the 'The Mysterious Glitch'
Guys$(Guys_Name) = ReadData$()
Next Guys_Name

;combat routine

;Initialize AND Randomize
;create stats

;Number of NPC's that you will fight.
NUM_GUYS = Rnd (5)+ 1


NPC_HITPOINTS = RndRange (2,10)

HITPOINTS = RndRange (7,18);ADJUSTED TO EQUAL THE ODDS.

Print "YOUR HIT POINTS " + Str$(HITPOINTS)
Print " "
Print "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
Print " "
Sync
Wait 3000

;Game Loop
Do
;Initiative:
;who's first
COINTOSS=Rnd (120)


Print "Number of NPCs " + Str$(NUM_GUYS)
Print " "
Sync

If COINTOSS>60
Print "The initiative is yours."
Print " "
Gosub MEFIRST:
Else
Print "NPC(s) has initiative."
Print " "
Gosub NPCFIRST:
EndIf


Print "Press a key to go on."
Print " "
Sync
WaitKey
Cls ;clear screen for next round of combat.
Loop


;npcfirst
NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
randomNPC = RndRange(1,6);randomNPC draws a random npc from the data.

For N = 1 To NUM_GUYS
Print Guys$(randomNPC)
Print " "

ATTACK = RndRange (1,6)+1
Print " "
Sync
;damage (HEALTH-ATTACK)

HITPOINTS=HITPOINTS-ATTACK

;adjust health
;report results
Print "YOUR HIT POINTS " + Str$(HITPOINTS)
Print " "
Sync
Wait 2000
;if_dead
If HITPOINTS<1
Print "You're DEAD!"
Print " "
Sync
Wait 3000
Gosub THE_END
EndIf

Next

Return

;mefirst:
MEFIRST:
;attack (is it successful)
NPC_ATTACK=RndRange (1,8)
;damage (HEALTH-ATTACK)
NPC_HITPOINTS=NPC_HITPOINTS-NPC_ATTACK
;adjust health
;report results
Print "NPC HIT POINTS " + Str$(NPC_HITPOINTS)
Print " "
Sync
Wait 2000
;if_NPC_dead - GET RID OF HIM...
If NPC_HITPOINTS < 1
NUM_GUYS = NUM_GUYS - 1
Print "ONE NPC DEAD!"
Print " "
Sync
Wait 3000
EndIf

;When last npc is dead game over...
If NUM_GUYS < 1
Print "You win."
Gosub THE_END
Login required to view complete source code




Pagan Slim

Strange, but when compiled this version doesn't run on windows 7 any longer.  All I changed was the randomNPC thing.

Pagan Slim

O.K.  I'm an idiot.  It was already random.  I just screwed it up.  I'll crawl back into my cave now.  ;p

Big C.

hey slim,

First:
at me... your code runs very well under win7 :)

Second:
If I understand you right then you try to randomize the attacking NPC

I will give you a hint:

Quote;Number of NPC's that you will fight.
NUM_GUYS = Rnd (5)+ 1

As this line says here you randomize the guys that will attack the Player. The result will hold in the var NUM_GUYS.

Quote;N is which of the guys who attack.
randomNPC = RndRange(1,6);randomNPC draws a random npc from the data.

Here you determine from the available guys exactly one

QuoteFor N = 1 To NUM_GUYS

With this line you start a For/Next Loop which will run from 1 to NUM_GUYS. Remember the NUM_GUYS holds the Number of Guys which will attack the Player! For example: If the value of NUM_GUYS = 4 (= 4 Guys should attack the player) the for/next loop will go through four times. But remember: you define exactly one guy with the line above.

I think you want to do this (?)

NPCFIRST:
;attack (is it successful)
;N is which of the guys who attack.
;randomNPC = RndRange(1,6);randomNPC draws a random npc from the data.

For N = 1 To NUM_GUYS
   randomNPC = RndRange(1,6); <----- put this line here to randomize the attacking guy from the group (remember NUM_GUYS)
   Print Guys$(randomNPC)


attached a hardcopy to see what the game will output

Big C.

P.S.: use the "insert Code" icon from the editor to post your code  ;)