Hi people of the codea world, I was wondering if you could share A code that makes A sprite shoot one bullet when the screen is tapped one time. I am new to video game programming, sorry.
Have a look at the examples that come with Codea.
However what you need to do is create a function called touched and then check the state of the touch parameter that’s passed and then when the state = BEGAN fire your bullet.
-- Codea calls this function for each and every touch event function touched(t) if t.state == BEGAN then print("Bang!") -- add your fire bullet code here. end end
Also check out the touch overview in the built in documentation (http://twolivesleft.com/Codea/Reference/Touch.html)
@The_Waffle_Man Here’s a very simple example.
displayMode(FULLSCREEN) function setup() dx=0 dy=0 x=WIDTH/2 y=HEIGHT/2 end function draw() background(40, 40, 50) sprite("Tyrian Remastered:Eye Small",x,y) sprite("Tyrian Remastered:Eye Mecha",WIDTH/2,HEIGHT/2) x=x+dx y=y+dy end function touched(t) if t.state==BEGAN then x=WIDTH/2 y=HEIGHT/2 dx=1 dy=2 end end
Thank you guys for the feedback! I will try to build on these codes.
In which direction would you like the bullet to be firing? If you tell me what kind of game you are making I can probably help
I would like for the bullet to shoot straight up. Basically the game is a vertical slider,where the ship freely slides around the screen When you tilt the device(the ship always faces and will shoot up, like in the super old space-like game " Galaga"). You tap the screen once to shoot at randomy generated downward moving sprites such as astroids or other ships to earn points. The game doesn’t end. It’s all about being your highest score. Like that terribly addicting game flappy birds, lol.
And please DO NOT steal my idea. I will be more than happy to share the code that I come up with it (and with the help of my fellow coders). But please don’t think you can just copy, paste and claim it as your own. That’s not cool. I don’t mean to sound defensive, But… Anyways
Thank you people who have helped me out with this whole thing. I will not forget to mention you in the “Credits” section of the game.
@The_Waffle_Man - I’m afraid there are already a gazillion games like that, so you can’t claim copyright, but generally, you don’t need to worry about forum members stealing stuff.
And if you are new to game programming, your code won’t be worth stealing for a while anyway, because it takes time to build up your skills (not trying to be nasty, but it’s true).
Plus I think you’ll find that game has already been created in Codea (in the examples provided) - it’d would be worth your while duplicating the Bit invader example and throughly understanding that first, then try and modify it to use the accelerometer.
Start small and make baby steps - you’ll learn a LOT more that way.
Also @Ignatz just posted an excellent link on another page, pointing to some simple examples that would also help you to learn a bit more about Codea and games programming.
@The_Waffle_Man Don’t worry about your game being similar to another game, basically all games are similar in one way or another. Write what you want, learn from it, and have fun with it because that’s what it’s all about. If someone steals your idea then that means you did a good job. Just look at all of the similar games in the App store. I’m sure you’ll find similar programs here that you can look at if you get stuck. Also, you’ll get a lot of help from us if you need it.