Results 1 to 9 of 9

Thread: new to lua: collision checking

  
  1. #1
    soulkiller is offline -Hacks Smarty
    Join Date
    Jan 2006
    Location
    pffff I\'m not telling you
    Posts
    197
    Rep Power
    14

    Default

    I'm pretty new to programing (maybe half a year) and a week old to lua and i was starting to make my own script to test my skills for prog for the psp in lua
    this is what i got so far
    Code:
    --############ACTIVATE USB MODE#############
    System.usbDiskModeActivate()
    --#######COLORS################
    blue = Color.new(0 , 0, 255)
    orange = Color.new(255, 102, 0)
    black = Color.new(0 , 0 , 0)
    green = Color.new(0 , 255, 0)
    red = Color.new(255 , 0, 0)
    white = Color.new(255 , 255, 255)
    --#########LOADING IMAGES##########
    grass = Image.load("img/grass.png")
    flower = Image.load("img/flower.png")
    player = Image.load("img/player.png")
    enemy = Image.load("img/enemy.png")
    heart_p = Image.load("img/heart_p.png")
    heart_e = Image.load("img/heart_e.png")
    --########VARIBLES############
    enemy_stats = {3,300,150}
    player_stats = {3,100,50}
    --###########FUNCTIONS#############
    function swidth(a)
    	width = 480 - a
    	return width
    end
    function sheight(a)
    	height = 480 - a
    	return height
    end
    --########MAIN PROGRAM############
    while true do
    	pad = Controls.read()
    	screen:clear()
    	--########DISPLAY GRASS TILE#########
    	for a = 0,14 do
    		for b = 0,8 do
    			screen:blit(32 * a,32 * b,grass,false)
    		end
    	end
    	--#########CONTROLS################
    	if pad:up() and player_stats[3] > 0 then
    		player_stats[3] = player_stats[3] - 2
    	end
    	if pad:down() and player_stats[3] < 272 - 32 then
    		player_stats[3] = player_stats[3] + 2
    	end
    	if pad:left() and player_stats[2] > 0 then
    		player_stats[2] = player_stats[2] - 2
    	end
    	if pad:right() and player_stats[2] < swidth(32) then
    		player_stats[2] = player_stats[2] + 2
    	end
    	--##########HEALTH################
    	if player_stats[1] == 3 then
    		screen:blit(0,0,heart_p,true)
    		screen:blit(32,0,heart_p,true)
    		screen:blit(64,0,heart_p,true)
    	end
    	if player_stats[1] == 2 then
    		screen:blit(0,0,heart_p,true)
    		screen:blit(32,0,heart_p,true)
    	end
    	if player_stats[1] == 1 then
    		screen:blit(0,0,heart_p,true)
    	end
    	if player_stats[0] == 0 then
    		screen:print(200,136,"Player is dead",red)
    		screen.waitVblankStart(600)
    		break
    	end
    	if enemy_stats[1] == 3 then
    		screen:blit(swidth(32),0,heart_e,true)
    		screen:blit(480 - 64,0,heart_e,true)
    		screen:blit(480 - 96,0,heart_e,true)
    	end
    	if enemy_stats[1] == 2 then
    		screen:blit(swidth(32),0,heart_e,true)
    		screen:blit(480 - 64,0,heart_e,true)
    	end
    	if enemy_stats[1] == 1 then
    		screen:blit(480 - 32,0,heart_e,true)
    	end
    	if enemy_stats[0] == 0 then
    		screen:print(200,136,"Enemy 1 is dead",blue)
    		screen.waitVblankStart(600)
    		break
    	end
    	--###########PRINT MAIN IMAGES##############
    	screen:blit(300,128,flower,false)
    	screen:blit(101,210,flower,false)
    	screen:blit(player_stats[2],player_stats[3],player,false)
    	screen:blit(enemy_stats[2],enemy_stats[3],enemy,false)
    	screen.flip()
    end
    I know somethigns are weird like the functions but remember I wanted to use all elements that i have learned. anyways I wanted to know how would I
    1.check for collisions
    2.picture animation
    3.make sure the the cross button wasn't pressed before (like so you can't hold down cross and it keeps doin its loop)
    4.my pictures have their white backround with them and transparencys on?
    any and all help will be greatly appreaticated

    GOOGLE IS YOUR FREIND, USE IT. IF GOOGLE FAILS THEN REFER TO THIS LINK MQ:BtG Programmer

  2. #2
    SHiZNuT is offline -Hacks Neophyte
    Join Date
    Jan 2006
    Location
    Santa Clause, To: You!
    Posts
    51
    Rep Power
    14

    Default

    I will try to answer some of these, but I am going to speak in pseudo-code, because I haven't really tried LUA

    1. To check for collisions, you have to decide which sides are going to be checked for all sides, something like this should work

    Code:
    if player_left <= enemy_right
        --collision on player's left side
    end
    
    if player_top <= enemy_bottom
        --collision on player's top side
    end
    Of course, it would be different depending on which way the screen's coordinates go, and which way the player is facing. Collision detection is basically checking to see if the X values (or Y values) of two objects overlap.
    ==========
    2. Picture animation is simply changing a graphic quickly. So for example a persons hand waving you would have a picture of the hand raised up high, then quickly switch to a picture of the hand in the middle, then a picture of the hand down low, then back up and repeat. So for an animation, you have to have several of the same picture (but with things changed slightly, like the hand), and just cycle through them
    ==========
    3. The easiest way to prevent button repetition is to have some code like this
    Code:
    newButton = Get input from PSP()
    if newButton == CROSS
        if oldButton != cross (the opposite of ==)
            FIRE THE GUNS!!()
            oldButton = newButton
        end
    end
    If you loop through that, then if the user is still holding down the cross it won't repeat the action
    ============
    4. I believe the lua blit: function has a transparency setting (alpha). It should be set to true, but I think it's automatically true. Make sure that your actual graphics have a transparent background. You may need a program such as Jasc PSP(Paint Shop Pro, not related to Playstation Portable!) or Adobe Photoshop. You can get free trials of both.


    Well I hope that answered something :P
    \"I like my women like I like my Reese\'s Cups: Peanut Butter AND chocolate\"

  3. #3
    illfoundedmind is offline -Hacks Enthusiast
    Join Date
    Nov 2005
    Location
    WTF~~~~~~~~~~> Rank: %NULL
    Posts
    389
    Rep Power
    14

    Default

    Easiest way to do collisions is with a matrix
    july 19

  4. #4
    SHiZNuT is offline -Hacks Neophyte
    Join Date
    Jan 2006
    Location
    Santa Clause, To: You!
    Posts
    51
    Rep Power
    14

    Default

    Quote Originally Posted by illfoundedmind
    Easiest way to do collisions is with a matrix
    do tell

    aka: whaddayamean?
    \"I like my women like I like my Reese\'s Cups: Peanut Butter AND chocolate\"

  5. #5
    illfoundedmind is offline -Hacks Enthusiast
    Join Date
    Nov 2005
    Location
    WTF~~~~~~~~~~> Rank: %NULL
    Posts
    389
    Rep Power
    14

    Default

    A matrix i.e

    A B C D E F G H I J K L M N O P Q R
    |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|1
    |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|2
    |_|_|_|_|_|_|_|_|_|_|_|X|_|_|_|_|_|3
    |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|4
    |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|5
    |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|6
    |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|7
    |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|8
    |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|9

    Check value
    july 19

  6. #6
    soulkiller is offline -Hacks Smarty
    Join Date
    Jan 2006
    Location
    pffff I\'m not telling you
    Posts
    197
    Rep Power
    14

    Default

    wouldn't the matrix one get extremly long and complicated and would have so many loops that it would slow down the program? or is their some briliantly simple 5 line solution
    GOOGLE IS YOUR FREIND, USE IT. IF GOOGLE FAILS THEN REFER TO THIS LINK MQ:BtG Programmer

  7. #7
    illfoundedmind is offline -Hacks Enthusiast
    Join Date
    Nov 2005
    Location
    WTF~~~~~~~~~~> Rank: %NULL
    Posts
    389
    Rep Power
    14

    Default

    Quote Originally Posted by soulkiller
    or is their some briliantly simple 5 line solution
    Yes that would be the case, about 14 lines.
    july 19

  8. #8
    soulkiller is offline -Hacks Smarty
    Join Date
    Jan 2006
    Location
    pffff I\'m not telling you
    Posts
    197
    Rep Power
    14

    Default

    Quote Originally Posted by illfoundedmind
    Quote Originally Posted by soulkiller
    or is their some briliantly simple 5 line solution
    Yes that would be the case, about 14 lines.
    Could you please give an example of this 14 line matrix collsion checking or give us some idea about the collsion checking thats in that rpg game your making because I remeber you talking about redoing the collsion checking for your rpg game on the lua player fourms over at ps2dev
    GOOGLE IS YOUR FREIND, USE IT. IF GOOGLE FAILS THEN REFER TO THIS LINK MQ:BtG Programmer

  9. #9
    illfoundedmind is offline -Hacks Enthusiast
    Join Date
    Nov 2005
    Location
    WTF~~~~~~~~~~> Rank: %NULL
    Posts
    389
    Rep Power
    14

    Default

    Did I? Well for the RPG I'm helping dev. it uses an Isometric tile configuration which... well won't help you (it is the only Isometric homebrewed RPG).

    But shines tout. should:
    http://ps2dev.org/psp/Tools (check out the last example)
    july 19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •