I've seen this problem sometimes cropping up! One of the reasons this problem can occur is when your http_proxy variable is not set properly! The $http_proxy variable in your terminal overrides the http::proxy variable in /etc/apt/conf file and the connection is not established if the http_proxy variable in the terminal is set to [proxy]:[port] instead of http://[proxy]:[port]. To check this out do the following:
Type: echo $http_proxy in the terminal
If it is something like this: 10.1.1.30:8080, then type: http_proxy="http://10.1.1.30:8080" . (we're just adding the 'http://' before the content of the variable)
If the problem was because of the overriding variables, it'd be solved by now .. try typing sudo apt-get update and see if it works.
public function isDead(){ timeline.pause(); var isDeadTimeline = Timeline { repeatCount: 1 keyFrames : [ at (0s){rotation => 0}, at (0.2s){rotation => 180;}, KeyFrame { time: 0.6s action: function(){ Main.score+=15; rotation = 0; timeline.playFromStart(); } } ] }; isDeadTimeline.play(); }
public override function create(): Node { timeline.play(); return Group { content: bind [image] }; } }
Understanding the code:
We make an ImageView object for the monster and bind the x and y coordinates to variables to allow movement. Also, the 'rotation' transformation is added which will be used to animate the monster when it dies ( it turns upside down when the isDead() function is called! :) ).
Next, we define the timeline for making the monster move to and fro. The to and fro motion is enabled by the "autoReverse: True" expression.
var timeline = Timeline { rate: bind animationRate; repeatCount: Timeline.INDEFINITE autoReverse: true keyFrames : [ at (0s) {monsterX => 0;}, at (4s) {monsterX => 440;} ] }
After this, we write the isDead function . This function pauses the timeline we wrote above and rotates the monster by 180 degrees and then makes the timeline play from start. It also increases you score by 15 points.
public function isDead(){ timeline.pause(); var isDeadTimeline = Timeline { repeatCount: 1 keyFrames : [ at (0s){rotation => 0}, at (0.2s){rotation => 180;}, KeyFrame { time: 0.6s action: function(){ Main.score+=15; rotation = 0; timeline.playFromStart(); } } ] }; isDeadTimeline.play(); }
This was most of what was done in this class. You would have noticed that we haven't used the attackTimeline and the attack() function. I was writing them to enable the monster attack the player also, but i haven't finished that part. So, we'll skip them for the while. Now we jump to the important part: Collision Detection. Our task is gravely simplified by the intersects() function of the Node class. It returns true when your node intersects the mentioned rectangle. Read the API for details. Here are the snippets from the prevous class, tanks.fx:
public function colissionDetect(){ if(monster.intersects(bulletX,bulletY,10,15)){ monster.isDead(); }
}
We've defined our rectangle with respect to the coordinates of the bullet using the bulletX and bulletY variables. Whenever the monster intersects this bullet, the monster.isDead() function is triggered. Note that we are polling to verify the intersection every 0.1 second by playing the colissionTimeline variable:
var colissionTimeline = Timeline { repeatCount: Timeline.INDEFINITE keyFrames : [ KeyFrame { time : 0.1s action: function(){colissionDetect()} } ] }
This timeline is played throughout the duration of the game.
So, that's all, we're done with most of the part of the game. The scoring part is simple, you can figure it out very easily in the Main.fx file:
/* * Main.fx * * Created on Jun 21, 2009, 9:17:55 AM */
/** * @author Sagar Jauhari */ public var score = 0; public var lives = 3;
public var screenWidth = 500; public var screenHeight = 500;
var scoreText = Text { font : Font { size: 20 } x: screenWidth-40, y: screenHeight-30 content: bind {java.lang.String.valueOf(score)} };
var mdeia = MediaPlayer { media : Media { source: "" } }
public function run(){ Stage { title: "Space Invaders FX by Sagar Jauhari" width: 500 height: 500 scene: Scene { content: bind [tank{},scoreText] } } }
We defined a variable ScoreText and bound its value to the score variable which is changed everytime you hit the monster.
More to be done:
The monster has to be coded to attact the tank also! Right now the game is too easy!
Background music can be played and specific sounds can be added to the fire() and isDead() functions.
The sourcecode of the game can be downloaded from here.
Ohk, so I wrote this simple game in JavaFX, named it Space Invaders FX ..
The entire source code for the game can be downloaded from here.
The source code has three files, tank.fx, monster.fx and Main.fx. In this post we will talk about tank.fx. This class controls the movements, shooting and everything else to do with the tank. Here it is:
/* * tank.fx * * Created on Jun 21, 2009, 9:19:12 AM */
Now we come to the more interesting part: the shooting! :). To represent a bullet, I made a polygon. The idea is to traverse this polygon from bottom to top by binding its y coordinate to a variable and linearly varying that variable with time using the Timeline class. Initially the bullet is invisible, then, while shooting it becomes visible and then again it becomes invisible. This gives the impression that multiple bullets are being shot contrary to the fact that actually, it is the same bullet again and again! Also, there is a constraint that at any point of time, only one bullet is in the scene. This is managed by the 'fireAgain' flag. See here:
Finally, there's this function called fire() which fires the bullet.
public function fire(){ if(fireAgain){ timeline.playFromStart(); } }
So this was most of what was done with the tank. The collision detection with the 'monster' and some other snippets not explained here will be explained in the next post when we discuss the 'monsters.fx' class.
I found a way to install the adobe flash plugin on my ubuntu box. Till now I was trying to install the .deb package from the adobe site which is named as (ubuntu 8.04+ ) and it alway got installed but never worked! So here's a way:
It took some time but I managed to configure the Idea Netsetter wireless USB plug and surf device on my Ubuntu laptop. It wasn't as tough as I had thought. Here's the procedure:
Step 1. Write the following in your /etc/wvdial.conf file, save and close:
Step 2. Add the following lines to your /etc/network/interfaces file:
iface ppp0 inet ppp provider ppp0 auto ppp0
It would look something like this (only the encircled part is important):
Step 3. Restart the network services by the following command:
$ sudo /etc/init.d/networking restart
Step 4. Go to System-> Administration -> Network. You'd see something like this: Uncheck the 'Wired' connection (disable it). Now go to the properties of Point to point connection do the following settings in the respective tabs:
[GENERAL]:
Check on 'Enable this connection'
Connection type: PPPoE
Username: idea
password: idea
[MODEM]:
Ethernet interface: eth0
[OPTIONS]
Check 'Set modem as default'
Check 'Use the internet service provider nameservers'
Check 'Retry if connection breaks'
Step 5. Again restart the network connection (step 3).
Step 6. Plug in your Idea Netsetter in one of the USB ports and run the following command in your terminal: $ sudo wvdial
That's it .. if everything's fine wvdial would show your new Local and Remote IP address for the idea connection.