Jump to content

Photo

pfpixel randomized and collision


6 replies to this topic

#1 KevKelley ONLINE  

KevKelley

    Star Raider

  • 92 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Fri Dec 28, 2018 3:42 PM

I was playing around with my game and considered having an added element for difficulty in which should a shopping cart collide with a car it would leave a pfpixel.First I was having difficulty trying to get the pixel to appear at the moment of collision with the car but then I considered having the pixels appear on the far left of the screen.

The two things I would like to accomplish was to have the pixels randomly generate in a column on the far left after a cart/car collision. I figured out how to get one to spawn (and only one) but not randomly. I would like to have multiple pfpixel should the cart collide multiple times, up to maybe a few at max.

The other issue I had was how to get the player to collide with the pfpixel to make it disappear before a car were to collide with it.

I had checked RTs page and the forums but couldn't quite find something applicable to my scenario.

#2 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,815 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Fri Dec 28, 2018 9:46 PM

Was the Seaweed Assault code useful at all?



#3 KevKelley ONLINE  

KevKelley

    Star Raider

  • Topic Starter
  • 92 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Sat Dec 29, 2018 2:37 AM

I had not seen that one. I'll look through it in the morning and hope to understand. Just when I thought researched everything.

Thanks!

#4 Impaler_26 OFFLINE  

Impaler_26

    Cookie Meister

  • 2,673 posts
  • Braindead
  • Location:Hueco Mundo

Posted Sat Dec 29, 2018 4:19 AM

Have a look at the Zombie Chase code in the bB "samples" folder.



#5 bogax OFFLINE  

bogax

    Dragonstomper

  • 787 posts

Posted Sat Dec 29, 2018 9:12 PM

I was playing around with my game and considered having an added element for difficulty in which should a shopping cart collide with a car it would leave a pfpixel.First I was having difficulty trying to get the pixel to appear at the moment of collision with the car but then I considered having the pixels appear on the far left of the screen.

The two things I would like to accomplish was to have the pixels randomly generate in a column on the far left after a cart/car collision. I figured out how to get one to spawn (and only one) but not randomly. I would like to have multiple pfpixel should the cart collide multiple times, up to maybe a few at max.
 

 

you don't really give enough informations to know exactly what you want

 

what's you're max?

 

how many pixels in the column?

 

what kernel?

 

are the pf pixels going to be permanent or will they be removed too?

 

do they need to be in some sort of sequence ie if you choose a pixel at random and it's already on then what?

 

 

probably the simplest thing would be to choose a pixel at random and see if it's on

if it is choose another until you find one that's not

that could take a lot of time if there's a bunch of them already on

 

 

here I've made a custom routine to count through a column of 11 pixels in a psuedo random fashion

it's kind of messy and takes a fair amount of code about, 100 bytes

 

press fire to fill in a pixel, when all the pixels in the column are filled it clears the column and reseeds with rand

 

 
  dim seed = s
 
  COLUPF = $56
 
 
 
loop
 
  if !joy0fire || !f{0} then skip
  if !c then seed = rand : c = 11 : pfvline 31 0 10 off
  c = c - 1 : gosub myrnd
  pfpixel 31 temp1 on
skip
  if joy0fire then f{0} = 0 else f{0} = 1 
 
  var40 = $55 : var36 = seed/2 & $0F : var32 = c
 
 
  drawscreen
 
  goto loop
 
 
  ; bits 5, 6 are a parameter used to select an increment for a pseudo random counter  
  ; the counter is used to select random number from the scatter table
  ; so it looks less like a counter and more like something random
  ; the scatter table is 2 tables of 22 random numbers interleaved
  ; one table for the odd counter numbers one for even counter numbers
  ; while counting we wont touch bit 0 of the counter so it will count
  ; through odd numbers or even numbers depending on how bit 0 is initalized   
  ; if bit 7 of seed is set the counter is complemented for the scatter table look up
  ; 4 increments * 2 tables * 2 for complementing gives 16 possible sequences
 
myrnd
  temp1 = (seed/32) & $03                  ; get the current increment number
  temp2 = (seed & $1F) + rinc[temp1]       ; increment the counter
  if temp2 > 21 then temp2 = temp2 - 22    ; mod 22
  if seed{7} then temp1 = 21 - temp1       ; conditionally complement the pointer 
  temp1 = scatter[temp2]                   ; randomize it
  seed = ((seed ^ temp2) & $E0) ^ temp2    ; put the new counter value back into bits 0..4 of seed
  return
 
  data scatter
  $07, $06 
  $08, $09 
  $03, $0A 
  $00, $01 
  $05, $02 
  $0A, $00 
  $04, $05 
  $09, $08
  $06, $03 
  $02, $04 
  $01, $07 
end
 
 
  data rinc
  $06, $0A, $0E, $12
end
 

Attached Files



#6 KevKelley ONLINE  

KevKelley

    Star Raider

  • Topic Starter
  • 92 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Sun Dec 30, 2018 2:07 AM


 
you don't really give enough informations to know exactly what you want
 
what's you're max?
 
how many pixels in the column?
 
what kernel?
 
are the pf pixels going to be permanent or will they be removed too?
 
do they need to be in some sort of sequence ie if you choose a pixel at random and it's already on then what?
 
 


I was using the standard kernel. I think the max number of pixels would be around 8 and in no particular order and would remain until player0 hits them.

I will check out your sample program. I'm still kind of learning the in and outs of vbB and my game is kind of my tool to become acquainted.

#7 bogax OFFLINE  

bogax

    Dragonstomper

  • 787 posts

Posted Sun Dec 30, 2018 8:46 AM

here's another one that searches in the column for a pixel to set

 

 
  dim pxpntr = temp1
  dim cnt = temp2
 
  COLUPF = $56
 
 
 
loop
 
  if !joy0fire || !f{0} then skip
  if !c then c = 11 : pfvline 31 0 10 off
  c = c - 1 : gosub setrndpix
skip
  if joy0fire then f{0} = 0 else f{0} = 1 
 
  var40 = $55 : var32 = c
 
 
  drawscreen
 
  goto loop
 
 
  ;  the screen in the standard kernel is an array of 48 bytes
  ;  the bytes are named var0..var47
  ;  there are 4 bytes to a row ie every forth byte for a column
  ;  some of the bytes are displayed in reverse 
  ;  in this case the last pfpixel column corresponds to 
  ;  bit 7 of the 4th byte which is byte 3 relative to var0
  ;  rand returns a number 0..255 we need a random number 0..10
  ;  to specify the row, and the column is every 4th byte
  ;  in some other languages rand would return a number 0 to .99999
  ;  and we'd multiply by 11 to get a number in the range 0..10
  ;  we can think of 255 as .11111111 * 256 (.11111111 being the binary equivalent of .9999)
  ;  so we can divide rand by 256 and multiply by 11 then multiply by 4 (every 4th byte)
  ;  or just divide by 64.  we only have 8 bits and fractional parts are truncated
  ;  so here the division is differed as long as possible to keep the intermediates
  ;  as large as possible so as not to lose accuracy in truncated fractional bits
  ;  then OR with 3 'cause we need the 4th byte which is byte 3
  ;  could have referenced to var3 and set bits 0,1 to 0   
  ;  the pfpixel is checked by ANDing the appropriate bit and testing for 0
  ;  (you can't use a variable with the bits{x} notation)
  ;  if the bit is set the pixel pointer is incremented by three rows (to make it appear
  ;  more random than just counting through the column of pixels)and wrapped
  ;  in the column if neccesary  could use a simple counter and a scatter table
  ;  which would be faster and probably use roughly the same amount of code
  ;  cnt keeps track of how many pixels we've searched through so we don't search
  ;  forever for a pixel to set if all the pixels are already set set
 
setrndpix
  pxpntr = rand/2 : pxpntr = (((pxpntr/2 + pxpntr)/4 + pxpntr)/4) | $03 : var36 = pxpntr   ; rand * 11/64 and set bits 0,1
  cnt = 11
pixloop  
  cnt = cnt - 1
  pxpntr = pxpntr + 12 : if pxpntr > 43 then pxpntr = pxpntr - 44                          ; increment the pixel pointer by three rows and wrapp if necessary
  if !var0[pxpntr] & $80 then var0[pxpntr] = var0[pxpntr] | $80 : return                   ; if the pixel is clear set it and return
  if cnt then pixloop                                                                      ; if that wasn't 11th try (try 0, we're counting down) try again
  return
 
 
 

Attached Files






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users