retrobrad
A little car game im making...

 
Post new topic   Reply to topic    retrobrad Forum Index -> Work in progress...
View previous topic :: View next topic  
Author Message
retrobrad
Administrator
Administrator


Joined: 08 Jun 2007
Posts: 1039
Location: NSW, Australia

PostPosted: Mon Dec 24, 2007 7:06 am    Post subject: A little car game im making... Reply with quote

Hi guys, ive been programming some microcontrollers lately, just doing some experimenting and ive nearly finished my first simple little game!

it just uses an 8x8 led matrix and you are a little red dot (which is the car) the screen scrolls along and you need to avoid all the walls etc...

Its not quite finished yet, all i really need to add is a score counter (maybe it can count how far you can get before hitting anything) and the main thing that it needs is some collision detection.



heres a video of it i put on youtube.
http://www.youtube.com/watch?v=WcVt0YJibgM


Last edited by retrobrad on Mon Dec 24, 2007 11:18 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
retrobrad
Administrator
Administrator


Joined: 08 Jun 2007
Posts: 1039
Location: NSW, Australia

PostPosted: Mon Dec 24, 2007 11:01 am    Post subject: Reply with quote

HERES THE ASSEMBLY CODE LISTING:


; this is my first attempt at a led game!
; its a car game where you need to dodge all the
; walls etc...
;
; there is room for improvement with the code, but im still learning!!!
;
;
; by brad slattery....



LIST p=16F628 ;tell assembler what chip we are using
include "P16F628.inc" ;include the defaults for the chip
__config 0x3D18 ;sets the configuration settings (oscillator type etc.)

PC equ 0x02

cblock 0x20 ;start of general purpose registers
counta
countb
pc_display_data
b_data_loop
vram_1
vram_2
vram_3
vram_4
vram_5
vram_6
vram_7
vram_8
repeat_frame
car_data
vtemp_1
vtemp_2
vtemp_3
vtemp_4
vtemp_5
vtemp_6
vtemp_7
endc

org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)

bsf STATUS, RP0 ;select bank 1
movlw b'00000000' ;set PortB all outputs
movwf TRISB
movlw b'11110000' ;set PortA last four bits inputs
movwf TRISA ;and first four bits outputs.
bcf STATUS, RP0 ;select bank 0


setup
movlw h'00'
movwf pc_display_data ;sets the display data program counter to '0'
movwf vram_1 ;these eight lines clear the video ram
movwf vram_2 ;to make sure you dont get a screen
movwf vram_3 ;full of junk when you first turn on
movwf vram_4 ;the game. - try removing these eight
movwf vram_5 ;lines of code and you will see what i
movwf vram_6 ;mean!
movwf vram_7 ;
movwf vram_8 ;
movlw b'00001000' ;sets the start point of the
movwf car_data ;car, approx middle of screen.

begin
call display_frame ;calls display frame routine, returns when it is finished
call fill_video_ram ;calls fill video ram routinw, returns when it is finished
goto begin ;jump back to the heading 'begin' and do it all again!


display_frame ;the main routine to display the 'graphics'
movlw d'15' ;repeats every 'frame' 15 times (increase this number to
movwf repeat_frame ;slow the track speed down and vice versa...)
loop call car ;calls the car routine to determine where it is, and place it on screen
movlw h'00' ;this scrolls through PORTA, activating each column in sequence
movwf PORTA ;with the assistance of the 7442 1 of 10 decoder.
movf vram_1, 0 ;then each time a column is activated, it grabs a byte of data
movwf PORTB ;from vram and places it on the screen, in that activated column.
call delay1
call blank
movlw h'01'
movwf PORTA
movf vram_2, 0
movwf PORTB
call delay1
call blank
movlw h'02'
movwf PORTA
movf vram_3, 0
movwf PORTB
call delay1
call blank
movlw h'03'
movwf PORTA
movf vram_4, 0
movwf PORTB
call delay1
call blank
movlw h'04'
movwf PORTA
movf vram_5, 0
movwf PORTB
call delay1
call blank
movlw h'05'
movwf PORTA
movf vram_6, 0
movwf PORTB
call delay1
call blank
movlw h'06'
movwf PORTA
movf vram_7, 0
movwf PORTB
call delay1
call blank
movlw h'07'
movwf PORTA
movf vram_8, 0
movwf PORTB
call delay1
call blank
decfsz repeat_frame
goto loop
return


car ;routine to draw the car on the display
btfsc PORTA, 6 ;checks to see if the 'left' button has been pressed
call go_left ;if it has, call the shift left routine, if not then continue below
btfsc PORTA, 7 ;check to see if the 'right' button has been pressed
call go_right ;if it has, call the shift right routine, if not the continue below
call port_a_output ;calls port a output routine (to set porta bit-4 as an output)
movf car_data, 0 ;move data from car_data to w register
movwf PORTB ;output w to PORTB
call delay1 ;wait a little bit....
call port_a_input ;calls port a input routine (to set porta bit-4 as an input)
return

port_a_output
bsf STATUS, RP0 ;this needs to be here so you dont get red
movlw b'11101111' ;ghosting on the screen that you'd get if
movwf TRISA ;you left porta bit-4 as a constant output
bcf STATUS, RP0 ;
movlw b'00001000'
movwf PORTA
return


port_a_input
bsf STATUS, RP0 ;set porta bit-4 back to an input (high - Z state)
movlw b'11110000' ;so it doesnt interfere with our display data
movwf TRISA ;
bcf STATUS, RP0 ;
return

go_left ;shifts the car left
rlf car_data, 1 ;by shifting the data
call delay2 ;in car_data
return

go_right ;shifts the car right
rrf car_data, 1 ;by shifting the data
call delay2 ;in car_data
return


fill_video_ram ;this routine saves all video ram
movf vram_1, 0 ;to a temp location and then
movwf vtemp_1 ;shifts all data to the next
movf vram_2, 0 ;video ram location and also
movwf vtemp_2 ;loads in the next byte of data
movf vram_3, 0 ;to vram_1
movwf vtemp_3 ;
movf vram_4, 0 ;
movwf vtemp_4 ;
movf vram_5, 0 ;
movwf vtemp_5 ;
movf vram_6, 0 ;
movwf vtemp_6 ;
movf vram_7, 0 ;
movwf vtemp_7 ;
call display_data ;
movwf vram_1 ;
movf vtemp_1, 0 ;
movwf vram_2 ;
movf vtemp_2, 0 ;
movwf vram_3 ;
movf vtemp_3, 0 ;
movwf vram_4 ;
movf vtemp_4, 0 ;
movwf vram_5 ;
movf vtemp_5, 0 ;
movwf vram_6 ;
movf vtemp_6, 0 ;
movwf vram_7 ;
movf vtemp_7, 0 ;
movwf vram_8 ;
return


display_data ;this is all the track data
incf pc_display_data, 1 ;NOTE: there is enough pic program memory left to
movf pc_display_data, 0 ;store a track twice the size as this one...
addwf PC
nop
retlw b'10000001' ;start 8-bytes
retlw b'11000011'
retlw b'11100111'
retlw b'11001111'
retlw b'11001111'
retlw b'11000111'
retlw b'11100011'
retlw b'11110001' ;end 8-bytes
retlw b'11111001' ;start 8-bytes
retlw b'11110001'
retlw b'11100011'
retlw b'11000111'
retlw b'11001111'
retlw b'11000111'
retlw b'11100011'
retlw b'11110011' ;end 8-bytes
retlw b'11110011' ;start 8-bytes
retlw b'11100111'
retlw b'10000111'
retlw b'10000001'
retlw b'10010001'
retlw b'10111001'
retlw b'10111001'
retlw b'10111001' ;end 8-bytes
retlw b'10111001' ;start 8-bytes
retlw b'10111001'
retlw b'10010001'
retlw b'10000001'
retlw b'11000011'
retlw b'11100111'
retlw b'11101111'
retlw b'11101111' ;end 8-bytes
retlw b'11101111' ;start 8-bytes
retlw b'11100111'
retlw b'11110011'
retlw b'11111001'
retlw b'11111101'
retlw b'11111101'
retlw b'11111101'
retlw b'11111001' ;end 8-bytes
retlw b'11110001' ;start 8-bytes
retlw b'11100011'
retlw b'11000111'
retlw b'10001111'
retlw b'10011111'
retlw b'10011111'
retlw b'10001111'
retlw b'11000111' ;end 8-bytes
retlw b'11100111' ;start 8-bytes
retlw b'11100111'
retlw b'11100111'
retlw b'11100011'
retlw b'11000001'
retlw b'10010001'
retlw b'10111001'
retlw b'10010001' ;end 8-bytes
retlw b'10000001' ;start 8-bytes
retlw b'10000101'
retlw b'10001111'
retlw b'10000101'
retlw b'10100001'
retlw b'11110001'
retlw b'10100011'
retlw b'10000011' ;end 8-bytes
retlw b'10000011' ;start 8-bytes
retlw b'10011011'
retlw b'10011001'
retlw b'10000001'
retlw b'11000011'
retlw b'11000111'
retlw b'11001111'
retlw b'11000111' ;end 8-bytes
retlw b'11100011' ;start 8-bytes
retlw b'11100001'
retlw b'11000001'
retlw b'10000001'
retlw b'10101011'
retlw b'10101011'
retlw b'10101011'
retlw b'10101011' ;end 8-bytes
retlw b'10101011' ;start 8-bytes
retlw b'10001001'
retlw b'10001001'
retlw b'11011101'
retlw b'11011101'
retlw b'10011101'
retlw b'10011101'
retlw b'11001001' ;end 8-bytes
retlw b'11100001' ;start 8-bytes
retlw b'11100011'
retlw b'11110111'
retlw b'11100111'
retlw b'11000111'
retlw b'10000111'
retlw b'10001111'
retlw b'10001111' ;end 8-bytes
movlw h'01'
movwf pc_display_data
retlw b'10000001' ;this needs to be the same as the very first byte of data
return


blank
movlw b'00000000' ;fills port b with all 0's (all leds off)
movwf PORTB
return


delay1 movlw d'03' ;delay routine (a fast one)
movwf counta
movwf countb
d1 decfsz counta, f
goto d1
decfsz countb, f
goto d1
return

delay2 movlw d'20' ;delay routine (a slow one)
movwf counta
movwf countb
d2 decfsz counta, f
goto d2
decfsz countb, f
goto d2
return

end
Back to top
View user's profile Send private message Send e-mail
tomz/TIDE
Moderator
Moderator


Joined: 08 Jul 2007
Posts: 562
Location: nsw.Australia

PostPosted: Tue Dec 25, 2007 9:55 am    Post subject: A little car game Im making Reply with quote

Thats pretty neat mate! Excuse my following NOOB questions but this is an area I know very little about.

Firstly, I checked out UTUBE along with the other similar stuff posted there,and found yours to be the most interesting one there,the others although interesting only scrape the top of the barrel as they dont do a lot,you've managed to take it a step further with implementing it into a game.(of sorts,still early days) The code is all alien to me so my first request is a link to where I can find out more about programming micro controllers.

As for your scoretable within the game, cant you use either a timer or some sort of grid-counter, the last one would just keep track of every 8X8 grid thats completed? I have no idea how you would implement the timer coz like I mentioned earlier, I KNOW NOTHING

And finally just another question, can the 8X8 grid be increased in size to maybe a 32X32 ?? Do they actually make a Led that big?

Smile tomz Smile
Back to top
View user's profile Send private message Send e-mail
retrobrad
Administrator
Administrator


Joined: 08 Jun 2007
Posts: 1039
Location: NSW, Australia

PostPosted: Tue Dec 25, 2007 12:30 pm    Post subject: Re: A little car game Im making Reply with quote

Some very good questions there!

Just to let you know, i have nearly finished the game, it now has collision detection, so it knows when you have hit a wall, it then tells you your score (in binary however) and then resets back to the start.

check out the new video here:
http://www.youtube.com/watch?v=yGmVZTzqS7E


i need to work on getting a proper score i.e a nice decimal readout of how far you have travelled etc...

you can make a 32x32 display, you simply lots of these 8x8 displays together, they are great and cheap too! about $15 for 10 including postage on ebay!

as for the coding, i'll have to write up a few simple tutorials for you guys, you can pretty much make microcontrollers do whatever you want! from simply flashing an led, to making a complete home security system - just from the one little chip!

and your right about the counter and it is simple to implement: heres how i did it:

you think of a 'variable' and assign it a name, it could be anything at all, but because it's a counter lets call it 'count' - you then set the variable count to any number value you want, in this case we want it to start at '0' and then count up from there when we tell it to. So you would 'move' the value '0' to the variable 'count'.

Okay now everytime the screen moves across one space you just tell the variable count to count up by one, or increment by one.

okay, now that said im going to write up a little microcontroller tutorial in its own topic!
Back to top
View user's profile Send private message Send e-mail
Misha
intermediate
intermediate


Joined: 04 Jul 2007
Posts: 234
Location: North Wales

PostPosted: Wed Dec 26, 2007 11:04 pm    Post subject: Reply with quote

Hi Guys,

Nice work Brad,wish i had the technical skills to be able to do stuff like this.
I`m having enough problems with my Miggy and trying to get to the bottom of those,so i`m back on emulation again for a while Sad

Well i hope all you guys @Retrobrad had a great Christmas,yeah i know i`ve not been around for a while but work takes over my life Sad
Back to top
View user's profile Send private message
Rybags
beginner
beginner


Joined: 03 Oct 2007
Posts: 26

PostPosted: Mon Dec 31, 2007 6:43 pm    Post subject: Reply with quote

Nice. I'll check the vid later.

I'm thinking of getting into PICs.

I'd like to make a slave processor on cartridge for the Atari 800. I'd like it to have shared RAM onboard (probably 8-16 KB).

It would be really useful for doing stuff like generating tile-based character screens for scrolling games, but primarily I'd like to have something which can be a software sprite generator.

But, I've got a whole heap of stuff "in progress" ATM - like a Covox stereo sound upgrade, and will also probably start coding a full ASM game sometime soon.

Knocked up a demo last night too - I'll put it up later.
Back to top
View user's profile Send private message
retrobrad
Administrator
Administrator


Joined: 08 Jun 2007
Posts: 1039
Location: NSW, Australia

PostPosted: Thu Jan 03, 2008 10:35 pm    Post subject: Reply with quote

that sounds great, id be very keen to see the progress of your project - make sure you keep us informed!

im almost finished another little project at the moment - it's on of theose persistance of vision things, where you have a line of about 32 leds and then spin them really fast and it displays 'images' in mid air = )


ill post pics and info when im finished
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    retrobrad Forum Index -> Work in progress... All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
Style Distributed by Olate